Class: OpenCensus::Trace::Formatters::Binary

Inherits:
Object
  • Object
show all
Defined in:
lib/opencensus/trace/formatters/binary.rb

Overview

This formatter serializes and deserializes span context according to the OpenCensus' BinaryEncoding specification. See documentation.

Instance Method Summary collapse

Instance Method Details

#deserialize(binary) ⇒ TraceContextData?

Deserialize a trace context header into a TraceContext object.

Parameters:

  • binary (String)

Returns:



38
39
40
41
42
43
44
45
# File 'lib/opencensus/trace/formatters/binary.rb', line 38

def deserialize binary
  data = binary.unpack(BINARY_FORMAT)
  if data[0].zero? && data[1].zero? && data[3] == 1 && data[5] == 2
    TraceContextData.new data[2], data[4], data[6]
  else
    nil
  end
end

#serialize(trace_context) ⇒ String

Serialize a TraceContextData object.

Parameters:

Returns:

  • (String)


53
54
55
56
57
58
59
60
61
62
63
# File 'lib/opencensus/trace/formatters/binary.rb', line 53

def serialize trace_context
  [
    0, # version
    0, # field 0
    trace_context.trace_id,
    1, # field 1
    trace_context.span_id,
    2, # field 2
    trace_context.trace_options
  ].pack(BINARY_FORMAT)
end