Class PubSubPositionDeserializer

java.lang.Object
com.linkedin.venice.pubsub.PubSubPositionDeserializer

public class PubSubPositionDeserializer extends Object
Utility for converting serialized PubSubPositionWireFormat data into concrete PubSubPosition instances using a configured PubSubPositionTypeRegistry.

This class offers static access to a default deserializer instance backed by the reserved registry. In most production cases, callers are encouraged to instantiate their own deserializer with a custom registry instead of relying on the default static entry point.

Deserialization involves reading the type ID from the wire format and delegating to the corresponding PubSubPositionFactory to produce the appropriate position implementation.

  • Field Details

    • DEFAULT_DESERIALIZER

      public static final PubSubPositionDeserializer DEFAULT_DESERIALIZER
      Note: The following default instance is only for convenience purposes until we've updated all the code to use pass the registry and resolver explicitly.
  • Constructor Details

  • Method Details

    • toPosition

      public PubSubPosition toPosition(PubSubPositionWireFormat positionWireFormat)
      Converts a wire format position to a PubSubPosition
      Parameters:
      positionWireFormat - the wire format position
      Returns:
      concrete position object represented by the wire format
    • toPosition

      public PubSubPosition toPosition(byte[] positionWireFormatBytes)
    • toPosition

      public PubSubPosition toPosition(ByteBuffer positionWireFormatBytes)
    • getPositionFromWireFormat

      public static PubSubPosition getPositionFromWireFormat(byte[] positionWireFormatBytes)
      Convenience method for converting a serialized byte array representing a PubSubPositionWireFormat into a concrete PubSubPosition instance.

      This uses the DEFAULT_DESERIALIZER with the reserved position type registry. Recommended only for use in non-critical paths or tests where custom registries are not required.

      Parameters:
      positionWireFormatBytes - the serialized bytes of PubSubPositionWireFormat
      Returns:
      deserialized PubSubPosition object
      Throws:
      VeniceException - if deserialization fails or type ID is unrecognized
    • getPositionFromWireFormat

      public static PubSubPosition getPositionFromWireFormat(ByteBuffer positionWireFormatBuffer)
    • getPositionFromWireFormat

      public static PubSubPosition getPositionFromWireFormat(PubSubPositionWireFormat positionWireFormat)
      Convenience method for converting a PubSubPositionWireFormat record into a concrete PubSubPosition.

      This uses the DEFAULT_DESERIALIZER with the reserved position type registry. Prefer constructing your own PubSubPositionDeserializer with a custom registry if needed.

      Parameters:
      positionWireFormat - the wire format record to convert
      Returns:
      deserialized PubSubPosition object
      Throws:
      VeniceException - if the type ID in the wire format is unrecognized
    • deserializePositionUsingFactoryClassName

      public static PubSubPosition deserializePositionUsingFactoryClassName(PubSubPositionWireFormat wireFormat, String factoryClassName)
      Deserializes a PubSubPositionWireFormat into a PubSubPosition using the provided fully-qualified PubSubPositionFactory class name.

      This method is intended for use cases where the factory class name is explicitly stored alongside the wire format, such as in repush checkpointing or change capture consumers. It bypasses the usual deserialization path involving PubSubPositionDeserializer and PubSubPositionTypeRegistry.

      Note: This method should NOT be used within Venice servers or controllers, where factory mappings are dynamically registered and accessed via type ID. Use this only when the factory class name is stored and reflection is the only viable deserialization strategy.

      The factory class must implement PubSubPositionFactory and provide a constructor with a single int argument representing the position type ID.

      Parameters:
      wireFormat - the wire format of the position
      factoryClassName - the fully-qualified class name of the factory to use for deserialization
      Returns:
      a PubSubPosition instance deserialized from the wire format
      Throws:
      VeniceException - if instantiation or deserialization fails
    • deserializePubSubPosition

      public static PubSubPosition deserializePubSubPosition(ByteBuffer positionWireBytes, String factoryClassName)
      Deserializes a PubSubPosition using the provided wire format bytes and factory class name.

      This helper is intended for use cases where the factory class name is explicitly stored alongside the position wire format bytes, such as in repush checkpoints or change capture consumers.

      It should not be used in Venice servers or controllers where position deserialization is handled via PubSubPositionDeserializer and PubSubPositionTypeRegistry based on type IDs.

      Parameters:
      positionWireBytes - the serialized wire format bytes in a ByteBuffer
      factoryClassName - the fully-qualified class name of the factory used to deserialize the position
      Returns:
      the deserialized PubSubPosition
      Throws:
      RuntimeException - if deserialization or factory instantiation fails
    • deserializePubSubPosition

      public static PubSubPosition deserializePubSubPosition(byte[] positionWireBytes, String factoryClassName)
    • deserializePubSubPosition

      public static PubSubPosition deserializePubSubPosition(PubSubPositionWireFormat wireFormat, String factoryClassName)
    • deserializeWireFormat

      public static PubSubPositionWireFormat deserializeWireFormat(ByteBuffer positionWireFormatBytes)
      Deserializes a PubSubPositionWireFormat from a ByteBuffer.

      This method extracts a byte array from the given ByteBuffer and uses PubSubPosition.PUBSUB_POSITION_WIRE_FORMAT_SERIALIZER} to decode it into a PubSubPositionWireFormat instance.

      This is typically used when reconstructing position metadata stored in serialized wire format, such as in checkpointing, audit logs, or administrative tooling.

      Parameters:
      positionWireFormatBytes - the wire format bytes wrapped in a ByteBuffer
      Returns:
      the deserialized PubSubPositionWireFormat
      Throws:
      RuntimeException - if deserialization fails
    • deserializeWireFormat

      public static PubSubPositionWireFormat deserializeWireFormat(byte[] positionWireFormatBytes)