|
|
|
@ -48,24 +48,37 @@ enum { |
|
|
|
|
* memory during encode. */ |
|
|
|
|
kUpb_EncodeOption_Deterministic = 1, |
|
|
|
|
|
|
|
|
|
/* When set, unknown fields are not printed. */ |
|
|
|
|
// When set, unknown fields are not printed.
|
|
|
|
|
kUpb_EncodeOption_SkipUnknown = 2, |
|
|
|
|
|
|
|
|
|
/* When set, the encode will fail if any required fields are missing. */ |
|
|
|
|
// When set, the encode will fail if any required fields are missing.
|
|
|
|
|
kUpb_EncodeOption_CheckRequired = 4, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
#define UPB_ENCODE_MAXDEPTH(depth) ((depth) << 16) |
|
|
|
|
|
|
|
|
|
typedef enum { |
|
|
|
|
kUpb_EncodeStatus_Ok = 0, |
|
|
|
|
kUpb_EncodeStatus_OutOfMemory = 1, // Arena alloc failed
|
|
|
|
|
kUpb_EncodeStatus_MaxDepthExceeded = 2, // Exceeded UPB_ENCODE_MAXDEPTH
|
|
|
|
|
kUpb_EncodeStatus_MaxDepthExceeded = 2, |
|
|
|
|
|
|
|
|
|
// kUpb_EncodeOption_CheckRequired failed but the parse otherwise succeeded.
|
|
|
|
|
kUpb_EncodeStatus_MissingRequired = 3, |
|
|
|
|
} upb_EncodeStatus; |
|
|
|
|
|
|
|
|
|
UPB_INLINE uint32_t upb_EncodeOptions_MaxDepth(uint16_t depth) { |
|
|
|
|
return (uint32_t)depth << 16; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
UPB_INLINE uint16_t upb_EncodeOptions_GetMaxDepth(uint32_t options) { |
|
|
|
|
return options >> 16; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Enforce an upper bound on recursion depth.
|
|
|
|
|
UPB_INLINE int upb_Encode_LimitDepth(uint32_t encode_options, uint32_t limit) { |
|
|
|
|
uint32_t max_depth = upb_EncodeOptions_GetMaxDepth(encode_options); |
|
|
|
|
if (max_depth > limit) max_depth = limit; |
|
|
|
|
return upb_EncodeOptions_MaxDepth(max_depth) | (encode_options & 0xffff); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
upb_EncodeStatus upb_Encode(const void* msg, const upb_MiniTable* l, |
|
|
|
|
int options, upb_Arena* arena, char** buf, |
|
|
|
|
size_t* size); |
|
|
|
|