Class MessageBuilderRecordSerializerBase<M extends Message,U extends Message,B extends Message.Builder>
- java.lang.Object
-
- com.apple.foundationdb.record.provider.common.MessageBuilderRecordSerializerBase<M,U,B>
-
- Type Parameters:
M
- generated Protobuf class for the record message typeU
- generated Protobuf class for the union messageB
- generated Protobuf class for the union message's builder
- All Implemented Interfaces:
RecordSerializer<M>
- Direct Known Subclasses:
MessageBuilderRecordSerializer
,TypedRecordSerializer
@API(UNSTABLE) public abstract class MessageBuilderRecordSerializerBase<M extends Message,U extends Message,B extends Message.Builder> extends Object implements RecordSerializer<M>
Base class for record serializers that use a supplied union message builder method reference to reconstruct records.- See Also:
DynamicMessageRecordSerializer
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.apple.foundationdb.record.provider.common.RecordSerializer
RecordSerializer.Counts, RecordSerializer.Events
-
-
Constructor Summary
Constructors Constructor Description MessageBuilderRecordSerializerBase(Supplier<B> builderSupplier)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description M
deserialize(RecordMetaData metaData, Tuple primaryKey, byte[] serialized, StoreTimer timer)
Convert a byte array to a Protobuf record.protected abstract M
getUnionField(Descriptors.Descriptor unionDescriptor, U storedRecord)
byte[]
serialize(RecordMetaData metaData, RecordType recordType, M record, StoreTimer timer)
Convert a Protobuf record to bytes.protected abstract void
setUnionField(RecordMetaData metaData, RecordType recordType, B unionBuilder, M record)
RecordSerializer<Message>
widen()
Convert this typed record serializer to an untyped one.
-
-
-
Method Detail
-
serialize
@Nonnull public byte[] serialize(@Nonnull RecordMetaData metaData, @Nonnull RecordType recordType, @Nonnull M record, @Nullable StoreTimer timer)
Description copied from interface:RecordSerializer
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.- Specified by:
serialize
in interfaceRecordSerializer<M extends Message>
- 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
-
setUnionField
protected abstract void setUnionField(@Nonnull RecordMetaData metaData, @Nonnull RecordType recordType, @Nonnull B unionBuilder, @Nonnull M record)
-
deserialize
@Nonnull public M deserialize(@Nonnull RecordMetaData metaData, @Nonnull Tuple primaryKey, @Nonnull byte[] serialized, @Nullable StoreTimer timer)
Description copied from interface:RecordSerializer
Convert a byte array to a Protobuf record. This should be the inverse of theserialize()
method.- Specified by:
deserialize
in interfaceRecordSerializer<M extends Message>
- 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
-
getUnionField
@Nonnull protected abstract M getUnionField(@Nonnull Descriptors.Descriptor unionDescriptor, @Nonnull U storedRecord)
-
widen
@Nonnull public RecordSerializer<Message> widen()
Description copied from interface:RecordSerializer
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.- Specified by:
widen
in interfaceRecordSerializer<M extends Message>
- 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
-
-