userver: /data/code/userver/libraries/protobuf/include/userver/protobuf/json/convert_options.hpp Source File
Loading...
Searching...
No Matches
convert_options.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/protobuf/json/convert_options.hpp
4/// @brief Protobuf messages to/from JSON `ValueBuilder`/`Value` conversion options.
5
6USERVER_NAMESPACE_BEGIN
7
8namespace protobuf::json {
9
10/// @brief Options which affect how JSON `Value` is converted to a protobuf message.
12 /// @brief Ignore unknown JSON fields and enum value names.
13 /// If not set, conversion of a JSON object containing unknown field (i.e. field that is not mapped to any protobuf
14 /// message field) or unknown enum value name will fail.
16
17 /// @brief Deserialize `google.protobuf.Any` from a raw `{"type_url": "...", "value": "<base64>"}`
18 /// or `{"typeUrl": "...", "value": "<base64>"}` JSON object
19 /// without looking up the payload descriptor in the descriptor pool.
20 /// When set, `value` must be a base64-encoded protobuf wire-format string.
21 ///
22 /// @warning This is a userver-only extension that is not supported in other frameworks.
23 /// Only userver can correctly parse this format.
24 bool nonportable_raw_any = false;
25};
26
27/// @brief Options which affect how protobuf message is converted to a JSON `ValueBuilder`/`Value`.
29 /// @brief Always output protobuf message fields that do not have explicit presence.
30 /// This fields are:
31 /// * implicit presence fields set to default value
32 /// * empty repeated/map fields
34
35 /// @brief Output enum values as integers, not as their string names.
37
38 /// @brief Output field names exactly how specified in the proto file (usually *lower_snake_case*).
39 /// By default, protobuf message field names are converted to `lowerCamelCase` format.
40 /// @note If protobuf message field has `json_name` option attached, then it's value is used for the JSON key
41 /// name and this option does not have effect.
42 /// @warning According to protobuf rules this option **does not have effect** on the field names specified in the
43 /// `google.protobuf.FieldMask` paths during conversion. I.e., field names inside `FieldMask` are always
44 /// encoded in `lowerCamelCase` no matter whether `preserve_proto_field_names` is on or off. Moreover,
45 /// `json_name` option is also not taken into account for `FieldMask` paths.
47
48 /// @brief Serialize `google.protobuf.Any` as a raw `{"typeUrl": "...", "value": "<base64>"}` JSON object
49 /// without looking up the payload descriptor in the descriptor pool.
50 /// When set, `value` is base64-encoded protobuf wire bytes of the payload.
51 /// If `preserve_proto_field_names` is true, `type_url` is used instead of `typeUrl`.
52 ///
53 /// @warning This is a userver-only extension that is not supported in other frameworks.
54 /// Only userver can correctly parse this format.
55 bool nonportable_raw_any = false;
56};
57
58} // namespace protobuf::json
59
60USERVER_NAMESPACE_END