目录

MoonSFV

MoonSFV is a strict, dependency-free implementation of RFC 8941 Structured Field Values for HTTP, written in MoonBit. It fills the gap between HTTP applications and the modern structured headers used by caching, privacy, client hints, and signature specifications.

Scope

  • RFC 8941 Items: integers, fixed-scale decimals, ASCII strings, tokens, byte sequences, booleans, and parameters.
  • Lists, inner lists, ordered dictionaries, duplicate-key rejection, and the RFC true shorthand.
  • Strict parsing with byte offsets; malformed input is rejected rather than repaired.
  • Canonical serialization that is stable on wasm, wasm-gc, JavaScript, and native backends.

MoonSFV is not an HTTP client, server, HTTP Message Signatures implementation, or a permissive parser for legacy headers.

Install

After publication:

moon add serene-WJ/moon_sfv

Library

test {
  let field = @moon_sfv.parse_dictionary("a=(1 2);ok, b=:SGk=:")
  inspect(@moon_sfv.serialize_dictionary(field), content="a=(1 2);ok, b=:SGk=:")
}

parse_item, parse_list, and parse_dictionary raise ParseError, whose variants retain the failing byte offset and expected syntax. The public model is BareItem, Item, InnerList, List, Dictionary, and Parameters.

CLI

moon run cmd/main -- normalize dictionary 'a=(1 2);ok, b=:SGk=:'
moon run cmd/main -- validate item '42;answer=?0'
moon run cmd/main -- parse list 'a, ("b" 2);level=3'
moon run cmd/main -- examples

The first command prints a=(1 2);ok, b=:SGk=:. Invalid input exits non-zero and prints a compact JSON diagnostic on stderr.

Verification

moon fmt --check
moon check --target all --deny-warn
moon test --target all --deny-warn
moon info
moon package

GitHub Actions runs these commands, validates the CLI, checks the effective MoonBit source footprint, and uploads the Mooncakes archive. The current initial implementation enforces a 600-line production baseline; the planned 4k expansion is a future milestone and is not represented as complete here.

RFC coverage

RFC 8941 construct MoonSFV API
Bare Items BareItem, serialize_bare_item
Parameters Parameters, Parameters::get
Items parse_item, serialize_item
Inner Lists InnerList, serialize_inner_list
Lists parse_list, serialize_list
Dictionaries parse_dictionary, serialize_dictionary

License

MIT.

邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

版权所有:中国计算机学会技术支持:开源发展技术委员会
京ICP备13000930号-9 京公网安备 11010802047560号