MCPcopy
hub / github.com/tinylib/msgp / readBytesBytes

Function readBytesBytes

msgp/read_bytes.go:796–856  ·  view source on GitHub ↗
(b []byte, scratch []byte, zc bool)

Source from the content-addressed store, hash-verified

794}
795
796func readBytesBytes(b []byte, scratch []byte, zc bool) (v []byte, o []byte, err error) {
797 l := len(b)
798 if l < 1 {
799 return nil, nil, ErrShortBytes
800 }
801
802 lead := b[0]
803 b = b[1:]
804 var read int
805 switch lead {
806 case mbin8:
807 if len(b) < 1 {
808 err = ErrShortBytes
809 return
810 }
811
812 read = int(b[0])
813 b = b[1:]
814
815 case mbin16:
816 if len(b) < 2 {
817 err = ErrShortBytes
818 return
819 }
820 read = int(big.Uint16(b))
821 b = b[2:]
822
823 case mbin32:
824 if len(b) < 4 {
825 err = ErrShortBytes
826 return
827 }
828 read = int(big.Uint32(b))
829 b = b[4:]
830
831 default:
832 err = badPrefix(BinType, lead)
833 return
834 }
835
836 if len(b) < read {
837 err = ErrShortBytes
838 return
839 }
840
841 // zero-copy
842 if zc {
843 v = b[0:read]
844 o = b[read:]
845 return
846 }
847
848 if cap(scratch) >= read {
849 v = scratch[0:read]
850 } else {
851 v = make([]byte, read)
852 }
853

Callers 2

ReadBytesBytesFunction · 0.85
ReadBytesZCFunction · 0.85

Calls 1

badPrefixFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…