Expand description
§nanondef
nanondef is a compact, no_std-friendly NFC Forum NDEF encoding and
decoding library, designed for embedded systems, WASM runtimes, and
efficient tag-parsing pipelines.
The crate provides:
- Fully-typed decoding of NDEF Messages, Records, and Payloads
- Zero-copy parsing via lifetimes (
&[u8]) - Pluggable
DecodePayloadtrait for supporting custom payload types - Compact encoding via the
Encodetrait (withheapless::Vecsupport) - Strongly typed NFC Capability Container (CC) components:
- [
CapabilityContainer] - [
Version] (nibble-packed major/minor) - [
Features] (bitflag wrapper)
- [
- Optional
serdesupport for serialization - Optional
wasm_bindgenbindings - Works in
no_std,alloc, or fullstdenvironments
The library aims to be:
- Correct – adheres to NFC Forum Type 2 / NDEF encoding rules
- Minimal – no dependencies by default (only
heaplessoptionally) - Zero-copy – payload fields borrow directly from the input buffer
- Flexible – users can define custom payload decoders
§Getting Started
§Decode a full NDEF message from a byte slice
use nanondef::message::{
record::{payload::UriPayload, Record, Tnf},
DecodeMessage, HeaplessMessage, MessageRecords,
};
// A single-record NDEF message containing a URI payload
let bytes: &[u8] = &[
0b1101_0001, // MB | ME | SR | TNF=WellKnown
0x01, // Type length = 1 ("U")
0x0B, // Payload length
b'U', // Type field
0x03, // Prefix code: "http://"
b'g',
b'i',
b't',
b'h',
b'u',
b'b',
b'.',
b'c',
b'o',
b'm',
];
// Decode the message
let msg = HeaplessMessage::<1>::decode_message(bytes).expect("should decode message");
// Extract the payload as a typed URI payload
let records = msg.records().expect("should provide records");
let Record::Uri(uri) = &records[0] else { panic!("should be a URI record") };
assert_eq!(uri.header.tnf, Tnf::WellKnown);
assert_eq!(uri.payload.prefix, "http://");
assert_eq!(uri.payload.uri, "github.com");Re-exports§
pub use error::Error;
Modules§
Structs§
- Range
- A half-open range of
usizevalues represented as(start, end). - Vec
stdoralloc - A contiguous growable array type, written as
Vec<T>, short for ‘vector’.
Traits§
Type Aliases§
- Consumed
- A value paired with the number of bytes consumed while decoding it.
- Consumed
Result - A result that returns a parsed value together with the number of bytes consumed while parsing it.
- Crate
Consumed - Convenience alias for the crate’s standard
Resulttype returning a parsed value together with the number of bytes consumed. - Offset
Result - A result that returns only the number of bytes consumed.
- Result