1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//! # 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 `DecodePayload` trait for supporting custom payload types
//! - Compact encoding via the `Encode` trait (with [`heapless::Vec`] support)
//! - Strongly typed NFC **Capability Container (CC)** components:
//! - [`CapabilityContainer`]
//! - [`Version`] (nibble-packed major/minor)
//! - [`Features`] (bitflag wrapper)
//! - Optional `serde` support for serialization
//! - Optional `wasm_bindgen` bindings
//! - Works in `no_std`, `alloc`, or full `std` environments
//!
//! The library aims to be:
//! - **Correct** – adheres to NFC Forum Type 2 / NDEF encoding rules
//! - **Minimal** – no dependencies by default (only `heapless` optionally)
//! - **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
//! ```rust
//! 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");
//! ```
pub
pub use *;
pub use *;
pub use *;
pub use Error;
pub use *;
extern crate alloc;
extern crate core;
pub type Result<T> = Result;
pub use Vec;