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:
parent
39833d7cf0
commit
e5a1a3129d
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue