mirror of
https://github.com/vee1e/flatbuffers.git
synced 2026-09-03 02:37:31 +00:00
[Java] Add support for shared strings on FlatBufferBuilder. (#6012)
Added a method FlatBufferBuilder::createSharedString that enable string sharing for building messages on java. The shared pool will only contains strings inserted by this methods.
This commit is contained in:
parent
ab6af18d9f
commit
b69fc8cc95
3 changed files with 80 additions and 15 deletions
|
|
@ -23,7 +23,9 @@ import java.io.*;
|
|||
import java.math.BigInteger;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.CharBuffer;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
|
@ -101,6 +103,8 @@ class JavaTest {
|
|||
|
||||
TestVectorOfBytes();
|
||||
|
||||
TestSharedStringPool();
|
||||
|
||||
System.out.println("FlatBuffers test: completed successfully");
|
||||
}
|
||||
|
||||
|
|
@ -1216,6 +1220,15 @@ class JavaTest {
|
|||
TestEq(monsterObject8.inventoryLength(), 2048);
|
||||
}
|
||||
|
||||
static void TestSharedStringPool() {
|
||||
FlatBufferBuilder fb = new FlatBufferBuilder(1);
|
||||
String testString = "My string";
|
||||
int offset = fb.createSharedString(testString);
|
||||
for (int i=0; i< 10; i++) {
|
||||
TestEq(offset, fb.createSharedString(testString));
|
||||
}
|
||||
}
|
||||
|
||||
static <T> void TestEq(T a, T b) {
|
||||
if (!a.equals(b)) {
|
||||
System.out.println("" + a.getClass().getName() + " " + b.getClass().getName());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue