File indexing completed on 2025-01-30 10:25:25
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef UPB_WIRE_ENCODE_H_
0011 #define UPB_WIRE_ENCODE_H_
0012
0013 #include <stddef.h>
0014 #include <stdint.h>
0015
0016 #include "upb/mem/arena.h"
0017 #include "upb/message/message.h"
0018 #include "upb/mini_table/message.h"
0019
0020
0021 #include "upb/port/def.inc"
0022
0023 #ifdef __cplusplus
0024 extern "C" {
0025 #endif
0026
0027 enum {
0028
0029
0030
0031
0032
0033
0034 kUpb_EncodeOption_Deterministic = 1,
0035
0036
0037 kUpb_EncodeOption_SkipUnknown = 2,
0038
0039
0040 kUpb_EncodeOption_CheckRequired = 4,
0041 };
0042
0043
0044 typedef enum {
0045 kUpb_EncodeStatus_Ok = 0,
0046 kUpb_EncodeStatus_OutOfMemory = 1,
0047 kUpb_EncodeStatus_MaxDepthExceeded = 2,
0048
0049
0050 kUpb_EncodeStatus_MissingRequired = 3,
0051 } upb_EncodeStatus;
0052
0053
0054 UPB_INLINE uint32_t upb_EncodeOptions_MaxDepth(uint16_t depth) {
0055 return (uint32_t)depth << 16;
0056 }
0057
0058 UPB_INLINE uint16_t upb_EncodeOptions_GetMaxDepth(uint32_t options) {
0059 return options >> 16;
0060 }
0061
0062
0063 UPB_INLINE int upb_Encode_LimitDepth(uint32_t encode_options, uint32_t limit) {
0064 uint32_t max_depth = upb_EncodeOptions_GetMaxDepth(encode_options);
0065 if (max_depth > limit) max_depth = limit;
0066 return upb_EncodeOptions_MaxDepth(max_depth) | (encode_options & 0xffff);
0067 }
0068
0069 UPB_API upb_EncodeStatus upb_Encode(const upb_Message* msg,
0070 const upb_MiniTable* l, int options,
0071 upb_Arena* arena, char** buf, size_t* size);
0072
0073
0074 UPB_API upb_EncodeStatus upb_EncodeLengthPrefixed(const upb_Message* msg,
0075 const upb_MiniTable* l,
0076 int options, upb_Arena* arena,
0077 char** buf, size_t* size);
0078
0079
0080 UPB_API const char* upb_EncodeStatus_String(upb_EncodeStatus status);
0081
0082 #ifdef __cplusplus
0083 }
0084 #endif
0085
0086 #include "upb/port/undef.inc"
0087
0088 #endif