Top Description Inners Fields Constructors Methods
org.apache.avro.message

public Class BinaryMessageEncoder<D>

extends Object
implements MessageEncoder<D>
Class Inheritance
All Implemented Interfaces
org.apache.avro.message.MessageEncoder
Imports
org.apache.avro.AvroRuntimeException, .Schema, .SchemaNormalization, org.apache.avro.generic.GenericData, java.io.IOException, .OutputStream, java.nio.ByteBuffer, java.security.NoSuchAlgorithmException

A MessageEncoder that adds a header and 8-byte schema fingerprint to each datum encoded as binary.

This class is thread-safe.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
BinaryMessageEncoder.V1MessageEncoder<D>

This is a RawDatumEncoder that adds the V1 header to the outgoing buffer.

Field Summary

Modifier and TypeField and Description
pack-priv static final byte[]
private final RawMessageEncoder<D>

Constructor Summary

AccessConstructor and Description
public
BinaryMessageEncoder(GenericData
the data model for datum instances
model
,
Schema
the Schema for datum instances
schema
)

Creates a new BinaryMessageEncoder that uses the given data model to deconstruct datum instances described by the schema.

public
BinaryMessageEncoder(GenericData
the data model for datum instances
model
,
Schema
the Schema for datum instances
schema
,
boolean
whether to copy buffers before returning encoded results
shouldCopy
)

Creates a new BinaryMessageEncoder that uses the given data model to deconstruct datum instances described by the schema.

Method Summary

Modifier and TypeMethod and Description
public ByteBuffer
encode(D
a datum
datum
)

Implements org.apache.avro.message.MessageEncoder.encode.

Serialize a single datum to a ByteBuffer.
public void
encode(D
a datum
datum
,
OutputStream
an OutputStream to serialize the datum to
stream
)

Implements org.apache.avro.message.MessageEncoder.encode.

Serialize a single datum to an OutputStream.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

V1_HEADERback to summary
pack-priv static final byte[] V1_HEADER
writeCodecback to summary
private final RawMessageEncoder<D> writeCodec

Constructor Detail

BinaryMessageEncoderback to summary
public BinaryMessageEncoder(GenericData model, Schema schema)

Creates a new BinaryMessageEncoder that uses the given data model to deconstruct datum instances described by the schema.

Buffers returned by BinaryMessageEncoder#encode are copied and will not be modified by future calls to encode.

Parameters
model:GenericData

the data model for datum instances

schema:Schema

the Schema for datum instances

BinaryMessageEncoderback to summary
public BinaryMessageEncoder(GenericData model, Schema schema, boolean shouldCopy)

Creates a new BinaryMessageEncoder that uses the given data model to deconstruct datum instances described by the schema.

If shouldCopy is true, then buffers returned by BinaryMessageEncoder#encode are copied and will not be modified by future calls to encode.

If shouldCopy is false, then buffers returned by encode wrap a thread-local buffer that can be reused by future calls to encode, but may not be. Callers should only set shouldCopy to false if the buffer will be copied before the current thread's next call to encode.

Parameters
model:GenericData

the data model for datum instances

schema:Schema

the Schema for datum instances

shouldCopy:boolean

whether to copy buffers before returning encoded results

Method Detail

encodeback to summary
public ByteBuffer encode(D datum) throws IOException

Implements org.apache.avro.message.MessageEncoder.encode.

Doc from org.apache.avro.message.MessageEncoder.encode.

Serialize a single datum to a ByteBuffer.

Parameters
datum:D

a datum

Returns:ByteBuffer

a ByteBuffer containing the serialized datum

Annotations
@Override
encodeback to summary
public void encode(D datum, OutputStream stream) throws IOException

Implements org.apache.avro.message.MessageEncoder.encode.

Doc from org.apache.avro.message.MessageEncoder.encode.

Serialize a single datum to an OutputStream.

Parameters
datum:D

a datum

stream:OutputStream

an OutputStream to serialize the datum to

Annotations
@Override
org.apache.avro.message back to summary

private Class BinaryMessageEncoder.V1MessageEncoder<D>

extends RawMessageEncoder<D>
Class Inheritance

This is a RawDatumEncoder that adds the V1 header to the outgoing buffer. BinaryDatumEncoder wraps this class to avoid confusion over what it does. It should not have an "is a" relationship with RawDatumEncoder because it adds the extra bytes.

Field Summary

Modifier and TypeField and Description
private final byte[]

Constructor Summary

AccessConstructor and Description
pack-priv
V1MessageEncoder(GenericData model, Schema schema, boolean shouldCopy)

Method Summary

Modifier and TypeMethod and Description
public void
encode(D
a datum
datum
,
OutputStream
an OutputStream to serialize the datum to
stream
)

Overrides org.apache.avro.message.RawMessageEncoder.encode.

Implements org.apache.avro.message.MessageEncoder.encode.

Serialize a single datum to an OutputStream.
private static byte[]
Inherited from org.apache.avro.message.RawMessageEncoder:
encode

Field Detail

headerBytesback to summary
private final byte[] headerBytes

Constructor Detail

V1MessageEncoderback to summary
pack-priv V1MessageEncoder(GenericData model, Schema schema, boolean shouldCopy)

Method Detail

encodeback to summary
public void encode(D datum, OutputStream stream) throws IOException

Overrides org.apache.avro.message.RawMessageEncoder.encode.

Implements org.apache.avro.message.MessageEncoder.encode.

Doc from org.apache.avro.message.MessageEncoder.encode.

Serialize a single datum to an OutputStream.

Parameters
datum:D

a datum

stream:OutputStream

an OutputStream to serialize the datum to

Annotations
@Override
getWriteHeaderback to summary
private static byte[] getWriteHeader(Schema schema)