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)
| 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) |
| 461 | func (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 |