Package org.apache.avro.message
Class RawMessageEncoder<D>
java.lang.Object
org.apache.avro.message.RawMessageEncoder<D>
- All Implemented Interfaces:
MessageEncoder<D>
A
MessageEncoder
that encodes only a datum's bytes, without
additional information (such as a schema fingerprint).
This class is thread-safe.
-
Constructor Summary
ConstructorDescriptionRawMessageEncoder
(GenericData model, Schema schema) Creates a newRawMessageEncoder
that uses the givendata model
to deconstruct datum instances described by theschema
.RawMessageEncoder
(GenericData model, Schema schema, boolean shouldCopy) Creates a newRawMessageEncoder
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
-
RawMessageEncoder
Creates a newRawMessageEncoder
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
-
RawMessageEncoder
Creates a newRawMessageEncoder
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
-