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

Method ReadMapKeyPtr

msgp/read.go:490–532  ·  view source on GitHub ↗

ReadMapKeyPtr returns a []byte pointing to the contents of a valid map key. The key cannot be empty, and it must be shorter than the total buffer size of the *Reader. Additionally, the returned slice is only valid until the next *Reader method call. Users should exercise extreme care when using this

()

Source from the content-addressed store, hash-verified

488// method; writing into the returned slice may
489// corrupt future reads.
490func (m *Reader) ReadMapKeyPtr() ([]byte, error) {
491 lead, err := m.R.PeekByte()
492 if err != nil {
493 return nil, err
494 }
495 var read int
496 var p []byte
497 if isfixstr(lead) {
498 read = int(rfixstr(lead))
499 m.R.Skip(1)
500 goto fill
501 }
502 switch lead {
503 case mstr8, mbin8:
504 p, err = m.R.Next(2)
505 if err != nil {
506 return nil, err
507 }
508 read = int(p[1])
509 case mstr16, mbin16:
510 p, err = m.R.Next(3)
511 if err != nil {
512 return nil, err
513 }
514 read = int(big.Uint16(p[1:]))
515 case mstr32, mbin32:
516 p, err = m.R.Next(5)
517 if err != nil {
518 return nil, err
519 }
520 read = int(big.Uint32(p[1:]))
521 default:
522 return nil, badPrefix(StrType, lead)
523 }
524fill:
525 if read == 0 {
526 return nil, ErrShortBytes
527 }
528 if uint64(read) > m.GetMaxStringLength() {
529 return nil, ErrLimitExceeded
530 }
531 return m.R.Next(read)
532}
533
534// ReadArrayHeader reads the next object as an
535// array header and returns the size of the array

Callers 2

FuzzReaderFunction · 0.95
rwMapFunction · 0.80

Calls 5

GetMaxStringLengthMethod · 0.95
isfixstrFunction · 0.85
rfixstrFunction · 0.85
badPrefixFunction · 0.85
SkipMethod · 0.80

Tested by 1

FuzzReaderFunction · 0.76