in dax/internal/cbor/cbor.go [430:482]
func (r *Reader) readRawTypeHeader(o io.Writer) (hdr int, value uint64, err error) {
b, err := r.br.ReadByte()
if err != nil {
return 0, 0, err
}
// Use the buffer r.buf to store the header byte and write it to output writer o
if o != nil {
r.buf[0] = b
if _, err = o.Write(r.buf[:1]); err != nil {
return 0, 0, err
}
}
hdr = int(b)
c := 0
// Read the remaining bytes and store them at buffer r.buf
switch hdr & MinorTypeMask {
default:
value = uint64(hdr) & MinorTypeMask
return // no more byte to read
case Size8:
c = 1
if _, err = io.ReadFull(r.br, r.buf[:c]); err == nil {
value = uint64(r.buf[0])
}
case Size16:
c = 2
if _, err = io.ReadFull(r.br, r.buf[:c]); err == nil {
value = uint64(binary.BigEndian.Uint16(r.buf))
}
case Size32:
c = 4
if _, err = io.ReadFull(r.br, r.buf[:c]); err == nil {
value = uint64(binary.BigEndian.Uint32(r.buf))
}
case Size64:
c = 8
if _, err = io.ReadFull(r.br, r.buf[:c]); err == nil {
value = binary.BigEndian.Uint64(r.buf)
}
}
// Write remaining bytes stored in r.buf to output writer o
if o != nil {
if _, err = o.Write(r.buf[:c]); err != nil {
return 0, 0, err
}
}
return
}