def encoder.build

mylsm-lsm-store@0.6.0.1 · src/SstFile.bend:475

import mylsm-lsm-store@0.6.0.1/src/SstFile.bend as SstFile
import Base
import mylsm-lsm-store@0.6.0.1/src/MemTable.bend as MemTable
import mylsm-lsm-store@0.6.0.1/src/hub_sha/sha256.bend as SHA
import bend-kit-bytes@0.3.2.0/bytes.bend as Bytes

475# Propagate the block-summary result into an encoder header and footer.
476def encoder.build(
477  +entries: List<&2, MemTable.Entry>,
478  +level: U32,
479  +block_count: U32,
480  prepared: Result<&1, &1, Error, List<&1, Bytes.Bytes> & List<&1, Bytes.Bytes>>
481) -> Result<&1, &1, Error, Encoder>:
482  match prepared:
483    case Fail{error}:
484      Fail{error}
485    case Done{(chunks, hashes)}:
486      +total = U32.from_nat(List.length(&2, MemTable.Entry, entries))
487      root = SHA.sha256_packed_bytes(Bytes.concat(header_bytes(level, total, block_count) <> hashes))
488      footer = Bytes.concat([hex_bytes.fin(Bytes.from_hex("454e4433")), u32_bytes(total), root])
489      Done{Enc{Header{}, chunks, level, total, block_count, footer}}

Uses (18)

Used by (1)