2022-01-20 18:27:56 +00:00
|
|
|
// This file Copyright © 2008-2022 Mnemosyne LLC.
|
2022-08-08 18:05:39 +00:00
|
|
|
// It may be used under GPLv2 (SPDX: GPL-2.0-only), GPLv3 (SPDX: GPL-3.0-only),
|
2022-01-20 18:27:56 +00:00
|
|
|
// or any future license endorsed by Mnemosyne LLC.
|
|
|
|
// License text can be found in the licenses/ folder.
|
2012-12-14 04:34:42 +00:00
|
|
|
|
2017-11-14 20:21:28 +00:00
|
|
|
#pragma once
|
|
|
|
|
2020-08-11 18:11:55 +00:00
|
|
|
#ifndef LIBTRANSMISSION_VARIANT_MODULE
|
2017-04-19 12:04:45 +00:00
|
|
|
#error only libtransmission/variant-*.c should #include this header.
|
2012-12-14 04:34:42 +00:00
|
|
|
#endif
|
|
|
|
|
2022-04-08 01:50:26 +00:00
|
|
|
#include <cstdint> // int64_t
|
2021-11-17 03:29:30 +00:00
|
|
|
#include <optional>
|
|
|
|
#include <string_view>
|
|
|
|
|
2021-11-18 05:37:35 +00:00
|
|
|
#include "transmission.h"
|
|
|
|
|
|
|
|
#include "variant.h"
|
2020-08-11 18:11:55 +00:00
|
|
|
|
2021-10-06 14:26:07 +00:00
|
|
|
using VariantWalkFunc = void (*)(tr_variant const* val, void* user_data);
|
2012-12-14 04:34:42 +00:00
|
|
|
|
|
|
|
struct VariantWalkFuncs
|
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
VariantWalkFunc intFunc;
|
|
|
|
VariantWalkFunc boolFunc;
|
|
|
|
VariantWalkFunc realFunc;
|
|
|
|
VariantWalkFunc stringFunc;
|
|
|
|
VariantWalkFunc dictBeginFunc;
|
|
|
|
VariantWalkFunc listBeginFunc;
|
|
|
|
VariantWalkFunc containerEndFunc;
|
2012-12-14 04:34:42 +00:00
|
|
|
};
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
void tr_variantWalk(tr_variant const* top, struct VariantWalkFuncs const* walkFuncs, void* user_data, bool sort_dicts);
|
2012-12-14 04:34:42 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
void tr_variantToBufJson(tr_variant const* top, struct evbuffer* buf, bool lean);
|
2012-12-14 04:34:42 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
void tr_variantToBufBenc(tr_variant const* top, struct evbuffer* buf);
|
2012-12-14 04:34:42 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void tr_variantInit(tr_variant* v, char type);
|
2012-12-14 04:34:42 +00:00
|
|
|
|
|
|
|
/** @brief Private function that's exposed here only for unit tests */
|
2021-11-17 03:29:30 +00:00
|
|
|
std::optional<int64_t> tr_bencParseInt(std::string_view* benc_inout);
|
2012-12-14 04:34:42 +00:00
|
|
|
|
|
|
|
/** @brief Private function that's exposed here only for unit tests */
|
2021-11-17 03:29:30 +00:00
|
|
|
std::optional<std::string_view> tr_bencParseStr(std::string_view* benc_inout);
|
|
|
|
|
2022-01-24 06:30:00 +00:00
|
|
|
bool tr_variantParseBenc(tr_variant& top, int parse_opts, std::string_view benc, char const** setme_end, tr_error** error);
|
2021-11-17 03:29:30 +00:00
|
|
|
|
2022-04-06 21:39:39 +00:00
|
|
|
bool tr_variantParseJson(tr_variant& setme, int opts, std::string_view json, char const** setme_end, tr_error** error);
|