try something like this - see these test cases net.openhft.chronicle.wire.BinaryWire2Test#testByteArrayValueWithRealBytesNegative
@Test
public void testByteArrayValueWithRealBytesNegative() {
Wire wire = createWire();
final byte[] expected = {-1, -2, -3, -4, -5, -6, -7};
wire.writeDocument(false, wir -> wir.writeEventName(() -> "put")
.marshallable(w -> w.write("key").text("1")
.write("value")
.object(expected)));
System.out.println(wire);
wire.readDocument(null, wir -> wire.read(() -> "put")
.marshallable(w -> w.read(() -> "key").object(Object.class, "1", Assert::assertEquals)
.read(() -> "value").object(Object.class, expected, (e, v) -> {
Assert.assertArrayEquals(e, (byte[]) v);
})));
}
@Test
public void testBytesArray() {
Wire wire = createWire();
Random rand = new Random();
for (int i = 0; i < 70000; i += rand.nextInt(i + 1) + 1) {
System.out.println(i);
wire.clear();
final byte[] fromBytes = new byte[i];
wire.writeDocument(false, w -> w.write("bytes").bytes(fromBytes));
Wires.fromSizePrefixedBlobs(wire);
int finalI = i;
wire.readDocument(null, w -> assertEquals(finalI, w.read(() -> "bytes").bytes().length));
}
}
@Test
public void testSmallArray() {
Wire wire = createWire();
wire.writeDocument(false, w -> w.write("index")
.int64array(10));
assertEquals("--- !!data #binary\n" +
"index: [\n" +
" # length: 10, used: 0\n" +
" 0, 0, 0, 0, 0, 0, 0, 0, 0, 0\n" +
"]\n", Wires.fromSizePrefixedBlobs(wire.bytes()));
}