Skip to content

Commit

Permalink
nom 8
Browse files Browse the repository at this point in the history
  • Loading branch information
agourlay committed Feb 1, 2025
1 parent afcd86a commit 575e2f7
Show file tree
Hide file tree
Showing 5 changed files with 172 additions and 142 deletions.
13 changes: 3 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ keywords = ["java", "jvm", "heap-dump", "analyzer", "hprof"]
edition = "2021"

[dependencies]
nom = "7.1.3"
nom = "8.0.0"
indicatif = "0.17.11"
clap = { version = "4.5.27", features = ["cargo"] }
indoc = "2.0.5"
Expand Down
7 changes: 4 additions & 3 deletions src/parser/file_header_parser.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::parser::primitive_parsers::*;
use nom::combinator::map;
use nom::sequence::tuple;
use nom::IResult;
use nom::Parser;

#[derive(Debug, PartialEq, Eq)]
pub struct FileHeader {
Expand All @@ -22,11 +22,12 @@ impl FileHeader {

pub fn parse_file_header(i: &[u8]) -> IResult<&[u8], FileHeader> {
map(
tuple((parse_c_string, parse_u32, parse_u64)),
(parse_c_string, parse_u32, parse_u64),
|(format, size_pointers, timestamp)| {
FileHeader::from_bytes(format, size_pointers, timestamp)
},
)(i)
)
.parse(i)
}

#[cfg(test)]
Expand Down
4 changes: 3 additions & 1 deletion src/parser/primitive_parsers.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use nom::sequence::terminated;
use nom::Parser;
use nom::{bytes, number, IResult};

pub fn parse_c_string(i: &[u8]) -> IResult<&[u8], &[u8]> {
terminated(
bytes::streaming::take_until("\0"),
bytes::streaming::tag("\0"),
)(i)
)
.parse(i)
}

pub fn parse_i8(i: &[u8]) -> IResult<&[u8], i8> {
Expand Down
Loading

0 comments on commit 575e2f7

Please sign in to comment.