This commit is contained in:
TGIshib
2016-08-03 13:29:50 +03:00
parent 867dfc5957
commit dc7f5bc0d8
9 changed files with 241 additions and 12 deletions

View File

@@ -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)

View File

@@ -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.