Browse Source

codec: msgpack: handle binary when decoding into a string.

Fixes #96
Ugorji Nwoke 10 years ago
parent
commit
5c83d75b24
1 changed files with 5 additions and 9 deletions
  1. 5 9
      codec/msgpack.go

+ 5 - 9
codec/msgpack.go

@@ -536,15 +536,11 @@ func (d *msgpackDecDriver) DecodeBytes(bs []byte, isstring, zerocopy bool) (bsOu
 		d.readNextBd()
 		d.readNextBd()
 	}
 	}
 	var clen int
 	var clen int
-	if isstring {
-		clen = d.readContainerLen(msgpackContainerStr)
+	// ignore isstring. Expect that the bytes may be found from msgpackContainerStr or msgpackContainerBin
+	if bd := d.bd; bd == mpBin8 || bd == mpBin16 || bd == mpBin32 {
+		clen = d.readContainerLen(msgpackContainerBin)
 	} else {
 	} else {
-		// bytes can be decoded from msgpackContainerStr or msgpackContainerBin
-		if bd := d.bd; bd == mpBin8 || bd == mpBin16 || bd == mpBin32 {
-			clen = d.readContainerLen(msgpackContainerBin)
-		} else {
-			clen = d.readContainerLen(msgpackContainerStr)
-		}
+		clen = d.readContainerLen(msgpackContainerStr)
 	}
 	}
 	// println("DecodeBytes: clen: ", clen)
 	// println("DecodeBytes: clen: ", clen)
 	d.bdRead = false
 	d.bdRead = false
@@ -617,7 +613,7 @@ func (d *msgpackDecDriver) readContainerLen(ct msgpackContainerType) (clen int)
 	} else if (ct.bFixMin & bd) == ct.bFixMin {
 	} else if (ct.bFixMin & bd) == ct.bFixMin {
 		clen = int(ct.bFixMin ^ bd)
 		clen = int(ct.bFixMin ^ bd)
 	} else {
 	} else {
-		d.d.errorf("readContainerLen: %s: hex: %x, dec: %d", msgBadDesc, bd, bd)
+		d.d.errorf("readContainerLen: %s: hex: %x, decimal: %d", msgBadDesc, bd, bd)
 		return
 		return
 	}
 	}
 	d.bdRead = false
 	d.bdRead = false