Commit d332db6b authored by Jonathan Mace's avatar Jonathan Mace

Add accessor methods

parent b72617bd
......@@ -109,13 +109,17 @@ func WriteBool(v bool) []byte {
}
func ReadTaint(bytes []byte) *bool {
boolValue := ReadBool(bytes)
if boolValue == nil { return nil }
*boolValue = !*boolValue
return boolValue
//boolValue := ReadBool(bytes)
//if boolValue == nil { return nil }
//*boolValue = !*boolValue
//return boolValue
// This should be read inverted, but currently not
return ReadBool(bytes)
}
func WriteTaint(v bool) []byte {
if v { return []byte{0} }
return []byte{1}
//if v { return []byte{0} }
//return []byte{1}
// This should be written inverted, but currently not
return WriteBool(v)
}
\ No newline at end of file
......@@ -10,44 +10,95 @@ import (
// An example of a class that would be generated by BDL for Zipkin
type ZipkinMetadata struct {
traceID *int64 // sfixed64 traceID = 0;
spanID *int64 // sfixed64 spanID = 1;
parentSpanID *int64 // sfixed64 parentSpanID = 2;
sampled *bool // taint sampled = 3;
tags map[string](string) // map<string, string> tags = 4;
overflowed bool
unknown []atomlayer.Atom
TraceID *int64 // sfixed64 TraceID = 0;
SpanID *int64 // sfixed64 SpanID = 1;
ParentSpanID *int64 // sfixed64 ParentSpanID = 2;
Sampled *bool // taint Sampled = 3;
Tags map[string](string) // map<string, string> Tags = 4;
overflowed bool
unknown []atomlayer.Atom
}
func (zipkinMetadata *ZipkinMetadata) HasTraceID() bool {
return zipkinMetadata.TraceID != nil
}
func (zipkinMetadata *ZipkinMetadata) GetTraceID() int64 {
return *zipkinMetadata.TraceID
}
func (zipkinMetadata *ZipkinMetadata) SetTraceID(traceID int64) {
zipkinMetadata.TraceID = &traceID
}
func (zipkinMetadata *ZipkinMetadata) HasSpanID() bool {
return zipkinMetadata.SpanID != nil
}
func (zipkinMetadata *ZipkinMetadata) GetSpanID() int64 {
return *zipkinMetadata.SpanID
}
func (zipkinMetadata *ZipkinMetadata) SetSpanID(spanID int64) {
zipkinMetadata.SpanID = &spanID
}
func (zipkinMetadata *ZipkinMetadata) HasParentSpanID() bool {
return zipkinMetadata.ParentSpanID != nil
}
func (zipkinMetadata *ZipkinMetadata) GetParentSpanID() int64 {
return *zipkinMetadata.ParentSpanID
}
func (zipkinMetadata *ZipkinMetadata) SetParentSpanID(parentSpanID int64) {
zipkinMetadata.ParentSpanID = &parentSpanID
}
func (zipkinMetadata *ZipkinMetadata) HasSampled() bool {
return zipkinMetadata.Sampled != nil
}
func (zipkinMetadata *ZipkinMetadata) GetSampled() bool {
return *zipkinMetadata.Sampled
}
func (zipkinMetadata *ZipkinMetadata) SetSampled(sampled bool) {
zipkinMetadata.Sampled = &sampled
}
func (zipkinMetadata *ZipkinMetadata) Overflowed() bool {
return zipkinMetadata.overflowed
}
func (zipkinMetadata *ZipkinMetadata) Read(r *baggageprotocol.Reader) {
// traceID
// TraceID
if r.EnterIndexed(0) {
zipkinMetadata.traceID = bdl.ReadInt64Fixed(r.Next());
zipkinMetadata.TraceID = bdl.ReadInt64Fixed(r.Next());
r.Exit()
}
// spanID
// SpanID
if r.EnterIndexed(1) {
zipkinMetadata.spanID = bdl.ReadInt64Fixed(r.Next());
zipkinMetadata.SpanID = bdl.ReadInt64Fixed(r.Next());
r.Exit()
}
// parentSpanID
// ParentSpanID
if r.EnterIndexed(2) {
zipkinMetadata.parentSpanID = bdl.ReadInt64Fixed(r.Next());
zipkinMetadata.ParentSpanID = bdl.ReadInt64Fixed(r.Next());
r.Exit()
}
// sampled
// Sampled
if r.EnterIndexed(3) {
zipkinMetadata.sampled = bdl.ReadTaint(r.Next())
zipkinMetadata.Sampled = bdl.ReadTaint(r.Next())
r.Exit()
}
// tags
// Tags
if r.EnterIndexed(4) {
zipkinMetadata.tags = make(map[string](string))
zipkinMetadata.Tags = make(map[string](string))
for {
key := r.Enter()
if key == nil { break }
......@@ -56,7 +107,7 @@ func (zipkinMetadata *ZipkinMetadata) Read(r *baggageprotocol.Reader) {
if value != nil {
tagsKey := string(key[1:])
tagsValue := string(value)
zipkinMetadata.tags[tagsKey] = tagsValue
zipkinMetadata.Tags[tagsKey] = tagsValue
}
r.Exit()
}
......@@ -67,45 +118,45 @@ func (zipkinMetadata *ZipkinMetadata) Read(r *baggageprotocol.Reader) {
}
func (zipkinMetadata *ZipkinMetadata) Write(w *baggageprotocol.Writer) {
// traceID
if zipkinMetadata.traceID != nil {
// TraceID
if zipkinMetadata.TraceID != nil {
w.Enter(0)
w.Write(bdl.WriteInt64Fixed(*zipkinMetadata.traceID))
w.Write(bdl.WriteInt64Fixed(*zipkinMetadata.TraceID))
w.Exit()
}
// spanID
if zipkinMetadata.spanID != nil {
// SpanID
if zipkinMetadata.SpanID != nil {
w.Enter(1)
w.Write(bdl.WriteInt64Fixed(*zipkinMetadata.spanID))
w.Write(bdl.WriteInt64Fixed(*zipkinMetadata.SpanID))
w.Exit()
}
// parentSpanID
if zipkinMetadata.parentSpanID != nil {
// ParentSpanID
if zipkinMetadata.ParentSpanID != nil {
w.Enter(2)
w.Write(bdl.WriteInt64Fixed(*zipkinMetadata.parentSpanID))
w.Write(bdl.WriteInt64Fixed(*zipkinMetadata.ParentSpanID))
w.Exit()
}
// sampled
if zipkinMetadata.sampled != nil {
// Sampled
if zipkinMetadata.Sampled != nil {
w.Enter(3)
w.Write(bdl.WriteTaint(*zipkinMetadata.sampled))
w.Write(bdl.WriteTaint(*zipkinMetadata.Sampled))
w.Exit()
}
// tags
if len(zipkinMetadata.tags) > 0 {
// Tags
if len(zipkinMetadata.Tags) > 0 {
var tagKeys []atomlayer.Atom
for tagKey := range(zipkinMetadata.tags) {
for tagKey := range(zipkinMetadata.Tags) {
tagKeys = append(tagKeys, atomlayer.Atom(tagKey))
}
sort.Sort(baggageprotocol.LexicographicAtomSorter(tagKeys))
for _,tagKey := range(tagKeys) {
tagValue := []byte(zipkinMetadata.tags[string(tagKey)])
tagValue := []byte(zipkinMetadata.Tags[string(tagKey)])
w.EnterKey(tagKey)
w.Write(tagValue)
w.Exit()
......
......@@ -5,7 +5,6 @@ import (
"github.com/tracingplane/tracingplane-go/tracingplane"
"testing"
"github.com/tracingplane/tracingplane-go/atomlayer"
"fmt"
)
func TestZipkin(t *testing.T) {
......@@ -26,12 +25,12 @@ func TestZipkin(t *testing.T) {
assert.Nil(t, err)
assert.Empty(t, zmd.unknown)
assert.False(t, zmd.overflowed)
assert.NotNil(t, zmd.traceID)
assert.Equal(t, int64(55), *zmd.traceID)
assert.NotNil(t, zmd.spanID)
assert.Equal(t, int64(70), *zmd.spanID)
assert.NotNil(t, zmd.parentSpanID)
assert.Equal(t, int64(10), *zmd.parentSpanID)
assert.NotNil(t, zmd.TraceID)
assert.Equal(t, int64(55), *zmd.TraceID)
assert.NotNil(t, zmd.SpanID)
assert.Equal(t, int64(70), *zmd.SpanID)
assert.NotNil(t, zmd.ParentSpanID)
assert.Equal(t, int64(10), *zmd.ParentSpanID)
var baggage2 tracingplane.BaggageContext
baggage2.Set(2, &zmd)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment