public final void encodeType(final int size, final BCF2Type type) throws IOException { if ( size <= BCF2Utils.MAX_INLINE_ELEMENTS ) { final int typeByte = BCF2Utils.encodeTypeDescriptor(size, type); encodeStream.write(typeByte); } else { final int typeByte = BCF2Utils.encodeTypeDescriptor(BCF2Utils.OVERFLOW_ELEMENT_MARKER, type); encodeStream.write(typeByte); // write in the overflow size encodeTypedInt(size); } }
public final void encodeType(final int size, final BCF2Type type) throws IOException { if ( size <= BCF2Utils.MAX_INLINE_ELEMENTS ) { final int typeByte = BCF2Utils.encodeTypeDescriptor(size, type); encodeStream.write(typeByte); } else { final int typeByte = BCF2Utils.encodeTypeDescriptor(BCF2Utils.OVERFLOW_ELEMENT_MARKER, type); encodeStream.write(typeByte); // write in the overflow size encodeTypedInt(size); } }
@Requires("size >= 0") @Ensures("encodeStream.size() > old(encodeStream.size())") public final void encodeType(final int size, final BCF2Type type) throws IOException { if ( size <= BCF2Utils.MAX_INLINE_ELEMENTS ) { final int typeByte = BCF2Utils.encodeTypeDescriptor(size, type); encodeStream.write(typeByte); } else { final int typeByte = BCF2Utils.encodeTypeDescriptor(BCF2Utils.OVERFLOW_ELEMENT_MARKER, type); encodeStream.write(typeByte); // write in the overflow size encodeTypedInt(size); } }
@Test(dataProvider = "BCF2EncodingTestProviderBasicTypes") public void testBCF2EncodingVectorsWithMissing(final List<BCF2TypedValue> toEncode) throws IOException { for ( final BCF2TypedValue tv : toEncode ) { if ( tv.type != BCF2Type.CHAR ) { for ( final int length : Arrays.asList(2, 5, 10, 15, 20, 25) ) { final byte td = BCF2Utils.encodeTypeDescriptor(1, tv.type); final BCF2Encoder encoder = new BCF2Encoder(); for ( int i = 0; i < length; i++ ) { encoder.encodeRawValue(i % 2 == 0 ? null : tv.value, tv.type); } final BCF2Decoder decoder = new BCF2Decoder(encoder.getRecordBytes()); for ( int i = 0; i < length; i++ ) { final Object decoded = decoder.decodeTypedValue(td); myAssertEquals(i % 2 == 0 ? new BCF2TypedValue(null, tv.type) : tv, decoded); } } } } }