|
@@ -19,9 +19,10 @@ const (
|
|
|
mpFixMapMax = 0x8f
|
|
mpFixMapMax = 0x8f
|
|
|
mpFixArrayMin = 0x90
|
|
mpFixArrayMin = 0x90
|
|
|
mpFixArrayMax = 0x9f
|
|
mpFixArrayMax = 0x9f
|
|
|
- mpFixRawMin = 0xa0
|
|
|
|
|
- mpFixRawMax = 0xbf
|
|
|
|
|
|
|
+ mpFixStrMin = 0xa0
|
|
|
|
|
+ mpFixStrMax = 0xbf
|
|
|
mpNil = 0xc0
|
|
mpNil = 0xc0
|
|
|
|
|
+ _ = 0xc1
|
|
|
mpFalse = 0xc2
|
|
mpFalse = 0xc2
|
|
|
mpTrue = 0xc3
|
|
mpTrue = 0xc3
|
|
|
mpFloat = 0xca
|
|
mpFloat = 0xca
|
|
@@ -34,42 +35,33 @@ const (
|
|
|
mpInt16 = 0xd1
|
|
mpInt16 = 0xd1
|
|
|
mpInt32 = 0xd2
|
|
mpInt32 = 0xd2
|
|
|
mpInt64 = 0xd3
|
|
mpInt64 = 0xd3
|
|
|
- mpRaw16 = 0xda
|
|
|
|
|
- mpRaw32 = 0xdb
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // extensions below
|
|
|
|
|
+ mpBin8 = 0xc4
|
|
|
|
|
+ mpBin16 = 0xc5
|
|
|
|
|
+ mpBin32 = 0xc6
|
|
|
|
|
+ mpExt8 = 0xc7
|
|
|
|
|
+ mpExt16 = 0xc8
|
|
|
|
|
+ mpExt32 = 0xc9
|
|
|
|
|
+ mpFixExt1 = 0xd4
|
|
|
|
|
+ mpFixExt2 = 0xd5
|
|
|
|
|
+ mpFixExt4 = 0xd6
|
|
|
|
|
+ mpFixExt8 = 0xd7
|
|
|
|
|
+ mpFixExt16 = 0xd8
|
|
|
|
|
+
|
|
|
|
|
+ mpStr8 = 0xd9 // new
|
|
|
|
|
+ mpStr16 = 0xda
|
|
|
|
|
+ mpStr32 = 0xdb
|
|
|
|
|
+
|
|
|
mpArray16 = 0xdc
|
|
mpArray16 = 0xdc
|
|
|
mpArray32 = 0xdd
|
|
mpArray32 = 0xdd
|
|
|
|
|
+
|
|
|
mpMap16 = 0xde
|
|
mpMap16 = 0xde
|
|
|
mpMap32 = 0xdf
|
|
mpMap32 = 0xdf
|
|
|
|
|
+
|
|
|
mpNegFixNumMin = 0xe0
|
|
mpNegFixNumMin = 0xe0
|
|
|
mpNegFixNumMax = 0xff
|
|
mpNegFixNumMax = 0xff
|
|
|
|
|
|
|
|
- // extensions below
|
|
|
|
|
- // mpBin8 = 0xc4
|
|
|
|
|
- // mpBin16 = 0xc5
|
|
|
|
|
- // mpBin32 = 0xc6
|
|
|
|
|
- // mpExt8 = 0xc7
|
|
|
|
|
- // mpExt16 = 0xc8
|
|
|
|
|
- // mpExt32 = 0xc9
|
|
|
|
|
- // mpFixExt1 = 0xd4
|
|
|
|
|
- // mpFixExt2 = 0xd5
|
|
|
|
|
- // mpFixExt4 = 0xd6
|
|
|
|
|
- // mpFixExt8 = 0xd7
|
|
|
|
|
- // mpFixExt16 = 0xd8
|
|
|
|
|
-
|
|
|
|
|
- // extensions based off v4: https://gist.github.com/frsyuki/5235364
|
|
|
|
|
- mpXv4Fixext0 = 0xc4
|
|
|
|
|
- mpXv4Fixext1 = 0xc5
|
|
|
|
|
- mpXv4Fixext2 = 0xc6
|
|
|
|
|
- mpXv4Fixext3 = 0xc7
|
|
|
|
|
- mpXv4Fixext4 = 0xc8
|
|
|
|
|
- mpXv4Fixext5 = 0xc9
|
|
|
|
|
-
|
|
|
|
|
- mpXv4Ext8m = 0xd4
|
|
|
|
|
- mpXv4Ext16m = 0xd5
|
|
|
|
|
- mpXv4Ext32m = 0xd6
|
|
|
|
|
- mpXv4Ext8 = 0xd7
|
|
|
|
|
- mpXv4Ext16 = 0xd8
|
|
|
|
|
- mpXv4Ext32 = 0xd9
|
|
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
// MsgpackSpecRpc implements Rpc using the communication protocol defined in
|
|
// MsgpackSpecRpc implements Rpc using the communication protocol defined in
|
|
@@ -78,14 +70,16 @@ var MsgpackSpecRpc msgpackSpecRpc
|
|
|
|
|
|
|
|
// A MsgpackContainer type specifies the different types of msgpackContainers.
|
|
// A MsgpackContainer type specifies the different types of msgpackContainers.
|
|
|
type msgpackContainerType struct {
|
|
type msgpackContainerType struct {
|
|
|
- cutoff int8
|
|
|
|
|
- b0, b1, b2 byte
|
|
|
|
|
|
|
+ fixCutoff int
|
|
|
|
|
+ bFixMin, b8, b16, b32 byte
|
|
|
|
|
+ hasFixMin, has8, has8Always bool
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
var (
|
|
|
- msgpackContainerRawBytes = msgpackContainerType{32, mpFixRawMin, mpRaw16, mpRaw32}
|
|
|
|
|
- msgpackContainerList = msgpackContainerType{16, mpFixArrayMin, mpArray16, mpArray32}
|
|
|
|
|
- msgpackContainerMap = msgpackContainerType{16, mpFixMapMin, mpMap16, mpMap32}
|
|
|
|
|
|
|
+ msgpackContainerStr = msgpackContainerType{32, mpFixStrMin, mpStr8, mpStr16, mpStr32, true, true, false}
|
|
|
|
|
+ msgpackContainerBin = msgpackContainerType{32, 0, mpBin8, mpBin16, mpBin32, false, true, true}
|
|
|
|
|
+ msgpackContainerList = msgpackContainerType{16, mpFixArrayMin, 0, mpArray16, mpArray32, true, false, false}
|
|
|
|
|
+ msgpackContainerMap = msgpackContainerType{16, mpFixMapMin, 0, mpMap16, mpMap32, true, false, false}
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
// msgpackSpecRpc is the implementation of Rpc that uses custom communication protocol
|
|
// msgpackSpecRpc is the implementation of Rpc that uses custom communication protocol
|
|
@@ -104,11 +98,13 @@ type MsgpackHandle struct {
|
|
|
// This setting is used only if an extension func isn't defined for []byte.
|
|
// This setting is used only if an extension func isn't defined for []byte.
|
|
|
RawToString bool
|
|
RawToString bool
|
|
|
// WriteExt flag supports encoding configured extensions with extension tags.
|
|
// WriteExt flag supports encoding configured extensions with extension tags.
|
|
|
|
|
+ // It also controls whether other elements of the new spec are encoded (ie Str8).
|
|
|
|
|
+ //
|
|
|
|
|
+ // With WriteExt=false, configured extensions are serialized as raw bytes
|
|
|
|
|
+ // and Str8 is not encoded.
|
|
|
//
|
|
//
|
|
|
- // With WriteExt=false, configured extensions are serialized as raw bytes.
|
|
|
|
|
- //
|
|
|
|
|
- // They can still be decoded into a typed object, provided an appropriate one is
|
|
|
|
|
- // provided, but the type cannot be inferred from the stream. If no appropriate
|
|
|
|
|
|
|
+ // A stream can still be decoded into a typed value, provided an appropriate value
|
|
|
|
|
+ // is provided, but the type cannot be inferred from the stream. If no appropriate
|
|
|
// type is provided (e.g. decoding into a nil interface{}), you get back
|
|
// type is provided (e.g. decoding into a nil interface{}), you get back
|
|
|
// a []byte or string based on the setting of RawToString.
|
|
// a []byte or string based on the setting of RawToString.
|
|
|
WriteExt bool
|
|
WriteExt bool
|
|
@@ -119,15 +115,17 @@ type MsgpackHandle struct {
|
|
|
|
|
|
|
|
type msgpackEncDriver struct {
|
|
type msgpackEncDriver struct {
|
|
|
w encWriter
|
|
w encWriter
|
|
|
|
|
+ h *MsgpackHandle
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
type msgpackDecDriver struct {
|
|
type msgpackDecDriver struct {
|
|
|
r decReader
|
|
r decReader
|
|
|
|
|
+ h *MsgpackHandle
|
|
|
bd byte
|
|
bd byte
|
|
|
bdRead bool
|
|
bdRead bool
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func (e *msgpackEncDriver) encodeBuiltinType(rt reflect.Type, rv reflect.Value) bool {
|
|
|
|
|
|
|
+func (e *msgpackEncDriver) encodeBuiltinType(rt uintptr, rv reflect.Value) bool {
|
|
|
//no builtin types. All encodings are based on kinds. Types supported as extensions.
|
|
//no builtin types. All encodings are based on kinds. Types supported as extensions.
|
|
|
return false
|
|
return false
|
|
|
}
|
|
}
|
|
@@ -195,19 +193,27 @@ func (e *msgpackEncDriver) encodeFloat64(f float64) {
|
|
|
|
|
|
|
|
func (e *msgpackEncDriver) encodeExtPreamble(xtag byte, l int) {
|
|
func (e *msgpackEncDriver) encodeExtPreamble(xtag byte, l int) {
|
|
|
switch {
|
|
switch {
|
|
|
- case l <= 4:
|
|
|
|
|
- e.w.writen2(0xd4|byte(l), xtag)
|
|
|
|
|
- case l <= 8:
|
|
|
|
|
- e.w.writen2(0xc0|byte(l), xtag)
|
|
|
|
|
|
|
+ case l == 1:
|
|
|
|
|
+ e.w.writen2(mpFixExt1, xtag)
|
|
|
|
|
+ case l == 2:
|
|
|
|
|
+ e.w.writen2(mpFixExt2, xtag)
|
|
|
|
|
+ case l == 4:
|
|
|
|
|
+ e.w.writen2(mpFixExt4, xtag)
|
|
|
|
|
+ case l == 8:
|
|
|
|
|
+ e.w.writen2(mpFixExt8, xtag)
|
|
|
|
|
+ case l == 16:
|
|
|
|
|
+ e.w.writen2(mpFixExt16, xtag)
|
|
|
case l < 256:
|
|
case l < 256:
|
|
|
- e.w.writen2(mpXv4Fixext5, xtag)
|
|
|
|
|
- e.w.writen1(byte(l))
|
|
|
|
|
|
|
+ e.w.writen2(mpExt8, byte(l))
|
|
|
|
|
+ e.w.writen1(xtag)
|
|
|
case l < 65536:
|
|
case l < 65536:
|
|
|
- e.w.writen2(mpXv4Ext16, xtag)
|
|
|
|
|
|
|
+ e.w.writen1(mpExt16)
|
|
|
e.w.writeUint16(uint16(l))
|
|
e.w.writeUint16(uint16(l))
|
|
|
|
|
+ e.w.writen1(xtag)
|
|
|
default:
|
|
default:
|
|
|
- e.w.writen2(mpXv4Ext32, xtag)
|
|
|
|
|
|
|
+ e.w.writen1(mpExt32)
|
|
|
e.w.writeUint32(uint32(l))
|
|
e.w.writeUint32(uint32(l))
|
|
|
|
|
+ e.w.writen1(xtag)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -220,8 +226,11 @@ func (e *msgpackEncDriver) encodeMapPreamble(length int) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func (e *msgpackEncDriver) encodeString(c charEncoding, s string) {
|
|
func (e *msgpackEncDriver) encodeString(c charEncoding, s string) {
|
|
|
- //ignore charEncoding.
|
|
|
|
|
- e.writeContainerLen(msgpackContainerRawBytes, len(s))
|
|
|
|
|
|
|
+ if c == c_RAW && e.h.WriteExt {
|
|
|
|
|
+ e.writeContainerLen(msgpackContainerBin, len(s))
|
|
|
|
|
+ } else {
|
|
|
|
|
+ e.writeContainerLen(msgpackContainerStr, len(s))
|
|
|
|
|
+ }
|
|
|
if len(s) > 0 {
|
|
if len(s) > 0 {
|
|
|
e.w.writestr(s)
|
|
e.w.writestr(s)
|
|
|
}
|
|
}
|
|
@@ -232,8 +241,11 @@ func (e *msgpackEncDriver) encodeSymbol(v string) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func (e *msgpackEncDriver) encodeStringBytes(c charEncoding, bs []byte) {
|
|
func (e *msgpackEncDriver) encodeStringBytes(c charEncoding, bs []byte) {
|
|
|
- //ignore charEncoding.
|
|
|
|
|
- e.writeContainerLen(msgpackContainerRawBytes, len(bs))
|
|
|
|
|
|
|
+ if c == c_RAW && e.h.WriteExt {
|
|
|
|
|
+ e.writeContainerLen(msgpackContainerBin, len(bs))
|
|
|
|
|
+ } else {
|
|
|
|
|
+ e.writeContainerLen(msgpackContainerStr, len(bs))
|
|
|
|
|
+ }
|
|
|
if len(bs) > 0 {
|
|
if len(bs) > 0 {
|
|
|
e.w.writeb(bs)
|
|
e.w.writeb(bs)
|
|
|
}
|
|
}
|
|
@@ -241,20 +253,22 @@ func (e *msgpackEncDriver) encodeStringBytes(c charEncoding, bs []byte) {
|
|
|
|
|
|
|
|
func (e *msgpackEncDriver) writeContainerLen(ct msgpackContainerType, l int) {
|
|
func (e *msgpackEncDriver) writeContainerLen(ct msgpackContainerType, l int) {
|
|
|
switch {
|
|
switch {
|
|
|
- case l < int(ct.cutoff):
|
|
|
|
|
- e.w.writen1(ct.b0 | byte(l))
|
|
|
|
|
|
|
+ case ct.hasFixMin && l < ct.fixCutoff:
|
|
|
|
|
+ e.w.writen1(ct.bFixMin | byte(l))
|
|
|
|
|
+ case ct.has8 && l < 256 && (ct.has8Always || e.h.WriteExt):
|
|
|
|
|
+ e.w.writen2(ct.b8, uint8(l))
|
|
|
case l < 65536:
|
|
case l < 65536:
|
|
|
- e.w.writen1(ct.b1)
|
|
|
|
|
|
|
+ e.w.writen1(ct.b16)
|
|
|
e.w.writeUint16(uint16(l))
|
|
e.w.writeUint16(uint16(l))
|
|
|
default:
|
|
default:
|
|
|
- e.w.writen1(ct.b2)
|
|
|
|
|
|
|
+ e.w.writen1(ct.b32)
|
|
|
e.w.writeUint32(uint32(l))
|
|
e.w.writeUint32(uint32(l))
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------
|
|
//---------------------------------------------
|
|
|
|
|
|
|
|
-func (d *msgpackDecDriver) decodeBuiltinType(rt reflect.Type, rv reflect.Value) bool {
|
|
|
|
|
|
|
+func (d *msgpackDecDriver) decodeBuiltinType(rt uintptr, rv reflect.Value) bool {
|
|
|
return false
|
|
return false
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -309,9 +323,9 @@ func (d *msgpackDecDriver) decodeNaked(h decodeHandleI) (rv reflect.Value, ctx d
|
|
|
case bd >= mpNegFixNumMin && bd <= mpNegFixNumMax:
|
|
case bd >= mpNegFixNumMin && bd <= mpNegFixNumMax:
|
|
|
// negative fixnum
|
|
// negative fixnum
|
|
|
v = int64(int8(bd))
|
|
v = int64(int8(bd))
|
|
|
- case bd == mpRaw16, bd == mpRaw32, bd >= mpFixRawMin && bd <= mpFixRawMax:
|
|
|
|
|
|
|
+ case bd == mpStr8, bd == mpStr16, bd == mpStr32, bd >= mpFixStrMin && bd <= mpFixStrMax:
|
|
|
ctx = dncContainer
|
|
ctx = dncContainer
|
|
|
- // v = containerRawBytes
|
|
|
|
|
|
|
+ // v = containerRaw
|
|
|
opts := h.(*MsgpackHandle)
|
|
opts := h.(*MsgpackHandle)
|
|
|
if opts.rawToStringOverride || opts.RawToString {
|
|
if opts.rawToStringOverride || opts.RawToString {
|
|
|
var rvm string
|
|
var rvm string
|
|
@@ -337,20 +351,17 @@ func (d *msgpackDecDriver) decodeNaked(h decodeHandleI) (rv reflect.Value, ctx d
|
|
|
} else {
|
|
} else {
|
|
|
rv = reflect.MakeMap(opts.MapType)
|
|
rv = reflect.MakeMap(opts.MapType)
|
|
|
}
|
|
}
|
|
|
- case bd >= mpXv4Fixext0 && bd <= mpXv4Fixext5, bd >= mpXv4Ext8m && bd <= mpXv4Ext32:
|
|
|
|
|
|
|
+ case bd >= mpFixExt1 && bd <= mpFixExt16, bd >= mpExt8 && bd <= mpExt32:
|
|
|
//ctx = dncExt
|
|
//ctx = dncExt
|
|
|
|
|
+ clen := d.readExtLen()
|
|
|
xtag := d.r.readn1()
|
|
xtag := d.r.readn1()
|
|
|
opts := h.(*MsgpackHandle)
|
|
opts := h.(*MsgpackHandle)
|
|
|
- rt, bfn := opts.getDecodeExtForTag(xtag)
|
|
|
|
|
- if rt == nil {
|
|
|
|
|
|
|
+ var bfn func(reflect.Value, []byte) error
|
|
|
|
|
+ rv, bfn = opts.getDecodeExtForTag(xtag)
|
|
|
|
|
+ if bfn == nil {
|
|
|
decErr("Unable to find type mapped to extension tag: %v", xtag)
|
|
decErr("Unable to find type mapped to extension tag: %v", xtag)
|
|
|
}
|
|
}
|
|
|
- if rt.Kind() == reflect.Ptr {
|
|
|
|
|
- rv = reflect.New(rt.Elem())
|
|
|
|
|
- } else {
|
|
|
|
|
- rv = reflect.New(rt).Elem()
|
|
|
|
|
- }
|
|
|
|
|
- if fnerr := bfn(rv, d.r.readn(d.readExtLen())); fnerr != nil {
|
|
|
|
|
|
|
+ if fnerr := bfn(rv, d.r.readn(clen)); fnerr != nil {
|
|
|
panic(fnerr)
|
|
panic(fnerr)
|
|
|
}
|
|
}
|
|
|
default:
|
|
default:
|
|
@@ -499,7 +510,7 @@ func (d *msgpackDecDriver) decodeBool() (b bool) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func (d *msgpackDecDriver) decodeString() (s string) {
|
|
func (d *msgpackDecDriver) decodeString() (s string) {
|
|
|
- clen := d.readContainerLen(msgpackContainerRawBytes)
|
|
|
|
|
|
|
+ clen := d.readContainerLen(msgpackContainerStr)
|
|
|
if clen > 0 {
|
|
if clen > 0 {
|
|
|
s = string(d.r.readn(clen))
|
|
s = string(d.r.readn(clen))
|
|
|
}
|
|
}
|
|
@@ -509,7 +520,7 @@ func (d *msgpackDecDriver) decodeString() (s string) {
|
|
|
|
|
|
|
|
// Callers must check if changed=true (to decide whether to replace the one they have)
|
|
// Callers must check if changed=true (to decide whether to replace the one they have)
|
|
|
func (d *msgpackDecDriver) decodeBytes(bs []byte) (bsOut []byte, changed bool) {
|
|
func (d *msgpackDecDriver) decodeBytes(bs []byte) (bsOut []byte, changed bool) {
|
|
|
- clen := d.readContainerLen(msgpackContainerRawBytes)
|
|
|
|
|
|
|
+ clen := d.readContainerLen(msgpackContainerBin)
|
|
|
// if clen < 0 {
|
|
// if clen < 0 {
|
|
|
// changed = true
|
|
// changed = true
|
|
|
// panic("length cannot be zero. this cannot be nil.")
|
|
// panic("length cannot be zero. this cannot be nil.")
|
|
@@ -553,12 +564,14 @@ func (d *msgpackDecDriver) readContainerLen(ct msgpackContainerType) (clen int)
|
|
|
switch {
|
|
switch {
|
|
|
case d.bd == mpNil:
|
|
case d.bd == mpNil:
|
|
|
clen = -1 // to represent nil
|
|
clen = -1 // to represent nil
|
|
|
- case d.bd == ct.b1:
|
|
|
|
|
|
|
+ case d.bd == ct.b8:
|
|
|
|
|
+ clen = int(d.r.readn1())
|
|
|
|
|
+ case d.bd == ct.b16:
|
|
|
clen = int(d.r.readUint16())
|
|
clen = int(d.r.readUint16())
|
|
|
- case d.bd == ct.b2:
|
|
|
|
|
|
|
+ case d.bd == ct.b32:
|
|
|
clen = int(d.r.readUint32())
|
|
clen = int(d.r.readUint32())
|
|
|
- case (ct.b0 & d.bd) == ct.b0:
|
|
|
|
|
- clen = int(ct.b0 ^ d.bd)
|
|
|
|
|
|
|
+ case (ct.bFixMin & d.bd) == ct.bFixMin:
|
|
|
|
|
+ clen = int(ct.bFixMin ^ d.bd)
|
|
|
default:
|
|
default:
|
|
|
decErr("readContainerLen: %s: hex: %x, dec: %d", msgBadDesc, d.bd, d.bd)
|
|
decErr("readContainerLen: %s: hex: %x, dec: %d", msgBadDesc, d.bd, d.bd)
|
|
|
}
|
|
}
|
|
@@ -578,39 +591,42 @@ func (d *msgpackDecDriver) readExtLen() (clen int) {
|
|
|
switch d.bd {
|
|
switch d.bd {
|
|
|
case mpNil:
|
|
case mpNil:
|
|
|
clen = -1 // to represent nil
|
|
clen = -1 // to represent nil
|
|
|
- case mpXv4Fixext5:
|
|
|
|
|
|
|
+ case mpFixExt1:
|
|
|
|
|
+ clen = 1
|
|
|
|
|
+ case mpFixExt2:
|
|
|
|
|
+ clen = 2
|
|
|
|
|
+ case mpFixExt4:
|
|
|
|
|
+ clen = 4
|
|
|
|
|
+ case mpFixExt8:
|
|
|
|
|
+ clen = 8
|
|
|
|
|
+ case mpFixExt16:
|
|
|
|
|
+ clen = 16
|
|
|
|
|
+ case mpExt8:
|
|
|
clen = int(d.r.readn1())
|
|
clen = int(d.r.readn1())
|
|
|
- case mpXv4Ext16:
|
|
|
|
|
|
|
+ case mpExt16:
|
|
|
clen = int(d.r.readUint16())
|
|
clen = int(d.r.readUint16())
|
|
|
- case mpXv4Ext32:
|
|
|
|
|
|
|
+ case mpExt32:
|
|
|
clen = int(d.r.readUint32())
|
|
clen = int(d.r.readUint32())
|
|
|
default:
|
|
default:
|
|
|
- switch {
|
|
|
|
|
- case d.bd >= mpXv4Fixext0 && d.bd <= mpXv4Fixext4:
|
|
|
|
|
- clen = int(d.bd & 0x0f)
|
|
|
|
|
- case d.bd >= mpXv4Ext8m && d.bd <= mpXv4Ext8:
|
|
|
|
|
- clen = int(d.bd & 0x03)
|
|
|
|
|
- default:
|
|
|
|
|
- decErr("decoding ext bytes: found unexpected byte: %x", d.bd)
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ decErr("decoding ext bytes: found unexpected byte: %x", d.bd)
|
|
|
}
|
|
}
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func (d *msgpackDecDriver) decodeExt(tag byte) (xbs []byte) {
|
|
func (d *msgpackDecDriver) decodeExt(tag byte) (xbs []byte) {
|
|
|
- // if (d.bd >= mpXv4Fixext0 && d.bd <= mpXv4Fixext5) ||
|
|
|
|
|
- // (d.bd >= mpXv4Ext8m && d.bd <= mpXv4Ext32) {
|
|
|
|
|
xbd := d.bd
|
|
xbd := d.bd
|
|
|
switch {
|
|
switch {
|
|
|
- case xbd >= mpXv4Fixext0 && xbd <= mpXv4Fixext5, xbd >= mpXv4Ext8m && xbd <= mpXv4Ext32:
|
|
|
|
|
|
|
+ case xbd == mpBin8, xbd == mpBin16, xbd == mpBin32:
|
|
|
|
|
+ xbs, _ = d.decodeBytes(nil)
|
|
|
|
|
+ case xbd == mpStr8, xbd == mpStr16, xbd == mpStr32,
|
|
|
|
|
+ xbd >= mpFixStrMin && xbd <= mpFixStrMax:
|
|
|
|
|
+ xbs = []byte(d.decodeString())
|
|
|
|
|
+ default:
|
|
|
|
|
+ clen := d.readExtLen()
|
|
|
if xtag := d.r.readn1(); xtag != tag {
|
|
if xtag := d.r.readn1(); xtag != tag {
|
|
|
decErr("Wrong extension tag. Got %b. Expecting: %v", xtag, tag)
|
|
decErr("Wrong extension tag. Got %b. Expecting: %v", xtag, tag)
|
|
|
}
|
|
}
|
|
|
- xbs = d.r.readn(d.readExtLen())
|
|
|
|
|
- case xbd == mpRaw16, xbd == mpRaw32, xbd >= mpFixRawMin && xbd <= mpFixRawMax:
|
|
|
|
|
- xbs, _ = d.decodeBytes(nil)
|
|
|
|
|
- default:
|
|
|
|
|
- decErr("Wrong byte descriptor (Expecting extensions or raw bytes). Got: 0x%x", xbd)
|
|
|
|
|
|
|
+ xbs = d.r.readn(clen)
|
|
|
}
|
|
}
|
|
|
d.bdRead = false
|
|
d.bdRead = false
|
|
|
return
|
|
return
|
|
@@ -729,14 +745,24 @@ func (_ *MsgpackHandle) TimeDecodeExt(rv reflect.Value, bs []byte) (err error) {
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func (_ *MsgpackHandle) newEncDriver(w encWriter) encDriver {
|
|
|
|
|
- return &msgpackEncDriver{w: w}
|
|
|
|
|
|
|
+func (h *MsgpackHandle) newEncDriver(w encWriter) encDriver {
|
|
|
|
|
+ return &msgpackEncDriver{w: w, h: h}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func (_ *MsgpackHandle) newDecDriver(r decReader) decDriver {
|
|
|
|
|
- return &msgpackDecDriver{r: r}
|
|
|
|
|
|
|
+func (h *MsgpackHandle) newDecDriver(r decReader) decDriver {
|
|
|
|
|
+ return &msgpackDecDriver{r: r, h: h}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func (o *MsgpackHandle) writeExt() bool {
|
|
|
|
|
- return o.WriteExt
|
|
|
|
|
|
|
+func (h *MsgpackHandle) writeExt() bool {
|
|
|
|
|
+ return h.WriteExt
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|