// Copyright 2026 Noverberrain.
// SPDX-License-Identifier: Apache-2.0

///|
fn Reader::read_hash_record(
  self : Reader,
  prefix : KeyPrefix,
  database : UInt64,
  max_string_bytes : Int32,
  max_hash_entries : Int32,
  max_packed_bytes : Int32,
  budget : DecodeBudget,
) -> HashRecord raise ParseError {
  let key = self.read_string(
    max_string_bytes,
    budget,
    allow_lzf=true,
    resource="string-bytes",
  )
  let offset = self.pos
  let (entries, storage, packed_storage) : (
    Array[HashEntry],
    HashStorage,
    StringStorage?,
  ) = if prefix.object_type == b'\x04' {
    let count = self.read_count()
    check_resource_limit("hash-entries", offset, count, max_hash_entries)
    if count == 0UL {
      raise InvalidHash(offset~, reason="empty hash")
    }
    let entries = []
    let seen : Map[Bytes, Unit] = Map([])
    for _ in 0..