private void assertCannotEncode( String string, int payloadSize ) { assertFalse( LongerShortString.encode( 0, string, new PropertyBlock(), payloadSize ) ); } }
@Override public void writeString( String value ) throws IllegalArgumentException { // Try short string first, i.e. inlined in the property block if ( LongerShortString.encode( keyId, value, block, PropertyType.getPayloadSize() ) ) { return; } // Fall back to dynamic string store byte[] encodedString = encodeString( value ); List<DynamicRecord> valueRecords = new ArrayList<>(); allocateStringRecords( valueRecords, encodedString, stringAllocator ); setSingleBlockValue( block, keyId, PropertyType.STRING, Iterables.first( valueRecords ).getId() ); for ( DynamicRecord valueRecord : valueRecords ) { valueRecord.setType( PropertyType.STRING.intValue() ); } block.setValueRecords( valueRecords ); }
private void assertCanEncodeAndDecodeToSame( String string, int payloadSize ) { PropertyBlock target = new PropertyBlock(); assertTrue( LongerShortString.encode( 0, string, target, payloadSize ) ); assertEquals( Values.stringValue( string ), LongerShortString.decode( target ) ); }
@Test public void testRandomStrings() { for ( int i = 0; i < 1000; i++ ) { for ( TestStringCharset charset : TestStringCharset.values() ) { List<String> list = randomStrings( 100, charset, 30 ); for ( String string : list ) { PropertyBlock record = new PropertyBlock(); if ( LongerShortString.encode( 10, string, record, DEFAULT_PAYLOAD_SIZE ) ) { assertEquals( Values.stringValue( string ), LongerShortString.decode( record ) ); } } } } }
@Override public void writeString( String value ) throws IllegalArgumentException { // Try short string first, i.e. inlined in the property block if ( LongerShortString.encode( keyId, value, block, PropertyType.getPayloadSize() ) ) { return; } // Fall back to dynamic string store byte[] encodedString = encodeString( value ); List<DynamicRecord> valueRecords = new ArrayList<>(); allocateStringRecords( valueRecords, encodedString, stringAllocator ); setSingleBlockValue( block, keyId, PropertyType.STRING, Iterables.first( valueRecords ).getId() ); for ( DynamicRecord valueRecord : valueRecords ) { valueRecord.setType( PropertyType.STRING.intValue() ); } block.setValueRecords( valueRecords ); }