MCPcopy Create free account
hub / github.com/couchbase/moss / Valid

Method Valid

segment.go:724–758  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

722}
723
724func (a *segment) Valid() error {
725 if a.kvs == nil || len(a.kvs) <= 0 {
726 return fmt.Errorf("expected kvs")
727 }
728 if a.buf == nil || len(a.buf) <= 0 {
729 return fmt.Errorf("expected buf")
730 }
731 for pos := 0; pos < a.Len(); pos++ {
732 x := pos * 2
733 if x < 0 || x >= len(a.kvs) {
734 return fmt.Errorf("pos to x error")
735 }
736
737 opklvl := a.kvs[x]
738
739 operation, keyLen, valLen := decodeOpKeyLenValLen(opklvl)
740 if operation == 0 {
741 return fmt.Errorf("should have some nonzero op")
742 }
743
744 kstart := int(a.kvs[x+1])
745 vstart := kstart + keyLen
746
747 if kstart+keyLen > len(a.buf) {
748 return fmt.Errorf("key larger than buf, pos: %d, kstart: %d, keyLen: %d, len(buf): %d, op: %x",
749 pos, kstart, keyLen, len(a.buf), operation)
750 }
751 if vstart+valLen > len(a.buf) {
752 return fmt.Errorf("val larger than buf, pos: %d, vstart: %d, valLen: %d, len(buf): %d, op: %x",
753 pos, vstart, valLen, len(a.buf), operation)
754 }
755 }
756
757 return nil
758}
759
760// ------------------------------------------------------
761

Callers

nothing calls this directly

Calls 2

LenMethod · 0.95
decodeOpKeyLenValLenFunction · 0.85

Tested by

no test coverage detected