def field.sized.checked

mylsm-lsm-store@0.6.0.1 · src/coordinator/CursorOpenCodec.bend:73

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

73# Slices a validated span using separate copies for its start and end offsets.
74def field.sized.checked(
75  payload: Bytes.Bytes,
76  offsets: U32 & U32 & U32,
77  lengths: U32 & U32,
78  fits: Bool
79) -> BoundResult:
80  match offsets:
81    case (slice_offset, (next_offset, _)):
82      match lengths:
83        case (slice_length, next_length):
84          match fits:
85            case True{}:
86              field.sized.sliced(Bytes.slice(payload,
87                U32.from_nat(Nat.add(U32.to_nat(slice_offset), 4n)),
88                slice_length),
89                U32.from_nat(Nat.add(Nat.add(U32.to_nat(next_offset), 4n),
90                  U32.to_nat(next_length))))
91            case False{}: BoundMalformed{}

Uses (11)

Used by (1)