This commit is contained in:
Wouter van Oortmerssen
2015-12-21 14:43:48 -08:00
3 changed files with 17 additions and 13 deletions

View File

@@ -146,6 +146,13 @@ namespace FlatBuffers
_buffer[offset] = value; _buffer[offset] = value;
} }
public void PutByte(int offset, byte value, int count)
{
AssertOffsetAndLength(offset, sizeof(byte) * count);
for (var i = 0; i < count; ++i)
_buffer[offset + i] = value;
}
// this method exists in order to conform with Java ByteBuffer standards // this method exists in order to conform with Java ByteBuffer standards
public void Put(int offset, byte value) public void Put(int offset, byte value)
{ {

View File

@@ -69,10 +69,7 @@ namespace FlatBuffers
public void Pad(int size) public void Pad(int size)
{ {
for (var i = 0; i < size; i++) _bb.PutByte(_space -= size, 0, size);
{
_bb.PutByte(--_space, 0);
}
} }
// Doubles the size of the ByteBuffer, and copies the old data towards // Doubles the size of the ByteBuffer, and copies the old data towards
@@ -116,7 +113,8 @@ namespace FlatBuffers
_space += (int)_bb.Length - oldBufSize; _space += (int)_bb.Length - oldBufSize;
} }
Pad(alignSize); if (alignSize > 0)
Pad(alignSize);
} }
public void PutBool(bool x) public void PutBool(bool x)
@@ -277,11 +275,10 @@ namespace FlatBuffers
public StringOffset CreateString(string s) public StringOffset CreateString(string s)
{ {
NotNested(); NotNested();
byte[] utf8 = Encoding.UTF8.GetBytes(s); AddByte(0);
AddByte((byte)0); var utf8StringLen = Encoding.UTF8.GetByteCount(s);
StartVector(1, utf8.Length, 1); StartVector(1, utf8StringLen, 1);
Buffer.BlockCopy(utf8, 0, _bb.Data, _space -= utf8.Length, Encoding.UTF8.GetBytes(s, 0, s.Length, _bb.Data, _space -= utf8StringLen);
utf8.Length);
return new StringOffset(EndVector().Value); return new StringOffset(EndVector().Value);
} }

View File

@@ -18,8 +18,7 @@ Windows, OS X, Linux), see `docs/html/index.html`
Discuss FlatBuffers with other developers and users on the Discuss FlatBuffers with other developers and users on the
[FlatBuffers Google Group][]. File issues on the [FlatBuffers Issues Tracker][] [FlatBuffers Google Group][]. File issues on the [FlatBuffers Issues Tracker][]
or post your questions to [stackoverflow.com][] with a mention of or post your questions to [stackoverflow.com][] using the [`flatbuffers` tag][].
**flatbuffers**.
For applications on Google Play that integrate this tool, usage is tracked. For applications on Google Play that integrate this tool, usage is tracked.
This tracking is done automatically using the embedded version string This tracking is done automatically using the embedded version string
@@ -34,3 +33,4 @@ you would leave it in.
[FlatBuffers Issues Tracker]: http://github.com/google/flatbuffers/issues [FlatBuffers Issues Tracker]: http://github.com/google/flatbuffers/issues
[stackoverflow.com]: http://www.stackoverflow.com [stackoverflow.com]: http://www.stackoverflow.com
[landing page]: http://google.github.io/flatbuffers [landing page]: http://google.github.io/flatbuffers
[`flatbuffers` tag]: https://stackoverflow.com/questions/tagged/flatbuffers