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)
| 925 | // - [ErrShortBytes] (b not long enough) |
| 926 | // - [TypeError] (object not 'str') |
| 927 | func 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 |
searching dependent graphs…