jppe-rs
This is a Rust-based implementation of byte stream structured serialization/deserialization general library, can be applied to network packet parsing, network packet group package, network communication, file content parsing, etc., feel good small partners please click like 👍~
Usage
Cargo.toml
[]
= { ="0.9.0", = ["derive"] }
Or
[]
= { ="0.9.0", = ["derive", "serde"] }
Simple Example
use ;
// If the value size is less than 0xff, byte_count does not need to be specified,otherwise, byte_count=<2|4|8>
Simple Example2
use ;
Default Example
[]
= { ="0.9.0", = ["derive", "jdefault"] }
use ;
// If the value size is less than 0xff, byte_count does not need to be specified,otherwise, byte_count=<2|4|8>
Other Example
- tcp_communication_example
- ethernet_example
- ipv4_example
- tcp_example
- http_hashmap_example
- http_vec_example
- parse_example: Including Ethernet/IPv4/TCP/UDP
Feature
ContainerAttrModifiers
-
byteorder=<"BE"|"LE">: The global byte order of struct and enum, eg:#[jppe(byteorder="LE")]. -
encode_with: custom encode function. -
decode_with: custom decode function. -
with: custom encode/decode function. -
get_variable_name: Get cache variable, must be used withvariable_name, eg: variable_name_example.
enum branch
-
branch_enum
FieldAttrModifiers
-
byteorder=<"BE"|"LE">: The byte order of locality field, eg:#[jppe(byteorder="LE")] -
length=<num|variable>: Data length, supportint/&str/String/&[u8]type, eg: length_example. -
offset=<num|variable>: Byte stream offset. -
count==<num|variable>: Data count, supportVec/HashMaptype. -
full=<int>: encode full value. -
untake: Bytes are not taken. -
linend|end_with=<string|bytes>: SupportingString/&str/&[u8]type. -
key|starts_with: It is suitable for accurate parsing of key/value structure data, supportingstring/&str/&[u8]types. -
split: SupportingHashMaptype, eg: split_example -
if_expr: SupportingOption<T>type, eg: if_expr_example. -
encode_with: custom encode function, eg: with_example. -
decode_with: custom decode function, eg: with_example. -
with: custom encode/decode function, eg: with_example. -
with_args: custom encode/decode function args, eg: with_args_example. -
encode_value: value processing expression, eg:#[jppe(encode_value="length * 2")]. -
decode_value: value processing expression, eg:#[jppe(decode_value="length / 2")]. -
variable_name: Set integer cache variable, eg: variable_name_example. -
byte_count=<1|2|4|8>: Specifies the byte count, automatic decode/encode length or other.-
String/&str/&[u8]: Fetches n byte mapping length in advance, eg: byte_count. -
HexString/HexBytes: Fetches n byte mapping length in advance, eg: byte_count. -
Enum: Thebyte_countbyte mapping enumeration is taken in advance and encoded through the enumeration inidex, eg: enum_byte_count -
Vec<T>
-
-
skip: Require implementDefaulttrait for data type. -
skip_encode: Skip encode function. -
skip_decode: Require implementDefaulttrait for data type. -
check_value -
default: eg: default example
enum branch
-
branch=<int|variable>: eg: branch example -
branch_option=<variable>: eg: branch_option example.rs -
branch_default: eg: branch_default example -
branch_bits: eg: branch_bits example -
branch_range: eg: branch_range example -
branch_value: eg: branch_value example
DataType
-
u8/u16/u32/u64/usize/u128 -
i8/i16/i32/i64/isize/i128 -
bool -
f32/f64 -
Stringand&str -
array[T; N] -
Tuple -
Vec<T> -
&[u8] -
Option<T> -
Struct -
Enum -
PhantomData -
HashMap: SupportString/&str/&[u8], eg: hashmap_example. -
HashSet<T>: TheHashSettype must specify#[jppe(count=xxx)]modifier, only supporting decode function, defaultcount=0, eg: hashset_example. -
MacAddress: eg: mac_example. -
std::net::Ipv4Addr/Ipv6Addr/IpAddr: IpAddr type requres specifying thelength=<16|4>modifier, Otherwise return an error, eg: ip_address_example. -
PpeAddress: Requres specifying thelength=<16|4|6|usize>modifier, Otherwise return an error, eg: ppe_address_example. -
HexString: eg: hex_example -
HexBytes: eg: hex_bytes_example -
DateTime -
Bit
TODO
- jnet-rs library.
- jget-rs library.
- jdefault-rs library.
- jfmt-rs library.