refactor(tuic-core): replace manual byte parsing with nom streaming parsers#16
Merged
Conversation
…arsers Replace the two sets of hand-written byte-parsing code (free helpers + tokio-util Decoder impls) with a single set of nom 8 streaming parsers. Both paths now use the same nom combinators; the only difference is how `nom::Err::Incomplete` is mapped — to `Ok(None)` in the codec path and to an `eyre::Report` error in the free helpers. - Add nom = "8" dependency - Define parse_header / parse_command_body / parse_address in mod.rs - Rewrite free helpers (decode_*) as thin wrappers around nom_parse() - Rewrite codec Decoder impls to call the same nom parsers - Encoder impls remain unchanged (nom is parsing-only) - All 18 tuic-core tests pass, all downstream crates compile clean
quinn's QuicServerConfig requires max_early_data_size to be either 0 or u32::MAX. The previous value of 16 KiB violated this constraint, causing a panic at quinn-proto/src/crypto/rustls.rs:526.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replace the two sets of hand-written byte-parsing code (free helpers + tokio-util
Decoderimpls) with a single set of nom 8 streaming parsers.Problem
tuic-coremaintained two parallel parsing implementations — free helper functions (decode_header,decode_command,decode_address) and tokio-utilDecoder/Encodercodecs — with identical parsing logic but different error contracts. The comment explicitly warned "Any change to the on-wire format MUST be mirrored across both implementations."Solution
Define a single set of nom streaming parsers:
parse_header&[u8](&[u8], Header)parse_command_body&[u8](&[u8], Command)parse_address&[u8](&[u8], Address)Both paths call the same parsers, differing only in how
nom::Err::Incompleteis mapped:Incomplete→Ok(None)(tokio-util contract)Incomplete→Err(eyre!("Incomplete data in ..."))Encoder implementations are unchanged (nom is parsing-only).
Changes
Cargo.toml— addnom = "8"src/proto/mod.rs— core parsers +nom_parse()wrapper + updated free helpers; ~110 lines of manual parsing deletedsrc/proto/header.rs—HeaderCodec::decodecallsparse_headersrc/proto/cmd.rs—CmdCodec::decodecallsparse_command_bodysrc/proto/addr.rs—AddressCodec::decodecallsparse_addressVerification
tuic-coreunit tests passwind-tuic,wind-tuiche,tuic-tests) compile without changestuic-testsprotocol and integration tests pass