|
1 |
| -// Package with support of Tarantool's datetime data type. |
| 1 | +// Package datetime provides support for Tarantool's datetime data type. |
2 | 2 | //
|
3 | 3 | // Datetime data type supported in Tarantool since 2.10.
|
4 | 4 | //
|
@@ -34,9 +34,10 @@ import (
|
34 | 34 | // * [optional] all the other fields (nsec, tzoffset, tzindex) if any of them
|
35 | 35 | // were having not 0 value. They are packed naturally in little-endian order;
|
36 | 36 |
|
37 |
| -// Datetime external type. Supported since Tarantool 2.10. See more details in |
| 37 | +// ExtID represents the Datetime MessagePack extension type identifier. |
| 38 | +// Supported since Tarantool 2.10. See more details in |
38 | 39 | // issue https://github.com/tarantool/tarantool/issues/5946.
|
39 |
| -const datetimeExtID = 4 |
| 40 | +const ExtID = 4 |
40 | 41 |
|
41 | 42 | // datetime structure keeps a number of seconds and nanoseconds since Unix Epoch.
|
42 | 43 | // Time is normalized by UTC, so time-zone offset is informative only.
|
@@ -242,7 +243,7 @@ func (d *Datetime) ToTime() time.Time {
|
242 | 243 | return d.time
|
243 | 244 | }
|
244 | 245 |
|
245 |
| -func datetimeEncoder(e *msgpack.Encoder, v reflect.Value) ([]byte, error) { |
| 246 | +func EncodeExt(_ *msgpack.Encoder, v reflect.Value) ([]byte, error) { |
246 | 247 | dtime := v.Interface().(Datetime)
|
247 | 248 | tm := dtime.ToTime()
|
248 | 249 |
|
@@ -275,7 +276,7 @@ func datetimeEncoder(e *msgpack.Encoder, v reflect.Value) ([]byte, error) {
|
275 | 276 | return buf, nil
|
276 | 277 | }
|
277 | 278 |
|
278 |
| -func datetimeDecoder(d *msgpack.Decoder, v reflect.Value, extLen int) error { |
| 279 | +func DecodeExt(d *msgpack.Decoder, v reflect.Value, extLen int) error { |
279 | 280 | if extLen != maxSize && extLen != secondsSize {
|
280 | 281 | return fmt.Errorf("invalid data length: got %d, wanted %d or %d",
|
281 | 282 | extLen, secondsSize, maxSize)
|
@@ -333,6 +334,6 @@ func datetimeDecoder(d *msgpack.Decoder, v reflect.Value, extLen int) error {
|
333 | 334 | }
|
334 | 335 |
|
335 | 336 | func init() {
|
336 |
| - msgpack.RegisterExtDecoder(datetimeExtID, Datetime{}, datetimeDecoder) |
337 |
| - msgpack.RegisterExtEncoder(datetimeExtID, Datetime{}, datetimeEncoder) |
| 337 | + msgpack.RegisterExtDecoder(ExtID, Datetime{}, DecodeExt) |
| 338 | + msgpack.RegisterExtEncoder(ExtID, Datetime{}, EncodeExt) |
338 | 339 | }
|
0 commit comments