MCPcopy
hub / github.com/bradfitz/gomemcache / scanGetResponseLine

Function scanGetResponseLine

memcache/memcache.go:552–591  ·  view source on GitHub ↗

scanGetResponseLine populates it and returns the declared size of the item. It does not read the bytes of the item.

(line []byte, it *Item)

Source from the content-addressed store, hash-verified

550// scanGetResponseLine populates it and returns the declared size of the item.
551// It does not read the bytes of the item.
552func scanGetResponseLine(line []byte, it *Item) (size int, err error) {
553 errf := func(line []byte) (int, error) {
554 return -1, fmt.Errorf("memcache: unexpected line in get response: %q", line)
555 }
556 if !bytes.HasPrefix(line, []byte("VALUE ")) || !bytes.HasSuffix(line, []byte("\r\n")) {
557 return errf(line)
558 }
559 s := string(line[6 : len(line)-2])
560 var rest string
561 var found bool
562 it.Key, rest, found = cut(s, ' ')
563 if !found {
564 return errf(line)
565 }
566 val, rest, found := cut(rest, ' ')
567 if !found {
568 return errf(line)
569 }
570 flags64, err := strconv.ParseUint(val, 10, 32)
571 if err != nil {
572 return errf(line)
573 }
574 it.Flags = uint32(flags64)
575 val, rest, found = cut(rest, ' ')
576 size64, err := strconv.ParseUint(val, 10, 32)
577 if err != nil {
578 return errf(line)
579 }
580 if size64 > math.MaxInt { // Can happen if int is 32-bit
581 return errf(line)
582 }
583 if !found { // final CAS ID is optional.
584 return int(size64), nil
585 }
586 it.CasID, err = strconv.ParseUint(rest, 10, 64)
587 if err != nil {
588 return errf(line)
589 }
590 return int(size64), nil
591}
592
593// Similar to strings.Cut in Go 1.18, but sep can only be 1 byte.
594func cut(s string, sep byte) (before, after string, found bool) {

Callers 3

parseGetResponseFunction · 0.85
TestScanGetResponseLineFunction · 0.85

Calls 1

cutFunction · 0.85

Tested by 2

TestScanGetResponseLineFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…