#nfc #record #cbor #payload #data #text

no-std ndef

This crate provides a #[no_std] library to implement a NFC Data Exchange Format structures

1 unstable release

0.2.0 Dec 18, 2024

#367 in Embedded development

Download history 111/week @ 2024-12-16

111 downloads per month

MIT/Apache

25KB
544 lines

ndef

Crates.io

#![no_std] Rust library to manipulate NDEF.

Features

  • alloc: enable a global allocator
    • allow more than 8 records per message
    • allow more than 256 bytes of payload size
    • allow to decode UTF-16 RTD Text record (always encoded in UTF-8)
    • allow to encode RTD external record
  • cbor: add minicbor dependency
    • provide a custom cbor RTD external record
    • provide a convenient record payload from cbor encodable type (need alloc too)

Example Usage

Cargo.toml

[dependencies]
ndef = "0.1.0"

main.rs

use ndef::{Message, Payload, Record, RecordType};

fn main() {
    let mut msg = Message::default();
    let mut rec1 = Record::new(
        None,
        Payload::RTD(RecordType::Text {
            enc: "en",
            txt: "NDEF Text from Rust🦀!",
        }),
    );
    msg.append_record(&mut rec1).unwrap();

    // Print message raw data
    println!("message raw data: {:?}", msg.to_vec().unwrap().as_slice());
}

Dependencies

~0.3–1MB
~21K SLoC