A11 (C++ runtime)
Native C++ implementation of the A11 streaming action runtime
Loading...
Searching...
No Matches
json_codec.h
Go to the documentation of this file.
1/*
2 * Copyright 2026 The A11 Authors
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
27#ifndef A11_JSON_CODEC_H_
28#define A11_JSON_CODEC_H_
29
30#include <string>
31#include <string_view>
32
33#include <absl/status/statusor.h>
34#include <nlohmann/json.hpp>
35
36namespace a11 {
37
44absl::StatusOr<nlohmann::json> ParseJson(std::string_view encoded,
45 std::string_view what);
46
48absl::StatusOr<nlohmann::ordered_json> ParseOrderedJson(
49 std::string_view encoded, std::string_view what);
50
56bool IsValidUtf8(std::string_view text);
57
63const nlohmann::json* FindUnencodableString(const nlohmann::json& value);
64
72absl::StatusOr<std::string> DumpJson(const nlohmann::json& value,
73 std::string_view what);
74
76absl::StatusOr<std::string> DumpOrderedJson(const nlohmann::ordered_json& value,
77 std::string_view what);
78
84std::string DumpJsonLossy(const nlohmann::json& value);
85
87absl::StatusOr<std::string> PackMsgpack(const nlohmann::json& value,
88 std::string_view what);
89
91absl::StatusOr<std::string> PackOrderedMsgpack(
92 const nlohmann::ordered_json& value, std::string_view what);
93
95absl::StatusOr<nlohmann::json> UnpackMsgpack(std::string_view encoded,
96 std::string_view what);
97
98} // namespace a11
99
100#endif // A11_JSON_CODEC_H_
std::string value
Definition discover.cc:100
std::optional< std::string > text
The text, where the value is a string literal or a name bound to one.
Definition discover.cc:596
Definition action.cc:66
absl::StatusOr< Json > ParseJson(std::string_view encoded, std::string_view what)
Parses JSON text, returning a status for invalid input.
Definition json_codec.cc:373
const Json * FindUnencodableString(const Json &value)
Definition json_codec.cc:436
absl::StatusOr< std::string > DumpOrderedJson(const nlohmann::ordered_json &value, std::string_view what)
Serialize host fields retaining their declared insertion order.
Definition json_codec.cc:444
std::string DumpJsonLossy(const Json &value)
Definition json_codec.cc:449
absl::StatusOr< Json > UnpackMsgpack(std::string_view encoded, std::string_view what)
Decodes MessagePack bytes, or explains why they are not.
Definition json_codec.cc:489
absl::StatusOr< std::string > PackOrderedMsgpack(const nlohmann::ordered_json &value, std::string_view what)
Encode host fields retaining their declared insertion order.
Definition json_codec.cc:484
absl::StatusOr< std::string > DumpJson(const Json &value, std::string_view what)
Definition json_codec.cc:440
bool IsValidUtf8(std::string_view text)
Whether text is valid strict UTF-8.
Definition json_codec.cc:383
absl::StatusOr< nlohmann::ordered_json > ParseOrderedJson(std::string_view encoded, std::string_view what)
Parse host fields retaining their declared insertion order.
Definition json_codec.cc:378
absl::StatusOr< std::string > PackMsgpack(const Json &value, std::string_view what)
Definition json_codec.cc:479