SciParse
Zero-copy SCION packet parsing and serialization and control plane components.
Overview
SciParse provides efficient, zero-copy parsing and construction of SCION network packets.
It offers two complementary representations:
- Views - zero-copy projections over byte buffers that provide direct field access without allocation or data copying, with only the validation required to uphold memory safety.
- Models - structured Rust types for constructing new packets or performing complex modifications that are impractical using views alone.
Additionally, the crate includes control-plane components like PathSegments and signed messages.
Parsing a packet (zero-copy view)
Use ScionRawPacketView to parse an incoming packet directly from a byte buffer without any allocation.
use View;
use ScionRawPacketView;
Classifying a packet by payload protocol
Classify a raw packet view into UDP, SCMP, or other to access protocol-specific fields:
use View;
use ScionRawPacketView;
use ClassifiedPacketView;
Converting a view to a model
Convert a zero-copy view into an owned model to perform complex modifications.
use View;
use ScionRawPacketView;
use ;
use ClassifiedPacketView;
Constructing and encoding a packet using a model
Build a SCION/UDP packet using ScionUdpPacket::new, which takes source and destination
socket addresses, a path, and the raw payload. The header fields and UDP datagram are
constructed automatically:
use WireEncode;
use ScionSocketAddr;
use Path;
use ScionUdpPacket;
Design
Views
Views are #[repr(transparent)] wrappers around [u8] slices. A view is created by validating
that the buffer is large enough to safely access all fields (View::has_required_size), then
transmuting the slice into the view type. Because views are just reinterpreted pointers,
mutability and ownership are handled by Rust's built-in types (&View, &mut View,
Box<View>).
Views guarantee memory safety but do not guarantee semantic correctness - for example,
a view will not check that the next_header field actually matches the payload contents. It is
the caller's responsibility to validate fields as needed.
Models
Models are standard Rust structs that own their data. They implement the WireEncode trait,
which provides:
required_size()- the exact number of bytes needed for the wire encoding.wire_valid()- minimal validation to prevent encoding structurally invalid packets.encode()/encode_to_vec()- serialization into a byte buffer.
Layouts
Layouts define the size and position of every field within a header or data structure at the bit level. They serve as the single source of truth that both views and models use for reading and writing data. Layouts also provide debug annotations for visualizing binary structures.
License
Licensed under the Apache License, Version 2.0.