Copyright 2017, OpenCensus Authors Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Package propagation implements the binary trace context format.
package propagation // import "go.opencensus.io/trace/propagation"
TODO: link to external spec document.
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};

import (
	

	
)
Binary returns the binary format representation of a SpanContext. If sc is the zero value, Binary returns nil.
func ( trace.SpanContext) []byte {
	if  == (trace.SpanContext{}) {
		return nil
	}
	var  [29]byte
	copy([2:18], .TraceID[:])
	[18] = 1
	copy([19:27], .SpanID[:])
	[27] = 2
	[28] = uint8(.TraceOptions)
	return [:]
}
FromBinary returns the SpanContext represented by b. If b has an unsupported version ID or contains no TraceID, FromBinary returns with ok==false.
func ( []byte) ( trace.SpanContext,  bool) {
	if len() == 0 || [0] != 0 {
		return trace.SpanContext{}, false
	}
	 = [1:]
	if len() >= 17 && [0] == 0 {
		copy(.TraceID[:], [1:17])
		 = [17:]
	} else {
		return trace.SpanContext{}, false
	}
	if len() >= 9 && [0] == 1 {
		copy(.SpanID[:], [1:9])
		 = [9:]
	}
	if len() >= 2 && [0] == 2 {
		.TraceOptions = trace.TraceOptions([1])
	}
	return , true
}
HTTPFormat implementations propagate span contexts in HTTP requests. SpanContextFromRequest extracts a span context from incoming requests. SpanContextToRequest modifies the given request to include the given span context.
type HTTPFormat interface {
	SpanContextFromRequest(req *http.Request) (sc trace.SpanContext, ok bool)
	SpanContextToRequest(sc trace.SpanContext, req *http.Request)
}