73 lines
1.6 KiB
C++
73 lines
1.6 KiB
C++
#pragma once
|
|
|
|
#include <Arduino.h>
|
|
#include <cbor.h>
|
|
|
|
#include "OpenPrintTagData.h"
|
|
|
|
class OpenPrintTagParser
|
|
{
|
|
public:
|
|
bool parse(
|
|
const uint8_t* memory,
|
|
size_t memoryLength,
|
|
OpenPrintTagData& data);
|
|
|
|
private:
|
|
static constexpr uint8_t NdefTlvType = 0x03;
|
|
static constexpr uint8_t TerminatorTlvType = 0xFE;
|
|
|
|
static constexpr const char* ExpectedMimeType =
|
|
"application/vnd.openprinttag";
|
|
|
|
bool findNdefMessage(
|
|
const uint8_t* memory,
|
|
size_t memoryLength,
|
|
const uint8_t*& ndefMessage,
|
|
size_t& ndefMessageLength) const;
|
|
|
|
bool parseNdefRecord(
|
|
const uint8_t* ndefMessage,
|
|
size_t ndefMessageLength,
|
|
const uint8_t*& payload,
|
|
size_t& payloadLength) const;
|
|
|
|
bool mimeTypeMatches(
|
|
const uint8_t* mimeType,
|
|
size_t mimeTypeLength) const;
|
|
|
|
bool parseCborPayload(
|
|
const uint8_t* payload,
|
|
size_t payloadLength,
|
|
OpenPrintTagData& data) const;
|
|
|
|
bool parseMainData(
|
|
const uint8_t* mainData,
|
|
size_t mainDataLength,
|
|
OpenPrintTagData& data) const;
|
|
|
|
bool readUnsignedInteger(
|
|
CborValue* value,
|
|
uint64_t& result) const;
|
|
|
|
bool readTextString(
|
|
CborValue* value,
|
|
String& result) const;
|
|
|
|
bool readByteString(
|
|
CborValue* value,
|
|
uint8_t* buffer,
|
|
size_t bufferCapacity,
|
|
size_t& bytesRead) const;
|
|
|
|
bool skipValue(
|
|
CborValue* value) const;
|
|
|
|
String formatUuid(
|
|
const uint8_t* bytes,
|
|
size_t length) const;
|
|
|
|
String formatColor(
|
|
const uint8_t* bytes,
|
|
size_t length) const;
|
|
}; |