Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:13:17

0001 // Protocol Buffers - Google's data interchange format
0002 // Copyright 2023 Google LLC.  All rights reserved.
0003 //
0004 // Use of this source code is governed by a BSD-style
0005 // license that can be found in the LICENSE file or at
0006 // https://developers.google.com/open-source/licenses/bsd
0007 
0008 #ifndef UPB_MINI_DESCRIPTOR_INTERNAL_BASE92_H_
0009 #define UPB_MINI_DESCRIPTOR_INTERNAL_BASE92_H_
0010 
0011 #include <stdint.h>
0012 
0013 #include "upb/base/internal/log2.h"
0014 
0015 // Must be last.
0016 #include "upb/port/def.inc"
0017 
0018 #ifdef __cplusplus
0019 extern "C" {
0020 #endif
0021 
0022 UPB_INLINE char _upb_ToBase92(int8_t ch) {
0023   extern const char _kUpb_ToBase92[];
0024   UPB_ASSERT(0 <= ch && ch < 92);
0025   return _kUpb_ToBase92[ch];
0026 }
0027 
0028 UPB_INLINE char _upb_FromBase92(uint8_t ch) {
0029   extern const int8_t _kUpb_FromBase92[];
0030   if (' ' > ch || ch > '~') return -1;
0031   return _kUpb_FromBase92[ch - ' '];
0032 }
0033 
0034 UPB_INLINE const char* _upb_Base92_DecodeVarint(const char* ptr,
0035                                                 const char* end, char first_ch,
0036                                                 uint8_t min, uint8_t max,
0037                                                 uint32_t* out_val) {
0038   uint32_t val = 0;
0039   uint32_t shift = 0;
0040   const int bits_per_char =
0041       upb_Log2Ceiling(_upb_FromBase92(max) - _upb_FromBase92(min));
0042   char ch = first_ch;
0043   while (1) {
0044     uint32_t bits = _upb_FromBase92(ch) - _upb_FromBase92(min);
0045     val |= bits << shift;
0046     if (ptr == end || *ptr < min || max < *ptr) {
0047       *out_val = val;
0048       UPB_ASSUME(ptr != NULL);
0049       return ptr;
0050     }
0051     ch = *ptr++;
0052     shift += bits_per_char;
0053     if (shift >= 32) return NULL;
0054   }
0055 }
0056 
0057 #ifdef __cplusplus
0058 } /* extern "C" */
0059 #endif
0060 
0061 #include "upb/port/undef.inc"
0062 
0063 #endif  // UPB_MINI_DESCRIPTOR_INTERNAL_BASE92_H_