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
61bool IsValidUtf8(std::string_view text);
62
75const nlohmann::json* FindUnencodableString(const nlohmann::json& value);
76
101absl::StatusOr<std::string> DumpJson(const nlohmann::json& value,
102 std::string_view what);
103
110std::string DumpJsonLossy(const nlohmann::json& value);
111
113absl::StatusOr<std::string> PackMsgpack(const nlohmann::json& value,
114 std::string_view what);
115
117absl::StatusOr<nlohmann::json> UnpackMsgpack(std::string_view encoded,
118 std::string_view what);
119
120} // namespace a11
121
122#endif // A11_JSON_CODEC_H_
std::string value
Definition discover.cc:114
std::optional< std::string > text
The text, where the value is a string literal or a name bound to one.
Definition discover.cc:612
Definition action.cc:63
absl::StatusOr< Json > ParseJson(std::string_view encoded, std::string_view what)
Parses JSON text, or explains why it is not JSON.
Definition json_codec.cc:342
const Json * FindUnencodableString(const Json &value)
Definition json_codec.cc:367
std::string DumpJsonLossy(const Json &value)
Definition json_codec.cc:412
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:437
absl::StatusOr< std::string > DumpJson(const Json &value, std::string_view what)
Definition json_codec.cc:387
bool IsValidUtf8(std::string_view text)
Whether text is valid UTF-8.
Definition json_codec.cc:363
absl::StatusOr< std::string > PackMsgpack(const Json &value, std::string_view what)
Definition json_codec.cc:418