ErlangBinary extends ErlangTerm { @Override public byte[] asBinary (byte[] defaultValue) { return bytes.clone(); } ErlangBinary(TermType type, @NonNull ByteBuf buffer);  ErlangBinary(@NonNull byte[] bytes); @Override byte[] asBinary(byte[] defaultValue); @Override String asText(String defaultValue);  }
@Test public void instantiate () { val value = new byte[] { 1, 2, 3 }; assertThat(new ErlangBinary(value).asBinary()) .isEqualTo(value); }
@Test public void newInstance () { val value = new byte[] { 1, 2, 3 }; val bytes = Bytes.resizableArray() .write1B(BINARY.getCode()) .write4B(value.length) .writeNB(value) .arrayCopy(); ErlangBinary binary = ErlangTerm.newInstance(wrappedBuffer(bytes)); assertThat(binary).isNotNull(); SoftAssertions.assertSoftly(softly -> { softly.assertThat(binary.isBinary()) .isTrue(); softly.assertThat(binary.asBinary()) .isEqualTo(value); }); }
@Test public void decode () throws Exception { val value = new byte[] { 1, 2, 3 }; val bytes = Bytes.resizableArray() .write1B(BINARY.getCode()) .write4B(value.length) .writeNB(value) .arrayCopy(); try (val input = new OtpInputStream(bytes)) { ErlangBinary binary = ErlangTerm.newInstance(wrappedBuffer(bytes)); assertThat(binary.asBinary()) .isEqualTo(input.read_binary()); } }