• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2023 Google LLC.  All rights reserved.
3 //
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file or at
6 // https://developers.google.com/open-source/licenses/bsd
7 
8 #ifndef UPB_JSON_ENCODE_H_
9 #define UPB_JSON_ENCODE_H_
10 
11 #include "upb/reflection/def.h"
12 
13 // Must be last.
14 #include "upb/port/def.inc"
15 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19 
20 enum {
21   /* When set, emits 0/default values.  TODO: proto3 only? */
22   upb_JsonEncode_EmitDefaults = 1 << 0,
23 
24   /* When set, use normal (snake_case) field names instead of JSON (camelCase)
25      names. */
26   upb_JsonEncode_UseProtoNames = 1 << 1,
27 
28   /* When set, emits enums as their integer values instead of as their names. */
29   upb_JsonEncode_FormatEnumsAsIntegers = 1 << 2
30 };
31 
32 /* Encodes the given |msg| to JSON format.  The message's reflection is given in
33  * |m|.  The DefPool in |ext_pool| is used to find extensions (if NULL,
34  * extensions will not be printed).
35  *
36  * Output is placed in the given buffer, and always NULL-terminated.  The output
37  * size (excluding NULL) is returned.  This means that a return value >= |size|
38  * implies that the output was truncated.  (These are the same semantics as
39  * snprintf()). */
40 UPB_API size_t upb_JsonEncode(const upb_Message* msg, const upb_MessageDef* m,
41                               const upb_DefPool* ext_pool, int options,
42                               char* buf, size_t size, upb_Status* status);
43 
44 #ifdef __cplusplus
45 } /* extern "C" */
46 #endif
47 
48 #include "upb/port/undef.inc"
49 
50 #endif /* UPB_JSONENCODE_H_ */
51