Interface RecordSerializer<M extends Message>
-
- Type Parameters:
M
- type used to represent stored records
- All Known Implementing Classes:
DynamicMessageRecordSerializer
,MessageBuilderRecordSerializer
,MessageBuilderRecordSerializerBase
,TransformedRecordSerializer
,TransformedRecordSerializerJCE
,TypedRecordSerializer
@API(MAINTAINED) public interface RecordSerializer<M extends Message>
A converter between a Protobuf record and a byte string stored in one or more values in the FDB key-value store.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
RecordSerializer.Counts
Instrumentation counts related to record serialization.static class
RecordSerializer.Events
Instrumentation events related to record serialization.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description M
deserialize(RecordMetaData metaData, Tuple primaryKey, byte[] serialized, StoreTimer timer)
Convert a byte array to a Protobuf record.byte[]
serialize(RecordMetaData metaData, RecordType recordType, M record, StoreTimer timer)
Convert a Protobuf record to bytes.RecordSerializer<Message>
widen()
Convert this typed record serializer to an untyped one.
-
-
-
Method Detail
-
serialize
@Nonnull byte[] serialize(@Nonnull RecordMetaData metaData, @Nonnull RecordType recordType, @Nonnull M record, @Nullable StoreTimer timer)
Convert a Protobuf record to bytes. While Protobuf messages provide their ownMessageLite.toByteArray()
method for serialization, record stores may elect to first wrap the raw Protobuf record in another wrapping type or perform additional transformations like encrypt or compress records. Implementors of this interface can control how exactly which transformations are done, with the main constraint being that whatever operation is done should be reversible by calling thedeserialize()
method on those bytes. Implementors should also be careful as they evolve this method that thedeserialize
method is still able to read older data unless they are certain that any record store that used the older implementation has since been cleared out or migrated to a newer format.- Parameters:
metaData
- the store's meta-datarecordType
- the record type of the messagerecord
- the Protobuf record to serializetimer
- a timer used to instrument serialization- Returns:
- the serialized record
-
deserialize
@Nonnull M deserialize(@Nonnull RecordMetaData metaData, @Nonnull Tuple primaryKey, @Nonnull byte[] serialized, @Nullable StoreTimer timer)
Convert a byte array to a Protobuf record. This should be the inverse of theserialize()
method.- Parameters:
metaData
- the store's meta-dataprimaryKey
- the primary key of the recordserialized
- the serialized bytestimer
- a timer used to instrument deserialization- Returns:
- the deserialized record
-
widen
@Nonnull RecordSerializer<Message> widen()
Convert this typed record serializer to an untyped one.- If this serializer wraps another serializer, for example, because it does compressions, then
widen
that serializer and return the result wrapped equivalently. - If this serializer parses messages in a type-sensitive way, return the closest general purpose way.
- If this serializer is inherently bound to its type parameter, throw an exception.
If a
FDBTypedRecordStore
is created without callingFDBTypedRecordStore.Builder.setUntypedSerializer(com.apple.foundationdb.record.provider.common.RecordSerializer<com.google.protobuf.Message>)
, then in order to make the untyped record store that is paired with the typed store (used, for instance, to rebuild indexes), the given typed serializer will be widened by calling this method.- Returns:
- a new serializer that works the same way but handles all record types.
- If this serializer wraps another serializer, for example, because it does compressions, then
-
-