Data extraction routines
(ctx context.Context, what string, n int)
| 173 | |
| 174 | // Data extraction routines |
| 175 | func (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 | |
| 198 | func (tmplContext *BulkTemplateContext) binExtractInt8(ctx context.Context, what string) (value int8) { |
| 199 | bin, success := tmplContext.binExtract(ctx, what, 1) |
no test coverage detected