LengthPrefixCoder extends StructuredCoder<T> { public static <T> LengthPrefixCoder<T> of(Coder<T> valueCoder) { checkNotNull(valueCoder, "Coder not expected to be null"); return new LengthPrefixCoder<>(valueCoder); } private  LengthPrefixCoder(Coder<T> valueCoder); static LengthPrefixCoder<T> of(Coder<T> valueCoder); @Override void encode(T value, OutputStream outStream); @Override T decode(InputStream inStream); @Override List<? extends Coder<?>> getCoderArguments(); Coder<T> getValueCoder(); @Override void verifyDeterministic(); @Override boolean consistentWithEquals(); @Override boolean isRegisterByteSizeObserverCheap(T value);  }
@Test public void testCoderIsSerializableWithWellKnownCoderType() throws Exception { CoderProperties.coderSerializable(LengthPrefixCoder.of(GlobalWindow.Coder.INSTANCE)); }
@Test public void testRegisterByteSizeObserver() throws Exception { CoderProperties.testByteCount( LengthPrefixCoder.of(VarIntCoder.of()), Coder.Context.NESTED, new Integer[] {0, 10, 1000}); }
@Test public void testMultiCoderCycle() throws Exception { LengthPrefixCoder<Long> lengthPrefixedValueCoder = LengthPrefixCoder.of(BigEndianLongCoder.of()); LengthPrefixCoder<byte[]> lengthPrefixedBytesCoder = LengthPrefixCoder.of(ByteArrayCoder.of()); byte[] userEncoded = CoderUtils.encodeToByteArray(lengthPrefixedValueCoder, 22L); byte[] decodedToBytes = CoderUtils.decodeFromByteArray(lengthPrefixedBytesCoder, userEncoded); byte[] reencodedBytes = CoderUtils.encodeToByteArray(lengthPrefixedBytesCoder, decodedToBytes); long userDecoded = CoderUtils.decodeFromByteArray(lengthPrefixedValueCoder, reencodedBytes); assertFalse( "Length-prefix decoding to bytes should drop the length", Arrays.equals(userEncoded, decodedToBytes)); assertArrayEquals(userEncoded, reencodedBytes); assertEquals(22L, userDecoded); }