def encode.chunks

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

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

1771# Pure whole-file encoder for fixtures and small in-memory callers. Production
1772# persistence uses next_chunk directly and never joins the complete file.
1773def encode.chunks(
1774  fuel: Nat,
1775  pair: Encoder & Maybe<&1, Bytes.Bytes>,
1776  acc: List<&1, Bytes.Bytes>
1777) -> Result<&1, &1, Error, Bytes.Bytes>:
1778  match fuel:
1779    case 0n:
1780      Fail{TooLarge{}}
1781    case 1n+rest:
1782      match pair:
1783        case (_, None{}):
1784          Done{Bytes.concat(List.reverse(&1, Bytes.Bytes, acc))}
1785        case (encoder, Some{chunk}):
1786          encode.chunks(rest, next_chunk(encoder), Con{chunk, acc})

Uses (12)

Used by (1)