|
| absl::Status | StatusFromNativeError (int native_code, absl::string_view operation) |
| |
| int | NativeErrorFromStatus (const absl::Status &status) |
| |
| absl::StatusOr< Json > | ParseJson (std::string_view encoded, std::string_view what) |
| | Parses JSON text, or explains why it is not JSON.
|
| |
| bool | IsValidUtf8 (std::string_view text) |
| | Whether text is valid UTF-8.
|
| |
| const Json * | FindUnencodableString (const Json &value) |
| |
| absl::StatusOr< std::string > | DumpJson (const Json &value, std::string_view what) |
| |
| std::string | DumpJsonLossy (const Json &value) |
| |
| absl::StatusOr< std::string > | PackMsgpack (const Json &value, std::string_view what) |
| |
| absl::StatusOr< Json > | UnpackMsgpack (std::string_view encoded, std::string_view what) |
| | Decodes MessagePack bytes, or explains why they are not.
|
| |
| const nlohmann::json * | FindUnencodableString (const nlohmann::json &value) |
| | The first string inside value that is not valid UTF-8, or nullptr.
|
| |
| absl::StatusOr< std::string > | DumpJson (const nlohmann::json &value, std::string_view what) |
| | Serializes value, rejecting strings that are not valid UTF-8.
|
| |
| std::string | DumpJsonLossy (const nlohmann::json &value) |
| | Serializes value, replacing anything that is not valid UTF-8.
|
| |
| absl::StatusOr< std::string > | PackMsgpack (const nlohmann::json &value, std::string_view what) |
| | Encodes value as MessagePack, or says why it cannot be.
|
| |
| absl::StatusCode | StatusCodeFromHttp (int http_code) |
| | Maps an HTTP status code to a canonical status code.
|
| |
| int | StatusCodeToHttp (absl::StatusCode code) |
| | Maps a canonical status code to its HTTP status code.
|
| |
| absl::StatusCode | StatusCodeFromWebSocket (std::uint16_t close_code) |
| | Maps a WebSocket close code to a canonical status code.
|
| |
| std::uint16_t | StatusCodeToWebSocket (absl::StatusCode code) |
| | Maps a canonical status code to its WebSocket close code.
|
| |
| absl::Status | MakeStatus (absl::StatusCode code, const std::string &message, const nlohmann::json &details) |
| | Builds a status carrying an A11 structured-details payload.
|
| |
| nlohmann::json | StatusDetails (const absl::Status &status) |
| | Extracts the structured-details payload from a status.
|
| |
| absl::StatusOr< nlohmann::json > | StatusToJson (const absl::Status &status) |
| | Serializes a status (code, message, details) to JSON.
|
| |
| nlohmann::json | StatusToJsonOrEmptyDetails (const absl::Status &status) |
| | Serializes a status to JSON, never failing.
|
| |
| absl::StatusOr< absl::Status > | StatusFromJson (const nlohmann::json &value) |
| | Reconstructs a status from its JSON representation.
|
| |
| absl::StatusOr< std::string > symbian::DumpJson |
( |
const nlohmann::json & |
value, |
|
|
std::string_view |
what |
|
) |
| |
Serializes value, rejecting strings that are not valid UTF-8.
Strict on purpose: JSON is defined over text, and a chunk holding arbitrary bytes has to be encoded (base64, as data/json.cc does) rather than smuggled into a string field where a peer's parser would reject it. This is the one caller of nlohmann that wants the error rather than a replacement character.
String values and object keys are checked before invoking nlohmann's strict serializer, including in native tests compiled without exceptions.
| const nlohmann::json * symbian::FindUnencodableString |
( |
const nlohmann::json & |
value | ) |
|
The first string inside value that is not valid UTF-8, or nullptr.
The strings that come from outside are not only at the top level: a response header's value and a directory entry's name are both fields of a record, and both are exactly where something outside this process can put arbitrary bytes.
Iterative, not recursive: this runs on whatever fiber is serializing, and A11's fiber stacks are fixed and small, so the depth of the document must not decide how much stack the check needs.
| bool symbian::IsValidUtf8 |
( |
std::string_view |
text | ) |
|
Whether text is valid UTF-8.
Public because the answer has to be available before nlohmann is asked. See DumpJson for why asking nlohmann is not safe.
Strict by the definition every other A11 language's string type enforces, which is stricter than "the bytes are shaped like UTF-8": overlong encodings, surrogate halves and anything above U+10FFFF are all rejected. Python's bytes.decode("utf-8"), Kotlin's String(bytes) and JavaScript's TextDecoder with fatal all refuse them, so a chunk carrying them is one a peer cannot read – and a value this side refuses to write is a much better outcome than a session that dies one hop away.