public class RawMessageEncoder<D> extends Object implements MessageEncoder<D>
MessageEncoder
that encodes only a datum's bytes, without
additional information (such as a schema fingerprint).
This class is thread-safe.
Constructor and Description |
---|
RawMessageEncoder(GenericData model,
Schema schema)
Creates a new
RawMessageEncoder that uses the given
data model to deconstruct datum instances described by
the schema . |
RawMessageEncoder(GenericData model,
Schema schema,
boolean shouldCopy)
Creates a new
RawMessageEncoder 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 RawMessageEncoder(GenericData model, Schema schema)
RawMessageEncoder
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 RawMessageEncoder(GenericData model, Schema schema, boolean shouldCopy)
RawMessageEncoder
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.