mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-28 17:20:00 +00:00
Base type safety in C#. Clear FlatBufferBuilder in C#.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* Copyright 2014 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@@ -49,6 +49,17 @@ namespace FlatBuffers
|
||||
_bb = new ByteBuffer(new byte[initialSize]);
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
_space = _bb.Length;
|
||||
_bb.Reset();
|
||||
_minAlign = 1;
|
||||
_vtable = null;
|
||||
_objectStart = 0;
|
||||
_vtables = new int[16];
|
||||
_numVtables = 0;
|
||||
_vectorNumElems = 0;
|
||||
}
|
||||
|
||||
public int Offset { get { return _bb.Length - _space; } }
|
||||
|
||||
@@ -196,10 +207,10 @@ namespace FlatBuffers
|
||||
Prep(alignment, elemSize * count); // Just in case alignment > int.
|
||||
}
|
||||
|
||||
public int EndVector()
|
||||
public VectorOffset EndVector()
|
||||
{
|
||||
PutInt(_vectorNumElems);
|
||||
return Offset;
|
||||
return new VectorOffset(Offset);
|
||||
}
|
||||
|
||||
public void Nested(int obj)
|
||||
@@ -250,7 +261,7 @@ namespace FlatBuffers
|
||||
public void AddDouble(int o, double x, double d) { if (x != d) { AddDouble(x); Slot(o); } }
|
||||
public void AddOffset(int o, int x, int d) { if (x != d) { AddOffset(x); Slot(o); } }
|
||||
|
||||
public int CreateString(string s)
|
||||
public StringOffset CreateString(string s)
|
||||
{
|
||||
NotNested();
|
||||
byte[] utf8 = Encoding.UTF8.GetBytes(s);
|
||||
@@ -258,7 +269,7 @@ namespace FlatBuffers
|
||||
StartVector(1, utf8.Length, 1);
|
||||
Buffer.BlockCopy(utf8, 0, _bb.Data, _space -= utf8.Length,
|
||||
utf8.Length);
|
||||
return EndVector();
|
||||
return new StringOffset(EndVector().Value);
|
||||
}
|
||||
|
||||
// Structs are stored inline, so nothing additional is being added.
|
||||
|
||||
Reference in New Issue
Block a user