Class BinaryFormatImpl
- java.lang.Object
-
- io.opencensus.trace.propagation.BinaryFormat
-
- io.opencensus.implcore.trace.propagation.BinaryFormatImpl
-
final class BinaryFormatImpl extends BinaryFormat
Implementation of theBinaryFormat
.BinaryFormat format:
- Binary value: <version_id><version_format>
- version_id: 1-byte representing the version id.
- For version_id = 0:
- version_format: <field><field>
- field_format: <field_id><field_format>
- Fields:
- TraceId: (field_id = 0, len = 16, default = "0000000000000000") - 16-byte array representing the trace_id.
- SpanId: (field_id = 1, len = 8, default = "00000000") - 8-byte array representing the span_id.
- TraceOptions: (field_id = 2, len = 1, default = "0") - 1-byte array representing the trace_options.
- Fields MUST be encoded using the field id order (smaller to higher).
- Valid value example:
- {0, 0, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 1, 97, 98, 99, 100, 101, 102, 103, 104, 2, 1}
- version_id = 0;
- trace_id = {64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79}
- span_id = {97, 98, 99, 100, 101, 102, 103, 104};
- trace_options = {1};
-
-
Field Summary
Fields Modifier and Type Field Description private static int
ALL_FORMAT_LENGTH
UseTraceOptions.DEFAULT
unless its optional field is present.private static byte
ID_SIZE
private static int
REQUIRED_FORMAT_LENGTH
Version, Trace and Span IDs are required fields.private static byte
SPAN_ID_FIELD_ID
(package private) static int
SPAN_ID_FIELD_ID_OFFSET
private static int
SPAN_ID_OFFSET
private static byte
TRACE_ID_FIELD_ID
(package private) static int
TRACE_ID_FIELD_ID_OFFSET
private static int
TRACE_ID_OFFSET
private static byte
TRACE_OPTION_FIELD_ID
(package private) static int
TRACE_OPTION_FIELD_ID_OFFSET
private static int
TRACE_OPTIONS_OFFSET
private static Tracestate
TRACESTATE_DEFAULT
private static byte
VERSION_ID
private static int
VERSION_ID_OFFSET
-
Constructor Summary
Constructors Constructor Description BinaryFormatImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description SpanContext
fromByteArray(byte[] bytes)
Parses theSpanContext
from a byte array using the binary format.byte[]
toByteArray(SpanContext spanContext)
Serializes aSpanContext
into a byte array using the binary format.-
Methods inherited from class io.opencensus.trace.propagation.BinaryFormat
fromBinaryValue, toBinaryValue
-
-
-
-
Field Detail
-
TRACESTATE_DEFAULT
private static final Tracestate TRACESTATE_DEFAULT
-
VERSION_ID
private static final byte VERSION_ID
- See Also:
- Constant Field Values
-
VERSION_ID_OFFSET
private static final int VERSION_ID_OFFSET
- See Also:
- Constant Field Values
-
ID_SIZE
private static final byte ID_SIZE
- See Also:
- Constant Field Values
-
TRACE_ID_FIELD_ID
private static final byte TRACE_ID_FIELD_ID
- See Also:
- Constant Field Values
-
TRACE_ID_FIELD_ID_OFFSET
static final int TRACE_ID_FIELD_ID_OFFSET
- See Also:
- Constant Field Values
-
TRACE_ID_OFFSET
private static final int TRACE_ID_OFFSET
- See Also:
- Constant Field Values
-
SPAN_ID_FIELD_ID
private static final byte SPAN_ID_FIELD_ID
- See Also:
- Constant Field Values
-
SPAN_ID_FIELD_ID_OFFSET
static final int SPAN_ID_FIELD_ID_OFFSET
- See Also:
- Constant Field Values
-
SPAN_ID_OFFSET
private static final int SPAN_ID_OFFSET
- See Also:
- Constant Field Values
-
TRACE_OPTION_FIELD_ID
private static final byte TRACE_OPTION_FIELD_ID
- See Also:
- Constant Field Values
-
TRACE_OPTION_FIELD_ID_OFFSET
static final int TRACE_OPTION_FIELD_ID_OFFSET
- See Also:
- Constant Field Values
-
TRACE_OPTIONS_OFFSET
private static final int TRACE_OPTIONS_OFFSET
- See Also:
- Constant Field Values
-
REQUIRED_FORMAT_LENGTH
private static final int REQUIRED_FORMAT_LENGTH
Version, Trace and Span IDs are required fields.- See Also:
- Constant Field Values
-
ALL_FORMAT_LENGTH
private static final int ALL_FORMAT_LENGTH
UseTraceOptions.DEFAULT
unless its optional field is present.- See Also:
- Constant Field Values
-
-
Method Detail
-
toByteArray
public byte[] toByteArray(SpanContext spanContext)
Description copied from class:BinaryFormat
Serializes aSpanContext
into a byte array using the binary format.- Overrides:
toByteArray
in classBinaryFormat
- Parameters:
spanContext
- theSpanContext
to serialize.- Returns:
- the serialized binary value.
-
fromByteArray
public SpanContext fromByteArray(byte[] bytes) throws SpanContextParseException
Description copied from class:BinaryFormat
Parses theSpanContext
from a byte array using the binary format.- Overrides:
fromByteArray
in classBinaryFormat
- Parameters:
bytes
- a binary encoded buffer from which theSpanContext
will be parsed.- Returns:
- the parsed
SpanContext
. - Throws:
SpanContextParseException
- if the version is not supported or the input is invalid
-
-