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

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

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

      • ProtobufEncoder

        public ProtobufEncoder​(OutputStream os)
                        throws IOException
        Constructor
        Parameters:
        os - The output stream to bound to this encoder. Not expected to be buffered.
        Throws:
        IOException - In case of an IO error while preparing to write to the stream
      • ProtobufEncoder

        public ProtobufEncoder​(OutputStream os,
                               FileWriteOptions options)
                        throws IOException
        Constructor
        Parameters:
        os - The output stream to bound to this encoder. Not expected to be buffered.
        options - The write options defining how to handle the output stream
        Throws:
        IOException - In case of an IO error while preparing to write to the stream
    • Method Detail

      • encode

        public void encode​(T item)
                    throws IOException
        Specified by:
        encode in interface ItemEncoder<T extends com.google.protobuf.Message>
        Parameters:
        item - The item to encode into the output stream provided at construction type
        Throws:
        IOException - In case of write error
      • getFactory

        public static <R extends com.google.protobuf.Message> EncoderFactory<R> getFactory()
        Returns:
        A decoder factory producing protobuf decoders based on the given type