Interface RecordSerializer<M extends Message>

    • 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 own MessageLite.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 the deserialize() method on those bytes. Implementors should also be careful as they evolve this method that the deserialize 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-data
        recordType - the record type of the message
        record - the Protobuf record to serialize
        timer - 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 the serialize() method.
        Parameters:
        metaData - the store's meta-data
        primaryKey - the primary key of the record
        serialized - the serialized bytes
        timer - a timer used to instrument deserialization
        Returns:
        the deserialized record