From 58ffab29003d6f0fd7f7b4866c31002501d50536 Mon Sep 17 00:00:00 2001 From: Asdine El Hrychy Date: Sat, 18 Jul 2020 18:42:52 +0200 Subject: [PATCH] Add comment about duration types --- document/encoding/msgpack/codec.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/document/encoding/msgpack/codec.go b/document/encoding/msgpack/codec.go index 566d37913..e6e7a7a6b 100644 --- a/document/encoding/msgpack/codec.go +++ b/document/encoding/msgpack/codec.go @@ -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