WPILibC++ 2027.0.0-alpha-3
Loading...
Searching...
No Matches
reader.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_WIRE_INTERNAL_READER_H_
9#define UPB_WIRE_INTERNAL_READER_H_
10
11// Must be last.
12#include "upb/port/def.inc"
13
14#define kUpb_WireReader_WireTypeBits 3
15#define kUpb_WireReader_WireTypeMask 7
16
17typedef struct {
18 const char* ptr;
19 uint64_t val;
20} UPB_PRIVATE(_upb_WireReader_LongVarint);
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
26UPB_PRIVATE(_upb_WireReader_LongVarint)
28
30 const char* ptr, uint64_t* val, int maxlen, uint64_t maxval) {
31 uint64_t byte = (uint8_t)*ptr;
32 if (UPB_LIKELY((byte & 0x80) == 0)) {
33 *val = (uint32_t)byte;
34 return ptr + 1;
35 }
36 const char* start = ptr;
37 UPB_PRIVATE(_upb_WireReader_LongVarint)
39 if (!res.ptr || (maxlen < 10 && res.ptr - start > maxlen) ||
40 res.val > maxval) {
41 return NULL; // Malformed.
42 }
43 *val = res.val;
44 return res.ptr;
45}
46
48 return tag >> kUpb_WireReader_WireTypeBits;
49}
50
53}
54
55#ifdef __cplusplus
56} /* extern "C" */
57#endif
58
59#include "upb/port/undef.inc"
60
61#endif // UPB_WIRE_INTERNAL_READER_H_
#define UPB_API_INLINE
Definition def.inc:163
#define UPB_LIKELY(x)
Definition def.inc:264
#define UPB_PRIVATE(x)
Definition def.inc:393
#define UPB_FORCEINLINE
Definition def.inc:288
auto ptr(T p) -> const void *
Converts p to const void* for pointer formatting.
Definition format.h:3963
UPB_PRIVATE _upb_WireReader_ReadLongVarint(const char *ptr, uint64_t val)
UPB_FORCEINLINE const char *UPB_PRIVATE _upb_WireReader_ReadVarint(const char *ptr, uint64_t *val, int maxlen, uint64_t maxval)
Definition reader.h:29
UPB_API_INLINE uint32_t upb_WireReader_GetFieldNumber(uint32_t tag)
Definition reader.h:47
UPB_API_INLINE uint8_t upb_WireReader_GetWireType(uint32_t tag)
Definition reader.h:51
#define kUpb_WireReader_WireTypeMask
Definition reader.h:15
#define kUpb_WireReader_WireTypeBits
Definition reader.h:14
Definition reader.h:17
uint64_t val
Definition reader.h:19
const char * ptr
Definition reader.h:18