diff options
author | TGIshib <justzeddicus@gmail.com> | 2016-08-03 13:29:50 +0300 |
---|---|---|
committer | TGIshib <justzeddicus@gmail.com> | 2016-08-03 13:29:50 +0300 |
commit | dc7f5bc0d80730ef45b368be90ac1208c1394707 (patch) | |
tree | 6ffc3c1f9e16e7354aed376b48e9486f410c5a0b /net | |
parent | 867dfc59576f23b93754f68eb81445d1f52eb9a6 (diff) | |
download | flatbuffers-dc7f5bc0d80730ef45b368be90ac1208c1394707.tar.gz flatbuffers-dc7f5bc0d80730ef45b368be90ac1208c1394707.tar.bz2 flatbuffers-dc7f5bc0d80730ef45b368be90ac1208c1394707.zip |
Remake
Diffstat (limited to 'net')
-rw-r--r-- | net/FlatBuffers/FlatBufferBuilder.cs | 12 | ||||
-rw-r--r-- | net/FlatBuffers/Table.cs | 18 |
2 files changed, 23 insertions, 7 deletions
diff --git a/net/FlatBuffers/FlatBufferBuilder.cs b/net/FlatBuffers/FlatBufferBuilder.cs index 590e6ac0..4d34ab97 100644 --- a/net/FlatBuffers/FlatBufferBuilder.cs +++ b/net/FlatBuffers/FlatBufferBuilder.cs @@ -295,6 +295,18 @@ namespace FlatBuffers PutInt(_vectorNumElems); return new VectorOffset(Offset); } + + /// <summary> + /// Creates a vector of tables. + /// </summary> + /// <param name="offsets">Offsets of the tables.</param> + public VectorOffset CreateVectorOfTables<T>(Offset<T>[] offsets) where T : class + { + NotNested(); + StartVector(sizeof(int), offsets.Length, sizeof(int)); + for (int i = offsets.Length - 1; i >= 0; i--) AddOffset(offsets[i].Value); + return EndVector(); + } /// @cond FLATBUFFERS_INTENRAL public void Nested(int obj) diff --git a/net/FlatBuffers/Table.cs b/net/FlatBuffers/Table.cs index bd5e3641..be180766 100644 --- a/net/FlatBuffers/Table.cs +++ b/net/FlatBuffers/Table.cs @@ -31,10 +31,12 @@ namespace FlatBuffers // Look up a field in the vtable, return an offset into the object, or 0 if the field is not // present. - protected int __offset(int vtableOffset) + protected int __offset(int vtableOffset) { return __offset(vtableOffset, bb_pos - bb.GetInt(bb_pos), bb, false); } + + protected static int __offset(int vtableOffset, int vtable, ByteBuffer _bb, bool invoked_static) { - int vtable = bb_pos - bb.GetInt(bb_pos); - return vtableOffset < bb.GetShort(vtable) ? (int)bb.GetShort(vtable + vtableOffset) : 0; + if (!invoked_static) return vtableOffset < _bb.GetShort(vtable) ? (int)_bb.GetShort(vtable + vtableOffset) : 0; + else return (int)_bb.GetShort(vtable + vtableOffset - _bb.GetInt(vtable)) + vtable; } // Retrieve the relative offset stored at "offset" @@ -44,12 +46,14 @@ namespace FlatBuffers } // Create a .NET String from UTF-8 data stored inside the flatbuffer. - protected string __string(int offset) + protected string __string(int offset) { return __string(offset, bb); } + + protected static string __string(int offset, ByteBuffer _bb) { - offset += bb.GetInt(offset); - var len = bb.GetInt(offset); + offset += _bb.GetInt(offset); + var len = _bb.GetInt(offset); var startPos = offset + sizeof(int); - return Encoding.UTF8.GetString(bb.Data, startPos , len); + return Encoding.UTF8.GetString(_bb.Data, startPos, len); } // Get the length of a vector whose offset is stored at "offset" in this object. |