Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-07-13 08:34:21

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_WIRE_INTERNAL_READER_H_
0009 #define UPB_WIRE_INTERNAL_READER_H_
0010 
0011 // Must be last.
0012 #include "upb/port/def.inc"
0013 
0014 #define kUpb_WireReader_WireTypeBits 3
0015 #define kUpb_WireReader_WireTypeMask 7
0016 
0017 typedef struct {
0018   const char* ptr;
0019   uint64_t val;
0020 } UPB_PRIVATE(_upb_WireReader_LongVarint);
0021 
0022 #ifdef __cplusplus
0023 extern "C" {
0024 #endif
0025 
0026 UPB_PRIVATE(_upb_WireReader_LongVarint)
0027 UPB_PRIVATE(_upb_WireReader_ReadLongVarint)(const char* ptr, uint64_t val);
0028 
0029 UPB_FORCEINLINE const char* UPB_PRIVATE(_upb_WireReader_ReadVarint)(
0030     const char* ptr, uint64_t* val, int maxlen, uint64_t maxval) {
0031   uint64_t byte = (uint8_t)*ptr;
0032   if (UPB_LIKELY((byte & 0x80) == 0)) {
0033     *val = (uint32_t)byte;
0034     return ptr + 1;
0035   }
0036   const char* start = ptr;
0037   UPB_PRIVATE(_upb_WireReader_LongVarint)
0038   res = UPB_PRIVATE(_upb_WireReader_ReadLongVarint)(ptr, byte);
0039   if (!res.ptr || (maxlen < 10 && res.ptr - start > maxlen) ||
0040       res.val > maxval) {
0041     return NULL;  // Malformed.
0042   }
0043   *val = res.val;
0044   return res.ptr;
0045 }
0046 
0047 UPB_API_INLINE uint32_t upb_WireReader_GetFieldNumber(uint32_t tag) {
0048   return tag >> kUpb_WireReader_WireTypeBits;
0049 }
0050 
0051 UPB_API_INLINE uint8_t upb_WireReader_GetWireType(uint32_t tag) {
0052   return tag & kUpb_WireReader_WireTypeMask;
0053 }
0054 
0055 #ifdef __cplusplus
0056 } /* extern "C" */
0057 #endif
0058 
0059 #include "upb/port/undef.inc"
0060 
0061 #endif  // UPB_WIRE_INTERNAL_READER_H_