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

Method BulkDecodeNextEntry

lib/bulk.go:461–915  ·  view source on GitHub ↗

BulkDecodeNextEntry extract a JSON object from the binary. Note that both 'when' and 'wherewhen' returned in standard unix epoch seconds (not in nanoseconds)

(ctx context.Context)

Source from the content-addressed store, hash-verified

459// BulkDecodeNextEntry extract a JSON object from the binary. Note that both 'when' and 'wherewhen'
460// returned in standard unix epoch seconds (not in nanoseconds)
461func (tmplContext *BulkTemplateContext) BulkDecodeNextEntry(ctx context.Context) (body map[string]interface{}, payload []byte, when int64, wherewhen int64, olc string, noteID string, success bool) {
462
463 // Exit if nothing left
464 if tmplContext.BinLen == 0 {
465 if debugBin {
466 logDebug(ctx, "bulk: nothing left")
467 }
468 return
469 }
470
471 // Trace
472 if debugBin {
473 logDebug(ctx, "%x", tmplContext.Bin)
474 }
475
476 // Plug the noteID into the context for later substitution
477 tmplContext.noteID = noteID
478
479 // Extract the bin header, and process the variable-length area
480 noOmitEmpty := false
481 var flags uint64
482 var binHeader uint8
483
484 if tmplContext.NoteFormat == BulkNoteFormatOriginal {
485
486 // If there was a payload, extract it
487 if tmplContext.ORIGTemplatePayloadLen != 0 {
488 tmplContext.BinOffset = tmplContext.ORIGTemplatePayloadOffset
489 payload = tmplContext.binExtractBytes(ctx, "orig-payload", tmplContext.ORIGTemplatePayloadLen)
490 }
491
492 // If there were flags, extract them
493 if tmplContext.ORIGTemplateFlagsOffset != 0 {
494 tmplContext.BinOffset = tmplContext.ORIGTemplateFlagsOffset
495 flags = tmplContext.binExtractUint64(ctx, "orig-flags")
496 }
497
498 } else {
499
500 // Extract the header and variable-length area position
501 tmplContext.BinOffset = 0
502 binHeader = tmplContext.binExtractUint8(ctx, "binhdr")
503
504 // Check if NO_VARIABLE flag is set
505 if (binHeader & bulkflagNoVariable) != 0 {
506 // No variable section - mask off all variable data flags and skip reading offset
507 binHeader &= ^uint8(bulkflagPayloadL | bulkflagPayloadH |
508 bulkflagFlagsL | bulkflagFlagsH |
509 bulkflagOLCL | bulkflagOLCH)
510 // tmplContext.BinOffset remains at current position (1)
511 } else {
512 // Has variable section, read the offset
513 tmplContext.BinOffset = int(tmplContext.binExtractUint16(ctx, "binoff"))
514 }
515
516 // Extract the No OmitEmpty flag
517 noOmitEmpty = (binHeader & bulkflagNoOmitEmpty) != 0
518

Callers 10

hubNotefileAddNoteFunction · 0.95
hubWebRequestFunction · 0.80
TestBulkDecodeFunction · 0.80
TestBulkEncodeFunction · 0.80
TestVariableLengthArraysFunction · 0.80
TestBulkFlagNoVariableFunction · 0.80
TestBulkEncodeDecodeFunction · 0.80
TestOLCEncodingRoundTripFunction · 0.80
TestBulkTimeFieldType23Function · 0.80
eventBulkFunction · 0.80

Calls 15

binExtractBytesMethod · 0.95
binExtractUint64Method · 0.95
binExtractUint8Method · 0.95
binExtractUint16Method · 0.95
binExtractUint32Method · 0.95
binExtractInt64Method · 0.95
UseNumberMethod · 0.95
TokenMethod · 0.95
binExtractStringMethod · 0.95
MoreMethod · 0.95
binExtractInt8Method · 0.95
binExtractInt16Method · 0.95

Tested by 7

TestBulkDecodeFunction · 0.64
TestBulkEncodeFunction · 0.64
TestVariableLengthArraysFunction · 0.64
TestBulkFlagNoVariableFunction · 0.64
TestBulkEncodeDecodeFunction · 0.64
TestOLCEncodingRoundTripFunction · 0.64
TestBulkTimeFieldType23Function · 0.64