MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / Unserialize

Method Unserialize

src/wallet/migrate.cpp:481–520  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

479
480 template <typename Stream>
481 void Unserialize(Stream& s)
482 {
483 // Current position within the page
484 int64_t pos = PageHeader::SIZE;
485
486 // Get the items
487 for (uint32_t i = 0; i < m_header.entries; ++i) {
488 // Get the index
489 uint16_t index;
490 s >> index;
491 if (m_header.other_endian) {
492 index = internal_bswap_16(index);
493 }
494 indexes.push_back(index);
495 pos += sizeof(uint16_t);
496
497 // Go to the offset from the index
498 int64_t to_jump = index - pos;
499 if (to_jump < 0) {
500 throw std::runtime_error("Internal record position not in page");
501 }
502 s.ignore(to_jump);
503
504 // Read the record
505 RecordHeader rec_hdr(m_header.other_endian);
506 s >> rec_hdr;
507 to_jump += RecordHeader::SIZE;
508
509 if (rec_hdr.type != RecordType::KEYDATA) {
510 throw std::runtime_error("Unknown record type in internal page");
511 }
512 InternalRecord record(rec_hdr);
513 s >> record;
514 records.emplace_back(record);
515 to_jump += InternalRecord::FIXED_SIZE + rec_hdr.len;
516
517 // Go back to the indexes
518 s.seek(-to_jump, SEEK_CUR);
519 }
520 }
521};
522
523static void SeekToPage(AutoFile& s, uint32_t page_num, uint32_t page_size)

Callers

nothing calls this directly

Calls 5

internal_bswap_16Function · 0.85
push_backMethod · 0.45
ignoreMethod · 0.45
emplace_backMethod · 0.45
seekMethod · 0.45

Tested by

no test coverage detected