Class ProtobufDecoder<T extends com.google.protobuf.Message>

  • Type Parameters:
    T - The data type of the decoded items. Must be a protobuf generated type (i.e. must extend Message).
    All Implemented Interfaces:
    Closeable, AutoCloseable, ItemDecoder<T>

    public class ProtobufDecoder<T extends com.google.protobuf.Message>
    extends Object
    implements ItemDecoder<T>
    An ItemDecoder that decodes objects encoded in Protocol Buffers format (sequential, delimited proto objects).
    Author:
    Eyal Schneider
    • Constructor Detail

      • ProtobufDecoder

        public ProtobufDecoder​(Class<T> clazz,
                               InputStream is)
                        throws IOException
        Constructor
        Parameters:
        clazz - The class identifying the type of the decoded items
        is - The input stream to bound to this decoder. Not expected to be buffered.
        Throws:
        IOException - In case of an IO error while preparing to read from the input stream
      • ProtobufDecoder

        public ProtobufDecoder​(Class<T> clazz,
                               InputStream is,
                               FileReadOptions options,
                               com.google.protobuf.ExtensionRegistryLite registry)
                        throws IOException
        Constructor
        Parameters:
        clazz - The class identifying the type of the decoded items
        is - The input stream to bound to this decoder. Not expected to be buffered.
        options - The read options defining how to handle the input stream
        registry - An extension registry for supporting user-defined fields not specified in the protobuf class specification.
        Throws:
        IOException - In case of an IO error while preparing to read from the input stream
    • Method Detail

      • decode

        public T decode()
                 throws IOException,
                        ValidationPipeException
        Description copied from interface: ItemDecoder
        Reads and decodes the next object from the input stream.
        Specified by:
        decode in interface ItemDecoder<T extends com.google.protobuf.Message>
        Returns:
        The decoded item from the input stream provided on construction, or null if end of stream was reached
        Throws:
        IOException - In case of a read error
        ValidationPipeException - In case that the data for decoding is illegal
      • getFactory

        public static <R extends com.google.protobuf.Message> DecoderFactory<R> getFactory​(Class<R> clazz)
        Parameters:
        clazz - The class identifying the type of the decoded items
        Returns:
        A decoder factory producing protobuf decoders based on the given type
      • getFactory

        public static <R extends com.google.protobuf.Message> DecoderFactory<R> getFactory​(Class<R> clazz,
                                                                                           com.google.protobuf.ExtensionRegistryLite registry)
        Parameters:
        clazz - The class identifying the type of the decoded items
        registry - An extension registry for supporting user-defined fields not specified in the protobuf class specification.
        Returns:
        A decoder factory producing protobuf decoders based on the given type