RecordSerializer { public static Object deserialize(Bytes data, int type) { switch (type) { case ColumnTypes.BYTEARRAY: case ColumnTypes.NOTNULL_BYTEARRAY: return data.to_array(); case ColumnTypes.INTEGER: case ColumnTypes.NOTNULL_INTEGER: return data.to_int(); case ColumnTypes.LONG: case ColumnTypes.NOTNULL_LONG: return data.to_long(); case ColumnTypes.STRING: case ColumnTypes.NOTNULL_STRING: return data.to_RawString(); case ColumnTypes.TIMESTAMP: case ColumnTypes.NOTNULL_TIMESTAMP: return data.to_timestamp(); case ColumnTypes.NULL: return null; case ColumnTypes.BOOLEAN: case ColumnTypes.NOTNULL_BOOLEAN: return data.to_boolean(); case ColumnTypes.DOUBLE: case ColumnTypes.NOTNULL_DOUBLE: return data.to_double(); default: throw new IllegalArgumentException("bad column type " + type); } } private  RecordSerializer(); static Object deserialize(Bytes data, int type); static Object deserialize(byte[] data, int type); static int deserializeCompare(byte[] data, int type, Object cvalue); static SQLRecordPredicateFunctions.CompareResult deserializeCompare(Bytes data, int type, Object cvalue); static Object deserializeTypeAndValue(ByteArrayCursor dii); static SQLRecordPredicateFunctions.CompareResult compareDeserializeTypeAndValue(ByteArrayCursor dii, Object cvalue); static void skipTypeAndValue(ByteArrayCursor dii); static byte[] serialize(Object v, int type); static void serializeTo(Object v, int type, ExtendedDataOutputStream out); static void validate(Object v, int type); static void serializeTypeAndValue(Object v, int type, ExtendedDataOutputStream oo); static void serializeValue(Object v, int type, ExtendedDataOutputStream oo); static DateTimeFormatter getUTCTimestampFormatter(); static Object convert(int type, Object value); static DataAccessor buildRawDataAccessor(Record record, Table table); static DataAccessor buildRawDataAccessorForPrimaryKey(Bytes key, Table table); static Record makeRecord(Table table, Object... values); static Bytes serializePrimaryKey(Map<String, Object> record, ColumnsList table, String[] columns); static byte[] serializePrimaryKeyRaw(Map<String, Object> record, ColumnsList table, String[] columns); static Bytes serializeIndexKey(DataAccessor record, ColumnsList index, String[] columns); static void validateIndexableValue(DataAccessor record, ColumnsList indexDefinition, String[] columns); static Object deserializePrimaryKey(Bytes key, Table table); static Map<String, Object> deserializePrimaryKeyAsMap(Bytes key, Table table); static Bytes serializeValue(Map<String, Object> record, Table table); static byte[] serializeValueRaw(Map<String, Object> record, Table table, int expectedSize); static byte[] buildRecord(
            int expectedSize, Table table,
            Function<String, Object> evaluator
    ); static Record toRecord(Map<String, Object> record, Table table); @SuppressFBWarnings("RV_RETURN_VALUE_IGNORED") static Map<String, Object> toBean(Record record, Table table);  }
@Test public void testDeserializeWithNullAndNonNullTypes() { byte[] byteValueForInt = Bytes.from_int(1000).to_array(); int iValue = (int) RecordSerializer.deserialize(byteValueForInt, ColumnTypes.INTEGER); assertEquals(iValue, 1000); int iValueNonNullType = (int) RecordSerializer.deserialize(byteValueForInt, ColumnTypes.NOTNULL_INTEGER); assertEquals(iValueNonNullType, 1000); byte[] byteValueForLong = Bytes.from_long(99999).to_array(); long lValue = (long) RecordSerializer.deserialize(byteValueForLong, ColumnTypes.LONG); assertEquals(lValue, 99999); long lValueNonNullType = (long) RecordSerializer.deserialize(byteValueForLong, ColumnTypes.NOTNULL_LONG); assertEquals(lValueNonNullType, 99999); byte[] strValueAsByteArray = Bytes.from_string("test").to_array(); RawString sValue = (RawString) RecordSerializer.deserialize(strValueAsByteArray, ColumnTypes.STRING); assertEquals(sValue, "test"); RawString sValueNonNullType = (RawString) RecordSerializer.deserialize(strValueAsByteArray, ColumnTypes.NOTNULL_STRING); assertEquals(sValueNonNullType, "test"); byte[] booleanToByteArray = Bytes.booleanToByteArray(Boolean.TRUE); Boolean bValue = (Boolean) RecordSerializer.deserialize(booleanToByteArray, ColumnTypes.BOOLEAN); assertEquals(bValue, Boolean.TRUE); booleanToByteArray = Bytes.booleanToByteArray(Boolean.FALSE); bValue = (Boolean) RecordSerializer.deserialize(booleanToByteArray, ColumnTypes.NOTNULL_BOOLEAN); assertEquals(bValue, Boolean.FALSE); byte[] doubleToByteArray = Bytes.doubleToByteArray(Double.valueOf(11.0120d)); Double dValue = (Double) RecordSerializer.deserialize(doubleToByteArray, ColumnTypes.DOUBLE); assertEquals(dValue, Double.valueOf(11.0120d)); dValue = (Double) RecordSerializer.deserialize(doubleToByteArray, ColumnTypes.NOTNULL_DOUBLE); assertEquals(dValue, Double.valueOf(11.0120d)); Timestamp ts = Timestamp.valueOf("2020-07-04 13:17:47.221"); byte[] tsToByteArray = Bytes.timestampToByteArray(ts); Timestamp tsValue = (Timestamp) RecordSerializer.deserialize(tsToByteArray, ColumnTypes.TIMESTAMP); assertEquals(tsValue, ts); tsValue = (Timestamp) RecordSerializer.deserialize(tsToByteArray, ColumnTypes.NOTNULL_TIMESTAMP); assertEquals(tsValue, ts); }