@Override public byte[] readDynamicRecordHeader( byte[] recordBytes ) { byte itemType = recordBytes[0]; if ( itemType == STRING.byteValue() ) { return headOf( recordBytes, DynamicArrayStore.STRING_HEADER_SIZE ); } else if ( itemType <= DOUBLE.byteValue() ) { return headOf( recordBytes, DynamicArrayStore.NUMBER_HEADER_SIZE ); } else if ( itemType == GEOMETRY.byteValue() ) { return headOf( recordBytes, DynamicArrayStore.GEOMETRY_HEADER_SIZE ); } else if ( itemType == TEMPORAL.byteValue() ) { return headOf( recordBytes, DynamicArrayStore.TEMPORAL_HEADER_SIZE ); } throw new IllegalArgumentException( "Unknown array type " + itemType ); }
private static void allocateFromString( Collection<DynamicRecord> target, String[] array, DynamicRecordAllocator recordAllocator ) { byte[][] stringsAsBytes = new byte[array.length][]; int totalBytesRequired = STRING_HEADER_SIZE; // 1b type + 4b array length for ( int i = 0; i < array.length; i++ ) { String string = array[i]; byte[] bytes = PropertyStore.encodeString( string ); stringsAsBytes[i] = bytes; totalBytesRequired += 4/*byte[].length*/ + bytes.length; } ByteBuffer buf = ByteBuffer.allocate( totalBytesRequired ); buf.put( PropertyType.STRING.byteValue() ); buf.putInt( array.length ); for ( byte[] stringAsBytes : stringsAsBytes ) { buf.putInt( stringAsBytes.length ); buf.put( stringAsBytes ); } allocateRecordsFromBytes( target, buf.array(), recordAllocator ); }
private void assertStringHeader( byte[] header, int itemCount ) { assertEquals( PropertyType.STRING.byteValue(), header[0] ); assertEquals( itemCount, ByteBuffer.wrap( header, 1, 4 ).getInt() ); }
private void assertArrayHeader( byte[] header, PropertyType type, int bitsPerItem ) { assertEquals( type.byteValue(), header[0] ); assertEquals( bitsPerItem, header[2] ); }
private void assertGeometryHeader( byte[] header, int geometryTpe, int dimension, int crsTableId, int crsCode ) { assertEquals( PropertyType.GEOMETRY.byteValue(), header[0] ); assertEquals( geometryTpe, header[1] ); assertEquals( dimension, header[2] ); assertEquals( crsTableId, header[3] ); assertEquals( crsCode, ByteBuffer.wrap( header, 4, 2 ).getShort() ); }
@Override public byte[] readDynamicRecordHeader( byte[] recordBytes ) { byte itemType = recordBytes[0]; if ( itemType == STRING.byteValue() ) { return headOf( recordBytes, DynamicArrayStore.STRING_HEADER_SIZE ); } else if ( itemType <= DOUBLE.byteValue() ) { return headOf( recordBytes, DynamicArrayStore.NUMBER_HEADER_SIZE ); } else if ( itemType == GEOMETRY.byteValue() ) { return headOf( recordBytes, DynamicArrayStore.GEOMETRY_HEADER_SIZE ); } else if ( itemType == TEMPORAL.byteValue() ) { return headOf( recordBytes, DynamicArrayStore.TEMPORAL_HEADER_SIZE ); } throw new IllegalArgumentException( "Unknown array type " + itemType ); }
private static void allocateFromString( Collection<DynamicRecord> target, String[] array, DynamicRecordAllocator recordAllocator ) { byte[][] stringsAsBytes = new byte[array.length][]; int totalBytesRequired = STRING_HEADER_SIZE; // 1b type + 4b array length for ( int i = 0; i < array.length; i++ ) { String string = array[i]; byte[] bytes = PropertyStore.encodeString( string ); stringsAsBytes[i] = bytes; totalBytesRequired += 4/*byte[].length*/ + bytes.length; } ByteBuffer buf = ByteBuffer.allocate( totalBytesRequired ); buf.put( PropertyType.STRING.byteValue() ); buf.putInt( array.length ); for ( byte[] stringAsBytes : stringsAsBytes ) { buf.putInt( stringAsBytes.length ); buf.put( stringAsBytes ); } allocateRecordsFromBytes( target, buf.array(), recordAllocator ); }