同步操作将从 邢楠/msgpack 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
package msgpackimport ("bytes""io""reflect""time""github.com/vmihailenco/msgpack/codes")type writer interface {io.WriterWriteByte(byte) errorWriteString(string) (int, error)}type byteWriter struct {io.Writerbuf []bytebootstrap [64]byte}func newByteWriter(w io.Writer) *byteWriter {bw := &byteWriter{Writer: w,}bw.buf = bw.bootstrap[:]return bw}func (w *byteWriter) WriteByte(c byte) error {w.buf = w.buf[:1]w.buf[0] = c_, err := w.Write(w.buf)return err}func (w *byteWriter) WriteString(s string) (int, error) {w.buf = append(w.buf[:0], s...)return w.Write(w.buf)}// Marshal returns the MessagePack encoding of v.func Marshal(v interface{}) ([]byte, error) {var buf bytes.Buffererr := NewEncoder(&buf).Encode(v)return buf.Bytes(), err}type Encoder struct {w writerbuf []bytesortMapKeys boolstructAsArray booluseJSONTag booluseCompact bool}// NewEncoder returns a new encoder that writes to w.func NewEncoder(w io.Writer) *Encoder {bw, ok := w.(writer)if !ok {bw = newByteWriter(w)}return &Encoder{w: bw,buf: make([]byte, 9),}}// SortMapKeys causes the Encoder to encode map keys in increasing order.// Supported map types are:// - map[string]string// - map[string]interface{}func (e *Encoder) SortMapKeys(flag bool) *Encoder {e.sortMapKeys = flagreturn e}// StructAsArray causes the Encoder to encode Go structs as MessagePack arrays.func (e *Encoder) StructAsArray(flag bool) *Encoder {e.structAsArray = flagreturn e}// UseJSONTag causes the Encoder to use json struct tag as fallback option// if there is no msgpack tag.func (e *Encoder) UseJSONTag(flag bool) *Encoder {e.useJSONTag = flagreturn e}// UseCompactEncoding causes the Encoder to chose the most compact encoding.// For example, it allows to encode Go int64 as msgpack int8 saving 7 bytes.func (e *Encoder) UseCompactEncoding(flag bool) *Encoder {e.useCompact = flagreturn e}func (e *Encoder) Encode(v interface{}) error {switch v := v.(type) {case nil:return e.EncodeNil()case string:return e.EncodeString(v)case []byte:return e.EncodeBytes(v)case int:return e.encodeInt64Cond(int64(v))case int64:return e.encodeInt64Cond(v)case uint:return e.encodeUint64Cond(uint64(v))case uint64:return e.encodeUint64Cond(v)case bool:return e.EncodeBool(v)case float32:return e.EncodeFloat32(v)case float64:return e.EncodeFloat64(v)case time.Duration:return e.encodeInt64Cond(int64(v))case time.Time:return e.EncodeTime(v)}return e.EncodeValue(reflect.ValueOf(v))}func (e *Encoder) EncodeMulti(v ...interface{}) error {for _, vv := range v {if err := e.Encode(vv); err != nil {return err}}return nil}func (e *Encoder) EncodeValue(v reflect.Value) error {fn := getEncoder(v.Type())return fn(e, v)}func (e *Encoder) EncodeNil() error {return e.writeCode(codes.Nil)}func (e *Encoder) EncodeBool(value bool) error {if value {return e.writeCode(codes.True)}return e.writeCode(codes.False)}func (e *Encoder) writeCode(c codes.Code) error {return e.w.WriteByte(byte(c))}func (e *Encoder) write(b []byte) error {_, err := e.w.Write(b)return err}func (e *Encoder) writeString(s string) error {_, err := e.w.WriteString(s)return err}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。