Initially discussed in #178.

Allows adding an already encoded UTF-8 string directly without
having to convert to a ``String`` first.

Change-Id: I23f9c738eec18fd35f4c14f58dbd0f6cf0970dc7
This commit is contained in:
pjulien 2015-05-06 19:41:44 -04:00 committed by Wouter van Oortmerssen
parent 39833d7cf0
commit e5a1a3129d
1 changed files with 15 additions and 0 deletions

View File

@ -262,6 +262,21 @@ public class FlatBufferBuilder {
return endVector();
}
/**
* Encode the string {@code s} in the buffer using UTF-8.
*
* @param s An already encoded UTF-8 string
* @return The offset in the buffer where the encoded string starts
*/
public int createString(ByteBuffer s) {
int length = s.remaining();
addByte((byte)0);
startVector(1, length, 1);
bb.position(space -= length);
bb.put(s);
return endVector();
}
/**
* Should not be creating any other object, string or vector
* while an object is being constructed