WPILibC++ 2027.0.0-alpha-3
Loading...
Searching...
No Matches
decoder.h
Go to the documentation of this file.
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_MINI_DESCRIPTOR_INTERNAL_DECODER_H_
9#define UPB_MINI_DESCRIPTOR_INTERNAL_DECODER_H_
10
11#include "upb/base/status.h"
13
14// Must be last.
15#include "upb/port/def.inc"
16
17// upb_MdDecoder: used internally for decoding MiniDescriptors for messages,
18// extensions, and enums.
19typedef struct {
20 const char* end;
22 jmp_buf err;
24
25UPB_PRINTF(2, 3)
27 const char* fmt, ...) {
28 if (d->status) {
29 va_list argp;
30 upb_Status_SetErrorMessage(d->status, "Error building mini table: ");
31 va_start(argp, fmt);
32 upb_Status_VAppendErrorFormat(d->status, fmt, argp);
33 va_end(argp);
34 }
35 UPB_LONGJMP(d->err, 1);
36}
37
39 const void* ptr) {
40 if (!ptr) upb_MdDecoder_ErrorJmp(d, "Out of memory");
41}
42
44 upb_MdDecoder* d, const char* ptr, char first_ch, uint8_t min, uint8_t max,
45 uint32_t* out_val) {
46 ptr = _upb_Base92_DecodeVarint(ptr, d->end, first_ch, min, max, out_val);
47 if (!ptr) upb_MdDecoder_ErrorJmp(d, "Overlong varint");
48 return ptr;
49}
50
51#include "upb/port/undef.inc"
52
53#endif // UPB_MINI_DESCRIPTOR_INTERNAL_DECODER_H_
UPB_INLINE const char * _upb_Base92_DecodeVarint(const char *ptr, const char *end, char first_ch, uint8_t min, uint8_t max, uint32_t *out_val)
Definition base92.h:34
#define UPB_PRINTF(str, first_vararg)
Definition def.inc:291
#define UPB_NORETURN
Definition def.inc:290
#define UPB_LONGJMP(buf, val)
Definition def.inc:370
#define UPB_INLINE
Definition def.inc:144
auto ptr(T p) -> const void *
Converts p to const void* for pointer formatting.
Definition format.h:3963
UPB_NORETURN UPB_INLINE void upb_MdDecoder_ErrorJmp(upb_MdDecoder *d, const char *fmt,...)
Definition decoder.h:26
UPB_INLINE void upb_MdDecoder_CheckOutOfMemory(upb_MdDecoder *d, const void *ptr)
Definition decoder.h:38
UPB_INLINE const char * upb_MdDecoder_DecodeBase92Varint(upb_MdDecoder *d, const char *ptr, char first_ch, uint8_t min, uint8_t max, uint32_t *out_val)
Definition decoder.h:43
Definition decoder.h:19
jmp_buf err
Definition decoder.h:22
const char * end
Definition decoder.h:20
upb_Status * status
Definition decoder.h:21
Definition status.h:18