Giter Club home page Giter Club logo

libndef's Introduction

Introduction

This is a C++/Qt library to encode and decode messages based on NDEF (NFC Data Exchange Format) Specification.

For more info please visit: http://www.nfc-forum.org/specs/spec_list/

It depends on Qt Core module (from Qt Framework, visit: http://qt.nokia.com).

Source code available at GitHub: https://github.com/nfc-tools/libndef

Installation

  • Checkout the source tree:

git clone https://github.com/nfc-tools/libndef.git

Examples

Create & serialize a NDEF message

#include <ndefmessage.h>

// First we create a valid NDEF message object...
NDEFMessage msg;
msg.appendRecord(NDEFRecord::createUriRecord("http://code.google.com/p/libndef"));
msg.appendRecord(NDEFRecord::createTextRecord("Hello, world!", "en-US"));

// ...and then we can serialize it and send everywhere.
QByteArray output = msg.toByteArray();

Parse a NDEF message stream

#include <ndefmessage.h>

// Imagine we've read a byte stream from a NFC tag.
QByteArray input = read_from_nfc_tag();

// Now we can parse it...
NDEFMessage msg = NDEFMessage::fromByteArray(input);

// ...and then we can use it.
if (msg.isValid())
    printf("Num of records: %d", msg.recordCount());

Encapsulate a NDEF message into a TLV record

#include <tlv.h>

// Imagine we've a valid NDEF message.
NDEFMessage msg;

// Now we can easily encapsulate it inside a TLV record...
Tlv tlv = Tlv::createNDEFMessageTlv(msg);

// ...and then we can serialize it and send everywhere.
QByteArray output = tlv.toByteArray();

Extract a NDEF Message from a TLV record

#include <tlv.h>

// Imagine we've a TLV byte stream.
QByteArray input;

// We can obtain the list of TLV records...
TlvList list = Tlv::fromByteArray(input);

// ...and then we can search for a NDEF one.
foreach (Tlv tlv, list)
{
    if (tlv.type() == Tlv::NDEF)
    {
        NDEFMessage msg = NDEFMessage::fromByteArray(tlv.value());
        if (msg.isValid())
            printf("Num of records: %d", msg.recordCount());
    }
}

libndef's People

Contributors

jiapengli avatar neomilium avatar zuck avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.