2023-02-11 20:49:42 +00:00
|
|
|
// This file Copyright © 2008-2023 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>
|
2023-01-28 02:12:09 +00:00
|
|
|
#include <string>
|
2021-11-17 03:29:30 +00:00
|
|
|
#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
|
|
|
};
|
|
|
|
|
2022-09-07 16:04:28 +00: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
|
|
|
|
2022-11-03 23:08:02 +00:00
|
|
|
[[nodiscard]] std::string tr_variantToStrJson(tr_variant const* top, bool lean);
|
2012-12-14 04:34:42 +00:00
|
|
|
|
2022-11-03 23:08:02 +00:00
|
|
|
[[nodiscard]] std::string tr_variantToStrBenc(tr_variant const* top);
|
2012-12-14 04:34:42 +00:00
|
|
|
|
|
|
|
/** @brief Private function that's exposed here only for unit tests */
|
2022-09-09 02:49:51 +00: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-09 02:49:51 +00:00
|
|
|
[[nodiscard]] std::optional<std::string_view> tr_bencParseStr(std::string_view* benc_inout);
|
2021-11-17 03:29:30 +00:00
|
|
|
|
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);
|