public class BinaryMessageEncoder<D> extends Object implements MessageEncoder<D>
MessageEncoder
that adds a header and 8-byte schema fingerprint to
each datum encoded as binary.
This class is thread-safe.
Constructor and Description |
---|
BinaryMessageEncoder(GenericData model,
Schema schema)
Creates a new
BinaryMessageEncoder that uses the given
data model to deconstruct datum instances described by
the schema . |
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 . |
Modifier and Type | Method and Description |
---|---|
ByteBuffer |
encode(D datum)
Serialize a single datum to a ByteBuffer.
|
void |
encode(D datum,
OutputStream stream)
Serialize a single datum to an OutputStream.
|
public BinaryMessageEncoder(GenericData model, Schema schema)
BinaryMessageEncoder
that uses the given
data model
to deconstruct datum instances described by
the schema
.
Buffers returned by encode(D)
are copied and will
not be modified by future calls to encode
.
model
- the data model
for datum instancesschema
- the Schema
for datum instancespublic BinaryMessageEncoder(GenericData model, Schema schema, boolean shouldCopy)
BinaryMessageEncoder
that uses the given
data model
to deconstruct datum instances described by
the schema
.
If shouldCopy
is true, then buffers returned by
encode(D)
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
.
model
- the data model
for datum instancesschema
- the Schema
for datum instancesshouldCopy
- whether to copy buffers before returning encoded resultspublic ByteBuffer encode(D datum) throws IOException
MessageEncoder
encode
in interface MessageEncoder<D>
datum
- a datumIOException
public void encode(D datum, OutputStream stream) throws IOException
MessageEncoder
encode
in interface MessageEncoder<D>
datum
- a datumstream
- an OutputStream to serialize the datum toIOException
Copyright © 2009–2022 The Apache Software Foundation. All rights reserved.