WPILibC++ 2027.0.0-alpha-3
Loading...
Searching...
No Matches
base92.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_BASE92_H_
9#define UPB_MINI_DESCRIPTOR_INTERNAL_BASE92_H_
10
11#include <stdint.h>
12
14
15// Must be last.
16#include "upb/port/def.inc"
17
18#ifdef __cplusplus
19extern "C" {
20#endif
21
22UPB_INLINE char _upb_ToBase92(int8_t ch) {
23 extern const char _kUpb_ToBase92[];
24 UPB_ASSERT(0 <= ch && ch < 92);
25 return _kUpb_ToBase92[ch];
26}
27
28UPB_INLINE char _upb_FromBase92(uint8_t ch) {
29 extern const int8_t _kUpb_FromBase92[];
30 if (' ' > ch || ch > '~') return -1;
31 return _kUpb_FromBase92[ch - ' '];
32}
33
34UPB_INLINE const char* _upb_Base92_DecodeVarint(const char* ptr,
35 const char* end, char first_ch,
36 uint8_t min, uint8_t max,
37 uint32_t* out_val) {
38 uint32_t val = 0;
39 uint32_t shift = 0;
40 const int bits_per_char =
42 char ch = first_ch;
43 while (1) {
44 uint32_t bits = _upb_FromBase92(ch) - _upb_FromBase92(min);
45 val |= bits << shift;
46 if (ptr == end || *ptr < min || max < *ptr) {
47 *out_val = val;
48 UPB_ASSUME(ptr != NULL);
49 return ptr;
50 }
51 ch = *ptr++;
52 shift += bits_per_char;
53 if (shift >= 32) return NULL;
54 }
55}
56
57#ifdef __cplusplus
58} /* extern "C" */
59#endif
60
61#include "upb/port/undef.inc"
62
63#endif // UPB_MINI_DESCRIPTOR_INTERNAL_BASE92_H_
UPB_INLINE char _upb_ToBase92(int8_t ch)
Definition base92.h:22
UPB_INLINE char _upb_FromBase92(uint8_t ch)
Definition base92.h:28
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_ASSUME(expr)
Definition def.inc:319
#define UPB_ASSERT(expr)
Definition def.inc:329
#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_INLINE int upb_Log2Ceiling(int x)
Definition log2.h:19