MCPcopy Index your code
hub / github.com/CrowdStrike/csproto / DecodeString

Method DecodeString

decoder.go:166–182  ·  view source on GitHub ↗

DecodeString decodes a length-delimited string from the stream and returns the value. io.ErrUnexpectedEOF is returned if the operation would read past the end of the data.

()

Source from the content-addressed store, hash-verified

164//
165// io.ErrUnexpectedEOF is returned if the operation would read past the end of the data.
166func (d *Decoder) DecodeString() (string, error) {
167 if d.offset >= len(d.p) {
168 return "", io.ErrUnexpectedEOF
169 }
170 b, err := d.DecodeBytes()
171 if err != nil {
172 return "", fmt.Errorf("invalid data at byte %d: %w", d.offset, err)
173 }
174 switch d.mode {
175 case DecoderModeFast:
176 return *(*string)(unsafe.Pointer(&b)), nil //nolint: gosec // using unsafe on purpose
177
178 default:
179 // safe mode by default
180 return string(b), nil
181 }
182}
183
184// DecodeBytes decodes a length-delimited slice of bytes from the stream and returns the value.
185//

Callers 15

TestDecodeStringFunction · 0.95
UnmarshalMethod · 0.95
UnmarshalMethod · 0.95
UnmarshalMethod · 0.95
UnmarshalMethod · 0.95
UnmarshalMethod · 0.95
UnmarshalMethod · 0.95
UnmarshalMethod · 0.95
UnmarshalMethod · 0.95

Calls 1

DecodeBytesMethod · 0.95

Tested by 4

TestDecodeStringFunction · 0.76