ErlangBitString extends ErlangTerm { public byte[] getBits () { return bits.clone(); } ErlangBitString(TermType type, @NonNull ByteBuf buffer); @Builder  ErlangBitString(@NonNull byte[] bits, int pad); byte[] getBits();  }
@Test public void newInstance () { val value = new byte[] { 1, 2, 3 }; val pad = 3; val bytes = Bytes.resizableArray() .write1B(BIT_BINNARY.getCode()) .write4B(value.length) .write1B(8 - pad) .writeNB(value) .arrayCopy(); ErlangBitString bitString = ErlangTerm.newInstance(wrappedBuffer(bytes)); assertThat(bitString).isNotNull(); SoftAssertions.assertSoftly(softly -> { softly.assertThat(bitString.getBits()) .isEqualTo(new byte[] { 1, 2, 0 }); softly.assertThat(bitString.getPad()) .isEqualTo(3); }); }
@Test public void decode () throws Exception { val bits = new byte[] { 1, 2, 3 }; val pad = 3; val bytes = Bytes.resizableArray() .write1B(BIT_BINNARY.getCode()) .write4B(bits.length) .write1B(8 - pad) .writeNB(new byte[] { 1, 2, 0 }) .arrayCopy(); try (val input = new OtpInputStream(bytes)) { ErlangBitString bitString = ErlangTerm.newInstance(wrappedBuffer(bytes)); assertThat(bitString.getBits()) .isEqualTo(input.read_bitstr(new int[1])); } }