in binary.go [46:82]
func encBinary(b []byte, v []byte) []byte {
var (
length uint16
vLength int
)
if v == nil {
return encByte(b, BC_NULL)
}
vLength = len(v)
for {
if vLength > CHUNK_SIZE {
length = CHUNK_SIZE
b = encByte(b, BC_BINARY_CHUNK, byte(length>>8), byte(length))
} else {
length = uint16(vLength)
if vLength <= int(BINARY_DIRECT_MAX) {
b = encByte(b, byte(int(BC_BINARY_DIRECT)+vLength))
} else if vLength <= int(BINARY_SHORT_MAX) {
b = encByte(b, byte(int(BC_BINARY_SHORT)+vLength>>8), byte(vLength))
} else {
b = encByte(b, BC_BINARY, byte(vLength>>8), byte(vLength))
}
}
b = append(b, v[:length]...)
v = v[length:]
vLength = len(v)
if vLength == 0 {
break
}
}
return b
}