File indexing completed on 2025-01-18 10:13:17
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef UPB_MINI_DESCRIPTOR_INTERNAL_DECODER_H_
0009 #define UPB_MINI_DESCRIPTOR_INTERNAL_DECODER_H_
0010
0011 #include "upb/base/status.h"
0012 #include "upb/mini_descriptor/internal/base92.h"
0013
0014
0015 #include "upb/port/def.inc"
0016
0017
0018
0019 typedef struct {
0020 const char* end;
0021 upb_Status* status;
0022 jmp_buf err;
0023 } upb_MdDecoder;
0024
0025 UPB_PRINTF(2, 3)
0026 UPB_NORETURN UPB_INLINE void upb_MdDecoder_ErrorJmp(upb_MdDecoder* d,
0027 const char* fmt, ...) {
0028 if (d->status) {
0029 va_list argp;
0030 upb_Status_SetErrorMessage(d->status, "Error building mini table: ");
0031 va_start(argp, fmt);
0032 upb_Status_VAppendErrorFormat(d->status, fmt, argp);
0033 va_end(argp);
0034 }
0035 UPB_LONGJMP(d->err, 1);
0036 }
0037
0038 UPB_INLINE void upb_MdDecoder_CheckOutOfMemory(upb_MdDecoder* d,
0039 const void* ptr) {
0040 if (!ptr) upb_MdDecoder_ErrorJmp(d, "Out of memory");
0041 }
0042
0043 UPB_INLINE const char* upb_MdDecoder_DecodeBase92Varint(
0044 upb_MdDecoder* d, const char* ptr, char first_ch, uint8_t min, uint8_t max,
0045 uint32_t* out_val) {
0046 ptr = _upb_Base92_DecodeVarint(ptr, d->end, first_ch, min, max, out_val);
0047 if (!ptr) upb_MdDecoder_ErrorJmp(d, "Overlong varint");
0048 return ptr;
0049 }
0050
0051 #include "upb/port/undef.inc"
0052
0053 #endif