| // Copyright 2018 The Fuchsia Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| //! Serialization and deserialization of wire formats. |
| //! |
| //! This module provides efficient serialization and deserialization of the |
| //! various wire formats used by this program. Where possible, it uses lifetimes |
| //! and immutability to allow for safe zero-copy parsing. |
| //! |
| //! # Endianness |
| //! |
| //! All values exposed or consumed by this crate are in host byte order, so the |
| //! caller does not need to worry about it. Any necessary conversions are |
| //! performed under the hood. |
| |
| // TODO(joshlf): Move into debug_err! and debug_err_fn! definitions once |
| // attributes are allowed on expressions |
| // (https://github.com/rust-lang/rust/issues/15701). |
| #![cfg_attr(feature = "cargo-clippy", allow(block_in_if_condition_stmt))] |
| |
| /// Emit a debug message and return an error. |
| /// |
| /// Invoke the `debug!` macro on all but the first argument. A call to |
| /// `debug_err!(err, ...)` is an expression whose value is the expression `err`. |
| macro_rules! debug_err { |
| ($err:expr, $($arg:tt)*) => ( |
| // TODO(joshlf): Uncomment once attributes are allowed on expressions |
| // #[cfg_attr(feature = "cargo-clippy", allow(block_in_if_condition_stmt))] |
| { |
| use ::log::debug; |
| debug!($($arg)*); |
| $err |
| } |
| ) |
| } |
| |
| /// Create a closure which emits a debug message and returns an error. |
| /// |
| /// Create a closure which, when called, invokes the `debug!` macro on all but |
| /// the first argument, and returns the first argument. |
| macro_rules! debug_err_fn { |
| ($err:expr, $($arg:tt)*) => ( |
| // TODO(joshlf): Uncomment once attributes are allowed on expressions |
| // #[cfg_attr(feature = "cargo-clippy", allow(block_in_if_condition_stmt))] |
| || { |
| use ::log::debug; |
| debug!($($arg)*); |
| $err |
| } |
| ) |
| } |
| |
| pub mod arp; |
| pub mod ethernet; |
| pub mod icmp; |
| pub mod ipv4; |
| pub mod ipv6; |
| pub mod tcp; |
| #[cfg(test)] |
| mod testdata; |
| pub mod udp; |
| mod util; |