2018-01-30 19:19:15 +01:00
|
|
|
// Matrix Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2018 Jason Volk <jason@zemos.net>
|
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice is present in all copies. The
|
|
|
|
// full license for this software is available in the LICENSE file.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#define HAVE_IRCD_JSON_UTIL_H
|
|
|
|
|
|
|
|
namespace ircd::json
|
|
|
|
{
|
|
|
|
using name_hash_t = size_t;
|
2018-09-17 05:01:55 +02:00
|
|
|
constexpr name_hash_t name_hash(const string_view name);
|
2018-01-30 19:19:15 +01:00
|
|
|
constexpr name_hash_t operator ""_(const char *const name, const size_t len);
|
|
|
|
|
|
|
|
extern const string_view literal_null;
|
|
|
|
extern const string_view literal_true;
|
|
|
|
extern const string_view literal_false;
|
|
|
|
extern const string_view empty_string;
|
|
|
|
extern const string_view empty_object;
|
|
|
|
extern const string_view empty_array;
|
2018-05-20 07:10:58 +02:00
|
|
|
extern const int64_t undefined_number;
|
2018-01-30 19:19:15 +01:00
|
|
|
|
|
|
|
size_t serialized(const string_view &);
|
|
|
|
string_view stringify(mutable_buffer &, const string_view &);
|
|
|
|
|
|
|
|
using members = std::initializer_list<member>;
|
|
|
|
|
2018-03-21 07:51:14 +01:00
|
|
|
// Validate JSON - checks if valid JSON (not canonical).
|
2018-01-30 19:19:15 +01:00
|
|
|
bool valid(const string_view &, std::nothrow_t) noexcept;
|
|
|
|
void valid(const string_view &);
|
2018-03-29 05:47:26 +02:00
|
|
|
std::string why(const string_view &);
|
2018-03-29 06:11:26 +02:00
|
|
|
|
|
|
|
// (Internal) validates output
|
|
|
|
void valid_output(const string_view &, const size_t &expected);
|
2018-01-30 19:19:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
constexpr ircd::json::name_hash_t
|
|
|
|
ircd::json::operator ""_(const char *const text, const size_t len)
|
|
|
|
{
|
2018-09-17 05:01:55 +02:00
|
|
|
return name_hash(string_view(text, len));
|
2018-01-30 19:19:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
constexpr ircd::json::name_hash_t
|
2018-09-17 05:01:55 +02:00
|
|
|
ircd::json::name_hash(const string_view name)
|
2018-01-30 19:19:15 +01:00
|
|
|
{
|
|
|
|
return ircd::hash(name);
|
|
|
|
}
|