<commit_before>Using `#[packet]` in Your Own Project
=====================================

The libpnet library provides a few macros to reduce the boilerplate involved in
implementing new protocols. Unfortunately, with the current state of Rust macro
support, these aren't as easy to use in your own project as the rest of the
library is.

This document is a brief guide to getting a Rust package set up to use the
`syntex`-based `pnet_macros` crate in your own crates. It's currently only been
tested in the context of building an executable rather than a library, but it
should be fairly easily adaptable.

Setting Up `Cargo.toml`
-----------------------

In order to use `syntex`, you need to set up your package to use a non-standard
build script. You will provide a build script that invokes the `syntex`
pre-processor to do macro expansion on the protocol implementation source files.

Here's an example `Cargo.toml` file that describes the necessary build script
and dependencies:

```toml

[package]
name = "my_pnet_package"
version = "0.1.0"
authors = ["<NAME> <<EMAIL>>"]
build = "build.rs"
[build-dependencies]
syntex = "0.31.*"
pnet_macros = "*"
[dependencies]
pnet = "*"
pnet_macros_support = "*"

```

First, note the `build = "build.rs"` line in the `[package]` section. This gives
the filename of the custom build script that `cargo` will invoke for you when
you run `cargo build`. The filename is relative to the package root directory,
so if you follow the example, you'll need to create a `build.rs` file in the
same directory as your `Cargo.toml` file.

Next, you'll notice the `[build-dependencies]` section. This describes the
crates that are required at compile-time to run whatever code is in the build
script described by the `build` option in the `[package]` section. Here you need
to use the same major and minor version of `syntex` that is used by the version
of `pnet_macros` you're depending on. And, of course, `pnet_macros` itself.

Finally, you'll need a couple of entries in `[dependencies]` for `pnet` itself
and `pnet_macros_support`, which provides the network types used in the
`#[packet]` macro expansion.

Setting up Your Directory Tree
------------------------------

The basic directory structure will look something like this:

```

Cargo.toml<commit_msg>Add comment: syntex version must match pnet_macros<commit_after>Using `#[packet]` in Your Own Project
=====================================

The libpnet library provides a few macros to reduce the boilerplate involved in
implementing new protocols. Unfortunately, with the current state of Rust macro
support, these aren't as easy to use in your own project as the rest of the
library is.

This document is a brief guide to getting a Rust package set up to use the
`syntex`-based `pnet_macros` crate in your own crates. It's currently only been
tested in the context of building an executable rather than a library, but it
should be fairly easily adaptable.

Setting Up `Cargo.toml`
-----------------------

In order to use `syntex`, you need to set up your package to use a non-standard
build script. You will provide a build script that invokes the `syntex`
pre-processor to do macro expansion on the protocol implementation source files.

Here's an example `Cargo.toml` file that describes the necessary build script
and dependencies:

```toml

[package]
name = "my_pnet_package"
version = "0.1.0"
authors = ["<NAME> <<EMAIL>>"]
build = "build.rs"
[build-dependencies]
syntex = "0.42.*" # syntex version must match the version being used in pnet_macros/Cargo.toml
pnet_macros = "*"
[dependencies]
pnet = "*"
pnet_macros_support = "*"

```

First, note the `build = "build.rs"` line in the `[package]` section. This gives
the filename of the custom build script that `cargo` will invoke for you when
you run `cargo build`. The filename is relative to the package root directory,
so if you follow the example, you'll need to create a `build.rs` file in the
same directory as your `Cargo.toml` file.

Next, you'll notice the `[build-dependencies]` section. This describes the
crates that are required at compile-time to run whatever code is in the build
script described by the `build` option in the `[package]` section. Here you need
to use the same major and minor version of `syntex` that is used by the version
of `pnet_macros` you're depending on. And, of course, `pnet_macros` itself.

Finally, you'll need a couple of entries in `[dependencies]` for `pnet` itself
and `pnet_macros_support`, which provides the network types used in the
`#[packet]` macro expansion.

Setting up Your Directory Tree
------------------------------

The basic directory structure will look something like this:

```

Cargo.toml
{'fraction_non_alphanumeric': 0.11078098471986418, 'fraction_numerical': 0.0025466893039049238, 'mean_word_length': 4.190528634361233, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4584760', 'n_tokens_mistral': 1341, 'n_tokens_neox': 1290, 'n_words': 673}