Class BinaryMessageDecoder<D>
- All Implemented Interfaces:
MessageDecoder<D>
MessageDecoder that reads a binary-encoded datum. This checks for
the datum header and decodes the payload with the schema that corresponds to
the 8-byte schema fingerprint.
Instances can decode message payloads for known schemas, which
are schemas added using addSchema(Schema), schemas resolved by the
SchemaStore passed to the constructor, or the expected schema passed
to the constructor. Messages encoded using an unknown schema will cause
instances to throw a MissingSchemaException.
It is safe to continue using instances of this class after decode(java.io.InputStream, D)
throws BadHeaderException or MissingSchemaException.
This class is thread-safe.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.avro.message.MessageDecoder
MessageDecoder.BaseDecoder<D> -
Constructor Summary
ConstructorsConstructorDescriptionBinaryMessageDecoder(GenericData model, Schema readSchema) Creates a newBinaryMessageEncoderthat uses the givendata modelto construct datum instances described by theschema.BinaryMessageDecoder(GenericData model, Schema readSchema, SchemaStore resolver) Creates a newBinaryMessageEncoderthat uses the givendata modelto construct datum instances described by theschema. -
Method Summary
-
Constructor Details
-
BinaryMessageDecoder
Creates a newBinaryMessageEncoderthat uses the givendata modelto construct datum instances described by theschema.The
readSchemais as used the expected schema (read schema). Datum instances created by this class will be described by the expected schema.If
readSchemaisnull, the write schema of an incoming buffer is used as read schema for that datum instance.The schema used to decode incoming buffers is determined by the schema fingerprint encoded in the message header. This class can decode messages that were encoded using the
readSchema(if any) and other schemas that are added usingaddSchema(Schema).- Parameters:
model- thedata modelfor datum instancesreadSchema- theSchemaused to construct datum instances
-
BinaryMessageDecoder
Creates a newBinaryMessageEncoderthat uses the givendata modelto construct datum instances described by theschema.The
readSchemais used as the expected schema (read schema). Datum instances created by this class will be described by the expected schema.If
readSchemaisnull, the write schema of an incoming buffer is used as read schema for that datum instance.The schema used to decode incoming buffers is determined by the schema fingerprint encoded in the message header. This class can decode messages that were encoded using the
readSchema(if any), other schemas that are added usingaddSchema(Schema), or schemas returned by theresolver.- Parameters:
model- thedata modelfor datum instancesreadSchema- theSchemaused to construct datum instancesresolver- aSchemaStoreused to find schemas by fingerprint
-
-
Method Details
-
addSchema
Adds aSchemathat can be used to decode buffers.- Parameters:
writeSchema- aSchemato use when decoding buffers
-
decode
Description copied from interface:MessageDecoderDeserialize a single datum from an InputStream.- Parameters:
stream- stream to read fromreuse- a datum instance to reuse, avoiding instantiation if possible- Returns:
- a datum read from the stream
- Throws:
IOException
-