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
ConstructorsConstructorDescriptionBinaryMessageEncoder(GenericData model, Schema schema) Creates a newBinaryMessageEncoderthat uses the givendata modelto deconstruct datum instances described by theschema.BinaryMessageEncoder(GenericData model, Schema schema, boolean shouldCopy) Creates a newBinaryMessageEncoderthat uses the givendata modelto deconstruct datum instances described by theschema. -
Method Summary
Modifier and TypeMethodDescriptionSerialize a single datum to a ByteBuffer.voidencode(D datum, OutputStream stream) Serialize a single datum to an OutputStream.
-
Constructor Details
-
BinaryMessageEncoder
Creates a newBinaryMessageEncoderthat uses the givendata modelto 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 modelfor datum instancesschema- theSchemafor datum instances
-
BinaryMessageEncoder
Creates a newBinaryMessageEncoderthat uses the givendata modelto deconstruct datum instances described by theschema.If
shouldCopyis true, then buffers returned byencode(D)are copied and will not be modified by future calls toencode.If
shouldCopyis false, then buffers returned byencodewrap a thread-local buffer that can be reused by future calls toencode, but may not be. Callers should only setshouldCopyto false if the buffer will be copied before the current thread's next call toencode.- Parameters:
model- thedata modelfor datum instancesschema- theSchemafor datum instancesshouldCopy- whether to copy buffers before returning encoded results
-
-
Method Details
-
encode
Description copied from interface:MessageEncoderSerialize a single datum to a ByteBuffer.- Specified by:
encodein interfaceMessageEncoder<D>- Parameters:
datum- a datum- Returns:
- a ByteBuffer containing the serialized datum
- Throws:
IOException
-
encode
Description copied from interface:MessageEncoderSerialize a single datum to an OutputStream.- Specified by:
encodein interfaceMessageEncoder<D>- Parameters:
datum- a datumstream- an OutputStream to serialize the datum to- Throws:
IOException
-