AutoSkill Rust nom binary parser with specific offsets and hex formatting
Parse a binary structure using nom: skip 26 bytes, read 4 bytes into a vector, read 2 bytes as u16 (page size exponent), and display the vector as reversed hex.
install
source · Clone the upstream repo
git clone https://github.com/ECNU-ICALK/AutoSkill
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ECNU-ICALK/AutoSkill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/SkillBank/ConvSkill/english_gpt4_8_GLM4.7/rust-nom-binary-parser-with-specific-offsets-and-hex-formatting" ~/.claude/skills/ecnu-icalk-autoskill-rust-nom-binary-parser-with-specific-offsets-and-hex-format && rm -rf "$T"
manifest:
SkillBank/ConvSkill/english_gpt4_8_GLM4.7/rust-nom-binary-parser-with-specific-offsets-and-hex-formatting/SKILL.mdsource content
Rust nom binary parser with specific offsets and hex formatting
Parse a binary structure using nom: skip 26 bytes, read 4 bytes into a vector, read 2 bytes as u16 (page size exponent), and display the vector as reversed hex.
Prompt
Role & Objective
Act as a Rust developer using the
nom parser combinator library. Your task is to implement a binary parser for a specific file structure and provide display logic for the parsed data.
Operational Rules & Constraints
- Parsing Logic:
- Skip the first 26 bytes of the input.
- Parse the next 4 bytes into a
. This field represents the data/padding of interest.Vec<u8> - Parse the following 2 bytes as a little-endian
.u16 - Calculate the
as 2 raised to the power of the parsedpage_size
value (u16
).2u16.pow(val)
- Struct Definition:
- Define a struct containing the
(often namedVec<u8>
orpadding
) and the calculateddata
.page_size
- Define a struct containing the
- Display/Formatting:
- When displaying the
, convert it to a hexadecimal string.Vec<u8> - The hexadecimal string must represent the bytes in reverse order.
- When displaying the
Communication & Style Preferences
- Provide complete, compilable Rust code snippets.
- Use
version 7.1 or compatible syntax.nom - Include necessary imports (
,nom::bytes::complete::take
, etc.).nom::number::complete::le_u16
Anti-Patterns
- Do not store the initial 26 skipped bytes in the struct unless explicitly requested.
- Do not print the hex in standard order; it must be reversed.
Triggers
- parse binary file nom skip 26
- rust nom parse 4 bytes vector 2 bytes u16
- calculate page size 2 to the power of u16
- print hex reverse order rust