Skip to content

Commit

Permalink
add unmarshal, update serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Boten committed Jan 25, 2022
1 parent 51a6785 commit cab5b78
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 17 deletions.
11 changes: 9 additions & 2 deletions model/internal/data/optional.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,20 @@ func (o *OptionalDouble) MarshalTo(dAtA []byte) (n int, err error) {
return o.marshalToSizedBuffer(dAtA[:size])
}

// TODO: implement Unmarshal, MarshalJSON, UnmarshalJSON
// TODO: implement MarshalJSON, UnmarshalJSON

func (o *OptionalDouble) marshalToSizedBuffer(dAtA []byte) (int, error) {
i := len(dAtA)
i -= 8
encoding_binary.LittleEndian.PutUint64(dAtA[i:], uint64(math.Float64bits(float64(o.DoubleValue))))
i--
dAtA[i] = 0x21
return len(dAtA) - i, nil
}

func (o *OptionalDouble) Unmarshal(dAtA []byte) error {
v := uint64(encoding_binary.LittleEndian.Uint64(dAtA))
v2 := float64(math.Float64frombits(v))
o.DoubleValue = v2
o.isSet = true
return nil
}
40 changes: 26 additions & 14 deletions model/internal/data/protogen/metrics/v1/metrics.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion model/otlp/pb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func TestProtobufMetricsSizerWithOptional(t *testing.T) {

p := NewProtobufMetricsUnmarshaler()
unmarshalled, err := p.UnmarshalMetrics(bytes)
assert.Error(t, err)
assert.NoError(t, err)
assert.Equal(t, metric, unmarshalled.ResourceMetrics().At(0).InstrumentationLibraryMetrics().At(0).Metrics().At(0))

}
Expand Down

0 comments on commit cab5b78

Please sign in to comment.