moonbit-bits-patterns

Extracts and validates bit-packed fields from BytesView slices using be/le width patterns.

Updated Jan 7, 2026
One-click install
npx skills add https://github.com/peter-jerry-ye/skills --skill moonbit-bits-patterns
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: moonbit-bits-patterns
Source: https://github.com/peter-jerry-ye/skills/tree/main/skills/moonbit-bits-patterns
Command: npx skills add https://github.com/peter-jerry-ye/skills --skill moonbit-bits-patterns

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This skill addresses the challenge of extracting and validating bit-level fields from BytesView slices, enabling precise interpretation of packed data without manual bit-twiddling.

Core Features & Use Cases

  • Explicit bit-width patterns: Use patterns with be/le suffixes to describe exact field sizes and endianness.
  • Field binding and guards: Bind fields to locals, ignore unused bits, and implement validation guards.
  • Compositional parsing: Slice Bytes to BytesView and chain parsers, returning (field, rest) for multi-step decoding of protocols or file formats.
  • Use Case: Decode a packet header where [u1be(flag), u3be(type), u4be(code), ..] determine routing or validation.

Quick Start

Create a BytesView with a slice of the payload and pattern-match it using the syntax described above, e.g., match bytes[0:1] with [u1be(flag), u7be(..rest)] to extract a flag.

Frequently Asked Questions about moonbit-bits-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I parse bit-packed fields from a BytesView slice?

To parse bit-packed fields from a BytesView, use explicit bit-width patterns with be/le suffixes to describe exact field sizes and endianness. This enables precise interpretation of packed data for protocol parsing without manual bit-twiddling.

What is the best way to extract protocol headers with specific endianness?

Extracting protocol headers with specific endianness is best done using explicit bit-width patterns. You can bind fields to locals, ignore unused bits, and enforce deterministic matches across headers to validate routing or payload data.

Can I chain parsers to decode multi-step file formats?

Yes, you can chain parsers for multi-step decoding by slicing Bytes to BytesView. This compositional parsing approach returns the extracted field and the remaining data, allowing sequential decoding of complex protocols or file formats.

How do I validate specific bit patterns in embedded data decoding?

To validate specific bit patterns in embedded data decoding, apply explicit width patterns with validation guards. You can bind extracted fields to locals and implement guards to enforce deterministic matches across structured inputs.

Does this bit pattern matching support both big-endian and little-endian formats?

Yes, bit pattern matching supports both big-endian and little-endian formats. You use explicit be and le suffixes in your width patterns to determine the exact endianness and meaning across headers, tags, and payloads.