blob: c92164ff82229989405a05facef6ac54b7c3f097 [file] [log] [blame]
Austin Schuhe89fa2d2019-08-14 20:24:23 -07001/*
2 * Copyright 2014 Google Inc. All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.google.flatbuffers;
18
19import java.nio.ByteBuffer;
20
21/// @cond FLATBUFFERS_INTERNAL
22
23/**
24 * All structs in the generated code derive from this class, and add their own accessors.
25 */
26public class Struct {
27 /** Used to hold the position of the `bb` buffer. */
28 protected int bb_pos;
29 /** The underlying ByteBuffer to hold the data of the Struct. */
30 protected ByteBuffer bb;
31
32 /**
33 * Re-init the internal state with an external buffer {@code ByteBuffer} and an offset within.
34 *
35 * This method exists primarily to allow recycling Table instances without risking memory leaks
36 * due to {@code ByteBuffer} references.
37 */
38 protected void __reset(int _i, ByteBuffer _bb) {
39 bb = _bb;
40 if (bb != null) {
41 bb_pos = _i;
42 } else {
43 bb_pos = 0;
44 }
45 }
46
47 /**
48 * Resets internal state with a null {@code ByteBuffer} and a zero position.
49 *
50 * This method exists primarily to allow recycling Struct instances without risking memory leaks
51 * due to {@code ByteBuffer} references. The instance will be unusable until it is assigned
52 * again to a {@code ByteBuffer}.
53 *
54 * @param struct the instance to reset to initial state
55 */
56 public void __reset() {
57 __reset(0, null);
58 }
59}
60
61/// @endcond