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_BASE_UPCAST_H_ 9 #define UPB_BASE_UPCAST_H_ 10 11 // Must be last. 12 #include "upb/port/def.inc" 13 14 // This macro provides a way to upcast message pointers in a way that is 15 // somewhat more bulletproof than blindly casting a pointer. Example: 16 // 17 // typedef struct { 18 // upb_Message UPB_PRIVATE(base); 19 // } pkg_FooMessage; 20 // 21 // void f(pkg_FooMessage* msg) { 22 // upb_Decode(UPB_UPCAST(msg), ...); 23 // } 24 25 #define UPB_UPCAST(x) (&(x)->base##_dont_copy_me__upb_internal_use_only) 26 27 #include "upb/port/undef.inc" 28 29 #endif /* UPB_BASE_UPCAST_H_ */ 30