MCPcopy Index your code
hub / github.com/tinylib/msgp / WriteTimeExt

Method WriteTimeExt

msgp/write.go:653–691  ·  view source on GitHub ↗

WriteTimeExt will write t using the official msgpack extension spec. https://github.com/msgpack/msgpack/blob/master/spec.md#timestamp-extension-type

(t time.Time)

Source from the content-addressed store, hash-verified

651// WriteTimeExt will write t using the official msgpack extension spec.
652// https://github.com/msgpack/msgpack/blob/master/spec.md#timestamp-extension-type
653func (mw *Writer) WriteTimeExt(t time.Time) error {
654 // Time rounded towards zero.
655 secPrec := t.Truncate(time.Second)
656 remain := t.Sub(secPrec).Nanoseconds()
657 asSecs := secPrec.Unix()
658 switch {
659 case remain == 0 && asSecs > 0 && asSecs <= math.MaxUint32:
660 // 4 bytes
661 o, err := mw.require(6)
662 if err != nil {
663 return err
664 }
665 mw.buf[o] = mfixext4
666 mw.buf[o+1] = byte(msgTimeExtension)
667 binary.BigEndian.PutUint32(mw.buf[o+2:], uint32(asSecs))
668 return nil
669 case asSecs < 0 || asSecs >= (1<<34):
670 // 12 bytes
671 o, err := mw.require(12 + 3)
672 if err != nil {
673 return err
674 }
675 mw.buf[o] = mext8
676 mw.buf[o+1] = 12
677 mw.buf[o+2] = byte(msgTimeExtension)
678 binary.BigEndian.PutUint32(mw.buf[o+3:], uint32(remain))
679 binary.BigEndian.PutUint64(mw.buf[o+3+4:], uint64(asSecs))
680 default:
681 // 8 bytes
682 o, err := mw.require(10)
683 if err != nil {
684 return err
685 }
686 mw.buf[o] = mfixext8
687 mw.buf[o+1] = byte(msgTimeExtension)
688 binary.BigEndian.PutUint64(mw.buf[o+2:], uint64(asSecs)|(uint64(remain)<<34))
689 }
690 return nil
691}
692
693// WriteJSONNumber writes the json.Number to the stream as either integer or float.
694func (mw *Writer) WriteJSONNumber(n json.Number) error {

Callers

nothing calls this directly

Calls 1

requireMethod · 0.95

Tested by

no test coverage detected