public class BinaryMessageDecoder<D> extends MessageDecoder.BaseDecoder<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.
MessageDecoder.BaseDecoder<D>
Constructor and Description |
---|
BinaryMessageDecoder(GenericData model,
Schema readSchema)
Creates a new
BinaryMessageEncoder that uses the given
data model to construct datum instances described by the
schema . |
BinaryMessageDecoder(GenericData model,
Schema readSchema,
SchemaStore resolver)
Creates a new
BinaryMessageEncoder that uses the given
data model to construct datum instances described by the
schema . |
Modifier and Type | Method and Description |
---|---|
void |
addSchema(Schema writeSchema)
Adds a
Schema that can be used to decode buffers. |
D |
decode(InputStream stream,
D reuse)
Deserialize a single datum from an InputStream.
|
public BinaryMessageDecoder(GenericData model, Schema readSchema)
BinaryMessageEncoder
that uses the given
data model
to construct datum instances described by the
schema
.
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
is null
, 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 using addSchema(Schema)
.
model
- the data model
for datum instancesreadSchema
- the Schema
used to construct datum instancespublic BinaryMessageDecoder(GenericData model, Schema readSchema, SchemaStore resolver)
BinaryMessageEncoder
that uses the given
data model
to construct datum instances described by the
schema
.
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
is null
, 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 using addSchema(Schema)
, or schemas returned by the
resolver
.
model
- the data model
for datum instancesreadSchema
- the Schema
used to construct datum instancesresolver
- a SchemaStore
used to find schemas by fingerprintpublic void addSchema(Schema writeSchema)
Schema
that can be used to decode buffers.writeSchema
- a Schema
to use when decoding bufferspublic D decode(InputStream stream, D reuse) throws IOException
MessageDecoder
stream
- stream to read fromreuse
- a datum instance to reuse, avoiding instantiation if possibleIOException
Copyright © 2009–2020 The Apache Software Foundation. All rights reserved.