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

Function locate

msgp/edit.go:115–150  ·  view source on GitHub ↗

locate does a naive O(n) search for the map key; returns start, end (returns 0,0 on error)

(raw []byte, key string)

Source from the content-addressed store, hash-verified

113// locate does a naive O(n) search for the map key; returns start, end
114// (returns 0,0 on error)
115func locate(raw []byte, key string) (start int, end int) {
116 var (
117 sz uint32
118 bts []byte
119 field []byte
120 err error
121 )
122 sz, bts, err = ReadMapHeaderBytes(raw)
123 if err != nil {
124 return
125 }
126
127 // loop and locate field
128 for i := uint32(0); i < sz; i++ {
129 field, bts, err = ReadStringZC(bts)
130 if err != nil {
131 return 0, 0
132 }
133 if UnsafeString(field) == key {
134 // start location
135 l := len(raw)
136 start = l - len(bts)
137 bts, err = Skip(bts)
138 if err != nil {
139 return 0, 0
140 }
141 end = l - len(bts)
142 return
143 }
144 bts, err = Skip(bts)
145 if err != nil {
146 return 0, 0
147 }
148 }
149 return 0, 0
150}
151
152// locate key AND value
153func locateKV(raw []byte, key string) (start int, end int) {

Callers 3

LocateFunction · 0.85
ReplaceFunction · 0.85
CopyReplaceFunction · 0.85

Calls 4

ReadMapHeaderBytesFunction · 0.85
ReadStringZCFunction · 0.85
SkipFunction · 0.85
UnsafeStringFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…