mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-26 06:32:39 +00:00
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:
committed by
Wouter van Oortmerssen
parent
39833d7cf0
commit
e5a1a3129d
@@ -262,6 +262,21 @@ public class FlatBufferBuilder {
|
|||||||
return endVector();
|
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
|
* Should not be creating any other object, string or vector
|
||||||
* while an object is being constructed
|
* while an object is being constructed
|
||||||
|
|||||||
Reference in New Issue
Block a user