Top Description Inners Fields Constructors Methods
org.apache.avro.message

public Class RawMessageEncoder<D>

extends Object
implements MessageEncoder<D>
Class Inheritance
All Implemented Interfaces
org.apache.avro.message.MessageEncoder
Known Direct Subclasses
org.apache.avro.message.BinaryMessageEncoder.V1MessageEncoder
Imports
org.apache.avro.Schema, org.apache.avro.generic.GenericData, org.apache.avro.io.BinaryEncoder, .DatumWriter, .EncoderFactory, org.apache.avro.util.internal.ThreadLocalWithInitial, java.io.ByteArrayOutputStream, .IOException, .OutputStream, java.nio.ByteBuffer

A MessageEncoder that encodes only a datum's bytes, without additional information (such as a schema fingerprint).

This class is thread-safe.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private final boolean
private static final ThreadLocal<BinaryEncoder>
private static final ThreadLocal<RawMessageEncoder.BufferOutputStream>
private final DatumWriter<D>

Constructor Summary

AccessConstructor and Description
public
RawMessageEncoder(GenericData
the data model for datum instances
model
,
Schema
the Schema for datum instances
schema
)

Creates a new RawMessageEncoder that uses the given data model to deconstruct datum instances described by the schema.

public
RawMessageEncoder(GenericData
the data model for datum instances
model
,
Schema
the Schema for datum instances
schema
,
boolean
whether to copy buffers before returning encoded results
shouldCopy
)

Creates a new RawMessageEncoder that uses the given data model to deconstruct datum instances described by the schema.

Method Summary

Modifier and TypeMethod and Description
public ByteBuffer
encode(D
a datum
datum
)

Implements org.apache.avro.message.MessageEncoder.encode.

Serialize a single datum to a ByteBuffer.
public void
encode(D
a datum
datum
,
OutputStream
an OutputStream to serialize the datum to
stream
)

Implements org.apache.avro.message.MessageEncoder.encode.

Serialize a single datum to an OutputStream.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

copyOutputBytesback to summary
private final boolean copyOutputBytes
ENCODERback to summary
private static final ThreadLocal<BinaryEncoder> ENCODER
TEMPback to summary
private static final ThreadLocal<RawMessageEncoder.BufferOutputStream> TEMP
writerback to summary
private final DatumWriter<D> writer

Constructor Detail

RawMessageEncoderback to summary
public RawMessageEncoder(GenericData model, Schema schema)

Creates a new RawMessageEncoder that uses the given data model to deconstruct datum instances described by the schema.

Buffers returned by RawMessageEncoder#encode are copied and will not be modified by future calls to encode.

Parameters
model:GenericData

the data model for datum instances

schema:Schema

the Schema for datum instances

RawMessageEncoderback to summary
public 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.

If shouldCopy is true, then buffers returned by RawMessageEncoder#encode 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.

Parameters
model:GenericData

the data model for datum instances

schema:Schema

the Schema for datum instances

shouldCopy:boolean

whether to copy buffers before returning encoded results

Method Detail

encodeback to summary
public ByteBuffer encode(D datum) throws IOException

Implements org.apache.avro.message.MessageEncoder.encode.

Doc from org.apache.avro.message.MessageEncoder.encode.

Serialize a single datum to a ByteBuffer.

Parameters
datum:D

a datum

Returns:ByteBuffer

a ByteBuffer containing the serialized datum

Annotations
@Override
encodeback to summary
public void encode(D datum, OutputStream stream) throws IOException

Implements org.apache.avro.message.MessageEncoder.encode.

Doc from org.apache.avro.message.MessageEncoder.encode.

Serialize a single datum to an OutputStream.

Parameters
datum:D

a datum

stream:OutputStream

an OutputStream to serialize the datum to

Annotations
@Override
org.apache.avro.message back to summary

private Class RawMessageEncoder.BufferOutputStream

extends ByteArrayOutputStream
Class Inheritance

Field Summary

Inherited from java.io.ByteArrayOutputStream:
bufcount

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv ByteBuffer
pack-priv ByteBuffer
Inherited from java.io.ByteArrayOutputStream:
closeresetsizetoByteArraytoStringtoStringtoStringtoStringwritewritewriteByteswriteTo

Constructor Detail

BufferOutputStreamback to summary
pack-priv BufferOutputStream()

Method Detail

toBufferWithCopyback to summary
pack-priv ByteBuffer toBufferWithCopy()
toBufferWithoutCopyback to summary
pack-priv ByteBuffer toBufferWithoutCopy()