Skip to content

Commit

Permalink
Add comment about duration types
Browse files Browse the repository at this point in the history
  • Loading branch information
asdine committed Jul 18, 2020
1 parent 77b441c commit 58ffab2
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions document/encoding/msgpack/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,13 @@ func (e *Encoder) EncodeValue(v document.Value) error {
case document.Float64Value:
return e.enc.EncodeFloat64(v.V.(float64))
case document.DurationValue:
// because messagepack doesn't have a duration type
// vmihailenco/msgpack EncodeDuration method
// encodes durations as int64 values.
// this means that the duration is lost during
// encoding and there is no way of knowing that
// an int64 is a duration during decoding.
// to avoid that, we create a custom duration type.
err := e.enc.EncodeExtHeader(DurationType, 8)
if err != nil {
return err
Expand Down

0 comments on commit 58ffab2

Please sign in to comment.