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 intALL_FORMAT_LENGTHUseTraceOptions.DEFAULTunless its optional field is present.private static byteID_SIZEprivate static intREQUIRED_FORMAT_LENGTHVersion, Trace and Span IDs are required fields.private static byteSPAN_ID_FIELD_ID(package private) static intSPAN_ID_FIELD_ID_OFFSETprivate static intSPAN_ID_OFFSETprivate static byteTRACE_ID_FIELD_ID(package private) static intTRACE_ID_FIELD_ID_OFFSETprivate static intTRACE_ID_OFFSETprivate static byteTRACE_OPTION_FIELD_ID(package private) static intTRACE_OPTION_FIELD_ID_OFFSETprivate static intTRACE_OPTIONS_OFFSETprivate static TracestateTRACESTATE_DEFAULTprivate static byteVERSION_IDprivate static intVERSION_ID_OFFSET
-
Constructor Summary
Constructors Constructor Description BinaryFormatImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description SpanContextfromByteArray(byte[] bytes)Parses theSpanContextfrom a byte array using the binary format.byte[]toByteArray(SpanContext spanContext)Serializes aSpanContextinto 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.DEFAULTunless its optional field is present.- See Also:
- Constant Field Values
-
-
Method Detail
-
toByteArray
public byte[] toByteArray(SpanContext spanContext)
Description copied from class:BinaryFormatSerializes aSpanContextinto a byte array using the binary format.- Overrides:
toByteArrayin classBinaryFormat- Parameters:
spanContext- theSpanContextto serialize.- Returns:
- the serialized binary value.
-
fromByteArray
public SpanContext fromByteArray(byte[] bytes) throws SpanContextParseException
Description copied from class:BinaryFormatParses theSpanContextfrom a byte array using the binary format.- Overrides:
fromByteArrayin classBinaryFormat- Parameters:
bytes- a binary encoded buffer from which theSpanContextwill be parsed.- Returns:
- the parsed
SpanContext. - Throws:
SpanContextParseException- if the version is not supported or the input is invalid
-
-