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
ConstructorDescriptionBinaryMessageDecoder
(GenericData model, Schema readSchema) Creates a newBinaryMessageEncoder
that uses the givendata model
to construct datum instances described by theschema
.BinaryMessageDecoder
(GenericData model, Schema readSchema, SchemaStore resolver) Creates a newBinaryMessageEncoder
that uses the givendata model
to construct datum instances described by theschema
. -
Method Summary
-
Constructor Details
-
BinaryMessageDecoder
Creates a newBinaryMessageEncoder
that uses the givendata model
to construct datum instances described by theschema
.The
readSchema
is as used the expected schema (read schema). Datum instances created by this class will be described by the expected schema.If
readSchema
isnull
, 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 model
for datum instancesreadSchema
- theSchema
used to construct datum instances
-
BinaryMessageDecoder
Creates a newBinaryMessageEncoder
that uses the givendata model
to construct datum instances described by theschema
.The
readSchema
is used as the expected schema (read schema). Datum instances created by this class will be described by the expected schema.If
readSchema
isnull
, 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 model
for datum instancesreadSchema
- theSchema
used to construct datum instancesresolver
- aSchemaStore
used to find schemas by fingerprint
-
-
Method Details
-
addSchema
Adds aSchema
that can be used to decode buffers.- Parameters:
writeSchema
- aSchema
to use when decoding buffers
-
decode
Description copied from interface:MessageDecoder
Deserialize 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
-