MCPcopy Create free account
hub / github.com/blues/note / binExtract

Method binExtract

lib/bulk.go:175–196  ·  view source on GitHub ↗

Data extraction routines

(ctx context.Context, what string, n int)

Source from the content-addressed store, hash-verified

173
174// Data extraction routines
175func (tmplContext *BulkTemplateContext) binExtract(ctx context.Context, what string, n int) (value []byte, success bool) {
176 // Catch bogus values of n
177 if n < 0 || (tmplContext.BinOffset+n) < 0 {
178 logWarn(ctx, "bulk underrun: invalid value of n %d at offset %d", n, tmplContext.BinOffset)
179 tmplContext.BinUnderrun = true
180 }
181
182 if (tmplContext.BinOffset + n) > tmplContext.BinLen {
183 logWarn(ctx, "bulk underrun: want %d at offset %d but record len is only %d", n, tmplContext.BinOffset, tmplContext.BinLen)
184 tmplContext.BinUnderrun = true
185 }
186 if tmplContext.BinUnderrun {
187 return
188 }
189 value = tmplContext.Bin[tmplContext.BinOffset : tmplContext.BinOffset+n]
190 if debugJSONBin {
191 logDebug(ctx, "binExtract(%s %d:%d): %X\n", what, tmplContext.BinOffset, n, value)
192 }
193 tmplContext.BinOffset += n
194 success = true
195 return
196}
197
198func (tmplContext *BulkTemplateContext) binExtractInt8(ctx context.Context, what string) (value int8) {
199 bin, success := tmplContext.binExtract(ctx, what, 1)

Callers 15

binExtractInt8Method · 0.95
binExtractUint8Method · 0.95
binExtractInt16Method · 0.95
binExtractUint16Method · 0.95
binExtractInt24Method · 0.95
binExtractUint24Method · 0.95
binExtractInt32Method · 0.95
binExtractUint32Method · 0.95
binExtractInt40Method · 0.95
binExtractUint40Method · 0.95
binExtractInt48Method · 0.95
binExtractUint48Method · 0.95

Calls 2

logWarnFunction · 0.85
logDebugFunction · 0.85

Tested by

no test coverage detected