Class ProtobufDecoder<T extends com.google.protobuf.Message>
- java.lang.Object
-
- org.pipecraft.pipes.serialization.ProtobufDecoder<T>
-
- Type Parameters:
T- The data type of the decoded items. Must be a protobuf generated type (i.e. must extendMessage).
- All Implemented Interfaces:
Closeable,AutoCloseable,ItemDecoder<T>
public class ProtobufDecoder<T extends com.google.protobuf.Message> extends Object implements ItemDecoder<T>
AnItemDecoderthat decodes objects encoded in Protocol Buffers format (sequential, delimited proto objects).- Author:
- Eyal Schneider
-
-
Constructor Summary
Constructors Constructor Description ProtobufDecoder(Class<T> clazz, InputStream is)ConstructorProtobufDecoder(Class<T> clazz, InputStream is, FileReadOptions options, com.google.protobuf.ExtensionRegistryLite registry)Constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Tdecode()Reads and decodes the next object from the input stream.static <R extends com.google.protobuf.Message>
DecoderFactory<R>getFactory(Class<R> clazz)static <R extends com.google.protobuf.Message>
DecoderFactory<R>getFactory(Class<R> clazz, com.google.protobuf.ExtensionRegistryLite registry)
-
-
-
Constructor Detail
-
ProtobufDecoder
public ProtobufDecoder(Class<T> clazz, InputStream is) throws IOException
Constructor- Parameters:
clazz- The class identifying the type of the decoded itemsis- 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 itemsis- The input stream to bound to this decoder. Not expected to be buffered.options- The read options defining how to handle the input streamregistry- 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:ItemDecoderReads and decodes the next object from the input stream.- Specified by:
decodein interfaceItemDecoder<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 errorValidationPipeException- In case that the data for decoding is illegal
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceItemDecoder<T extends com.google.protobuf.Message>- Throws:
IOException
-
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 itemsregistry- 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
-
-