Class ProtoSerializer
- java.lang.Object
-
- io.opentelemetry.exporter.internal.marshal.Serializer
-
- io.opentelemetry.exporter.internal.marshal.ProtoSerializer
-
- All Implemented Interfaces:
java.lang.AutoCloseable
final class ProtoSerializer extends Serializer implements java.lang.AutoCloseable
Serializer for the protobuf binary wire format.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<java.lang.String,byte[]>
idCache
private CodedOutputStream
output
private static java.lang.ThreadLocal<java.util.Map<java.lang.String,byte[]>>
THREAD_LOCAL_ID_CACHE
-
Constructor Summary
Constructors Constructor Description ProtoSerializer(java.io.OutputStream output)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
private static java.util.Map<java.lang.String,byte[]>
getIdCache()
void
serializeRepeatedMessage(ProtoFieldInfo field, Marshaler[] repeatedMessage)
Serializesrepeated message
field.void
serializeRepeatedMessage(ProtoFieldInfo field, java.util.List<? extends Marshaler> repeatedMessage)
Serializesrepeated message
field.<T> void
serializeRepeatedMessageWithContext(ProtoFieldInfo field, java.util.List<? extends T> messages, StatelessMarshaler<T> marshaler, MarshalerContext context)
Serializesrepeated message
field.void
writeBool(ProtoFieldInfo field, boolean value)
Writes a protobufbool
field, even if it matches the default value.void
writeByteBuffer(ProtoFieldInfo field, java.nio.ByteBuffer value)
void
writeBytes(ProtoFieldInfo field, byte[] value)
void
writeDouble(ProtoFieldInfo field, double value)
Writes a protobufdouble
field, even if it matches the default value.protected void
writeDoubleValue(double value)
protected void
writeEndMessage()
protected void
writeEndRepeated()
Writes end of repeated messages.protected void
writeEndRepeatedElement()
Writes end of a repeated message element.protected void
writeEndRepeatedPrimitive()
protected void
writeEndRepeatedVarint()
protected void
writeEnum(ProtoFieldInfo field, ProtoEnumInfo enumValue)
protected void
writeFixed32(ProtoFieldInfo field, int value)
protected void
writeFixed64(ProtoFieldInfo field, long value)
protected void
writeFixed64Value(long value)
protected void
writeint32(ProtoFieldInfo field, int value)
void
writeInt64(ProtoFieldInfo field, long value)
Writes a protobufint64
field, even if it matches the default value.void
writeSerializedMessage(byte[] protoSerialized, java.lang.String jsonSerialized)
Writes the value for a message field that has been pre-serialized.protected void
writeSInt32(ProtoFieldInfo field, int value)
protected void
writeSpanId(ProtoFieldInfo field, java.lang.String spanId)
protected void
writeSpanId(ProtoFieldInfo field, java.lang.String spanId, MarshalerContext context)
protected void
writeStartMessage(ProtoFieldInfo field, int protoMessageSize)
protected void
writeStartRepeated(ProtoFieldInfo field)
Writes start of repeated messages.protected void
writeStartRepeatedElement(ProtoFieldInfo field, int protoMessageSize)
Writes start of a repeated message element.protected void
writeStartRepeatedPrimitive(ProtoFieldInfo field, int protoSizePerElement, int numElements)
protected void
writeStartRepeatedVarint(ProtoFieldInfo field, int payloadSize)
void
writeString(ProtoFieldInfo field, byte[] utf8Bytes)
Writes a protobufstring
field, even if it matches the default value.void
writeString(ProtoFieldInfo field, java.lang.String string, int utf8Length, MarshalerContext context)
protected void
writeTraceId(ProtoFieldInfo field, java.lang.String traceId)
protected void
writeTraceId(ProtoFieldInfo field, java.lang.String traceId, MarshalerContext context)
protected void
writeUint32(ProtoFieldInfo field, int value)
void
writeUInt64(ProtoFieldInfo field, long value)
Writes a protobufuint64
field, even if it matches the default value.protected void
writeUInt64Value(long value)
-
Methods inherited from class io.opentelemetry.exporter.internal.marshal.Serializer
serializeBool, serializeByteAsFixed32, serializeByteBuffer, serializeBytes, serializeDouble, serializeDoubleOptional, serializeEnum, serializeFixed32, serializeFixed64, serializeFixed64Optional, serializeInt32, serializeInt64, serializeMessage, serializeMessageWithContext, serializeMessageWithContext, serializeRepeatedDouble, serializeRepeatedFixed64, serializeRepeatedFixed64, serializeRepeatedInt64, serializeRepeatedMessageWithContext, serializeRepeatedMessageWithContext, serializeRepeatedMessageWithContext, serializeRepeatedUInt64, serializeRepeatedUInt64, serializeRepeatedUInt64, serializeSInt32, serializeSpanId, serializeSpanId, serializeString, serializeStringWithContext, serializeTraceId, serializeTraceId, serializeUInt32, serializeUInt64
-
-
-
-
Field Detail
-
THREAD_LOCAL_ID_CACHE
private static final java.lang.ThreadLocal<java.util.Map<java.lang.String,byte[]>> THREAD_LOCAL_ID_CACHE
-
output
private final CodedOutputStream output
-
idCache
private final java.util.Map<java.lang.String,byte[]> idCache
-
-
Method Detail
-
writeTraceId
protected void writeTraceId(ProtoFieldInfo field, java.lang.String traceId) throws java.io.IOException
- Specified by:
writeTraceId
in classSerializer
- Throws:
java.io.IOException
-
writeTraceId
protected void writeTraceId(ProtoFieldInfo field, java.lang.String traceId, MarshalerContext context) throws java.io.IOException
- Overrides:
writeTraceId
in classSerializer
- Throws:
java.io.IOException
-
writeSpanId
protected void writeSpanId(ProtoFieldInfo field, java.lang.String spanId) throws java.io.IOException
- Specified by:
writeSpanId
in classSerializer
- Throws:
java.io.IOException
-
writeSpanId
protected void writeSpanId(ProtoFieldInfo field, java.lang.String spanId, MarshalerContext context) throws java.io.IOException
- Overrides:
writeSpanId
in classSerializer
- Throws:
java.io.IOException
-
writeBool
public void writeBool(ProtoFieldInfo field, boolean value) throws java.io.IOException
Description copied from class:Serializer
Writes a protobufbool
field, even if it matches the default value.- Specified by:
writeBool
in classSerializer
- Throws:
java.io.IOException
-
writeEnum
protected void writeEnum(ProtoFieldInfo field, ProtoEnumInfo enumValue) throws java.io.IOException
- Specified by:
writeEnum
in classSerializer
- Throws:
java.io.IOException
-
writeUint32
protected void writeUint32(ProtoFieldInfo field, int value) throws java.io.IOException
- Specified by:
writeUint32
in classSerializer
- Throws:
java.io.IOException
-
writeSInt32
protected void writeSInt32(ProtoFieldInfo field, int value) throws java.io.IOException
- Specified by:
writeSInt32
in classSerializer
- Throws:
java.io.IOException
-
writeint32
protected void writeint32(ProtoFieldInfo field, int value) throws java.io.IOException
- Specified by:
writeint32
in classSerializer
- Throws:
java.io.IOException
-
writeInt64
public void writeInt64(ProtoFieldInfo field, long value) throws java.io.IOException
Description copied from class:Serializer
Writes a protobufint64
field, even if it matches the default value.- Specified by:
writeInt64
in classSerializer
- Throws:
java.io.IOException
-
writeUInt64
public void writeUInt64(ProtoFieldInfo field, long value) throws java.io.IOException
Description copied from class:Serializer
Writes a protobufuint64
field, even if it matches the default value.- Specified by:
writeUInt64
in classSerializer
- Throws:
java.io.IOException
-
writeFixed64
protected void writeFixed64(ProtoFieldInfo field, long value) throws java.io.IOException
- Specified by:
writeFixed64
in classSerializer
- Throws:
java.io.IOException
-
writeFixed64Value
protected void writeFixed64Value(long value) throws java.io.IOException
- Specified by:
writeFixed64Value
in classSerializer
- Throws:
java.io.IOException
-
writeUInt64Value
protected void writeUInt64Value(long value) throws java.io.IOException
- Specified by:
writeUInt64Value
in classSerializer
- Throws:
java.io.IOException
-
writeFixed32
protected void writeFixed32(ProtoFieldInfo field, int value) throws java.io.IOException
- Specified by:
writeFixed32
in classSerializer
- Throws:
java.io.IOException
-
writeDouble
public void writeDouble(ProtoFieldInfo field, double value) throws java.io.IOException
Description copied from class:Serializer
Writes a protobufdouble
field, even if it matches the default value.- Specified by:
writeDouble
in classSerializer
- Throws:
java.io.IOException
-
writeDoubleValue
protected void writeDoubleValue(double value) throws java.io.IOException
- Specified by:
writeDoubleValue
in classSerializer
- Throws:
java.io.IOException
-
writeString
public void writeString(ProtoFieldInfo field, byte[] utf8Bytes) throws java.io.IOException
Description copied from class:Serializer
Writes a protobufstring
field, even if it matches the default value.- Specified by:
writeString
in classSerializer
- Throws:
java.io.IOException
-
writeString
public void writeString(ProtoFieldInfo field, java.lang.String string, int utf8Length, MarshalerContext context) throws java.io.IOException
- Specified by:
writeString
in classSerializer
- Throws:
java.io.IOException
-
writeBytes
public void writeBytes(ProtoFieldInfo field, byte[] value) throws java.io.IOException
- Specified by:
writeBytes
in classSerializer
- Throws:
java.io.IOException
-
writeByteBuffer
public void writeByteBuffer(ProtoFieldInfo field, java.nio.ByteBuffer value) throws java.io.IOException
- Specified by:
writeByteBuffer
in classSerializer
- Throws:
java.io.IOException
-
writeStartMessage
protected void writeStartMessage(ProtoFieldInfo field, int protoMessageSize) throws java.io.IOException
- Specified by:
writeStartMessage
in classSerializer
- Throws:
java.io.IOException
-
writeEndMessage
protected void writeEndMessage()
- Specified by:
writeEndMessage
in classSerializer
-
writeStartRepeatedPrimitive
protected void writeStartRepeatedPrimitive(ProtoFieldInfo field, int protoSizePerElement, int numElements) throws java.io.IOException
- Specified by:
writeStartRepeatedPrimitive
in classSerializer
- Throws:
java.io.IOException
-
writeEndRepeatedPrimitive
protected void writeEndRepeatedPrimitive()
- Specified by:
writeEndRepeatedPrimitive
in classSerializer
-
writeStartRepeatedVarint
protected void writeStartRepeatedVarint(ProtoFieldInfo field, int payloadSize) throws java.io.IOException
- Specified by:
writeStartRepeatedVarint
in classSerializer
- Throws:
java.io.IOException
-
writeEndRepeatedVarint
protected void writeEndRepeatedVarint()
- Specified by:
writeEndRepeatedVarint
in classSerializer
-
serializeRepeatedMessage
public void serializeRepeatedMessage(ProtoFieldInfo field, Marshaler[] repeatedMessage) throws java.io.IOException
Description copied from class:Serializer
Serializesrepeated message
field.- Specified by:
serializeRepeatedMessage
in classSerializer
- Throws:
java.io.IOException
-
serializeRepeatedMessage
public void serializeRepeatedMessage(ProtoFieldInfo field, java.util.List<? extends Marshaler> repeatedMessage) throws java.io.IOException
Description copied from class:Serializer
Serializesrepeated message
field.- Specified by:
serializeRepeatedMessage
in classSerializer
- Throws:
java.io.IOException
-
serializeRepeatedMessageWithContext
public <T> void serializeRepeatedMessageWithContext(ProtoFieldInfo field, java.util.List<? extends T> messages, StatelessMarshaler<T> marshaler, MarshalerContext context) throws java.io.IOException
Description copied from class:Serializer
Serializesrepeated message
field. This method reads elements from context, use together withStatelessMarshalerUtil.sizeRepeatedMessageWithContext(ProtoFieldInfo, List, StatelessMarshaler, MarshalerContext)
.- Specified by:
serializeRepeatedMessageWithContext
in classSerializer
- Throws:
java.io.IOException
-
writeStartRepeated
protected void writeStartRepeated(ProtoFieldInfo field)
Description copied from class:Serializer
Writes start of repeated messages.- Specified by:
writeStartRepeated
in classSerializer
-
writeEndRepeated
protected void writeEndRepeated()
Description copied from class:Serializer
Writes end of repeated messages.- Specified by:
writeEndRepeated
in classSerializer
-
writeStartRepeatedElement
protected void writeStartRepeatedElement(ProtoFieldInfo field, int protoMessageSize) throws java.io.IOException
Description copied from class:Serializer
Writes start of a repeated message element.- Specified by:
writeStartRepeatedElement
in classSerializer
- Throws:
java.io.IOException
-
writeEndRepeatedElement
protected void writeEndRepeatedElement()
Description copied from class:Serializer
Writes end of a repeated message element.- Specified by:
writeEndRepeatedElement
in classSerializer
-
writeSerializedMessage
public void writeSerializedMessage(byte[] protoSerialized, java.lang.String jsonSerialized) throws java.io.IOException
Description copied from class:Serializer
Writes the value for a message field that has been pre-serialized.- Specified by:
writeSerializedMessage
in classSerializer
- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in classSerializer
- Throws:
java.io.IOException
-
getIdCache
private static java.util.Map<java.lang.String,byte[]> getIdCache()
-
-