Files

68 lines
1.5 KiB
C++
Raw Permalink Normal View History

#pragma once
#include <cstddef>
#include <cstdint>
#include "StreamingJsonParser.h"
class ReleaseJsonParser {
public:
ReleaseJsonParser();
ReleaseJsonParser(const ReleaseJsonParser&) = delete;
ReleaseJsonParser& operator=(const ReleaseJsonParser&) = delete;
void reset();
void feed(const char* data, size_t len);
bool foundTag() const;
bool foundFirmware() const;
const char* getTagName() const;
const char* getFirmwareUrl() const;
size_t getFirmwareSize() const;
private:
enum class Position : uint8_t {
TOP_LEVEL,
IN_ASSETS_ARRAY,
IN_ASSET_OBJECT,
};
enum class LastKey : uint8_t {
NONE,
TAG_NAME,
ASSETS,
ASSET_NAME,
ASSET_URL,
ASSET_SIZE,
};
static void sOnKey(void* ctx, const char* key, size_t len);
static void sOnString(void* ctx, const char* value, size_t len);
static void sOnNumber(void* ctx, const char* value, size_t len);
static void sOnBool(void* ctx, bool value);
static void sOnNull(void* ctx);
static void sOnObjectStart(void* ctx);
static void sOnObjectEnd(void* ctx);
static void sOnArrayStart(void* ctx);
static void sOnArrayEnd(void* ctx);
void commitAsset();
StreamingJsonParser parser;
Position position;
LastKey lastKey;
uint8_t depth;
uint8_t assetDepth;
char tagName[32];
char firmwareUrl[512];
size_t firmwareSize;
bool tagFound;
bool firmwareFound;
char currentAssetName[32];
char currentAssetUrl[512];
size_t currentAssetSize;
};