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 2025 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 GOOGLE_UPB_UPB_WIRE_INTERNAL_DECODE_FAST_DATALAYOUT_H__
0009 #define GOOGLE_UPB_UPB_WIRE_INTERNAL_DECODE_FAST_DATALAYOUT_H__
0010 
0011 #include <stdint.h>
0012 
0013 // Must be last.
0014 #include "upb/port/def.inc"
0015 
0016 // The layout of the data field of _upb_FastTable_Entry.field_data is as
0017 // follows:
0018 //
0019 //                  48                32                16                 0
0020 // |--------|--------|--------|--------|--------|--------|--------|--------|
0021 // |   offset (16)   |case offset (16) |presence| submsg |  exp. tag (16)  |
0022 // |--------|--------|--------|--------|--------|--------|--------|--------|
0023 //
0024 // - `offset` is the offset of the field in the message struct.
0025 // - `case_offset` is the offset of the oneof selector for a oneof field
0026 //   (or 0 if not a oneof field).
0027 // - `presence` is either hasbit index or field number for oneofs.
0028 // - `submsg_index` is the index of the submessage in the mini table's
0029 //   subs array (or 0 if not a submessage field).
0030 // - `expected_tag` is the expected value of the tag for this field.
0031 
0032 UPB_INLINE bool upb_DecodeFast_MakeData(uint64_t offset, uint64_t case_offset,
0033                                         uint64_t presence,
0034                                         uint64_t submsg_index,
0035                                         uint64_t expected_tag,
0036                                         uint64_t* out_data) {
0037   if (offset > 0xffff || case_offset > 0xffff || presence > 0xff ||
0038       submsg_index > 0xff || expected_tag > 0xffff) {
0039     return false;
0040   }
0041 
0042   *out_data = (offset << 48) | (case_offset << 32) | (presence << 24) |
0043               (submsg_index << 16) | expected_tag;
0044   return true;
0045 }
0046 
0047 UPB_INLINE uint16_t upb_DecodeFastData_GetOffset(uint64_t data) {
0048   return data >> 48;
0049 }
0050 
0051 UPB_INLINE uint16_t upb_DecodeFastData_GetCaseOffset(uint64_t data) {
0052   return data >> 32;
0053 }
0054 
0055 UPB_INLINE uint8_t upb_DecodeFastData_GetPresence(uint64_t data) {
0056   return data >> 24;
0057 }
0058 
0059 UPB_INLINE uint8_t upb_DecodeFastData_GetSubmsgIndex(uint64_t data) {
0060   return data >> 16;
0061 }
0062 
0063 UPB_INLINE uint16_t upb_DecodeFastData_GetExpectedTag(uint64_t data) {
0064   return data;
0065 }
0066 
0067 UPB_INLINE int upb_DecodeFastData_GetTableSlot(uint64_t data) {
0068   uint16_t tag = upb_DecodeFastData_GetExpectedTag(data);
0069   return (tag & 0xf8) >> 3;
0070 }
0071 
0072 #include "upb/port/undef.inc"
0073 
0074 #endif  // GOOGLE_UPB_UPB_WIRE_INTERNAL_DECODE_FAST_DATALAYOUT_H__