mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-02 20:15:34 +00:00
Add FLATBUFFERS_COMPATIBILITY string (#5381)
* Add FLATBUFFERS_COMPATIBILITY string - Add a new __reset method NET/JAVA which hides internal state * Resolve PR notes * Use operator new() to __init of Struct and Table * Restrict visibility of C# Table/Struct to internal level
This commit is contained in:
committed by
Wouter van Oortmerssen
parent
a80db8538c
commit
0d2cebccfe
@@ -29,6 +29,21 @@ public class Struct {
|
||||
/** The underlying ByteBuffer to hold the data of the Struct. */
|
||||
protected ByteBuffer bb;
|
||||
|
||||
/**
|
||||
* Re-init the internal state with an external buffer {@code ByteBuffer} and an offset within.
|
||||
*
|
||||
* This method exists primarily to allow recycling Table instances without risking memory leaks
|
||||
* due to {@code ByteBuffer} references.
|
||||
*/
|
||||
protected void __reset(int _i, ByteBuffer _bb) {
|
||||
bb = _bb;
|
||||
if (bb != null) {
|
||||
bb_pos = _i;
|
||||
} else {
|
||||
bb_pos = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets internal state with a null {@code ByteBuffer} and a zero position.
|
||||
*
|
||||
@@ -39,8 +54,7 @@ public class Struct {
|
||||
* @param struct the instance to reset to initial state
|
||||
*/
|
||||
public void __reset() {
|
||||
bb = null;
|
||||
bb_pos = 0;
|
||||
__reset(0, null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -38,9 +38,9 @@ public class Table {
|
||||
/** The underlying ByteBuffer to hold the data of the Table. */
|
||||
protected ByteBuffer bb;
|
||||
/** Used to hold the vtable position. */
|
||||
protected int vtable_start;
|
||||
private int vtable_start;
|
||||
/** Used to hold the vtable size. */
|
||||
protected int vtable_size;
|
||||
private int vtable_size;
|
||||
Utf8 utf8 = Utf8.getDefault();
|
||||
|
||||
/**
|
||||
@@ -263,6 +263,25 @@ public class Table {
|
||||
return len_1 - len_2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-init the internal state with an external buffer {@code ByteBuffer} and an offset within.
|
||||
*
|
||||
* This method exists primarily to allow recycling Table instances without risking memory leaks
|
||||
* due to {@code ByteBuffer} references.
|
||||
*/
|
||||
protected void __reset(int _i, ByteBuffer _bb) {
|
||||
bb = _bb;
|
||||
if (bb != null) {
|
||||
bb_pos = _i;
|
||||
vtable_start = bb_pos - bb.getInt(bb_pos);
|
||||
vtable_size = bb.getShort(vtable_start);
|
||||
} else {
|
||||
bb_pos = 0;
|
||||
vtable_start = 0;
|
||||
vtable_size = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the internal state with a null {@code ByteBuffer} and a zero position.
|
||||
*
|
||||
@@ -271,10 +290,7 @@ public class Table {
|
||||
* again to a {@code ByteBuffer}.
|
||||
*/
|
||||
public void __reset() {
|
||||
bb = null;
|
||||
bb_pos = 0;
|
||||
vtable_start = 0;
|
||||
vtable_size = 0;
|
||||
__reset(0, null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user