diff options
author | Wouter van Oortmerssen <wvo@google.com> | 2016-08-26 12:03:28 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-08-26 12:03:28 -0700 |
commit | 49ee30a20752b4876a30bfded80c69f5babc9cb2 (patch) | |
tree | dfba3f53649d60d1672e5d0d4aef1b94d7ad0240 /net | |
parent | 223ebebbeb868ab80c93dca9679fbdf69a07ba55 (diff) | |
parent | 7c69c5dc3d635e29e3442339caa8eb06b8b9775c (diff) | |
download | flatbuffers-49ee30a20752b4876a30bfded80c69f5babc9cb2.tar.gz flatbuffers-49ee30a20752b4876a30bfded80c69f5babc9cb2.tar.bz2 flatbuffers-49ee30a20752b4876a30bfded80c69f5babc9cb2.zip |
Merge pull request #3978 from TGIshib/key
Find by key on C# and Java (2)
Diffstat (limited to 'net')
-rw-r--r-- | net/FlatBuffers/FlatBufferBuilder.cs | 12 | ||||
-rw-r--r-- | net/FlatBuffers/Table.cs | 46 |
2 files changed, 57 insertions, 1 deletions
diff --git a/net/FlatBuffers/FlatBufferBuilder.cs b/net/FlatBuffers/FlatBufferBuilder.cs index 8c57abec..82365902 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..ca52d7d0 100644 --- a/net/FlatBuffers/Table.cs +++ b/net/FlatBuffers/Table.cs @@ -37,11 +37,22 @@ namespace FlatBuffers return vtableOffset < bb.GetShort(vtable) ? (int)bb.GetShort(vtable + vtableOffset) : 0; } + protected static int __offset(int vtableOffset, int offset, ByteBuffer bb) + { + int vtable = bb.Length - offset; + return (int)bb.GetShort(vtable + vtableOffset - bb.GetInt(vtable)) + vtable; + } + // Retrieve the relative offset stored at "offset" protected int __indirect(int offset) { return offset + bb.GetInt(offset); } + + protected static int __indirect(int offset, ByteBuffer bb) + { + return offset + bb.GetInt(offset); + } // Create a .NET String from UTF-8 data stored inside the flatbuffer. protected string __string(int offset) @@ -103,7 +114,40 @@ namespace FlatBuffers return true; } - + + // Compare strings in the ByteBuffer. + protected static int CompareStrings(int offset_1, int offset_2, ByteBuffer bb) + { + offset_1 += bb.GetInt(offset_1); + offset_2 += bb.GetInt(offset_2); + var len_1 = bb.GetInt(offset_1); + var len_2 = bb.GetInt(offset_2); + var startPos_1 = offset_1 + sizeof(int); + var startPos_2 = offset_2 + sizeof(int); + var len = Math.Min(len_1, len_2); + byte[] bbArray = bb.Data; + for(int i = 0; i < len; i++) { + if (bbArray[i + startPos_1] != bbArray[i + startPos_2]) + return bbArray[i + startPos_1] - bbArray[i + startPos_2]; + } + return len_1 - len_2; + } + + // Compare string from the ByteBuffer with the string object + protected static int CompareStrings(int offset_1, byte[] key, ByteBuffer bb) + { + offset_1 += bb.GetInt(offset_1); + var len_1 = bb.GetInt(offset_1); + var len_2 = key.Length; + var startPos_1 = offset_1 + sizeof(int); + var len = Math.Min(len_1, len_2); + byte[] bbArray = bb.Data; + for (int i = 0; i < len; i++) { + if (bbArray[i + startPos_1] != key[i]) + return bbArray[i + startPos_1] - key[i]; + } + return len_1 - len_2; + } } } |