Package org.apache.avro.message
Class BinaryMessageEncoder<D>
java.lang.Object
org.apache.avro.message.BinaryMessageEncoder<D>
- All Implemented Interfaces:
MessageEncoder<D>
A
MessageEncoder
that adds a header and 8-byte schema fingerprint to
each datum encoded as binary.
This class is thread-safe.
-
Constructor Summary
ConstructorDescriptionBinaryMessageEncoder
(GenericData model, Schema schema) Creates a newBinaryMessageEncoder
that uses the givendata model
to deconstruct datum instances described by theschema
.BinaryMessageEncoder
(GenericData model, Schema schema, boolean shouldCopy) Creates a newBinaryMessageEncoder
that uses the givendata model
to deconstruct datum instances described by theschema
. -
Method Summary
Modifier and TypeMethodDescriptionSerialize a single datum to a ByteBuffer.void
encode
(D datum, OutputStream stream) Serialize a single datum to an OutputStream.
-
Constructor Details
-
BinaryMessageEncoder
Creates a newBinaryMessageEncoder
that uses the givendata model
to deconstruct datum instances described by theschema
.Buffers returned by
encode(D)
are copied and will not be modified by future calls toencode
.- Parameters:
model
- thedata model
for datum instancesschema
- theSchema
for datum instances
-
BinaryMessageEncoder
Creates a newBinaryMessageEncoder
that uses the givendata model
to deconstruct datum instances described by theschema
.If
shouldCopy
is true, then buffers returned byencode(D)
are copied and will not be modified by future calls toencode
.If
shouldCopy
is false, then buffers returned byencode
wrap a thread-local buffer that can be reused by future calls toencode
, but may not be. Callers should only setshouldCopy
to false if the buffer will be copied before the current thread's next call toencode
.- Parameters:
model
- thedata model
for datum instancesschema
- theSchema
for datum instancesshouldCopy
- whether to copy buffers before returning encoded results
-
-
Method Details
-
encode
Description copied from interface:MessageEncoder
Serialize a single datum to a ByteBuffer.- Specified by:
encode
in interfaceMessageEncoder<D>
- Parameters:
datum
- a datum- Returns:
- a ByteBuffer containing the serialized datum
- Throws:
IOException
-
encode
Description copied from interface:MessageEncoder
Serialize a single datum to an OutputStream.- Specified by:
encode
in interfaceMessageEncoder<D>
- Parameters:
datum
- a datumstream
- an OutputStream to serialize the datum to- Throws:
IOException
-