diff --git a/upbc/upbc_so.c b/upbc/upbc_so.c index 6e498865be..b40b9b645a 100644 --- a/upbc/upbc_so.c +++ b/upbc/upbc_so.c @@ -40,3 +40,43 @@ // Must be last. #include "upb/port/def.inc" + +// JavaScript doesn't directly support 64-bit ints so we must split them. + +UPB_API_INLINE uint32_t upb_Message_GetInt64Hi(const upb_Message* msg, + const upb_MiniTableField* field, + uint32_t default_value) { + return (uint32_t)(upb_Message_GetInt64(msg, field, default_value) >> 32); +} + +UPB_API_INLINE uint32_t upb_Message_GetInt64Lo(const upb_Message* msg, + const upb_MiniTableField* field, + uint32_t default_value) { + return (uint32_t)upb_Message_GetInt64(msg, field, default_value); +} + +UPB_API_INLINE bool upb_Message_SetInt64Split(upb_Message* msg, + const upb_MiniTableField* field, + uint32_t hi, uint32_t lo, + upb_Arena* a) { + return upb_Message_SetInt64(msg, field, ((int64_t)hi << 32) | lo, a); +} + +UPB_API_INLINE uint32_t upb_Message_GetUInt64Hi(const upb_Message* msg, + const upb_MiniTableField* field, + uint32_t default_value) { + return (uint32_t)(upb_Message_GetUInt64(msg, field, default_value) >> 32); +} + +UPB_API_INLINE uint32_t upb_Message_GetUInt64Lo(const upb_Message* msg, + const upb_MiniTableField* field, + uint32_t default_value) { + return (uint32_t)upb_Message_GetUInt64(msg, field, default_value); +} + +UPB_API_INLINE bool upb_Message_SetUInt64Split(upb_Message* msg, + const upb_MiniTableField* field, + uint32_t hi, uint32_t lo, + upb_Arena* a) { + return upb_Message_SetUInt64(msg, field, ((uint64_t)hi << 32) | lo, a); +}