Class Serializer

  • All Implemented Interfaces:
    java.lang.AutoCloseable
    Direct Known Subclasses:
    JsonSerializer, ProtoSerializer

    public abstract class Serializer
    extends java.lang.Object
    implements java.lang.AutoCloseable
    Serializer to use when converting from an SDK data object into a protobuf output format. Unlike CodedOutputStream, which strictly encodes data into the protobuf binary format, this
    • Handles proto3 semantics of not outputting the value when it matches the default of a field
    • Can be implemented to serialize into protobuf JSON format (not binary)

    This class is internal and is hence not for public use. Its APIs are unstable and can change at any time.

    • Constructor Detail

      • Serializer

        Serializer()
    • Method Detail

      • serializeTraceId

        public void serializeTraceId​(ProtoFieldInfo field,
                                     @Nullable
                                     java.lang.String traceId)
                              throws java.io.IOException
        Serializes a trace ID field.
        Throws:
        java.io.IOException
      • serializeTraceId

        public void serializeTraceId​(ProtoFieldInfo field,
                                     @Nullable
                                     java.lang.String traceId,
                                     MarshalerContext context)
                              throws java.io.IOException
        Throws:
        java.io.IOException
      • writeTraceId

        protected abstract void writeTraceId​(ProtoFieldInfo field,
                                             java.lang.String traceId)
                                      throws java.io.IOException
        Throws:
        java.io.IOException
      • writeTraceId

        protected void writeTraceId​(ProtoFieldInfo field,
                                    java.lang.String traceId,
                                    MarshalerContext context)
                             throws java.io.IOException
        Throws:
        java.io.IOException
      • serializeSpanId

        public void serializeSpanId​(ProtoFieldInfo field,
                                    @Nullable
                                    java.lang.String spanId)
                             throws java.io.IOException
        Serializes a span ID field.
        Throws:
        java.io.IOException
      • serializeSpanId

        public void serializeSpanId​(ProtoFieldInfo field,
                                    @Nullable
                                    java.lang.String spanId,
                                    MarshalerContext context)
                             throws java.io.IOException
        Throws:
        java.io.IOException
      • writeSpanId

        protected abstract void writeSpanId​(ProtoFieldInfo field,
                                            java.lang.String spanId)
                                     throws java.io.IOException
        Throws:
        java.io.IOException
      • writeSpanId

        protected void writeSpanId​(ProtoFieldInfo field,
                                   java.lang.String spanId,
                                   MarshalerContext context)
                            throws java.io.IOException
        Throws:
        java.io.IOException
      • serializeBool

        public void serializeBool​(ProtoFieldInfo field,
                                  boolean value)
                           throws java.io.IOException
        Serializes a protobuf bool field.
        Throws:
        java.io.IOException
      • writeBool

        public abstract void writeBool​(ProtoFieldInfo field,
                                       boolean value)
                                throws java.io.IOException
        Writes a protobuf bool field, even if it matches the default value.
        Throws:
        java.io.IOException
      • serializeEnum

        public void serializeEnum​(ProtoFieldInfo field,
                                  ProtoEnumInfo enumValue)
                           throws java.io.IOException
        Serializes a protobuf enum field.
        Throws:
        java.io.IOException
      • writeEnum

        protected abstract void writeEnum​(ProtoFieldInfo field,
                                          ProtoEnumInfo enumValue)
                                   throws java.io.IOException
        Throws:
        java.io.IOException
      • serializeUInt32

        public void serializeUInt32​(ProtoFieldInfo field,
                                    int value)
                             throws java.io.IOException
        Serializes a protobuf uint32 field.
        Throws:
        java.io.IOException
      • writeUint32

        protected abstract void writeUint32​(ProtoFieldInfo field,
                                            int value)
                                     throws java.io.IOException
        Throws:
        java.io.IOException
      • serializeSInt32

        public void serializeSInt32​(ProtoFieldInfo field,
                                    int value)
                             throws java.io.IOException
        Serializes a protobuf sint32 field.
        Throws:
        java.io.IOException
      • writeSInt32

        protected abstract void writeSInt32​(ProtoFieldInfo info,
                                            int value)
                                     throws java.io.IOException
        Throws:
        java.io.IOException
      • serializeInt32

        public void serializeInt32​(ProtoFieldInfo field,
                                   int value)
                            throws java.io.IOException
        Serializes a protobuf uint32 field.
        Throws:
        java.io.IOException
      • writeint32

        protected abstract void writeint32​(ProtoFieldInfo field,
                                           int value)
                                    throws java.io.IOException
        Throws:
        java.io.IOException
      • serializeInt64

        public void serializeInt64​(ProtoFieldInfo field,
                                   long value)
                            throws java.io.IOException
        Serializes a protobuf int64 field.
        Throws:
        java.io.IOException
      • serializeUInt64

        public void serializeUInt64​(ProtoFieldInfo field,
                                    long value)
                             throws java.io.IOException
        Serializes a protobuf uint64 field.
        Throws:
        java.io.IOException
      • writeInt64

        public abstract void writeInt64​(ProtoFieldInfo field,
                                        long value)
                                 throws java.io.IOException
        Writes a protobuf int64 field, even if it matches the default value.
        Throws:
        java.io.IOException
      • writeUInt64

        public abstract void writeUInt64​(ProtoFieldInfo field,
                                         long value)
                                  throws java.io.IOException
        Writes a protobuf uint64 field, even if it matches the default value.
        Throws:
        java.io.IOException
      • serializeFixed64

        public void serializeFixed64​(ProtoFieldInfo field,
                                     long value)
                              throws java.io.IOException
        Serializes a protobuf fixed64 field.
        Throws:
        java.io.IOException
      • serializeFixed64Optional

        public void serializeFixed64Optional​(ProtoFieldInfo field,
                                             long value)
                                      throws java.io.IOException
        Serializes a protobuf fixed64 field.
        Throws:
        java.io.IOException
      • writeFixed64

        protected abstract void writeFixed64​(ProtoFieldInfo field,
                                             long value)
                                      throws java.io.IOException
        Throws:
        java.io.IOException
      • writeFixed64Value

        protected abstract void writeFixed64Value​(long value)
                                           throws java.io.IOException
        Throws:
        java.io.IOException
      • writeUInt64Value

        protected abstract void writeUInt64Value​(long value)
                                          throws java.io.IOException
        Throws:
        java.io.IOException
      • serializeByteAsFixed32

        public void serializeByteAsFixed32​(ProtoFieldInfo field,
                                           byte value)
                                    throws java.io.IOException
        Serializes a byte as a protobuf fixed32 field. Ensures that there is no sign propagation if the high bit in the byte is set.
        Throws:
        java.io.IOException
      • serializeFixed32

        public void serializeFixed32​(ProtoFieldInfo field,
                                     int value)
                              throws java.io.IOException
        Serializes a protobuf fixed32 field.
        Throws:
        java.io.IOException
      • writeFixed32

        protected abstract void writeFixed32​(ProtoFieldInfo field,
                                             int value)
                                      throws java.io.IOException
        Throws:
        java.io.IOException
      • serializeDouble

        public void serializeDouble​(ProtoFieldInfo field,
                                    double value)
                             throws java.io.IOException
        Serializes a proto buf double field.
        Throws:
        java.io.IOException
      • serializeDoubleOptional

        public void serializeDoubleOptional​(ProtoFieldInfo field,
                                            double value)
                                     throws java.io.IOException
        Serializes a proto buf double field.
        Throws:
        java.io.IOException
      • writeDouble

        public abstract void writeDouble​(ProtoFieldInfo field,
                                         double value)
                                  throws java.io.IOException
        Writes a protobuf double field, even if it matches the default value.
        Throws:
        java.io.IOException
      • writeDoubleValue

        protected abstract void writeDoubleValue​(double value)
                                          throws java.io.IOException
        Throws:
        java.io.IOException
      • serializeString

        public void serializeString​(ProtoFieldInfo field,
                                    byte[] utf8Bytes)
                             throws java.io.IOException
        Serializes a protobuf string field. utf8Bytes is the UTF8 encoded bytes of the string to serialize.
        Throws:
        java.io.IOException
      • writeString

        public abstract void writeString​(ProtoFieldInfo field,
                                         byte[] utf8Bytes)
                                  throws java.io.IOException
        Writes a protobuf string field, even if it matches the default value.
        Throws:
        java.io.IOException
      • writeString

        public abstract void writeString​(ProtoFieldInfo field,
                                         java.lang.String string,
                                         int utf8Length,
                                         MarshalerContext context)
                                  throws java.io.IOException
        Throws:
        java.io.IOException
      • serializeBytes

        public void serializeBytes​(ProtoFieldInfo field,
                                   byte[] value)
                            throws java.io.IOException
        Serializes a protobuf bytes field.
        Throws:
        java.io.IOException
      • serializeByteBuffer

        public void serializeByteBuffer​(ProtoFieldInfo field,
                                        java.nio.ByteBuffer value)
                                 throws java.io.IOException
        Serializes a protobuf bytes field. Writes all content of the ByteBuffer regardless of the current position and limit. Does not alter the position or limit of the provided ByteBuffer.
        Throws:
        java.io.IOException
      • writeBytes

        public abstract void writeBytes​(ProtoFieldInfo field,
                                        byte[] value)
                                 throws java.io.IOException
        Throws:
        java.io.IOException
      • writeByteBuffer

        public abstract void writeByteBuffer​(ProtoFieldInfo field,
                                             java.nio.ByteBuffer value)
                                      throws java.io.IOException
        Throws:
        java.io.IOException
      • writeStartMessage

        protected abstract void writeStartMessage​(ProtoFieldInfo field,
                                                  int protoMessageSize)
                                           throws java.io.IOException
        Throws:
        java.io.IOException
      • writeEndMessage

        protected abstract void writeEndMessage()
                                         throws java.io.IOException
        Throws:
        java.io.IOException
      • serializeMessage

        public void serializeMessage​(ProtoFieldInfo field,
                                     Marshaler message)
                              throws java.io.IOException
        Serializes a protobuf embedded message.
        Throws:
        java.io.IOException
      • writeStartRepeatedPrimitive

        protected abstract void writeStartRepeatedPrimitive​(ProtoFieldInfo field,
                                                            int protoSizePerElement,
                                                            int numElements)
                                                     throws java.io.IOException
        Throws:
        java.io.IOException
      • writeEndRepeatedPrimitive

        protected abstract void writeEndRepeatedPrimitive()
                                                   throws java.io.IOException
        Throws:
        java.io.IOException
      • writeStartRepeatedVarint

        protected abstract void writeStartRepeatedVarint​(ProtoFieldInfo field,
                                                         int payloadSize)
                                                  throws java.io.IOException
        Throws:
        java.io.IOException
      • writeEndRepeatedVarint

        protected abstract void writeEndRepeatedVarint()
                                                throws java.io.IOException
        Throws:
        java.io.IOException
      • serializeRepeatedFixed64

        public void serializeRepeatedFixed64​(ProtoFieldInfo field,
                                             java.util.List<java.lang.Long> values)
                                      throws java.io.IOException
        Serializes a repeated fixed64 field.
        Throws:
        java.io.IOException
      • serializeRepeatedFixed64

        public void serializeRepeatedFixed64​(ProtoFieldInfo field,
                                             long[] values)
                                      throws java.io.IOException
        Serializes a repeated fixed64 field.
        Throws:
        java.io.IOException
      • serializeRepeatedUInt64

        public void serializeRepeatedUInt64​(ProtoFieldInfo field,
                                            long[] values)
                                     throws java.io.IOException
        Serializes a repeated uint64 field.
        Throws:
        java.io.IOException
      • serializeRepeatedUInt64

        public void serializeRepeatedUInt64​(ProtoFieldInfo field,
                                            java.util.List<java.lang.Long> values)
                                     throws java.io.IOException
        Serializes a repeated uint64 field.
        Throws:
        java.io.IOException
      • serializeRepeatedInt64

        public void serializeRepeatedInt64​(ProtoFieldInfo field,
                                           java.util.List<java.lang.Long> values)
                                    throws java.io.IOException
        Serializes a repeated int64 field.
        Throws:
        java.io.IOException
      • serializeRepeatedDouble

        public void serializeRepeatedDouble​(ProtoFieldInfo field,
                                            java.util.List<java.lang.Double> values)
                                     throws java.io.IOException
        Serializes a repeated double field.
        Throws:
        java.io.IOException
      • serializeRepeatedMessage

        public abstract void serializeRepeatedMessage​(ProtoFieldInfo field,
                                                      Marshaler[] repeatedMessage)
                                               throws java.io.IOException
        Serializes repeated message field.
        Throws:
        java.io.IOException
      • serializeRepeatedMessage

        public abstract void serializeRepeatedMessage​(ProtoFieldInfo field,
                                                      java.util.List<? extends Marshaler> repeatedMessage)
                                               throws java.io.IOException
        Serializes repeated message field.
        Throws:
        java.io.IOException
      • writeStartRepeated

        protected abstract void writeStartRepeated​(ProtoFieldInfo field)
                                            throws java.io.IOException
        Writes start of repeated messages.
        Throws:
        java.io.IOException
      • writeEndRepeated

        protected abstract void writeEndRepeated()
                                          throws java.io.IOException
        Writes end of repeated messages.
        Throws:
        java.io.IOException
      • writeStartRepeatedElement

        protected abstract void writeStartRepeatedElement​(ProtoFieldInfo field,
                                                          int protoMessageSize)
                                                   throws java.io.IOException
        Writes start of a repeated message element.
        Throws:
        java.io.IOException
      • writeEndRepeatedElement

        protected abstract void writeEndRepeatedElement()
                                                 throws java.io.IOException
        Writes end of a repeated message element.
        Throws:
        java.io.IOException
      • writeSerializedMessage

        public abstract void writeSerializedMessage​(byte[] protoSerialized,
                                                    java.lang.String jsonSerialized)
                                             throws java.io.IOException
        Writes the value for a message field that has been pre-serialized.
        Throws:
        java.io.IOException
      • close

        public abstract void close()
                            throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Throws:
        java.io.IOException