代码拉取完成,页面将自动刷新
package msgpack
import (
"math"
"reflect"
"github.com/liangdas/mqant/utils/msgpack.v2/codes"
)
func (e *Encoder) EncodeUint(v uint) error {
return e.EncodeUint64(uint64(v))
}
func (e *Encoder) EncodeUint8(v uint8) error {
return e.EncodeUint64(uint64(v))
}
func (e *Encoder) EncodeUint16(v uint16) error {
return e.EncodeUint64(uint64(v))
}
func (e *Encoder) EncodeUint32(v uint32) error {
return e.EncodeUint64(uint64(v))
}
func (e *Encoder) EncodeUint64(v uint64) error {
if v <= math.MaxInt8 {
return e.w.WriteByte(byte(v))
}
if v <= math.MaxUint8 {
return e.write1(codes.Uint8, v)
}
if v <= math.MaxUint16 {
return e.write2(codes.Uint16, v)
}
if v <= math.MaxUint32 {
return e.write4(codes.Uint32, v)
}
return e.write8(codes.Uint64, v)
}
func (e *Encoder) EncodeInt(v int) error {
return e.EncodeInt64(int64(v))
}
func (e *Encoder) EncodeInt8(v int8) error {
return e.EncodeInt64(int64(v))
}
func (e *Encoder) EncodeInt16(v int16) error {
return e.EncodeInt64(int64(v))
}
func (e *Encoder) EncodeInt32(v int32) error {
return e.EncodeInt64(int64(v))
}
func (e *Encoder) EncodeInt64(v int64) error {
if v >= 0 {
return e.EncodeUint64(uint64(v))
}
if v >= int64(int8(codes.NegFixedNumLow)) {
return e.w.WriteByte(byte(v))
}
if v >= math.MinInt8 {
return e.write1(codes.Int8, uint64(v))
}
if v >= math.MinInt16 {
return e.write2(codes.Int16, uint64(v))
}
if v >= math.MinInt32 {
return e.write4(codes.Int32, uint64(v))
}
return e.write8(codes.Int64, uint64(v))
}
func (e *Encoder) EncodeFloat32(n float32) error {
return e.write4(codes.Float, uint64(math.Float32bits(n)))
}
func (e *Encoder) EncodeFloat64(n float64) error {
return e.write8(codes.Double, math.Float64bits(n))
}
func (e *Encoder) write1(code byte, n uint64) error {
e.buf = e.buf[:2]
e.buf[0] = code
e.buf[1] = byte(n)
return e.write(e.buf)
}
func (e *Encoder) write2(code byte, n uint64) error {
e.buf = e.buf[:3]
e.buf[0] = code
e.buf[1] = byte(n >> 8)
e.buf[2] = byte(n)
return e.write(e.buf)
}
func (e *Encoder) write4(code byte, n uint64) error {
e.buf = e.buf[:5]
e.buf[0] = code
e.buf[1] = byte(n >> 24)
e.buf[2] = byte(n >> 16)
e.buf[3] = byte(n >> 8)
e.buf[4] = byte(n)
return e.write(e.buf)
}
func (e *Encoder) write8(code byte, n uint64) error {
e.buf = e.buf[:9]
e.buf[0] = code
e.buf[1] = byte(n >> 56)
e.buf[2] = byte(n >> 48)
e.buf[3] = byte(n >> 40)
e.buf[4] = byte(n >> 32)
e.buf[5] = byte(n >> 24)
e.buf[6] = byte(n >> 16)
e.buf[7] = byte(n >> 8)
e.buf[8] = byte(n)
return e.write(e.buf)
}
func encodeInt64Value(e *Encoder, v reflect.Value) error {
return e.EncodeInt64(v.Int())
}
func encodeUint64Value(e *Encoder, v reflect.Value) error {
return e.EncodeUint64(v.Uint())
}
func encodeFloat32Value(e *Encoder, v reflect.Value) error {
return e.EncodeFloat32(float32(v.Float()))
}
func encodeFloat64Value(e *Encoder, v reflect.Value) error {
return e.EncodeFloat64(v.Float())
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。