2022-01-20 12:27:56 -06:00
|
|
|
// This file Copyright © 2008-2022 Mnemosyne LLC.
|
2022-08-08 13:05:39 -05:00
|
|
|
// It may be used under GPLv2 (SPDX: GPL-2.0-only), GPLv3 (SPDX: GPL-3.0-only),
|
2022-01-20 12:27:56 -06: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 23:21:28 +03:00
|
|
|
#pragma once
|
|
|
|
|
2020-08-11 13:11:55 -05:00
|
|
|
#ifndef LIBTRANSMISSION_VARIANT_MODULE
|
2017-04-19 15:04:45 +03:00
|
|
|
#error only libtransmission/variant-*.c should #include this header.
|
2012-12-14 04:34:42 +00:00
|
|
|
#endif
|
|
|
|
|
2022-04-07 20:50:26 -05:00
|
|
|
#include <cstdint> // int64_t
|
2021-11-16 21:29:30 -06:00
|
|
|
#include <optional>
|
|
|
|
#include <string_view>
|
|
|
|
|
2021-11-17 23:37:35 -06:00
|
|
|
#include "transmission.h"
|
|
|
|
|
|
|
|
#include "variant.h"
|
2020-08-11 13:11:55 -05:00
|
|
|
|
2021-10-06 09:26:07 -05:00
|
|
|
using VariantWalkFunc = void (*)(tr_variant const* val, void* user_data);
|
2012-12-14 04:34:42 +00:00
|
|
|
|
|
|
|
struct VariantWalkFuncs
|
|
|
|
{
|
2017-04-19 15:04:45 +03:00
|
|
|
VariantWalkFunc intFunc;
|
|
|
|
VariantWalkFunc boolFunc;
|
|
|
|
VariantWalkFunc realFunc;
|
|
|
|
VariantWalkFunc stringFunc;
|
|
|
|
VariantWalkFunc dictBeginFunc;
|
|
|
|
VariantWalkFunc listBeginFunc;
|
|
|
|
VariantWalkFunc containerEndFunc;
|
2012-12-14 04:34:42 +00:00
|
|
|
};
|
|
|
|
|
2022-09-07 11:04:28 -05:00
|
|
|
void tr_variantWalk(tr_variant const* top, VariantWalkFuncs const* walk_funcs, void* user_data, bool sort_dicts);
|
2012-12-14 04:34:42 +00:00
|
|
|
|
2017-04-20 19:02:19 +03:00
|
|
|
void tr_variantToBufJson(tr_variant const* top, struct evbuffer* buf, bool lean);
|
2012-12-14 04:34:42 +00:00
|
|
|
|
2017-04-20 19:02:19 +03:00
|
|
|
void tr_variantToBufBenc(tr_variant const* top, struct evbuffer* buf);
|
2012-12-14 04:34:42 +00:00
|
|
|
|
2017-04-19 15:04:45 +03: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 */
|
2022-09-08 21:49:51 -05:00
|
|
|
[[nodiscard]] 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 */
|
2022-09-08 21:49:51 -05:00
|
|
|
[[nodiscard]] std::optional<std::string_view> tr_bencParseStr(std::string_view* benc_inout);
|
2021-11-16 21:29:30 -06:00
|
|
|
|
2022-01-24 00:30:00 -06:00
|
|
|
bool tr_variantParseBenc(tr_variant& top, int parse_opts, std::string_view benc, char const** setme_end, tr_error** error);
|
2021-11-16 21:29:30 -06:00
|
|
|
|
2022-04-06 16:39:39 -05:00
|
|
|
bool tr_variantParseJson(tr_variant& setme, int opts, std::string_view json, char const** setme_end, tr_error** error);
|