org.apache.avro.message

## Class BinaryMessageDecoder<D>

- java.lang.Object
- - org.apache.avro.message.MessageDecoder.BaseDecoder<D>
  - - org.apache.avro.message.BinaryMessageDecoder<D>

- All Implemented Interfaces:
    MessageDecoder<D>

      public class BinaryMessageDecoder<D>
      extends MessageDecoder.BaseDecoder<D>

  A `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

    Constructors
    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`.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    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.

    - ### Methods inherited from class org.apache.avro.message.MessageDecoder.BaseDecoder

      `decode, decode, decode, decode, decode`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### BinaryMessageDecoder

          public BinaryMessageDecoder(GenericData model,
                                      Schema readSchema)

      Creates a new `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)`.

      Parameters:
        `model` - the `data model` for datum instances
        `readSchema` - the `Schema` used to construct datum instances

    - #### BinaryMessageDecoder

          public 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`.

      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`.

      Parameters:
        `model` - the `data model` for datum instances
        `readSchema` - the `Schema` used to construct datum instances
        `resolver` - a `SchemaStore` used to find schemas by fingerprint

  - ### Method Detail

    - #### addSchema

          public void addSchema(Schema writeSchema)

      Adds a `Schema` that can be used to decode buffers.
      Parameters:
        `writeSchema` - a `Schema` to use when decoding buffers

    - #### decode

          public D decode(InputStream stream,
                          D reuse)
                   throws IOException

      Description copied from interface: `MessageDecoder`
      Deserialize a single datum from an InputStream.
      Parameters:
        `stream` - stream to read from
        `reuse` - a datum instance to reuse, avoiding instantiation if possible
      Returns:
        a datum read from the stream
      Throws:
        `IOException`

Copyright © 2009–2024 The Apache Software Foundation. All rights reserved.