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

Function ReadStringZC

msgp/read_bytes.go:927–978  ·  view source on GitHub ↗

ReadStringZC reads a messagepack string field without copying. The returned []byte points to the same memory as the input slice. Possible errors: - [ErrShortBytes] (b not long enough) - [TypeError] (object not 'str')

(b []byte)

Source from the content-addressed store, hash-verified

925// - [ErrShortBytes] (b not long enough)
926// - [TypeError] (object not 'str')
927func ReadStringZC(b []byte) (v []byte, o []byte, err error) {
928 if len(b) < 1 {
929 return nil, nil, ErrShortBytes
930 }
931
932 lead := b[0]
933 var read int
934
935 b = b[1:]
936 if isfixstr(lead) {
937 read = int(rfixstr(lead))
938 } else {
939 switch lead {
940 case mstr8:
941 if len(b) < 1 {
942 err = ErrShortBytes
943 return
944 }
945 read = int(b[0])
946 b = b[1:]
947
948 case mstr16:
949 if len(b) < 2 {
950 err = ErrShortBytes
951 return
952 }
953 read = int(big.Uint16(b))
954 b = b[2:]
955
956 case mstr32:
957 if len(b) < 4 {
958 err = ErrShortBytes
959 return
960 }
961 read = int(big.Uint32(b))
962 b = b[4:]
963
964 default:
965 err = TypeError{Method: StrType, Encoded: getType(lead)}
966 return
967 }
968 }
969
970 if len(b) < read {
971 err = ErrShortBytes
972 return
973 }
974
975 v = b[0:read]
976 o = b[read:]
977 return
978}
979
980// ReadStringBytes reads a 'str' object
981// from 'b' and returns its value and the

Callers 10

mainFunction · 0.92
TestReadZCStringFunction · 0.85
FuzzReadBytesFunction · 0.85
rwStringBytesFunction · 0.85
HasKeyFunction · 0.85
locateFunction · 0.85
locateKVFunction · 0.85
ReadMapKeyZCFunction · 0.85
ReadStringBytesFunction · 0.85
ReadStringAsBytesFunction · 0.85

Calls 3

isfixstrFunction · 0.85
rfixstrFunction · 0.85
getTypeFunction · 0.85

Tested by 2

TestReadZCStringFunction · 0.68
FuzzReadBytesFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…