Compare commits

...

13 Commits

Author SHA1 Message Date
copybara-service[bot] 37c18c5f2c
Merge 937d0e27bf into ec126a5069 2024-05-09 04:11:48 +08:00
Protobuf Team Bot ec126a5069 Replace the single user of `PROTOBUF_ALIGNAS` with `alignas` and remove the now
dead macro.
This reduces the compile time cost of port_def.inc

PiperOrigin-RevId: 631886181
2024-05-08 12:27:42 -07:00
Protobuf Team Bot 64580b29c1 Expose JavaPackageDirectory and FileClassName in java/names.h
PiperOrigin-RevId: 631870244
2024-05-08 11:35:56 -07:00
Protobuf Team Bot d5b7d7a87f Remove dead feature macro.
The opt-out code was removed some time ago.

PiperOrigin-RevId: 631826723
2024-05-08 09:30:53 -07:00
Brent Shaffer 01744cccae chore(php): conformance testing for edition (#16712)
COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/16712 from bshaffer:php-editions a1c41add7d
PiperOrigin-RevId: 631824623
2024-05-08 09:23:08 -07:00
Sandy Zhang b77343aa2c Add temporary alias for system_python.bzl at previous location .
This was added to protobuf_deps.bzl in cl/629786458 and no longer needs to be specified directly in WORKSPACE. However, an alias is needed to prevent users from breaking when upgrading from 26.x -> 27.x due to the obsolete load pointing to the wrong path.

This alias will be removed in a future release, tentatively 4.30.x.

PiperOrigin-RevId: 631821637
2024-05-08 09:18:42 -07:00
Protobuf Team Bot d8329b68e4 Add .to_owned(&self)->Msg functions to MsgMut and MsgView
PiperOrigin-RevId: 631686314
2024-05-08 00:54:28 -07:00
Protobuf Team Bot 6afb130dca Auto-generate files after cl/631620526 2024-05-08 02:19:22 +00:00
Eric Salo d923896299 upb: implement most of the non-universal setters
PiperOrigin-RevId: 631620526
2024-05-07 19:07:33 -07:00
Protobuf Team Bot 4d3a98c27e Auto-generate files after cl/631612923 2024-05-08 01:37:14 +00:00
Eric Salo 65821a67d6 upb: finish cleaning up message/accessors.h and message/internal/accessors.h
PiperOrigin-RevId: 631612923
2024-05-07 18:25:25 -07:00
Éamonn McManus 98d5bdd111 Add "reserved literals" to the list of reserved names for Java.
The identifiers `true`, `false`, and `null` are effectively reserved words in Java, although for some reason they are listed separately from the "keywords" in the Java Language Specification.

This doesn't matter for regular fields, because a proto field called `true` will be accessed with `getTrue` and `setTrue`. But for extensions, the generated Java code will have a public static field whose name is the same as the name of the extension field, with `_` appended if the name is a reserved word. Previously there was no `_` for `true` etc, so the generated code would not compile.

PiperOrigin-RevId: 631599695
2024-05-07 17:23:09 -07:00
Protobuf Team Bot 937d0e27bf Remove `Arena_pin` in favor and adopt the UPB freezing API instead.
PiperOrigin-RevId: 631451788
2024-05-07 13:12:53 -07:00
33 changed files with 1530 additions and 901 deletions

View File

@ -332,13 +332,14 @@ inline_sh_binary(
],
cmd = """
php -dextension=$(rootpath //php:extension) \\
-d include_path=conformance:src/google/protobuf \\
-d include_path=conformance:src/google/protobuf:editions/golden \\
$(rootpath conformance_php.php)
""",
visibility = ["//php:__subpackages__"],
deps = [
":conformance_php_proto",
"//:test_messages_proto3_php_proto",
"//editions:test_messages_proto3_editions_php_proto",
],
)

View File

@ -1,80 +1,134 @@
<?php
require_once("Conformance/WireFormat.php");
require_once("Conformance/ConformanceResponse.php");
require_once("Conformance/ConformanceRequest.php");
require_once("Conformance/FailureSet.php");
require_once("Conformance/JspbEncodingConfig.php");
require_once("Conformance/TestCategory.php");
require_once("Protobuf_test_messages/Proto3/ForeignMessage.php");
require_once("Protobuf_test_messages/Proto3/ForeignEnum.php");
require_once("Protobuf_test_messages/Proto3/TestAllTypesProto3.php");
require_once("Protobuf_test_messages/Proto3/TestAllTypesProto3/AliasedEnum.php");
require_once("Protobuf_test_messages/Proto3/TestAllTypesProto3/NestedMessage.php");
require_once("Protobuf_test_messages/Proto3/TestAllTypesProto3/NestedEnum.php");
require_once('Conformance/WireFormat.php');
require_once('Conformance/ConformanceResponse.php');
require_once('Conformance/ConformanceRequest.php');
require_once('Conformance/FailureSet.php');
require_once('Conformance/JspbEncodingConfig.php');
require_once('Conformance/TestCategory.php');
require_once('Protobuf_test_messages/Proto3/ForeignMessage.php');
require_once('Protobuf_test_messages/Proto3/ForeignEnum.php');
require_once('Protobuf_test_messages/Proto3/TestAllTypesProto3.php');
require_once('Protobuf_test_messages/Proto3/TestAllTypesProto3/AliasedEnum.php');
require_once('Protobuf_test_messages/Proto3/TestAllTypesProto3/NestedMessage.php');
require_once('Protobuf_test_messages/Proto3/TestAllTypesProto3/NestedEnum.php');
require_once('Protobuf_test_messages/Editions/Proto3/EnumOnlyProto3/PBBool.php');
require_once('Protobuf_test_messages/Editions/Proto3/EnumOnlyProto3.php');
require_once('Protobuf_test_messages/Editions/Proto3/TestAllTypesProto3/NestedMessage.php');
require_once('Protobuf_test_messages/Editions/Proto3/TestAllTypesProto3/NestedEnum.php');
require_once('Protobuf_test_messages/Editions/Proto3/TestAllTypesProto3/AliasedEnum.php');
require_once('Protobuf_test_messages/Editions/Proto3/TestAllTypesProto3.php');
require_once('Protobuf_test_messages/Editions/Proto3/NullHypothesisProto3.php');
require_once('Protobuf_test_messages/Editions/Proto3/ForeignEnum.php');
require_once('Protobuf_test_messages/Editions/Proto3/ForeignMessage.php');
require_once('GPBMetadata/Conformance.php');
require_once('GPBMetadata/TestMessagesProto3.php');
require_once('GPBMetadata/TestMessagesProto3Editions.php');
require_once("GPBMetadata/Conformance.php");
require_once("GPBMetadata/TestMessagesProto3.php");
use Conformance\ConformanceRequest;
use Conformance\ConformanceResponse;
use Conformance\TestCategory;
use Conformance\WireFormat;
use Protobuf_test_messages\Proto3\TestAllTypesProto3;
use Protobuf_test_messages\Editions\Proto3\TestAllTypesProto3 as TestAllTypesProto3Editions;
use \Conformance\TestCategory;
use \Conformance\WireFormat;
if (!ini_get("date.timezone")) {
ini_set("date.timezone", "UTC");
if (!ini_get('date.timezone')) {
ini_set('date.timezone', 'UTC');
}
$test_count = 0;
function doTest($request)
{
$test_message = new \Protobuf_test_messages\Proto3\TestAllTypesProto3();
$response = new \Conformance\ConformanceResponse();
if ($request->getPayload() == "protobuf_payload") {
if ($request->getMessageType() == "conformance.FailureSet") {
$response->setProtobufPayload("");
return $response;
} elseif ($request->getMessageType() == "protobuf_test_messages.proto3.TestAllTypesProto3") {
try {
$test_message->mergeFromString($request->getProtobufPayload());
} catch (Exception $e) {
$response->setParseError($e->getMessage());
return $response;
}
} elseif ($request->getMessageType() == "protobuf_test_messages.proto2.TestAllTypesProto2") {
$response->setSkipped("PHP doesn't support proto2");
return $response;
} else {
trigger_error("Protobuf request doesn't have specific payload type", E_USER_ERROR);
}
} elseif ($request->getPayload() == "json_payload") {
$ignore_json_unknown =
($request->getTestCategory() ==
TestCategory::JSON_IGNORE_UNKNOWN_PARSING_TEST);
try {
$test_message->mergeFromJsonString($request->getJsonPayload(),
$ignore_json_unknown);
} catch (Exception $e) {
$response->setParseError($e->getMessage());
return $response;
}
} elseif ($request->getPayload() == "text_payload") {
$response->setSkipped("PHP doesn't support text format yet");
return $response;
} else {
trigger_error("Request didn't have payload.", E_USER_ERROR);
$response = new ConformanceResponse();
switch ($request->getPayload()) {
case 'protobuf_payload':
switch ($request->getMessageType()) {
case 'protobuf_test_messages.proto3.TestAllTypesProto3':
$test_message = new TestAllTypesProto3();
break;
case 'protobuf_test_messages.editions.proto3.TestAllTypesProto3':
$test_message = new TestAllTypesProto3Editions();
break;
case 'conformance.FailureSet':
$response->setProtobufPayload('');
return $response;
case 'protobuf_test_messages.proto2.TestAllTypesProto2':
case 'protobuf_test_messages.editions.proto2.TestAllTypesProto2':
$response->setSkipped('PHP doesn\'t support proto2');
return $response;
case 'protobuf_test_messages.editions.TestAllTypesEdition2023':
$response->setSkipped('PHP doesn\'t support editions-specific features yet');
return $response;
case '':
trigger_error(
'Protobuf request doesn\'t have specific payload type',
E_USER_ERROR
);
default:
trigger_error(sprintf(
'Protobuf request doesn\'t support %s message type',
$request->getMessageType(),
), E_USER_ERROR);
}
try {
$test_message->mergeFromString($request->getProtobufPayload());
} catch (Exception $e) {
$response->setParseError($e->getMessage());
return $response;
}
break;
case 'json_payload':
switch ($request->getMessageType()) {
case 'protobuf_test_messages.editions.proto3.TestAllTypesProto3':
$test_message = new TestAllTypesProto3Editions();
break;
case 'protobuf_test_messages.editions.proto2.TestAllTypesProto2':
$response->setSkipped('PHP doesn\'t support proto2');
return $response;
default:
$test_message = new TestAllTypesProto3();
}
$ignore_json_unknown =
($request->getTestCategory() == TestCategory::JSON_IGNORE_UNKNOWN_PARSING_TEST);
try {
$test_message->mergeFromJsonString(
$request->getJsonPayload(),
$ignore_json_unknown
);
} catch (Exception $e) {
$response->setParseError($e->getMessage());
return $response;
}
break;
case 'text_payload':
$response->setSkipped('PHP doesn\'t support text format yet');
return $response;
default:
trigger_error('Request didn\'t have payload.', E_USER_ERROR);
}
if ($request->getRequestedOutputFormat() == WireFormat::UNSPECIFIED) {
trigger_error("Unspecified output format.", E_USER_ERROR);
} elseif ($request->getRequestedOutputFormat() == WireFormat::PROTOBUF) {
$response->setProtobufPayload($test_message->serializeToString());
} elseif ($request->getRequestedOutputFormat() == WireFormat::JSON) {
try {
$response->setJsonPayload($test_message->serializeToJsonString());
} catch (Exception $e) {
$response->setSerializeError($e->getMessage());
return $response;
}
switch ($request->getRequestedOutputFormat()) {
case WireFormat::TEXT_FORMAT:
$response->setSkipped('PHP doesn\'t support text format yet');
return $response;
case WireFormat::UNSPECIFIED:
trigger_error('Unspecified output format.', E_USER_ERROR);
case WireFormat::PROTOBUF:
$response->setProtobufPayload($test_message->serializeToString());
break;
case WireFormat::JSON:
try {
$response->setJsonPayload($test_message->serializeToJsonString());
} catch (Exception $e) {
$response->setSerializeError($e->getMessage());
return $response;
}
}
return $response;
@ -84,25 +138,25 @@ function doTestIO()
{
$length_bytes = fread(STDIN, 4);
if (strlen($length_bytes) == 0) {
return false; # EOF
return false; # EOF
} elseif (strlen($length_bytes) != 4) {
fwrite(STDERR, "I/O error\n");
return false;
fwrite(STDERR, "I/O error\n");
return false;
}
$length = unpack("V", $length_bytes)[1];
$length = unpack('V', $length_bytes)[1];
$serialized_request = fread(STDIN, $length);
if (strlen($serialized_request) != $length) {
trigger_error("I/O error", E_USER_ERROR);
trigger_error('I/O error', E_USER_ERROR);
}
$request = new \Conformance\ConformanceRequest();
$request = new ConformanceRequest();
$request->mergeFromString($serialized_request);
$response = doTest($request);
$serialized_response = $response->serializeToString();
fwrite(STDOUT, pack("V", strlen($serialized_response)));
fwrite(STDOUT, pack('V', strlen($serialized_response)));
fwrite(STDOUT, $serialized_response);
$GLOBALS['test_count'] += 1;
@ -111,10 +165,10 @@ function doTestIO()
}
while(true){
if (!doTestIO()) {
fprintf(STDERR,
"conformance_php: received EOF from test runner " .
"after %d tests, exiting\n", $test_count);
exit;
}
if (!doTestIO()) {
fprintf(STDERR,
'conformance_php: received EOF from test runner ' .
"after %d tests, exiting\n", $test_count);
exit;
}
}

View File

@ -1,8 +0,0 @@
Recommended.Proto3.ProtobufInput.GroupUnknownFields_Drop.TextFormatOutput
Recommended.Proto3.ProtobufInput.GroupUnknownFields_Print.TextFormatOutput
Recommended.Proto3.ProtobufInput.MessageUnknownFields_Drop.TextFormatOutput
Recommended.Proto3.ProtobufInput.MessageUnknownFields_Print.TextFormatOutput
Recommended.Proto3.ProtobufInput.RepeatedUnknownFields_Drop.TextFormatOutput
Recommended.Proto3.ProtobufInput.RepeatedUnknownFields_Print.TextFormatOutput
Recommended.Proto3.ProtobufInput.ScalarUnknownFields_Drop.TextFormatOutput
Recommended.Proto3.ProtobufInput.ScalarUnknownFields_Print.TextFormatOutput

View File

@ -1,5 +1,5 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("//:protobuf.bzl", "internal_objc_proto_library", "internal_py_proto_library")
load("//:protobuf.bzl", "internal_objc_proto_library", "internal_php_proto_library", "internal_py_proto_library")
load("//bazel:cc_proto_library.bzl", "cc_proto_library")
load("//bazel:upb_proto_library.bzl", "upb_c_proto_library", "upb_proto_reflection_library")
load(":defaults.bzl", "compile_edition_defaults", "embed_edition_defaults")
@ -236,6 +236,31 @@ java_lite_proto_library(
deps = [":test_messages_proto3_editions_proto"],
)
internal_php_proto_library(
name = "test_messages_proto3_editions_php_proto",
testonly = 1,
srcs = ["golden/test_messages_proto3_editions.proto"],
outs = [
"GPBMetadata/TestMessagesProto3Editions.php",
"Protobuf_test_messages/Editions/Proto3/EnumOnlyProto3.php",
"Protobuf_test_messages/Editions/Proto3/EnumOnlyProto3/PBBool.php",
"Protobuf_test_messages/Editions/Proto3/ForeignEnum.php",
"Protobuf_test_messages/Editions/Proto3/ForeignMessage.php",
"Protobuf_test_messages/Editions/Proto3/NullHypothesisProto3.php",
"Protobuf_test_messages/Editions/Proto3/TestAllTypesProto3.php",
"Protobuf_test_messages/Editions/Proto3/TestAllTypesProto3/AliasedEnum.php",
"Protobuf_test_messages/Editions/Proto3/TestAllTypesProto3/NestedEnum.php",
"Protobuf_test_messages/Editions/Proto3/TestAllTypesProto3/NestedMessage.php",
],
enable_editions = True,
includes = [
"golden",
"src",
],
proto_deps = ["//:well_known_protos"],
visibility = ["//conformance:__pkg__"],
)
internal_py_proto_library(
name = "test_messages_proto3_editions_py_pb2",
testonly = True,

View File

@ -0,0 +1,17 @@
# Copyright (c) 2009-2021, Google LLC
# All rights reserved.
#
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file or at
# https://developers.google.com/open-source/licenses/bsd
"""Temporary alias to repository rule for using Python 3.x headers from the system."""
load(
"//python/dist:system_python.bzl",
_system_python = "system_python",
)
# TODO: Temporary alias. This is deprecated and to be removed in a future
# release. Users should now get system_python from protobuf_deps.bzl.
system_python = _system_python

View File

@ -64,6 +64,7 @@ genrule(
conformance_test(
name = "conformance_test",
failure_list = "//conformance:failure_list_php.txt",
maximum_edition = "2023",
target_compatible_with = select({
"@platforms//os:osx": ["@platforms//:incompatible"],
"//conditions:default": [],
@ -75,6 +76,7 @@ conformance_test(
conformance_test(
name = "conformance_test_c",
failure_list = "//conformance:failure_list_php_c.txt",
maximum_edition = "2023",
target_compatible_with = select({
"@platforms//os:osx": [],
"//conditions:default": ["@platforms//:incompatible"],

View File

@ -6158,7 +6158,7 @@ upb_Message* _upb_Message_Copy(upb_Message* dst, const upb_Message* src,
return NULL;
}
UPB_PRIVATE(_upb_Message_SetTaggedMessagePtr)
(dst, mini_table, field,
(dst, field,
UPB_PRIVATE(_upb_TaggedMessagePtr_Pack)(dst_sub_message,
is_empty));
}

View File

@ -413,113 +413,6 @@ void upb_Status_VAppendErrorFormat(upb_Status* status, const char* fmt,
#ifndef UPB_MESSAGE_ACCESSORS_H_
#define UPB_MESSAGE_ACCESSORS_H_
#include <stddef.h>
#include <stdint.h>
#include <string.h>
#ifndef UPB_BASE_DESCRIPTOR_CONSTANTS_H_
#define UPB_BASE_DESCRIPTOR_CONSTANTS_H_
// Must be last.
// The types a field can have. Note that this list is not identical to the
// types defined in descriptor.proto, which gives INT32 and SINT32 separate
// types (we distinguish the two with the "integer encoding" enum below).
// This enum is an internal convenience only and has no meaning outside of upb.
typedef enum {
kUpb_CType_Bool = 1,
kUpb_CType_Float = 2,
kUpb_CType_Int32 = 3,
kUpb_CType_UInt32 = 4,
kUpb_CType_Enum = 5, // Enum values are int32. TODO: rename
kUpb_CType_Message = 6,
kUpb_CType_Double = 7,
kUpb_CType_Int64 = 8,
kUpb_CType_UInt64 = 9,
kUpb_CType_String = 10,
kUpb_CType_Bytes = 11
} upb_CType;
// The repeated-ness of each field; this matches descriptor.proto.
typedef enum {
kUpb_Label_Optional = 1,
kUpb_Label_Required = 2,
kUpb_Label_Repeated = 3
} upb_Label;
// Descriptor types, as defined in descriptor.proto.
typedef enum {
kUpb_FieldType_Double = 1,
kUpb_FieldType_Float = 2,
kUpb_FieldType_Int64 = 3,
kUpb_FieldType_UInt64 = 4,
kUpb_FieldType_Int32 = 5,
kUpb_FieldType_Fixed64 = 6,
kUpb_FieldType_Fixed32 = 7,
kUpb_FieldType_Bool = 8,
kUpb_FieldType_String = 9,
kUpb_FieldType_Group = 10,
kUpb_FieldType_Message = 11,
kUpb_FieldType_Bytes = 12,
kUpb_FieldType_UInt32 = 13,
kUpb_FieldType_Enum = 14,
kUpb_FieldType_SFixed32 = 15,
kUpb_FieldType_SFixed64 = 16,
kUpb_FieldType_SInt32 = 17,
kUpb_FieldType_SInt64 = 18,
} upb_FieldType;
#define kUpb_FieldType_SizeOf 19
#ifdef __cplusplus
extern "C" {
#endif
// Convert from upb_FieldType to upb_CType
UPB_INLINE upb_CType upb_FieldType_CType(upb_FieldType field_type) {
static const upb_CType c_type[] = {
kUpb_CType_Double, // kUpb_FieldType_Double
kUpb_CType_Float, // kUpb_FieldType_Float
kUpb_CType_Int64, // kUpb_FieldType_Int64
kUpb_CType_UInt64, // kUpb_FieldType_UInt64
kUpb_CType_Int32, // kUpb_FieldType_Int32
kUpb_CType_UInt64, // kUpb_FieldType_Fixed64
kUpb_CType_UInt32, // kUpb_FieldType_Fixed32
kUpb_CType_Bool, // kUpb_FieldType_Bool
kUpb_CType_String, // kUpb_FieldType_String
kUpb_CType_Message, // kUpb_FieldType_Group
kUpb_CType_Message, // kUpb_FieldType_Message
kUpb_CType_Bytes, // kUpb_FieldType_Bytes
kUpb_CType_UInt32, // kUpb_FieldType_UInt32
kUpb_CType_Enum, // kUpb_FieldType_Enum
kUpb_CType_Int32, // kUpb_FieldType_SFixed32
kUpb_CType_Int64, // kUpb_FieldType_SFixed64
kUpb_CType_Int32, // kUpb_FieldType_SInt32
kUpb_CType_Int64, // kUpb_FieldType_SInt64
};
// -1 here because the enum is one-based but the table is zero-based.
return c_type[field_type - 1];
}
UPB_INLINE bool upb_FieldType_IsPackable(upb_FieldType field_type) {
// clang-format off
const unsigned kUnpackableTypes =
(1 << kUpb_FieldType_String) |
(1 << kUpb_FieldType_Bytes) |
(1 << kUpb_FieldType_Message) |
(1 << kUpb_FieldType_Group);
// clang-format on
return (1 << field_type) & ~kUnpackableTypes;
}
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* UPB_BASE_DESCRIPTOR_CONSTANTS_H_ */
#ifndef UPB_BASE_STRING_VIEW_H_
#define UPB_BASE_STRING_VIEW_H_
@ -827,6 +720,109 @@ void upb_Arena_SetTraceHandler(void (*initArenaTraceHandler)(const upb_Arena*,
#include <stddef.h>
#ifndef UPB_BASE_DESCRIPTOR_CONSTANTS_H_
#define UPB_BASE_DESCRIPTOR_CONSTANTS_H_
// Must be last.
// The types a field can have. Note that this list is not identical to the
// types defined in descriptor.proto, which gives INT32 and SINT32 separate
// types (we distinguish the two with the "integer encoding" enum below).
// This enum is an internal convenience only and has no meaning outside of upb.
typedef enum {
kUpb_CType_Bool = 1,
kUpb_CType_Float = 2,
kUpb_CType_Int32 = 3,
kUpb_CType_UInt32 = 4,
kUpb_CType_Enum = 5, // Enum values are int32. TODO: rename
kUpb_CType_Message = 6,
kUpb_CType_Double = 7,
kUpb_CType_Int64 = 8,
kUpb_CType_UInt64 = 9,
kUpb_CType_String = 10,
kUpb_CType_Bytes = 11
} upb_CType;
// The repeated-ness of each field; this matches descriptor.proto.
typedef enum {
kUpb_Label_Optional = 1,
kUpb_Label_Required = 2,
kUpb_Label_Repeated = 3
} upb_Label;
// Descriptor types, as defined in descriptor.proto.
typedef enum {
kUpb_FieldType_Double = 1,
kUpb_FieldType_Float = 2,
kUpb_FieldType_Int64 = 3,
kUpb_FieldType_UInt64 = 4,
kUpb_FieldType_Int32 = 5,
kUpb_FieldType_Fixed64 = 6,
kUpb_FieldType_Fixed32 = 7,
kUpb_FieldType_Bool = 8,
kUpb_FieldType_String = 9,
kUpb_FieldType_Group = 10,
kUpb_FieldType_Message = 11,
kUpb_FieldType_Bytes = 12,
kUpb_FieldType_UInt32 = 13,
kUpb_FieldType_Enum = 14,
kUpb_FieldType_SFixed32 = 15,
kUpb_FieldType_SFixed64 = 16,
kUpb_FieldType_SInt32 = 17,
kUpb_FieldType_SInt64 = 18,
} upb_FieldType;
#define kUpb_FieldType_SizeOf 19
#ifdef __cplusplus
extern "C" {
#endif
// Convert from upb_FieldType to upb_CType
UPB_INLINE upb_CType upb_FieldType_CType(upb_FieldType field_type) {
static const upb_CType c_type[] = {
kUpb_CType_Double, // kUpb_FieldType_Double
kUpb_CType_Float, // kUpb_FieldType_Float
kUpb_CType_Int64, // kUpb_FieldType_Int64
kUpb_CType_UInt64, // kUpb_FieldType_UInt64
kUpb_CType_Int32, // kUpb_FieldType_Int32
kUpb_CType_UInt64, // kUpb_FieldType_Fixed64
kUpb_CType_UInt32, // kUpb_FieldType_Fixed32
kUpb_CType_Bool, // kUpb_FieldType_Bool
kUpb_CType_String, // kUpb_FieldType_String
kUpb_CType_Message, // kUpb_FieldType_Group
kUpb_CType_Message, // kUpb_FieldType_Message
kUpb_CType_Bytes, // kUpb_FieldType_Bytes
kUpb_CType_UInt32, // kUpb_FieldType_UInt32
kUpb_CType_Enum, // kUpb_FieldType_Enum
kUpb_CType_Int32, // kUpb_FieldType_SFixed32
kUpb_CType_Int64, // kUpb_FieldType_SFixed64
kUpb_CType_Int32, // kUpb_FieldType_SInt32
kUpb_CType_Int64, // kUpb_FieldType_SInt64
};
// -1 here because the enum is one-based but the table is zero-based.
return c_type[field_type - 1];
}
UPB_INLINE bool upb_FieldType_IsPackable(upb_FieldType field_type) {
// clang-format off
const unsigned kUnpackableTypes =
(1 << kUpb_FieldType_String) |
(1 << kUpb_FieldType_Bytes) |
(1 << kUpb_FieldType_Message) |
(1 << kUpb_FieldType_Group);
// clang-format on
return (1 << field_type) & ~kUnpackableTypes;
}
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* UPB_BASE_DESCRIPTOR_CONSTANTS_H_ */
#ifndef UPB_MESSAGE_INTERNAL_ARRAY_H_
#define UPB_MESSAGE_INTERNAL_ARRAY_H_
@ -1882,6 +1878,11 @@ UPB_API_INLINE void upb_MiniTableExtension_SetSubMessage(
e->UPB_PRIVATE(sub).UPB_PRIVATE(submsg) = m;
}
UPB_INLINE upb_FieldRep UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(
const struct upb_MiniTableExtension* e) {
return UPB_PRIVATE(_upb_MiniTableField_GetRep)(&e->UPB_PRIVATE(field));
}
#ifdef __cplusplus
} /* extern "C" */
#endif
@ -2796,7 +2797,6 @@ UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_DataIsZero)(
// const upb_MiniTableField* field,
// bool value, upb_Arena* a) {
// UPB_ASSUME(field->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Bool);
// UPB_ASSUME(upb_MiniTableField_IsScalar(field));
// UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(field) ==
// kUpb_FieldRep_1Byte);
// upb_Message_SetField(msg, field, &value, a);
@ -2927,8 +2927,8 @@ UPB_API_INLINE bool upb_Message_GetBool(const struct upb_Message* msg,
const upb_MiniTableField* f,
bool default_val) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Bool);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_1Byte);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_1Byte);
upb_MessageValue def;
def.bool_val = default_val;
return upb_Message_GetField(msg, f, def).bool_val;
@ -2938,8 +2938,8 @@ UPB_API_INLINE double upb_Message_GetDouble(const struct upb_Message* msg,
const upb_MiniTableField* f,
double default_val) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Double);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
upb_MessageValue def;
def.double_val = default_val;
@ -2950,8 +2950,8 @@ UPB_API_INLINE float upb_Message_GetFloat(const struct upb_Message* msg,
const upb_MiniTableField* f,
float default_val) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Float);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
upb_MessageValue def;
def.float_val = default_val;
@ -2963,8 +2963,8 @@ UPB_API_INLINE int32_t upb_Message_GetInt32(const struct upb_Message* msg,
int32_t default_val) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Int32 ||
upb_MiniTableField_CType(f) == kUpb_CType_Enum);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
upb_MessageValue def;
def.int32_val = default_val;
@ -2975,8 +2975,8 @@ UPB_API_INLINE int64_t upb_Message_GetInt64(const struct upb_Message* msg,
const upb_MiniTableField* f,
int64_t default_val) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Int64);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
upb_MessageValue def;
def.int64_val = default_val;
@ -3005,6 +3005,37 @@ UPB_API_INLINE const struct upb_Map* upb_Message_GetMap(
return ret;
}
UPB_API_INLINE uintptr_t upb_Message_GetTaggedMessagePtr(
const struct upb_Message* msg, const upb_MiniTableField* f,
struct upb_Message* default_val) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Message);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) ==
UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte));
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
uintptr_t tagged;
_upb_Message_GetNonExtensionField(msg, f, &default_val, &tagged);
return tagged;
}
// For internal use only; users cannot set tagged messages because only the
// parser and the message copier are allowed to directly create an empty
// message.
UPB_INLINE void UPB_PRIVATE(_upb_Message_SetTaggedMessagePtr)(
struct upb_Message* msg, const upb_MiniTableField* f,
uintptr_t sub_message) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Message);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) ==
UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte));
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
upb_Message_SetBaseField(msg, f, &sub_message);
}
UPB_API_INLINE const struct upb_Message* upb_Message_GetMessage(
const struct upb_Message* msg, const upb_MiniTableField* f) {
uintptr_t tagged = upb_Message_GetTaggedMessagePtr(msg, f, NULL);
return upb_TaggedMessagePtr_GetNonEmptyMessage(tagged);
}
UPB_API_INLINE upb_Array* upb_Message_GetMutableArray(
struct upb_Message* msg, const upb_MiniTableField* f) {
UPB_PRIVATE(_upb_MiniTableField_CheckIsArray)(f);
@ -3016,6 +3047,11 @@ UPB_API_INLINE struct upb_Map* upb_Message_GetMutableMap(
return (struct upb_Map*)upb_Message_GetMap(msg, f);
}
UPB_API_INLINE struct upb_Message* upb_Message_GetMutableMessage(
struct upb_Message* msg, const upb_MiniTableField* f) {
return (struct upb_Message*)upb_Message_GetMessage(msg, f);
}
UPB_API_INLINE upb_Array* upb_Message_GetOrCreateMutableArray(
struct upb_Message* msg, const upb_MiniTableField* f, upb_Arena* arena) {
UPB_ASSERT(arena);
@ -3091,7 +3127,6 @@ upb_Message_GetString(const struct upb_Message* msg,
upb_MiniTableField_CType(f) == kUpb_CType_Bytes);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) ==
kUpb_FieldRep_StringView);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
upb_MessageValue def;
def.str_val = default_val;
@ -3102,8 +3137,8 @@ UPB_API_INLINE uint32_t upb_Message_GetUInt32(const struct upb_Message* msg,
const upb_MiniTableField* f,
uint32_t default_val) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_UInt32);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
upb_MessageValue def;
def.uint32_val = default_val;
@ -3114,23 +3149,89 @@ UPB_API_INLINE uint64_t upb_Message_GetUInt64(const struct upb_Message* msg,
const upb_MiniTableField* f,
uint64_t default_val) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_UInt64);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
upb_MessageValue def;
def.uint64_val = default_val;
return upb_Message_GetField(msg, f, def).uint64_val;
}
UPB_API_INLINE bool upb_Message_SetBool(struct upb_Message* msg,
const upb_MiniTableField* f, bool value,
upb_Arena* a) {
// BaseField Setters ///////////////////////////////////////////////////////////
UPB_API_INLINE void upb_Message_SetBaseFieldBool(struct upb_Message* msg,
const upb_MiniTableField* f,
bool value) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Bool);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_1Byte);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
upb_MessageValue val;
val.bool_val = value;
return UPB_PRIVATE(_upb_Message_SetField)(msg, f, val, a);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_1Byte);
upb_Message_SetBaseField(msg, f, &value);
}
UPB_API_INLINE void upb_Message_SetBaseFieldDouble(struct upb_Message* msg,
const upb_MiniTableField* f,
double value) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Double);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
upb_Message_SetBaseField(msg, f, &value);
}
UPB_API_INLINE void upb_Message_SetBaseFieldFloat(struct upb_Message* msg,
const upb_MiniTableField* f,
float value) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Float);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
upb_Message_SetBaseField(msg, f, &value);
}
UPB_API_INLINE void upb_Message_SetBaseFieldInt32(struct upb_Message* msg,
const upb_MiniTableField* f,
int32_t value) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Int32 ||
upb_MiniTableField_CType(f) == kUpb_CType_Enum);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
upb_Message_SetBaseField(msg, f, &value);
}
UPB_API_INLINE void upb_Message_SetBaseFieldInt64(struct upb_Message* msg,
const upb_MiniTableField* f,
int64_t value) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Int64);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
upb_Message_SetBaseField(msg, f, &value);
}
UPB_API_INLINE void upb_Message_SetBaseFieldString(struct upb_Message* msg,
const upb_MiniTableField* f,
upb_StringView value) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_String ||
upb_MiniTableField_CType(f) == kUpb_CType_Bytes);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) ==
kUpb_FieldRep_StringView);
upb_Message_SetBaseField(msg, f, &value);
}
UPB_API_INLINE void upb_Message_SetBaseFieldUInt32(struct upb_Message* msg,
const upb_MiniTableField* f,
uint32_t value) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_UInt32);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
upb_Message_SetBaseField(msg, f, &value);
}
UPB_API_INLINE void upb_Message_SetBaseFieldUInt64(struct upb_Message* msg,
const upb_MiniTableField* f,
uint64_t value) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_UInt64);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
upb_Message_SetBaseField(msg, f, &value);
}
UPB_API_INLINE void upb_Message_SetClosedEnum(
@ -3138,55 +3239,142 @@ UPB_API_INLINE void upb_Message_SetClosedEnum(
const upb_MiniTableField* f, int32_t value) {
UPB_ASSERT(upb_MiniTableField_IsClosedEnum(f));
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
UPB_ASSERT(upb_MiniTableEnum_CheckValue(
upb_MiniTable_GetSubEnumTable(msg_mini_table, f), value));
upb_Message_SetBaseField(msg, f, &value);
}
// Extension Setters ///////////////////////////////////////////////////////////
UPB_API_INLINE bool upb_Message_SetExtensionBool(
struct upb_Message* msg, const upb_MiniTableExtension* e, bool value,
upb_Arena* a) {
UPB_ASSUME(upb_MiniTableExtension_CType(e) == kUpb_CType_Bool);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(e) ==
kUpb_FieldRep_1Byte);
return upb_Message_SetExtension(msg, e, &value, a);
}
UPB_API_INLINE bool upb_Message_SetExtensionDouble(
struct upb_Message* msg, const upb_MiniTableExtension* e, double value,
upb_Arena* a) {
UPB_ASSUME(upb_MiniTableExtension_CType(e) == kUpb_CType_Double);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(e) ==
kUpb_FieldRep_8Byte);
return upb_Message_SetExtension(msg, e, &value, a);
}
UPB_API_INLINE bool upb_Message_SetExtensionFloat(
struct upb_Message* msg, const upb_MiniTableExtension* e, float value,
upb_Arena* a) {
UPB_ASSUME(upb_MiniTableExtension_CType(e) == kUpb_CType_Float);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(e) ==
kUpb_FieldRep_4Byte);
return upb_Message_SetExtension(msg, e, &value, a);
}
UPB_API_INLINE bool upb_Message_SetExtensionInt32(
struct upb_Message* msg, const upb_MiniTableExtension* e, int32_t value,
upb_Arena* a) {
UPB_ASSUME(upb_MiniTableExtension_CType(e) == kUpb_CType_Int32 ||
upb_MiniTableExtension_CType(e) == kUpb_CType_Enum);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(e) ==
kUpb_FieldRep_4Byte);
return upb_Message_SetExtension(msg, e, &value, a);
}
UPB_API_INLINE bool upb_Message_SetExtensionInt64(
struct upb_Message* msg, const upb_MiniTableExtension* e, int64_t value,
upb_Arena* a) {
UPB_ASSUME(upb_MiniTableExtension_CType(e) == kUpb_CType_Int64);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(e) ==
kUpb_FieldRep_8Byte);
return upb_Message_SetExtension(msg, e, &value, a);
}
UPB_API_INLINE bool upb_Message_SetExtensionString(
struct upb_Message* msg, const upb_MiniTableExtension* e,
upb_StringView value, upb_Arena* a) {
UPB_ASSUME(upb_MiniTableExtension_CType(e) == kUpb_CType_String ||
upb_MiniTableExtension_CType(e) == kUpb_CType_Bytes);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(e) ==
kUpb_FieldRep_StringView);
return upb_Message_SetExtension(msg, e, &value, a);
}
UPB_API_INLINE bool upb_Message_SetExtensionUInt32(
struct upb_Message* msg, const upb_MiniTableExtension* e, uint32_t value,
upb_Arena* a) {
UPB_ASSUME(upb_MiniTableExtension_CType(e) == kUpb_CType_UInt32);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(e) ==
kUpb_FieldRep_4Byte);
return upb_Message_SetExtension(msg, e, &value, a);
}
UPB_API_INLINE bool upb_Message_SetExtensionUInt64(
struct upb_Message* msg, const upb_MiniTableExtension* e, uint64_t value,
upb_Arena* a) {
UPB_ASSUME(upb_MiniTableExtension_CType(e) == kUpb_CType_UInt64);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(e) ==
kUpb_FieldRep_8Byte);
return upb_Message_SetExtension(msg, e, &value, a);
}
// Universal Setters ///////////////////////////////////////////////////////////
UPB_API_INLINE bool upb_Message_SetBool(struct upb_Message* msg,
const upb_MiniTableField* f, bool value,
upb_Arena* a) {
return upb_MiniTableField_IsExtension(f)
? upb_Message_SetExtensionBool(
msg, (const upb_MiniTableExtension*)f, value, a)
: (upb_Message_SetBaseFieldBool(msg, f, value), true);
}
UPB_API_INLINE bool upb_Message_SetDouble(struct upb_Message* msg,
const upb_MiniTableField* f,
double value, upb_Arena* a) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Double);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
upb_MessageValue val;
val.double_val = value;
return UPB_PRIVATE(_upb_Message_SetField)(msg, f, val, a);
return upb_MiniTableField_IsExtension(f)
? upb_Message_SetExtensionDouble(
msg, (const upb_MiniTableExtension*)f, value, a)
: (upb_Message_SetBaseFieldDouble(msg, f, value), true);
}
UPB_API_INLINE bool upb_Message_SetFloat(struct upb_Message* msg,
const upb_MiniTableField* f,
float value, upb_Arena* a) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Float);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
upb_MessageValue val;
val.float_val = value;
return UPB_PRIVATE(_upb_Message_SetField)(msg, f, val, a);
return upb_MiniTableField_IsExtension(f)
? upb_Message_SetExtensionFloat(
msg, (const upb_MiniTableExtension*)f, value, a)
: (upb_Message_SetBaseFieldFloat(msg, f, value), true);
}
UPB_API_INLINE bool upb_Message_SetInt32(struct upb_Message* msg,
const upb_MiniTableField* f,
int32_t value, upb_Arena* a) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Int32 ||
upb_MiniTableField_CType(f) == kUpb_CType_Enum);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
upb_MessageValue val;
val.int32_val = value;
return UPB_PRIVATE(_upb_Message_SetField)(msg, f, val, a);
return upb_MiniTableField_IsExtension(f)
? upb_Message_SetExtensionInt32(
msg, (const upb_MiniTableExtension*)f, value, a)
: (upb_Message_SetBaseFieldInt32(msg, f, value), true);
}
UPB_API_INLINE bool upb_Message_SetInt64(struct upb_Message* msg,
const upb_MiniTableField* f,
int64_t value, upb_Arena* a) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Int64);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
upb_MessageValue val;
val.int64_val = value;
return UPB_PRIVATE(_upb_Message_SetField)(msg, f, val, a);
return upb_MiniTableField_IsExtension(f)
? upb_Message_SetExtensionInt64(
msg, (const upb_MiniTableExtension*)f, value, a)
: (upb_Message_SetBaseFieldInt64(msg, f, value), true);
}
// Sets the value of a message-typed field. The mini_tables of `msg` and
// `sub_message` must have been linked for this to work correctly.
UPB_API_INLINE void upb_Message_SetMessage(struct upb_Message* msg,
const upb_MiniTable* m,
const upb_MiniTableField* f,
struct upb_Message* sub_message) {
UPB_PRIVATE(_upb_Message_SetTaggedMessagePtr)
(msg, f, UPB_PRIVATE(_upb_TaggedMessagePtr_Pack)(sub_message, false));
}
// Sets the value of a `string` or `bytes` field. The bytes of the value are not
@ -3196,36 +3384,28 @@ UPB_API_INLINE bool upb_Message_SetInt64(struct upb_Message* msg,
UPB_API_INLINE bool upb_Message_SetString(struct upb_Message* msg,
const upb_MiniTableField* f,
upb_StringView value, upb_Arena* a) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_String ||
upb_MiniTableField_CType(f) == kUpb_CType_Bytes);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) ==
kUpb_FieldRep_StringView);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
upb_MessageValue val;
val.str_val = value;
return UPB_PRIVATE(_upb_Message_SetField)(msg, f, val, a);
return upb_MiniTableField_IsExtension(f)
? upb_Message_SetExtensionString(
msg, (const upb_MiniTableExtension*)f, value, a)
: (upb_Message_SetBaseFieldString(msg, f, value), true);
}
UPB_API_INLINE bool upb_Message_SetUInt32(struct upb_Message* msg,
const upb_MiniTableField* f,
uint32_t value, upb_Arena* a) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_UInt32);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
upb_MessageValue val;
val.uint32_val = value;
return UPB_PRIVATE(_upb_Message_SetField)(msg, f, val, a);
return upb_MiniTableField_IsExtension(f)
? upb_Message_SetExtensionUInt32(
msg, (const upb_MiniTableExtension*)f, value, a)
: (upb_Message_SetBaseFieldUInt32(msg, f, value), true);
}
UPB_API_INLINE bool upb_Message_SetUInt64(struct upb_Message* msg,
const upb_MiniTableField* f,
uint64_t value, upb_Arena* a) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_UInt64);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
upb_MessageValue val;
val.uint64_val = value;
return UPB_PRIVATE(_upb_Message_SetField)(msg, f, val, a);
return upb_MiniTableField_IsExtension(f)
? upb_Message_SetExtensionUInt64(
msg, (const upb_MiniTableExtension*)f, value, a)
: (upb_Message_SetBaseFieldUInt64(msg, f, value), true);
}
UPB_API_INLINE void upb_Message_Clear(struct upb_Message* msg,
@ -3504,41 +3684,6 @@ UPB_API_INLINE upb_Message* upb_TaggedMessagePtr_GetNonEmptyMessage(
#endif /* UPB_MINI_TABLE_TAGGED_PTR_H_ */
#ifndef UPB_MINI_TABLE_SUB_H_
#define UPB_MINI_TABLE_SUB_H_
// Must be last.
typedef union upb_MiniTableSub upb_MiniTableSub;
#ifdef __cplusplus
extern "C" {
#endif
// Constructors
UPB_API_INLINE upb_MiniTableSub
upb_MiniTableSub_FromEnum(const upb_MiniTableEnum* subenum);
UPB_API_INLINE upb_MiniTableSub
upb_MiniTableSub_FromMessage(const upb_MiniTable* submsg);
// Getters
UPB_API_INLINE const upb_MiniTableEnum* upb_MiniTableSub_Enum(
upb_MiniTableSub sub);
UPB_API_INLINE const upb_MiniTable* upb_MiniTableSub_Message(
upb_MiniTableSub sub);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* UPB_MINI_TABLE_SUB_H_ */
// Must be last.
#ifdef __cplusplus
@ -3581,6 +3726,10 @@ UPB_API_INLINE upb_MessageValue
upb_Message_GetField(const upb_Message* msg, const upb_MiniTableField* f,
upb_MessageValue default_val);
UPB_API_INLINE upb_TaggedMessagePtr upb_Message_GetTaggedMessagePtr(
const upb_Message* msg, const upb_MiniTableField* field,
upb_Message* default_val);
UPB_API_INLINE const upb_Array* upb_Message_GetArray(
const upb_Message* msg, const upb_MiniTableField* f);
@ -3607,12 +3756,18 @@ UPB_API_INLINE int64_t upb_Message_GetInt64(const upb_Message* msg,
UPB_API_INLINE const upb_Map* upb_Message_GetMap(const upb_Message* msg,
const upb_MiniTableField* f);
UPB_API_INLINE const upb_Message* upb_Message_GetMessage(
const upb_Message* msg, const upb_MiniTableField* f);
UPB_API_INLINE upb_Array* upb_Message_GetMutableArray(
upb_Message* msg, const upb_MiniTableField* f);
UPB_API_INLINE upb_Map* upb_Message_GetMutableMap(upb_Message* msg,
const upb_MiniTableField* f);
UPB_API_INLINE upb_Message* upb_Message_GetMutableMessage(
upb_Message* msg, const upb_MiniTableField* f);
UPB_API_INLINE upb_Array* upb_Message_GetOrCreateMutableArray(
upb_Message* msg, const upb_MiniTableField* f, upb_Arena* arena);
@ -3660,6 +3815,11 @@ UPB_API_INLINE bool upb_Message_SetInt64(upb_Message* msg,
const upb_MiniTableField* f,
int64_t value, upb_Arena* a);
UPB_API_INLINE void upb_Message_SetMessage(upb_Message* msg,
const upb_MiniTable* m,
const upb_MiniTableField* f,
upb_Message* sub_message);
UPB_API_INLINE bool upb_Message_SetString(upb_Message* msg,
const upb_MiniTableField* f,
upb_StringView value, upb_Arena* a);
@ -3672,55 +3832,6 @@ UPB_API_INLINE bool upb_Message_SetUInt64(upb_Message* msg,
const upb_MiniTableField* f,
uint64_t value, upb_Arena* a);
UPB_API_INLINE upb_TaggedMessagePtr upb_Message_GetTaggedMessagePtr(
const upb_Message* msg, const upb_MiniTableField* field,
upb_Message* default_val) {
UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_Message);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(field) ==
UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte));
UPB_ASSUME(upb_MiniTableField_IsScalar(field));
upb_TaggedMessagePtr tagged;
_upb_Message_GetNonExtensionField(msg, field, &default_val, &tagged);
return tagged;
}
UPB_API_INLINE const upb_Message* upb_Message_GetMessage(
const upb_Message* msg, const upb_MiniTableField* field) {
upb_TaggedMessagePtr tagged =
upb_Message_GetTaggedMessagePtr(msg, field, NULL);
return upb_TaggedMessagePtr_GetNonEmptyMessage(tagged);
}
UPB_API_INLINE upb_Message* upb_Message_GetMutableMessage(
upb_Message* msg, const upb_MiniTableField* field) {
return (upb_Message*)upb_Message_GetMessage(msg, field);
}
// For internal use only; users cannot set tagged messages because only the
// parser and the message copier are allowed to directly create an empty
// message.
UPB_INLINE void UPB_PRIVATE(_upb_Message_SetTaggedMessagePtr)(
struct upb_Message* msg, const upb_MiniTable* mini_table,
const upb_MiniTableField* f, upb_TaggedMessagePtr sub_message) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Message);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) ==
UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte));
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
upb_Message_SetBaseField(msg, f, &sub_message);
}
// Sets the value of a message-typed field. The `mini_table` and `field`
// parameters belong to `msg`, not `sub_message`. The mini_tables of `msg` and
// `sub_message` must have been linked for this to work correctly.
UPB_API_INLINE void upb_Message_SetMessage(upb_Message* msg,
const upb_MiniTable* mini_table,
const upb_MiniTableField* field,
upb_Message* sub_message) {
UPB_PRIVATE(_upb_Message_SetTaggedMessagePtr)
(msg, mini_table, field,
UPB_PRIVATE(_upb_TaggedMessagePtr_Pack)(sub_message, false));
}
UPB_API_INLINE void* upb_Message_ResizeArrayUninitialized(
upb_Message* msg, const upb_MiniTableField* f, size_t size,
upb_Arena* arena);
@ -3793,6 +3904,41 @@ UPB_INLINE void _upb_msg_map_set_value(void* msg, const void* val,
#define UPB_MINI_TABLE_DECODE_H_
#ifndef UPB_MINI_TABLE_SUB_H_
#define UPB_MINI_TABLE_SUB_H_
// Must be last.
typedef union upb_MiniTableSub upb_MiniTableSub;
#ifdef __cplusplus
extern "C" {
#endif
// Constructors
UPB_API_INLINE upb_MiniTableSub
upb_MiniTableSub_FromEnum(const upb_MiniTableEnum* subenum);
UPB_API_INLINE upb_MiniTableSub
upb_MiniTableSub_FromMessage(const upb_MiniTable* submsg);
// Getters
UPB_API_INLINE const upb_MiniTableEnum* upb_MiniTableSub_Enum(
upb_MiniTableSub sub);
UPB_API_INLINE const upb_MiniTable* upb_MiniTableSub_Message(
upb_MiniTableSub sub);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* UPB_MINI_TABLE_SUB_H_ */
// Export the newer headers, for legacy users. New users should include the
// more specific headers directly.
// IWYU pragma: begin_exports

View File

@ -80,6 +80,7 @@ def _proto_gen_impl(ctx):
srcs = ctx.files.srcs
langs = ctx.attr.langs or []
out_type = ctx.attr.out_type
enable_editions = ctx.attr.enable_editions
deps = depset(direct = ctx.files.srcs)
source_dir = _SourceDir(ctx)
gen_dir = _GenDir(ctx).rstrip("/")
@ -130,6 +131,8 @@ def _proto_gen_impl(ctx):
generated_files = []
for src in srcs:
args = []
if enable_editions:
args.append("--experimental_editions")
in_gen_dir = src.root.path == gen_dir
if in_gen_dir:
@ -231,6 +234,7 @@ Args:
srcs: Protocol Buffers definition files (.proto) to run the protocol compiler
against.
deps: a list of dependency labels; must be other proto libraries.
enable_editions: if true, sets the --experimental_editions flag.
includes: a list of include paths to .proto files.
protoc: the label of the protocol compiler to generate the sources.
plugin: the label of the protocol compiler plugin to be passed to the protocol
@ -247,6 +251,7 @@ _proto_gen = rule(
attrs = {
"srcs": attr.label_list(allow_files = True),
"deps": attr.label_list(providers = [ProtoGenInfo]),
"enable_editions": attr.bool(),
"includes": attr.string_list(),
"protoc": attr.label(
cfg = "exec",
@ -655,6 +660,7 @@ def _source_proto_library(
protoc = Label("//:protoc"),
testonly = None,
visibility = ["//visibility:public"],
enable_editions = False,
**kwargs):
"""Bazel rule to create generated protobuf code from proto source files for
languages not well supported by Bazel yet. This will output the generated
@ -699,6 +705,7 @@ def _source_proto_library(
srcs = proto_deps,
protoc = protoc,
includes = includes,
enable_editions = enable_editions,
)
full_deps.append(":%s_deps_genproto" % name)
@ -712,6 +719,7 @@ def _source_proto_library(
protoc = protoc,
testonly = testonly,
visibility = visibility,
enable_editions = enable_editions,
)
native.filegroup(

View File

@ -20,6 +20,9 @@
// serialization).
// -----------------------------------------------------------------------------
#define PBRUBY_CHECK_FROZEN_MAP(map_rb) \
PBRUBY_CHECK_FROZEN(upb_Map_IsFrozen(ruby_to_Map(map_rb)->map), map_rb)
// -----------------------------------------------------------------------------
// Map container type.
// -----------------------------------------------------------------------------
@ -83,7 +86,9 @@ VALUE Map_GetRubyWrapper(upb_Map* map, upb_CType key_type, TypeInfo value_type,
}
return ObjectCache_TryAdd(map, val);
}
if (upb_Map_IsFrozen(map) && !RB_OBJ_FROZEN(val)) {
RB_OBJ_FREEZE(val);
}
return val;
}
@ -105,7 +110,7 @@ static TypeInfo Map_keyinfo(Map* self) {
}
static upb_Map* Map_GetMutable(VALUE _self) {
rb_check_frozen(_self);
PBRUBY_CHECK_FROZEN_MAP(_self);
return (upb_Map*)ruby_to_Map(_self)->map;
}
@ -440,7 +445,7 @@ static VALUE Map_has_key(VALUE _self, VALUE key) {
*/
static VALUE Map_delete(VALUE _self, VALUE key) {
Map* self = ruby_to_Map(_self);
rb_check_frozen(_self);
PBRUBY_CHECK_FROZEN_MAP(_self);
upb_MessageValue key_upb =
Convert_RubyToUpb(key, "", Map_keyinfo(self), NULL);
@ -560,28 +565,41 @@ VALUE Map_eq(VALUE _self, VALUE _other) {
/*
* call-seq:
* Message.freeze => self
* Map.frozen? => bool
*
* Freezes the message object. We have to intercept this so we can pin the
* Ruby object into memory so we don't forget it's frozen.
* Returns true if the map is frozen in either Ruby or the underlying
* representation. Freezes the Ruby map object if it is not already frozen in
* Ruby but it is frozen in the underlying representation.
*/
VALUE Map_frozen(VALUE _self) {
if (RB_OBJ_FROZEN(_self)) {
return Qtrue;
}
// Underlying representation is frozen but _self is not.
if (upb_Map_IsFrozen(ruby_to_Map(_self)->map)) {
RB_OBJ_FREEZE(_self);
return Qtrue;
}
return Qfalse;
}
/*
* call-seq:
* Map.freeze => self
*
* Freezes the map object. We have to intercept this so we can freeze the
* underlying representation, not just the Ruby wrapper.
*/
VALUE Map_freeze(VALUE _self) {
Map* self = ruby_to_Map(_self);
if (RB_OBJ_FROZEN(_self)) return _self;
Arena_Pin(self->arena, _self);
RB_OBJ_FREEZE(_self);
Map* self = ruby_to_Map(_self);
if (self->value_type_info.type == kUpb_CType_Message) {
size_t iter = kUpb_Map_Begin;
upb_MessageValue key, val;
while (upb_Map_Next(self->map, &key, &val, &iter)) {
VALUE val_val =
Convert_UpbToRuby(val, self->value_type_info, self->arena);
Message_freeze(val_val);
}
upb_Map_Freeze(Map_GetMutable(_self), upb_MessageDef_MiniTable(self->value_type_info.def.msgdef));
} else {
upb_Map_Freeze(Map_GetMutable(_self), NULL);
}
RB_OBJ_FREEZE(_self);
return _self;
}
@ -671,6 +689,7 @@ void Map_register(VALUE module) {
rb_define_method(klass, "clone", Map_dup, 0);
rb_define_method(klass, "==", Map_eq, 1);
rb_define_method(klass, "freeze", Map_freeze, 0);
rb_define_method(klass, "frozen?", Map_frozen, 0);
rb_define_method(klass, "hash", Map_hash, 0);
rb_define_method(klass, "to_h", Map_to_h, 0);
rb_define_method(klass, "inspect", Map_inspect, 0);

View File

@ -14,6 +14,9 @@
#include "repeated_field.h"
#include "shared_message.h"
#define PBRUBY_CHECK_FROZEN_MESSAGE(msg_rb) \
PBRUBY_CHECK_FROZEN(upb_Message_IsFrozen(ruby_to_Message(msg_rb)->msg), msg_rb)
static VALUE cParseError = Qnil;
static VALUE cAbstractMessage = Qnil;
static ID descriptor_instancevar_interned;
@ -80,7 +83,7 @@ const upb_Message* Message_Get(VALUE msg_rb, const upb_MessageDef** m) {
}
upb_Message* Message_GetMutable(VALUE msg_rb, const upb_MessageDef** m) {
rb_check_frozen(msg_rb);
PBRUBY_CHECK_FROZEN_MESSAGE(msg_rb);
return (upb_Message*)Message_Get(msg_rb, m);
}
@ -116,7 +119,9 @@ VALUE Message_GetRubyWrapper(upb_Message* msg, const upb_MessageDef* m,
val = Message_alloc(klass);
Message_InitPtr(val, msg, arena);
}
if (upb_Message_IsFrozen(msg) && !RB_OBJ_FROZEN(val)) {
RB_OBJ_FREEZE(val);
}
return val;
}
@ -297,6 +302,7 @@ VALUE Message_getfield(VALUE _self, const upb_FieldDef* f) {
upb_Message* msg = (upb_Message*)self->msg;
upb_Arena* arena = Arena_get(self->arena);
if (upb_FieldDef_IsMap(f)) {
PBRUBY_ASSERT(!upb_Message_IsFrozen(msg));
upb_Map* map = upb_Message_Mutable(msg, f, arena).map;
const upb_FieldDef* key_f = map_field_key(f);
const upb_FieldDef* val_f = map_field_value(f);
@ -304,10 +310,12 @@ VALUE Message_getfield(VALUE _self, const upb_FieldDef* f) {
TypeInfo value_type_info = TypeInfo_get(val_f);
return Map_GetRubyWrapper(map, key_type, value_type_info, self->arena);
} else if (upb_FieldDef_IsRepeated(f)) {
PBRUBY_ASSERT(!upb_Message_IsFrozen(msg));
upb_Array* arr = upb_Message_Mutable(msg, f, arena).array;
return RepeatedField_GetRubyWrapper(arr, TypeInfo_get(f), self->arena);
} else if (upb_FieldDef_IsSubMessage(f)) {
if (!upb_Message_HasFieldByDef(self->msg, f)) return Qnil;
PBRUBY_ASSERT(!upb_Message_IsFrozen(msg));
upb_Message* submsg = upb_Message_Mutable(msg, f, arena).msg;
const upb_MessageDef* m = upb_FieldDef_MessageSubDef(f);
return Message_GetRubyWrapper(submsg, m, self->arena);
@ -358,6 +366,7 @@ static VALUE Message_field_accessor(VALUE _self, const upb_FieldDef* f,
upb_MessageDef_FindFieldByNumber(upb_FieldDef_MessageSubDef(f), 1);
upb_MessageValue msgval = Convert_RubyToUpb(
argv[1], upb_FieldDef_Name(f), TypeInfo_get(val_f), arena);
PBRUBY_ASSERT(!upb_Message_IsFrozen(msg));
upb_Message* wrapper = upb_Message_Mutable(msg, f, arena).msg;
upb_Message_SetFieldByDef(wrapper, val_f, msgval, arena);
}
@ -436,7 +445,7 @@ static VALUE Message_method_missing(int argc, VALUE* argv, VALUE _self) {
if (argc != 2) {
rb_raise(rb_eArgError, "Expected 2 arguments, received %d", argc);
}
rb_check_frozen(_self);
PBRUBY_CHECK_FROZEN_MESSAGE(_self);
break;
default:
if (argc != 1) {
@ -560,13 +569,16 @@ static void Message_InitFieldFromValue(upb_Message* msg, const upb_FieldDef* f,
if (TYPE(val) == T_NIL) return;
if (upb_FieldDef_IsMap(f)) {
PBRUBY_ASSERT(!upb_Message_IsFrozen(msg));
upb_Map* map = upb_Message_Mutable(msg, f, arena).map;
Map_InitFromValue(map, f, val, arena);
} else if (upb_FieldDef_Label(f) == kUpb_Label_Repeated) {
PBRUBY_ASSERT(!upb_Message_IsFrozen(msg));
upb_Array* arr = upb_Message_Mutable(msg, f, arena).array;
RepeatedField_InitFromValue(arr, f, val, arena);
} else if (upb_FieldDef_IsSubMessage(f)) {
if (TYPE(val) == T_HASH) {
PBRUBY_ASSERT(!upb_Message_IsFrozen(msg));
upb_Message* submsg = upb_Message_Mutable(msg, f, arena).msg;
Message_InitFromValue(submsg, upb_FieldDef_MessageSubDef(f), val, arena);
} else {
@ -810,35 +822,39 @@ static VALUE Message_to_h(VALUE _self) {
return Message_CreateHash(self->msg, self->msgdef);
}
/*
* call-seq:
* Message.frozen? => bool
*
* Returns true if the message is frozen in either Ruby or the underlying
* representation. Freezes the Ruby message object if it is not already frozen
* in Ruby but it is frozen in the underlying representation.
*/
VALUE Message_frozen(VALUE _self) {
if (RB_OBJ_FROZEN(_self)) {
return Qtrue;
}
// Underlying representation is frozen but _self is not.
if (upb_Message_IsFrozen(ruby_to_Message(_self)->msg)) {
RB_OBJ_FREEZE(_self);
return Qtrue;
}
return Qfalse;
}
/*
* call-seq:
* Message.freeze => self
*
* Freezes the message object. We have to intercept this so we can pin the
* Ruby object into memory so we don't forget it's frozen.
* Freezes the message object. We have to intercept this so we can freeze the
* underlying representation, not just the Ruby wrapper.
*/
VALUE Message_freeze(VALUE _self) {
Message* self = ruby_to_Message(_self);
if (RB_OBJ_FROZEN(_self)) return _self;
Arena_Pin(self->arena, _self);
Message* self = ruby_to_Message(_self);
upb_Message_Freeze(Message_GetMutable(_self, NULL), upb_MessageDef_MiniTable(self->msgdef));
RB_OBJ_FREEZE(_self);
int n = upb_MessageDef_FieldCount(self->msgdef);
for (int i = 0; i < n; i++) {
const upb_FieldDef* f = upb_MessageDef_Field(self->msgdef, i);
VALUE field = Message_getfield(_self, f);
if (field != Qnil) {
if (upb_FieldDef_IsMap(f)) {
Map_freeze(field);
} else if (upb_FieldDef_IsRepeated(f)) {
RepeatedField_freeze(field);
} else if (upb_FieldDef_IsSubMessage(f)) {
Message_freeze(field);
}
}
}
return _self;
}
@ -1352,6 +1368,7 @@ static void Message_define_class(VALUE klass) {
rb_define_method(klass, "==", Message_eq, 1);
rb_define_method(klass, "eql?", Message_eq, 1);
rb_define_method(klass, "freeze", Message_freeze, 0);
rb_define_method(klass, "frozen?", Message_frozen, 0);
rb_define_method(klass, "hash", Message_hash, 0);
rb_define_method(klass, "to_h", Message_to_h, 0);
rb_define_method(klass, "inspect", Message_inspect, 0);

View File

@ -221,15 +221,6 @@ void Arena_fuse(VALUE _arena, upb_Arena *other) {
VALUE Arena_new() { return Arena_alloc(cArena); }
void Arena_Pin(VALUE _arena, VALUE obj) {
Arena *arena;
TypedData_Get_Struct(_arena, Arena, &Arena_type, arena);
if (arena->pinned_objs == Qnil) {
RB_OBJ_WRITE(_arena, &arena->pinned_objs, rb_ary_new());
}
rb_ary_push(arena->pinned_objs, obj);
}
void Arena_register(VALUE module) {
VALUE internal = rb_define_module_under(module, "Internal");
VALUE klass = rb_define_class_under(internal, "Arena", rb_cObject);

View File

@ -50,13 +50,6 @@ upb_Arena* Arena_get(VALUE arena);
// possible.
void Arena_fuse(VALUE arena, upb_Arena* other);
// Pins this Ruby object to the lifetime of this arena, so that as long as the
// arena is alive this object will not be collected.
//
// We use this to guarantee that the "frozen" bit on the object will be
// remembered, even if the user drops their reference to this precise object.
void Arena_Pin(VALUE arena, VALUE obj);
// -----------------------------------------------------------------------------
// ObjectCache
// -----------------------------------------------------------------------------
@ -105,6 +98,9 @@ extern VALUE cTypeError;
rb_bug("Assertion failed at %s:%d, expr: %s", __FILE__, __LINE__, #expr)
#endif
#define PBRUBY_CHECK_FROZEN(expr, rb_obj) \
if (RB_UNLIKELY(expr)) rb_error_frozen_object(rb_obj)
#define PBRUBY_MAX(x, y) (((x) > (y)) ? (x) : (y))
#define UPB_UNUSED(var) (void)var

View File

@ -25,6 +25,9 @@ typedef struct {
VALUE cRepeatedField;
#define PBRUBY_CHECK_FROZEN_ARRAY(array_rb) \
PBRUBY_CHECK_FROZEN(upb_Array_IsFrozen(ruby_to_RepeatedField(array_rb)->array), array_rb)
static void RepeatedField_mark(void* _self) {
RepeatedField* self = (RepeatedField*)_self;
rb_gc_mark(self->type_class);
@ -44,7 +47,7 @@ static RepeatedField* ruby_to_RepeatedField(VALUE _self) {
}
static upb_Array* RepeatedField_GetMutable(VALUE _self) {
rb_check_frozen(_self);
PBRUBY_CHECK_FROZEN_ARRAY(_self);
return (upb_Array*)ruby_to_RepeatedField(_self)->array;
}
@ -78,7 +81,9 @@ VALUE RepeatedField_GetRubyWrapper(upb_Array* array, TypeInfo type_info,
PBRUBY_ASSERT(ruby_to_RepeatedField(val)->type_info.def.msgdef ==
type_info.def.msgdef);
PBRUBY_ASSERT(ruby_to_RepeatedField(val)->array == array);
if (upb_Array_IsFrozen(array) && !RB_OBJ_FROZEN(val)) {
RB_OBJ_FREEZE(val);
}
return val;
}
@ -471,29 +476,42 @@ VALUE RepeatedField_eq(VALUE _self, VALUE _other) {
return Qtrue;
}
/*
* call-seq:
* RepeatedField.frozen? => bool
*
* Returns true if the repeated field is frozen in either Ruby or the underlying
* representation. Freezes the Ruby repeated field object if it is not already
* frozen in Ruby but it is frozen in the underlying representation.
*/
VALUE RepeatedField_frozen(VALUE _self) {
if (RB_OBJ_FROZEN(_self)) {
return Qtrue;
}
// Underlying representation is frozen but _self is not.
if (upb_Array_IsFrozen(ruby_to_RepeatedField(_self)->array)) {
RB_OBJ_FREEZE(_self);
return Qtrue;
}
return Qfalse;
}
/*
* call-seq:
* RepeatedField.freeze => self
*
* Freezes the repeated field. We have to intercept this so we can pin the Ruby
* object into memory so we don't forget it's frozen.
* Freezes the repeated field object. We have to intercept this so we can freeze
* the underlying representation, not just the Ruby wrapper.
*/
VALUE RepeatedField_freeze(VALUE _self) {
RepeatedField* self = ruby_to_RepeatedField(_self);
if (RB_OBJ_FROZEN(_self)) return _self;
Arena_Pin(self->arena, _self);
RB_OBJ_FREEZE(_self);
RepeatedField* self = ruby_to_RepeatedField(_self);
if (self->type_info.type == kUpb_CType_Message) {
int size = upb_Array_Size(self->array);
int i;
for (i = 0; i < size; i++) {
upb_MessageValue msgval = upb_Array_Get(self->array, i);
VALUE val = Convert_UpbToRuby(msgval, self->type_info, self->arena);
Message_freeze(val);
}
upb_Array_Freeze(RepeatedField_GetMutable(_self), upb_MessageDef_MiniTable(self->type_info.def.msgdef));
} else {
upb_Array_Freeze(RepeatedField_GetMutable(_self), NULL);
}
RB_OBJ_FREEZE(_self);
return _self;
}
@ -640,6 +658,7 @@ void RepeatedField_register(VALUE module) {
rb_define_method(klass, "==", RepeatedField_eq, 1);
rb_define_method(klass, "to_ary", RepeatedField_to_ary, 0);
rb_define_method(klass, "freeze", RepeatedField_freeze, 0);
rb_define_method(klass, "frozen?", RepeatedField_frozen, 0);
rb_define_method(klass, "hash", RepeatedField_hash, 0);
rb_define_method(klass, "+", RepeatedField_plus, 1);
rb_define_method(klass, "concat", RepeatedField_concat, 1);

View File

@ -5650,7 +5650,7 @@ upb_Message* _upb_Message_Copy(upb_Message* dst, const upb_Message* src,
return NULL;
}
UPB_PRIVATE(_upb_Message_SetTaggedMessagePtr)
(dst, mini_table, field,
(dst, field,
UPB_PRIVATE(_upb_TaggedMessagePtr_Pack)(dst_sub_message,
is_empty));
}

View File

@ -415,113 +415,6 @@ void upb_Status_VAppendErrorFormat(upb_Status* status, const char* fmt,
#ifndef UPB_MESSAGE_ACCESSORS_H_
#define UPB_MESSAGE_ACCESSORS_H_
#include <stddef.h>
#include <stdint.h>
#include <string.h>
#ifndef UPB_BASE_DESCRIPTOR_CONSTANTS_H_
#define UPB_BASE_DESCRIPTOR_CONSTANTS_H_
// Must be last.
// The types a field can have. Note that this list is not identical to the
// types defined in descriptor.proto, which gives INT32 and SINT32 separate
// types (we distinguish the two with the "integer encoding" enum below).
// This enum is an internal convenience only and has no meaning outside of upb.
typedef enum {
kUpb_CType_Bool = 1,
kUpb_CType_Float = 2,
kUpb_CType_Int32 = 3,
kUpb_CType_UInt32 = 4,
kUpb_CType_Enum = 5, // Enum values are int32. TODO: rename
kUpb_CType_Message = 6,
kUpb_CType_Double = 7,
kUpb_CType_Int64 = 8,
kUpb_CType_UInt64 = 9,
kUpb_CType_String = 10,
kUpb_CType_Bytes = 11
} upb_CType;
// The repeated-ness of each field; this matches descriptor.proto.
typedef enum {
kUpb_Label_Optional = 1,
kUpb_Label_Required = 2,
kUpb_Label_Repeated = 3
} upb_Label;
// Descriptor types, as defined in descriptor.proto.
typedef enum {
kUpb_FieldType_Double = 1,
kUpb_FieldType_Float = 2,
kUpb_FieldType_Int64 = 3,
kUpb_FieldType_UInt64 = 4,
kUpb_FieldType_Int32 = 5,
kUpb_FieldType_Fixed64 = 6,
kUpb_FieldType_Fixed32 = 7,
kUpb_FieldType_Bool = 8,
kUpb_FieldType_String = 9,
kUpb_FieldType_Group = 10,
kUpb_FieldType_Message = 11,
kUpb_FieldType_Bytes = 12,
kUpb_FieldType_UInt32 = 13,
kUpb_FieldType_Enum = 14,
kUpb_FieldType_SFixed32 = 15,
kUpb_FieldType_SFixed64 = 16,
kUpb_FieldType_SInt32 = 17,
kUpb_FieldType_SInt64 = 18,
} upb_FieldType;
#define kUpb_FieldType_SizeOf 19
#ifdef __cplusplus
extern "C" {
#endif
// Convert from upb_FieldType to upb_CType
UPB_INLINE upb_CType upb_FieldType_CType(upb_FieldType field_type) {
static const upb_CType c_type[] = {
kUpb_CType_Double, // kUpb_FieldType_Double
kUpb_CType_Float, // kUpb_FieldType_Float
kUpb_CType_Int64, // kUpb_FieldType_Int64
kUpb_CType_UInt64, // kUpb_FieldType_UInt64
kUpb_CType_Int32, // kUpb_FieldType_Int32
kUpb_CType_UInt64, // kUpb_FieldType_Fixed64
kUpb_CType_UInt32, // kUpb_FieldType_Fixed32
kUpb_CType_Bool, // kUpb_FieldType_Bool
kUpb_CType_String, // kUpb_FieldType_String
kUpb_CType_Message, // kUpb_FieldType_Group
kUpb_CType_Message, // kUpb_FieldType_Message
kUpb_CType_Bytes, // kUpb_FieldType_Bytes
kUpb_CType_UInt32, // kUpb_FieldType_UInt32
kUpb_CType_Enum, // kUpb_FieldType_Enum
kUpb_CType_Int32, // kUpb_FieldType_SFixed32
kUpb_CType_Int64, // kUpb_FieldType_SFixed64
kUpb_CType_Int32, // kUpb_FieldType_SInt32
kUpb_CType_Int64, // kUpb_FieldType_SInt64
};
// -1 here because the enum is one-based but the table is zero-based.
return c_type[field_type - 1];
}
UPB_INLINE bool upb_FieldType_IsPackable(upb_FieldType field_type) {
// clang-format off
const unsigned kUnpackableTypes =
(1 << kUpb_FieldType_String) |
(1 << kUpb_FieldType_Bytes) |
(1 << kUpb_FieldType_Message) |
(1 << kUpb_FieldType_Group);
// clang-format on
return (1 << field_type) & ~kUnpackableTypes;
}
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* UPB_BASE_DESCRIPTOR_CONSTANTS_H_ */
#ifndef UPB_BASE_STRING_VIEW_H_
#define UPB_BASE_STRING_VIEW_H_
@ -829,6 +722,109 @@ void upb_Arena_SetTraceHandler(void (*initArenaTraceHandler)(const upb_Arena*,
#include <stddef.h>
#ifndef UPB_BASE_DESCRIPTOR_CONSTANTS_H_
#define UPB_BASE_DESCRIPTOR_CONSTANTS_H_
// Must be last.
// The types a field can have. Note that this list is not identical to the
// types defined in descriptor.proto, which gives INT32 and SINT32 separate
// types (we distinguish the two with the "integer encoding" enum below).
// This enum is an internal convenience only and has no meaning outside of upb.
typedef enum {
kUpb_CType_Bool = 1,
kUpb_CType_Float = 2,
kUpb_CType_Int32 = 3,
kUpb_CType_UInt32 = 4,
kUpb_CType_Enum = 5, // Enum values are int32. TODO: rename
kUpb_CType_Message = 6,
kUpb_CType_Double = 7,
kUpb_CType_Int64 = 8,
kUpb_CType_UInt64 = 9,
kUpb_CType_String = 10,
kUpb_CType_Bytes = 11
} upb_CType;
// The repeated-ness of each field; this matches descriptor.proto.
typedef enum {
kUpb_Label_Optional = 1,
kUpb_Label_Required = 2,
kUpb_Label_Repeated = 3
} upb_Label;
// Descriptor types, as defined in descriptor.proto.
typedef enum {
kUpb_FieldType_Double = 1,
kUpb_FieldType_Float = 2,
kUpb_FieldType_Int64 = 3,
kUpb_FieldType_UInt64 = 4,
kUpb_FieldType_Int32 = 5,
kUpb_FieldType_Fixed64 = 6,
kUpb_FieldType_Fixed32 = 7,
kUpb_FieldType_Bool = 8,
kUpb_FieldType_String = 9,
kUpb_FieldType_Group = 10,
kUpb_FieldType_Message = 11,
kUpb_FieldType_Bytes = 12,
kUpb_FieldType_UInt32 = 13,
kUpb_FieldType_Enum = 14,
kUpb_FieldType_SFixed32 = 15,
kUpb_FieldType_SFixed64 = 16,
kUpb_FieldType_SInt32 = 17,
kUpb_FieldType_SInt64 = 18,
} upb_FieldType;
#define kUpb_FieldType_SizeOf 19
#ifdef __cplusplus
extern "C" {
#endif
// Convert from upb_FieldType to upb_CType
UPB_INLINE upb_CType upb_FieldType_CType(upb_FieldType field_type) {
static const upb_CType c_type[] = {
kUpb_CType_Double, // kUpb_FieldType_Double
kUpb_CType_Float, // kUpb_FieldType_Float
kUpb_CType_Int64, // kUpb_FieldType_Int64
kUpb_CType_UInt64, // kUpb_FieldType_UInt64
kUpb_CType_Int32, // kUpb_FieldType_Int32
kUpb_CType_UInt64, // kUpb_FieldType_Fixed64
kUpb_CType_UInt32, // kUpb_FieldType_Fixed32
kUpb_CType_Bool, // kUpb_FieldType_Bool
kUpb_CType_String, // kUpb_FieldType_String
kUpb_CType_Message, // kUpb_FieldType_Group
kUpb_CType_Message, // kUpb_FieldType_Message
kUpb_CType_Bytes, // kUpb_FieldType_Bytes
kUpb_CType_UInt32, // kUpb_FieldType_UInt32
kUpb_CType_Enum, // kUpb_FieldType_Enum
kUpb_CType_Int32, // kUpb_FieldType_SFixed32
kUpb_CType_Int64, // kUpb_FieldType_SFixed64
kUpb_CType_Int32, // kUpb_FieldType_SInt32
kUpb_CType_Int64, // kUpb_FieldType_SInt64
};
// -1 here because the enum is one-based but the table is zero-based.
return c_type[field_type - 1];
}
UPB_INLINE bool upb_FieldType_IsPackable(upb_FieldType field_type) {
// clang-format off
const unsigned kUnpackableTypes =
(1 << kUpb_FieldType_String) |
(1 << kUpb_FieldType_Bytes) |
(1 << kUpb_FieldType_Message) |
(1 << kUpb_FieldType_Group);
// clang-format on
return (1 << field_type) & ~kUnpackableTypes;
}
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* UPB_BASE_DESCRIPTOR_CONSTANTS_H_ */
#ifndef UPB_MESSAGE_INTERNAL_ARRAY_H_
#define UPB_MESSAGE_INTERNAL_ARRAY_H_
@ -1884,6 +1880,11 @@ UPB_API_INLINE void upb_MiniTableExtension_SetSubMessage(
e->UPB_PRIVATE(sub).UPB_PRIVATE(submsg) = m;
}
UPB_INLINE upb_FieldRep UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(
const struct upb_MiniTableExtension* e) {
return UPB_PRIVATE(_upb_MiniTableField_GetRep)(&e->UPB_PRIVATE(field));
}
#ifdef __cplusplus
} /* extern "C" */
#endif
@ -2798,7 +2799,6 @@ UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_DataIsZero)(
// const upb_MiniTableField* field,
// bool value, upb_Arena* a) {
// UPB_ASSUME(field->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Bool);
// UPB_ASSUME(upb_MiniTableField_IsScalar(field));
// UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(field) ==
// kUpb_FieldRep_1Byte);
// upb_Message_SetField(msg, field, &value, a);
@ -2929,8 +2929,8 @@ UPB_API_INLINE bool upb_Message_GetBool(const struct upb_Message* msg,
const upb_MiniTableField* f,
bool default_val) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Bool);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_1Byte);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_1Byte);
upb_MessageValue def;
def.bool_val = default_val;
return upb_Message_GetField(msg, f, def).bool_val;
@ -2940,8 +2940,8 @@ UPB_API_INLINE double upb_Message_GetDouble(const struct upb_Message* msg,
const upb_MiniTableField* f,
double default_val) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Double);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
upb_MessageValue def;
def.double_val = default_val;
@ -2952,8 +2952,8 @@ UPB_API_INLINE float upb_Message_GetFloat(const struct upb_Message* msg,
const upb_MiniTableField* f,
float default_val) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Float);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
upb_MessageValue def;
def.float_val = default_val;
@ -2965,8 +2965,8 @@ UPB_API_INLINE int32_t upb_Message_GetInt32(const struct upb_Message* msg,
int32_t default_val) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Int32 ||
upb_MiniTableField_CType(f) == kUpb_CType_Enum);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
upb_MessageValue def;
def.int32_val = default_val;
@ -2977,8 +2977,8 @@ UPB_API_INLINE int64_t upb_Message_GetInt64(const struct upb_Message* msg,
const upb_MiniTableField* f,
int64_t default_val) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Int64);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
upb_MessageValue def;
def.int64_val = default_val;
@ -3007,6 +3007,37 @@ UPB_API_INLINE const struct upb_Map* upb_Message_GetMap(
return ret;
}
UPB_API_INLINE uintptr_t upb_Message_GetTaggedMessagePtr(
const struct upb_Message* msg, const upb_MiniTableField* f,
struct upb_Message* default_val) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Message);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) ==
UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte));
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
uintptr_t tagged;
_upb_Message_GetNonExtensionField(msg, f, &default_val, &tagged);
return tagged;
}
// For internal use only; users cannot set tagged messages because only the
// parser and the message copier are allowed to directly create an empty
// message.
UPB_INLINE void UPB_PRIVATE(_upb_Message_SetTaggedMessagePtr)(
struct upb_Message* msg, const upb_MiniTableField* f,
uintptr_t sub_message) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Message);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) ==
UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte));
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
upb_Message_SetBaseField(msg, f, &sub_message);
}
UPB_API_INLINE const struct upb_Message* upb_Message_GetMessage(
const struct upb_Message* msg, const upb_MiniTableField* f) {
uintptr_t tagged = upb_Message_GetTaggedMessagePtr(msg, f, NULL);
return upb_TaggedMessagePtr_GetNonEmptyMessage(tagged);
}
UPB_API_INLINE upb_Array* upb_Message_GetMutableArray(
struct upb_Message* msg, const upb_MiniTableField* f) {
UPB_PRIVATE(_upb_MiniTableField_CheckIsArray)(f);
@ -3018,6 +3049,11 @@ UPB_API_INLINE struct upb_Map* upb_Message_GetMutableMap(
return (struct upb_Map*)upb_Message_GetMap(msg, f);
}
UPB_API_INLINE struct upb_Message* upb_Message_GetMutableMessage(
struct upb_Message* msg, const upb_MiniTableField* f) {
return (struct upb_Message*)upb_Message_GetMessage(msg, f);
}
UPB_API_INLINE upb_Array* upb_Message_GetOrCreateMutableArray(
struct upb_Message* msg, const upb_MiniTableField* f, upb_Arena* arena) {
UPB_ASSERT(arena);
@ -3093,7 +3129,6 @@ upb_Message_GetString(const struct upb_Message* msg,
upb_MiniTableField_CType(f) == kUpb_CType_Bytes);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) ==
kUpb_FieldRep_StringView);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
upb_MessageValue def;
def.str_val = default_val;
@ -3104,8 +3139,8 @@ UPB_API_INLINE uint32_t upb_Message_GetUInt32(const struct upb_Message* msg,
const upb_MiniTableField* f,
uint32_t default_val) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_UInt32);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
upb_MessageValue def;
def.uint32_val = default_val;
@ -3116,23 +3151,89 @@ UPB_API_INLINE uint64_t upb_Message_GetUInt64(const struct upb_Message* msg,
const upb_MiniTableField* f,
uint64_t default_val) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_UInt64);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
upb_MessageValue def;
def.uint64_val = default_val;
return upb_Message_GetField(msg, f, def).uint64_val;
}
UPB_API_INLINE bool upb_Message_SetBool(struct upb_Message* msg,
const upb_MiniTableField* f, bool value,
upb_Arena* a) {
// BaseField Setters ///////////////////////////////////////////////////////////
UPB_API_INLINE void upb_Message_SetBaseFieldBool(struct upb_Message* msg,
const upb_MiniTableField* f,
bool value) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Bool);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_1Byte);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
upb_MessageValue val;
val.bool_val = value;
return UPB_PRIVATE(_upb_Message_SetField)(msg, f, val, a);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_1Byte);
upb_Message_SetBaseField(msg, f, &value);
}
UPB_API_INLINE void upb_Message_SetBaseFieldDouble(struct upb_Message* msg,
const upb_MiniTableField* f,
double value) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Double);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
upb_Message_SetBaseField(msg, f, &value);
}
UPB_API_INLINE void upb_Message_SetBaseFieldFloat(struct upb_Message* msg,
const upb_MiniTableField* f,
float value) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Float);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
upb_Message_SetBaseField(msg, f, &value);
}
UPB_API_INLINE void upb_Message_SetBaseFieldInt32(struct upb_Message* msg,
const upb_MiniTableField* f,
int32_t value) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Int32 ||
upb_MiniTableField_CType(f) == kUpb_CType_Enum);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
upb_Message_SetBaseField(msg, f, &value);
}
UPB_API_INLINE void upb_Message_SetBaseFieldInt64(struct upb_Message* msg,
const upb_MiniTableField* f,
int64_t value) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Int64);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
upb_Message_SetBaseField(msg, f, &value);
}
UPB_API_INLINE void upb_Message_SetBaseFieldString(struct upb_Message* msg,
const upb_MiniTableField* f,
upb_StringView value) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_String ||
upb_MiniTableField_CType(f) == kUpb_CType_Bytes);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) ==
kUpb_FieldRep_StringView);
upb_Message_SetBaseField(msg, f, &value);
}
UPB_API_INLINE void upb_Message_SetBaseFieldUInt32(struct upb_Message* msg,
const upb_MiniTableField* f,
uint32_t value) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_UInt32);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
upb_Message_SetBaseField(msg, f, &value);
}
UPB_API_INLINE void upb_Message_SetBaseFieldUInt64(struct upb_Message* msg,
const upb_MiniTableField* f,
uint64_t value) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_UInt64);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
upb_Message_SetBaseField(msg, f, &value);
}
UPB_API_INLINE void upb_Message_SetClosedEnum(
@ -3140,55 +3241,142 @@ UPB_API_INLINE void upb_Message_SetClosedEnum(
const upb_MiniTableField* f, int32_t value) {
UPB_ASSERT(upb_MiniTableField_IsClosedEnum(f));
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
UPB_ASSERT(upb_MiniTableEnum_CheckValue(
upb_MiniTable_GetSubEnumTable(msg_mini_table, f), value));
upb_Message_SetBaseField(msg, f, &value);
}
// Extension Setters ///////////////////////////////////////////////////////////
UPB_API_INLINE bool upb_Message_SetExtensionBool(
struct upb_Message* msg, const upb_MiniTableExtension* e, bool value,
upb_Arena* a) {
UPB_ASSUME(upb_MiniTableExtension_CType(e) == kUpb_CType_Bool);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(e) ==
kUpb_FieldRep_1Byte);
return upb_Message_SetExtension(msg, e, &value, a);
}
UPB_API_INLINE bool upb_Message_SetExtensionDouble(
struct upb_Message* msg, const upb_MiniTableExtension* e, double value,
upb_Arena* a) {
UPB_ASSUME(upb_MiniTableExtension_CType(e) == kUpb_CType_Double);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(e) ==
kUpb_FieldRep_8Byte);
return upb_Message_SetExtension(msg, e, &value, a);
}
UPB_API_INLINE bool upb_Message_SetExtensionFloat(
struct upb_Message* msg, const upb_MiniTableExtension* e, float value,
upb_Arena* a) {
UPB_ASSUME(upb_MiniTableExtension_CType(e) == kUpb_CType_Float);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(e) ==
kUpb_FieldRep_4Byte);
return upb_Message_SetExtension(msg, e, &value, a);
}
UPB_API_INLINE bool upb_Message_SetExtensionInt32(
struct upb_Message* msg, const upb_MiniTableExtension* e, int32_t value,
upb_Arena* a) {
UPB_ASSUME(upb_MiniTableExtension_CType(e) == kUpb_CType_Int32 ||
upb_MiniTableExtension_CType(e) == kUpb_CType_Enum);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(e) ==
kUpb_FieldRep_4Byte);
return upb_Message_SetExtension(msg, e, &value, a);
}
UPB_API_INLINE bool upb_Message_SetExtensionInt64(
struct upb_Message* msg, const upb_MiniTableExtension* e, int64_t value,
upb_Arena* a) {
UPB_ASSUME(upb_MiniTableExtension_CType(e) == kUpb_CType_Int64);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(e) ==
kUpb_FieldRep_8Byte);
return upb_Message_SetExtension(msg, e, &value, a);
}
UPB_API_INLINE bool upb_Message_SetExtensionString(
struct upb_Message* msg, const upb_MiniTableExtension* e,
upb_StringView value, upb_Arena* a) {
UPB_ASSUME(upb_MiniTableExtension_CType(e) == kUpb_CType_String ||
upb_MiniTableExtension_CType(e) == kUpb_CType_Bytes);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(e) ==
kUpb_FieldRep_StringView);
return upb_Message_SetExtension(msg, e, &value, a);
}
UPB_API_INLINE bool upb_Message_SetExtensionUInt32(
struct upb_Message* msg, const upb_MiniTableExtension* e, uint32_t value,
upb_Arena* a) {
UPB_ASSUME(upb_MiniTableExtension_CType(e) == kUpb_CType_UInt32);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(e) ==
kUpb_FieldRep_4Byte);
return upb_Message_SetExtension(msg, e, &value, a);
}
UPB_API_INLINE bool upb_Message_SetExtensionUInt64(
struct upb_Message* msg, const upb_MiniTableExtension* e, uint64_t value,
upb_Arena* a) {
UPB_ASSUME(upb_MiniTableExtension_CType(e) == kUpb_CType_UInt64);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(e) ==
kUpb_FieldRep_8Byte);
return upb_Message_SetExtension(msg, e, &value, a);
}
// Universal Setters ///////////////////////////////////////////////////////////
UPB_API_INLINE bool upb_Message_SetBool(struct upb_Message* msg,
const upb_MiniTableField* f, bool value,
upb_Arena* a) {
return upb_MiniTableField_IsExtension(f)
? upb_Message_SetExtensionBool(
msg, (const upb_MiniTableExtension*)f, value, a)
: (upb_Message_SetBaseFieldBool(msg, f, value), true);
}
UPB_API_INLINE bool upb_Message_SetDouble(struct upb_Message* msg,
const upb_MiniTableField* f,
double value, upb_Arena* a) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Double);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
upb_MessageValue val;
val.double_val = value;
return UPB_PRIVATE(_upb_Message_SetField)(msg, f, val, a);
return upb_MiniTableField_IsExtension(f)
? upb_Message_SetExtensionDouble(
msg, (const upb_MiniTableExtension*)f, value, a)
: (upb_Message_SetBaseFieldDouble(msg, f, value), true);
}
UPB_API_INLINE bool upb_Message_SetFloat(struct upb_Message* msg,
const upb_MiniTableField* f,
float value, upb_Arena* a) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Float);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
upb_MessageValue val;
val.float_val = value;
return UPB_PRIVATE(_upb_Message_SetField)(msg, f, val, a);
return upb_MiniTableField_IsExtension(f)
? upb_Message_SetExtensionFloat(
msg, (const upb_MiniTableExtension*)f, value, a)
: (upb_Message_SetBaseFieldFloat(msg, f, value), true);
}
UPB_API_INLINE bool upb_Message_SetInt32(struct upb_Message* msg,
const upb_MiniTableField* f,
int32_t value, upb_Arena* a) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Int32 ||
upb_MiniTableField_CType(f) == kUpb_CType_Enum);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
upb_MessageValue val;
val.int32_val = value;
return UPB_PRIVATE(_upb_Message_SetField)(msg, f, val, a);
return upb_MiniTableField_IsExtension(f)
? upb_Message_SetExtensionInt32(
msg, (const upb_MiniTableExtension*)f, value, a)
: (upb_Message_SetBaseFieldInt32(msg, f, value), true);
}
UPB_API_INLINE bool upb_Message_SetInt64(struct upb_Message* msg,
const upb_MiniTableField* f,
int64_t value, upb_Arena* a) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Int64);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
upb_MessageValue val;
val.int64_val = value;
return UPB_PRIVATE(_upb_Message_SetField)(msg, f, val, a);
return upb_MiniTableField_IsExtension(f)
? upb_Message_SetExtensionInt64(
msg, (const upb_MiniTableExtension*)f, value, a)
: (upb_Message_SetBaseFieldInt64(msg, f, value), true);
}
// Sets the value of a message-typed field. The mini_tables of `msg` and
// `sub_message` must have been linked for this to work correctly.
UPB_API_INLINE void upb_Message_SetMessage(struct upb_Message* msg,
const upb_MiniTable* m,
const upb_MiniTableField* f,
struct upb_Message* sub_message) {
UPB_PRIVATE(_upb_Message_SetTaggedMessagePtr)
(msg, f, UPB_PRIVATE(_upb_TaggedMessagePtr_Pack)(sub_message, false));
}
// Sets the value of a `string` or `bytes` field. The bytes of the value are not
@ -3198,36 +3386,28 @@ UPB_API_INLINE bool upb_Message_SetInt64(struct upb_Message* msg,
UPB_API_INLINE bool upb_Message_SetString(struct upb_Message* msg,
const upb_MiniTableField* f,
upb_StringView value, upb_Arena* a) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_String ||
upb_MiniTableField_CType(f) == kUpb_CType_Bytes);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) ==
kUpb_FieldRep_StringView);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
upb_MessageValue val;
val.str_val = value;
return UPB_PRIVATE(_upb_Message_SetField)(msg, f, val, a);
return upb_MiniTableField_IsExtension(f)
? upb_Message_SetExtensionString(
msg, (const upb_MiniTableExtension*)f, value, a)
: (upb_Message_SetBaseFieldString(msg, f, value), true);
}
UPB_API_INLINE bool upb_Message_SetUInt32(struct upb_Message* msg,
const upb_MiniTableField* f,
uint32_t value, upb_Arena* a) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_UInt32);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
upb_MessageValue val;
val.uint32_val = value;
return UPB_PRIVATE(_upb_Message_SetField)(msg, f, val, a);
return upb_MiniTableField_IsExtension(f)
? upb_Message_SetExtensionUInt32(
msg, (const upb_MiniTableExtension*)f, value, a)
: (upb_Message_SetBaseFieldUInt32(msg, f, value), true);
}
UPB_API_INLINE bool upb_Message_SetUInt64(struct upb_Message* msg,
const upb_MiniTableField* f,
uint64_t value, upb_Arena* a) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_UInt64);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
upb_MessageValue val;
val.uint64_val = value;
return UPB_PRIVATE(_upb_Message_SetField)(msg, f, val, a);
return upb_MiniTableField_IsExtension(f)
? upb_Message_SetExtensionUInt64(
msg, (const upb_MiniTableExtension*)f, value, a)
: (upb_Message_SetBaseFieldUInt64(msg, f, value), true);
}
UPB_API_INLINE void upb_Message_Clear(struct upb_Message* msg,
@ -3506,41 +3686,6 @@ UPB_API_INLINE upb_Message* upb_TaggedMessagePtr_GetNonEmptyMessage(
#endif /* UPB_MINI_TABLE_TAGGED_PTR_H_ */
#ifndef UPB_MINI_TABLE_SUB_H_
#define UPB_MINI_TABLE_SUB_H_
// Must be last.
typedef union upb_MiniTableSub upb_MiniTableSub;
#ifdef __cplusplus
extern "C" {
#endif
// Constructors
UPB_API_INLINE upb_MiniTableSub
upb_MiniTableSub_FromEnum(const upb_MiniTableEnum* subenum);
UPB_API_INLINE upb_MiniTableSub
upb_MiniTableSub_FromMessage(const upb_MiniTable* submsg);
// Getters
UPB_API_INLINE const upb_MiniTableEnum* upb_MiniTableSub_Enum(
upb_MiniTableSub sub);
UPB_API_INLINE const upb_MiniTable* upb_MiniTableSub_Message(
upb_MiniTableSub sub);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* UPB_MINI_TABLE_SUB_H_ */
// Must be last.
#ifdef __cplusplus
@ -3583,6 +3728,10 @@ UPB_API_INLINE upb_MessageValue
upb_Message_GetField(const upb_Message* msg, const upb_MiniTableField* f,
upb_MessageValue default_val);
UPB_API_INLINE upb_TaggedMessagePtr upb_Message_GetTaggedMessagePtr(
const upb_Message* msg, const upb_MiniTableField* field,
upb_Message* default_val);
UPB_API_INLINE const upb_Array* upb_Message_GetArray(
const upb_Message* msg, const upb_MiniTableField* f);
@ -3609,12 +3758,18 @@ UPB_API_INLINE int64_t upb_Message_GetInt64(const upb_Message* msg,
UPB_API_INLINE const upb_Map* upb_Message_GetMap(const upb_Message* msg,
const upb_MiniTableField* f);
UPB_API_INLINE const upb_Message* upb_Message_GetMessage(
const upb_Message* msg, const upb_MiniTableField* f);
UPB_API_INLINE upb_Array* upb_Message_GetMutableArray(
upb_Message* msg, const upb_MiniTableField* f);
UPB_API_INLINE upb_Map* upb_Message_GetMutableMap(upb_Message* msg,
const upb_MiniTableField* f);
UPB_API_INLINE upb_Message* upb_Message_GetMutableMessage(
upb_Message* msg, const upb_MiniTableField* f);
UPB_API_INLINE upb_Array* upb_Message_GetOrCreateMutableArray(
upb_Message* msg, const upb_MiniTableField* f, upb_Arena* arena);
@ -3662,6 +3817,11 @@ UPB_API_INLINE bool upb_Message_SetInt64(upb_Message* msg,
const upb_MiniTableField* f,
int64_t value, upb_Arena* a);
UPB_API_INLINE void upb_Message_SetMessage(upb_Message* msg,
const upb_MiniTable* m,
const upb_MiniTableField* f,
upb_Message* sub_message);
UPB_API_INLINE bool upb_Message_SetString(upb_Message* msg,
const upb_MiniTableField* f,
upb_StringView value, upb_Arena* a);
@ -3674,55 +3834,6 @@ UPB_API_INLINE bool upb_Message_SetUInt64(upb_Message* msg,
const upb_MiniTableField* f,
uint64_t value, upb_Arena* a);
UPB_API_INLINE upb_TaggedMessagePtr upb_Message_GetTaggedMessagePtr(
const upb_Message* msg, const upb_MiniTableField* field,
upb_Message* default_val) {
UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_Message);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(field) ==
UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte));
UPB_ASSUME(upb_MiniTableField_IsScalar(field));
upb_TaggedMessagePtr tagged;
_upb_Message_GetNonExtensionField(msg, field, &default_val, &tagged);
return tagged;
}
UPB_API_INLINE const upb_Message* upb_Message_GetMessage(
const upb_Message* msg, const upb_MiniTableField* field) {
upb_TaggedMessagePtr tagged =
upb_Message_GetTaggedMessagePtr(msg, field, NULL);
return upb_TaggedMessagePtr_GetNonEmptyMessage(tagged);
}
UPB_API_INLINE upb_Message* upb_Message_GetMutableMessage(
upb_Message* msg, const upb_MiniTableField* field) {
return (upb_Message*)upb_Message_GetMessage(msg, field);
}
// For internal use only; users cannot set tagged messages because only the
// parser and the message copier are allowed to directly create an empty
// message.
UPB_INLINE void UPB_PRIVATE(_upb_Message_SetTaggedMessagePtr)(
struct upb_Message* msg, const upb_MiniTable* mini_table,
const upb_MiniTableField* f, upb_TaggedMessagePtr sub_message) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Message);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) ==
UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte));
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
upb_Message_SetBaseField(msg, f, &sub_message);
}
// Sets the value of a message-typed field. The `mini_table` and `field`
// parameters belong to `msg`, not `sub_message`. The mini_tables of `msg` and
// `sub_message` must have been linked for this to work correctly.
UPB_API_INLINE void upb_Message_SetMessage(upb_Message* msg,
const upb_MiniTable* mini_table,
const upb_MiniTableField* field,
upb_Message* sub_message) {
UPB_PRIVATE(_upb_Message_SetTaggedMessagePtr)
(msg, mini_table, field,
UPB_PRIVATE(_upb_TaggedMessagePtr_Pack)(sub_message, false));
}
UPB_API_INLINE void* upb_Message_ResizeArrayUninitialized(
upb_Message* msg, const upb_MiniTableField* f, size_t size,
upb_Arena* arena);
@ -3795,6 +3906,41 @@ UPB_INLINE void _upb_msg_map_set_value(void* msg, const void* val,
#define UPB_MINI_TABLE_DECODE_H_
#ifndef UPB_MINI_TABLE_SUB_H_
#define UPB_MINI_TABLE_SUB_H_
// Must be last.
typedef union upb_MiniTableSub upb_MiniTableSub;
#ifdef __cplusplus
extern "C" {
#endif
// Constructors
UPB_API_INLINE upb_MiniTableSub
upb_MiniTableSub_FromEnum(const upb_MiniTableEnum* subenum);
UPB_API_INLINE upb_MiniTableSub
upb_MiniTableSub_FromMessage(const upb_MiniTable* submsg);
// Getters
UPB_API_INLINE const upb_MiniTableEnum* upb_MiniTableSub_Enum(
upb_MiniTableSub sub);
UPB_API_INLINE const upb_MiniTable* upb_MiniTableSub_Message(
upb_MiniTableSub sub);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* UPB_MINI_TABLE_SUB_H_ */
// Export the newer headers, for legacy users. New users should include the
// more specific headers directly.
// IWYU pragma: begin_exports

View File

@ -140,8 +140,7 @@ module Google
message = OBJECT_CACHE.get(msg.address)
if message.nil?
message = descriptor.msgclass.send(:private_constructor, arena, msg: msg)
message.freeze if frozen?
end
end
message
end

View File

@ -9,18 +9,20 @@ module Google
module Protobuf
class FFI
# Map
attach_function :map_clear, :upb_Map_Clear, [:Map], :void
attach_function :map_delete, :upb_Map_Delete, [:Map, MessageValue.by_value, MessageValue.by_ref], :bool
attach_function :map_get, :upb_Map_Get, [:Map, MessageValue.by_value, MessageValue.by_ref], :bool
attach_function :create_map, :upb_Map_New, [Internal::Arena, CType, CType], :Map
attach_function :map_size, :upb_Map_Size, [:Map], :size_t
attach_function :map_set, :upb_Map_Set, [:Map, MessageValue.by_value, MessageValue.by_value, Internal::Arena], :bool
attach_function :map_clear, :upb_Map_Clear, [:Map], :void
attach_function :map_delete, :upb_Map_Delete, [:Map, MessageValue.by_value, MessageValue.by_ref], :bool
attach_function :map_get, :upb_Map_Get, [:Map, MessageValue.by_value, MessageValue.by_ref], :bool
attach_function :create_map, :upb_Map_New, [Internal::Arena, CType, CType], :Map
attach_function :map_size, :upb_Map_Size, [:Map], :size_t
attach_function :map_set, :upb_Map_Set, [:Map, MessageValue.by_value, MessageValue.by_value, Internal::Arena], :bool
attach_function :map_freeze, :upb_Map_Freeze, [:Map, MiniTable.by_ref], :void
attach_function :map_frozen?, :upb_Map_IsFrozen, [:Map], :bool
# MapIterator
attach_function :map_next, :upb_MapIterator_Next, [:Map, :pointer], :bool
attach_function :map_done, :upb_MapIterator_Done, [:Map, :size_t], :bool
attach_function :map_key, :upb_MapIterator_Key, [:Map, :size_t], MessageValue.by_value
attach_function :map_value, :upb_MapIterator_Value, [:Map, :size_t], MessageValue.by_value
attach_function :map_next, :upb_MapIterator_Next, [:Map, :pointer], :bool
attach_function :map_done, :upb_MapIterator_Done, [:Map, :size_t], :bool
attach_function :map_key, :upb_MapIterator_Key, [:Map, :size_t], MessageValue.by_value
attach_function :map_value, :upb_MapIterator_Value, [:Map, :size_t], MessageValue.by_value
end
class Map
include Enumerable
@ -155,16 +157,27 @@ module Google
end
alias size length
def freeze
return self if frozen?
super
@arena.pin self
if value_type == :message
internal_iterator do |iterator|
value_message_value = Google::Protobuf::FFI.map_value(@map_ptr, iterator)
convert_upb_to_ruby(value_message_value, value_type, descriptor, arena).freeze
end
##
# Is this object frozen?
# Returns true if either this Ruby wrapper or the underlying
# representation are frozen. Freezes the wrapper if the underlying
# representation is already frozen but this wrapper isn't.
def frozen?
return true if super
if Google::Protobuf::FFI.map_frozen?(@map_ptr)
freeze
return true
end
false
end
##
# Freezes this object and its underlying representation. Returns self.
def freeze
return self if method(:frozen?).super_method.call
super
mini_table = (value_type == :message) ? Google::Protobuf::FFI.get_mini_table(@descriptor) : nil
Google::Protobuf::FFI.map_freeze(@map_ptr, mini_table)
self
end

View File

@ -24,6 +24,9 @@ module Google
attach_function :get_message_which_oneof, :upb_Message_WhichOneof, [:Message, OneofDescriptor], FieldDescriptor
attach_function :message_discard_unknown, :upb_Message_DiscardUnknown, [:Message, Descriptor, :int], :bool
attach_function :message_next, :upb_Message_Next, [:Message, Descriptor, :DefPool, :FieldDefPointer, MessageValue.by_ref, :pointer], :bool
attach_function :message_freeze, :upb_Message_Freeze, [:Message, MiniTable.by_ref], :void
attach_function :message_frozen?, :upb_Message_IsFrozen, [:Message], :bool
# MessageValue
attach_function :message_value_equal, :shared_Msgval_IsEqual, [MessageValue.by_value, MessageValue.by_value, CType, Descriptor], :bool
attach_function :message_value_hash, :shared_Msgval_GetHash, [MessageValue.by_value, CType, Descriptor, :uint64_t], :uint64_t
@ -58,16 +61,26 @@ module Google
instance
end
def freeze
return self if frozen?
super
@arena.pin self
self.class.descriptor.each do |field_descriptor|
next if field_descriptor.has_presence? && !Google::Protobuf::FFI.get_message_has(@msg, field_descriptor)
if field_descriptor.map? or field_descriptor.repeated? or field_descriptor.sub_message?
get_field(field_descriptor).freeze
end
##
# Is this object frozen?
# Returns true if either this Ruby wrapper or the underlying
# representation are frozen. Freezes the wrapper if the underlying
# representation is already frozen but this wrapper isn't.
def frozen?
return true if super
if Google::Protobuf::FFI.message_frozen?(@msg)
freeze
return true
end
false
end
##
# Freezes this object and its underlying representation. Returns self.
def freeze
return self if method(:frozen?).super_method.call
super
Google::Protobuf::FFI.message_freeze(@msg, Google::Protobuf::FFI.get_mini_table(self.class.descriptor))
self
end
@ -317,17 +330,20 @@ module Google
# index_internal or get_field would be logically correct, but slightly slower.
if field_descriptor.map?
define_method(field_name) do
raise FrozenError.new "can't get_map_field `#{field_name}` when frozen" if Google::Protobuf::FFI.message_frozen? @msg
mutable_message_value = Google::Protobuf::FFI.get_mutable_message @msg, field_descriptor, @arena
get_map_field(mutable_message_value[:map], field_descriptor)
end
elsif field_descriptor.repeated?
define_method(field_name) do
raise FrozenError.new "can't get_repeated_field `#{field_name}` when frozen" if Google::Protobuf::FFI.message_frozen? @msg
mutable_message_value = Google::Protobuf::FFI.get_mutable_message @msg, field_descriptor, @arena
get_repeated_field(mutable_message_value[:array], field_descriptor)
end
elsif field_descriptor.sub_message?
define_method(field_name) do
return nil unless Google::Protobuf::FFI.get_message_has @msg, field_descriptor
raise FrozenError.new "can't get_message `#{field_name}` when frozen" if Google::Protobuf::FFI.message_frozen? @msg
mutable_message = Google::Protobuf::FFI.get_mutable_message @msg, field_descriptor, @arena
sub_message = mutable_message[:msg]
sub_message_def = Google::Protobuf::FFI.get_subtype_as_message(field_descriptor)
@ -592,9 +608,11 @@ module Google
# @param field [FieldDescriptor] Descriptor of the field to get
def get_field(field, unwrap: false)
if field.map?
raise FrozenError.new "can't get_map_field `#{field}` when frozen" if Google::Protobuf::FFI.message_frozen? @msg
mutable_message_value = Google::Protobuf::FFI.get_mutable_message @msg, field, @arena
get_map_field(mutable_message_value[:map], field)
elsif field.repeated?
raise FrozenError.new "can't get_repeated_field `#{field}` when frozen" if Google::Protobuf::FFI.message_frozen? @msg
mutable_message_value = Google::Protobuf::FFI.get_mutable_message @msg, field, @arena
get_repeated_field(mutable_message_value[:array], field)
elsif field.sub_message?
@ -612,6 +630,7 @@ module Google
nil
end
else
raise FrozenError.new "can't get_message `#{field}` when frozen" if Google::Protobuf::FFI.message_frozen? @msg
mutable_message = Google::Protobuf::FFI.get_mutable_message @msg, field, @arena
sub_message = mutable_message[:msg]
Descriptor.send(:get_message, sub_message, sub_message_def, @arena)
@ -635,7 +654,6 @@ module Google
repeated_field = OBJECT_CACHE.get(array.address)
if repeated_field.nil?
repeated_field = RepeatedField.send(:construct_for_field, field, @arena, array: array)
repeated_field.freeze if frozen?
end
repeated_field
end
@ -648,7 +666,6 @@ module Google
map_field = OBJECT_CACHE.get(map.address)
if map_field.nil?
map_field = Google::Protobuf::Map.send(:construct_for_field, field, @arena, map: map)
map_field.freeze if frozen?
end
map_field
end

View File

@ -24,12 +24,14 @@ module Google
module Protobuf
class FFI
# Array
attach_function :append_array, :upb_Array_Append, [:Array, MessageValue.by_value, Internal::Arena], :bool
attach_function :get_msgval_at,:upb_Array_Get, [:Array, :size_t], MessageValue.by_value
attach_function :create_array, :upb_Array_New, [Internal::Arena, CType], :Array
attach_function :array_resize, :upb_Array_Resize, [:Array, :size_t, Internal::Arena], :bool
attach_function :array_set, :upb_Array_Set, [:Array, :size_t, MessageValue.by_value], :void
attach_function :array_size, :upb_Array_Size, [:Array], :size_t
attach_function :append_array, :upb_Array_Append, [:Array, MessageValue.by_value, Internal::Arena], :bool
attach_function :get_msgval_at, :upb_Array_Get, [:Array, :size_t], MessageValue.by_value
attach_function :create_array, :upb_Array_New, [Internal::Arena, CType], :Array
attach_function :array_resize, :upb_Array_Resize, [:Array, :size_t, Internal::Arena], :bool
attach_function :array_set, :upb_Array_Set, [:Array, :size_t, MessageValue.by_value], :void
attach_function :array_size, :upb_Array_Size, [:Array], :size_t
attach_function :array_freeze, :upb_Array_Freeze, [:Array, MiniTable.by_ref], :void
attach_function :array_frozen?, :upb_Array_IsFrozen, [:Array], :bool
end
class RepeatedField
@ -174,15 +176,27 @@ module Google
end
alias size :length
def freeze
return self if frozen?
super
@arena.pin self
if type == :message
each do |element|
element.freeze
end
##
# Is this object frozen?
# Returns true if either this Ruby wrapper or the underlying
# representation are frozen. Freezes the wrapper if the underlying
# representation is already frozen but this wrapper isn't.
def frozen?
return true if super
if Google::Protobuf::FFI.array_frozen?(array)
freeze
return true
end
false
end
##
# Freezes this object and its underlying representation. Returns self.
def freeze
return self if method(:frozen?).super_method.call
super
mini_table = (type == :message) ? Google::Protobuf::FFI.get_mini_table(@descriptor) : nil
Google::Protobuf::FFI.array_freeze(array, mini_table)
self
end

View File

@ -8,7 +8,7 @@
//! Tests covering accessors for singular bool, int32, int64, and bytes fields.
use googletest::prelude::*;
use protobuf::{MutProxy, Optional};
use protobuf::Optional;
use unittest_proto::{test_all_types, TestAllTypes};
#[test]
@ -498,15 +498,13 @@ fn test_nonempty_default_string_accessors() {
#[test]
fn test_singular_msg_field() {
use test_all_types::*;
let mut msg = TestAllTypes::new();
let msg_view = msg.optional_nested_message();
// testing reading an int inside a view
assert_that!(msg_view.bb(), eq(0));
assert_that!(msg.has_optional_nested_message(), eq(false));
let mut nested_msg_mut = msg.optional_nested_message_mut();
let nested_msg_mut = msg.optional_nested_message_mut();
// test reading an int inside a mut
assert_that!(nested_msg_mut.bb(), eq(0));
@ -780,3 +778,27 @@ fn test_submsg_setter() {
assert_that!(parent.optional_nested_message().bb(), eq(7));
}
#[test]
fn test_to_owned() {
let mut m = TestAllTypes::new();
m.set_optional_int32(42);
let clone = m.as_view().to_owned();
assert_that!(clone.optional_int32(), eq(42));
// to_owned should create a new message (modifying the original shouldn't affect
// the to_owned).
m.clear_optional_int32();
assert_that!(m.has_optional_int32(), eq(false));
assert_that!(clone.has_optional_int32(), eq(true));
assert_that!(clone.optional_int32(), eq(42));
let mut submsg_mut = m.optional_nested_message_mut();
submsg_mut.set_bb(7);
let submsg_clone = submsg_mut.to_owned();
assert_that!(submsg_clone.bb(), eq(7));
assert_that!(submsg_mut.bb(), eq(7));
submsg_mut.set_bb(8);
assert_that!(submsg_clone.bb(), eq(7));
assert_that!(submsg_mut.bb(), eq(8));
}

View File

@ -142,7 +142,7 @@ struct ArenaOptions {
// This is a thread-safe implementation: multiple threads may allocate from the
// arena concurrently. Destruction is not thread-safe and the destructing
// thread must synchronize with users of the arena first.
class PROTOBUF_EXPORT PROTOBUF_ALIGNAS(8) Arena final {
class PROTOBUF_EXPORT alignas(8) Arena final {
public:
// Default constructor with sensible default options, tuned for average
// use-cases.

View File

@ -78,8 +78,7 @@ std::string UniqueFileScopeIdentifier(const Descriptor* descriptor);
// Gets the unqualified class name for the file. For each .proto file, there
// will be one Java class containing all the immutable messages and another
// Java class containing all the mutable messages.
// TODO: remove the default value after updating client code.
std::string FileClassName(const FileDescriptor* file, bool immutable = true);
std::string FileClassName(const FileDescriptor* file, bool immutable);
// Returns the file's Java package name.
std::string FileJavaPackage(const FileDescriptor* file, bool immutable,

View File

@ -39,16 +39,17 @@ const char* DefaultPackage(Options options) {
bool IsReservedName(absl::string_view name) {
static const auto& kReservedNames =
*new absl::flat_hash_set<absl::string_view>({
"abstract", "assert", "boolean", "break", "byte",
"case", "catch", "char", "class", "const",
"continue", "default", "do", "double", "else",
"enum", "extends", "final", "finally", "float",
"for", "goto", "if", "implements", "import",
"instanceof", "int", "interface", "long", "native",
"new", "package", "private", "protected", "public",
"return", "short", "static", "strictfp", "super",
"switch", "synchronized", "this", "throw", "throws",
"transient", "try", "void", "volatile", "while",
"abstract", "assert", "boolean", "break", "byte",
"case", "catch", "char", "class", "const",
"continue", "default", "do", "double", "else",
"enum", "extends", "false", "final", "finally",
"float", "for", "goto", "if", "implements",
"import", "instanceof", "int", "interface", "long",
"native", "new", "package", "private", "protected",
"public", "return", "short", "static", "strictfp",
"super", "switch", "synchronized", "this", "throw",
"throws", "transient", "true", "try", "void",
"volatile", "while",
});
return kReservedNames.contains(name);
}
@ -140,6 +141,14 @@ std::string FileJavaPackage(const FileDescriptor* file, Options options) {
return FileJavaPackage(file, true /* immutable */, options);
}
std::string JavaPackageDirectory(const FileDescriptor* file) {
return JavaPackageToDir(FileJavaPackage(file));
}
std::string FileClassName(const FileDescriptor* file) {
return FileClassName(file, /*immutable=*/true);
}
std::string CapitalizedFieldName(const FieldDescriptor* field) {
return UnderscoresToCamelCase(FieldName(field), true);
}

View File

@ -72,6 +72,20 @@ std::string ClassName(const ServiceDescriptor* descriptor);
std::string FileJavaPackage(const FileDescriptor* descriptor,
Options options = {});
// Requires:
// descriptor != NULL
//
// Returns:
// Java package directory.
std::string JavaPackageDirectory(const FileDescriptor* file);
// Requires:
// descriptor != NULL
//
// Returns:
// The unqualified Java class name.
std::string FileClassName(const FileDescriptor* file);
// Requires:
// descriptor != NULL
// Returns:

View File

@ -37,7 +37,13 @@ class PROTOC_EXPORT Generator : public CodeGenerator {
std::string* error) const override;
uint64_t GetSupportedFeatures() const override {
return FEATURE_PROTO3_OPTIONAL;
return Feature::FEATURE_PROTO3_OPTIONAL;
}
Edition GetMinimumEdition() const override { return Edition::EDITION_PROTO2; }
Edition GetMaximumEdition() const override { return Edition::EDITION_2023; }
std::vector<const FieldDescriptor*> GetFeatureExtensions() const override {
return {};
}
private:

View File

@ -911,6 +911,10 @@ void GenerateRs(Context& ctx, const Descriptor& msg) {
$Msg::serialize$
}
pub fn to_owned(&self) -> $Msg$ {
$pb$::IntoProxied::into(*self, $pbi$::Private)
}
$accessor_fns_for_views$
}
@ -986,6 +990,10 @@ void GenerateRs(Context& ctx, const Descriptor& msg) {
$pb$::ViewProxy::as_view(self).serialize()
}
pub fn to_owned(&self) -> $Msg$ {
$pb$::ViewProxy::as_view(self).to_owned()
}
$get_upb_minitable$
$raw_arena_getter_for_msgmut$

View File

@ -403,39 +403,6 @@ static_assert(PROTOBUF_ABSL_MIN(20230125, 3),
#error PROTOBUF_FORCE_ALLOCATION_ON_CONSTRUCTION was previously defined
#endif
// Specify memory alignment for structs, classes, etc.
// Use like:
// class PROTOBUF_ALIGNAS(16) MyClass { ... }
// PROTOBUF_ALIGNAS(16) int array[4];
//
// In most places you can use the C++11 keyword "alignas", which is preferred.
//
// But compilers have trouble mixing __attribute__((...)) syntax with
// alignas(...) syntax.
//
// Doesn't work in clang or gcc:
// struct alignas(16) __attribute__((packed)) S { char c; };
// Works in clang but not gcc:
// struct __attribute__((packed)) alignas(16) S2 { char c; };
// Works in clang and gcc:
// struct alignas(16) S3 { char c; } __attribute__((packed));
//
// There are also some attributes that must be specified *before* a class
// definition: visibility (used for exporting functions/classes) is one of
// these attributes. This means that it is not possible to use alignas() with a
// class that is marked as exported.
#ifdef PROTOBUF_ALIGNAS
#error PROTOBUF_ALIGNAS was previously defined
#endif
#if defined(_MSC_VER)
#define PROTOBUF_ALIGNAS(byte_alignment) __declspec(align(byte_alignment))
#elif defined(__GNUC__)
#define PROTOBUF_ALIGNAS(byte_alignment) \
__attribute__((aligned(byte_alignment)))
#else
#define PROTOBUF_ALIGNAS(byte_alignment) alignas(byte_alignment)
#endif
#ifdef PROTOBUF_THREAD_LOCAL
#error PROTOBUF_THREAD_LOCAL was previously defined
#endif
@ -597,13 +564,6 @@ static_assert(PROTOBUF_ABSL_MIN(20230125, 3),
#define PROTOBUF_TSAN_DECLARE_MEMBER
#endif
#ifdef PROTOBUF_USE_TABLE_PARSER_ON_REFLECTION
#error PROTOBUF_USE_TABLE_PARSER_ON_REFLECTION was previously defined
#endif
#if !defined(PROTOBUF_TEMPORARY_DISABLE_TABLE_PARSER_ON_REFLECTION)
#define PROTOBUF_USE_TABLE_PARSER_ON_REFLECTION 1
#endif // PROTOBUF_ENABLE_FORCE_ALLOCATION_ON_CONSTRUCTION
// Note that this is performance sensitive: changing the parameters will change
// the registers used by the ABI calling convention, which subsequently affects
// register selection logic inside the function.

View File

@ -50,7 +50,6 @@
#undef PROTOBUF_ASSUME
#undef PROTOBUF_EXPORT_TEMPLATE_DECLARE
#undef PROTOBUF_EXPORT_TEMPLATE_DEFINE
#undef PROTOBUF_ALIGNAS
#undef PROTOBUF_THREAD_LOCAL
#undef PROTOBUF_CONSTINIT
#undef PROTOBUF_CONSTEXPR
@ -65,7 +64,6 @@
#undef PROTOBUF_MSAN
#undef PROTOBUF_TSAN
#undef PROTOBUF_TSAN_DECLARE_MEMBER
#undef PROTOBUF_USE_TABLE_PARSER_ON_REFLECTION
#undef PROTOBUF_BUILTIN_CONSTANT_P
#undef PROTOBUF_DESCRIPTOR_WEAK_MESSAGES_ALLOWED
#undef PROTOBUF_PREFETCH_PARSE_TABLE

View File

@ -8,30 +8,17 @@
#ifndef UPB_MESSAGE_ACCESSORS_H_
#define UPB_MESSAGE_ACCESSORS_H_
#include <stddef.h>
#include <stdint.h>
#include <string.h>
#include "upb/base/descriptor_constants.h"
#include "upb/base/string_view.h"
#include "upb/mem/arena.h"
#include "upb/message/array.h"
#include "upb/message/internal/accessors.h"
#include "upb/message/internal/array.h"
#include "upb/message/internal/map.h"
#include "upb/message/internal/message.h"
#include "upb/message/internal/tagged_ptr.h"
#include "upb/message/map.h"
#include "upb/message/message.h"
#include "upb/message/tagged_ptr.h"
#include "upb/message/value.h"
#include "upb/mini_table/enum.h"
#include "upb/mini_table/extension.h"
#include "upb/mini_table/field.h"
#include "upb/mini_table/internal/field.h"
#include "upb/mini_table/internal/message.h"
#include "upb/mini_table/message.h"
#include "upb/mini_table/sub.h"
// Must be last.
#include "upb/port/def.inc"
@ -76,6 +63,10 @@ UPB_API_INLINE upb_MessageValue
upb_Message_GetField(const upb_Message* msg, const upb_MiniTableField* f,
upb_MessageValue default_val);
UPB_API_INLINE upb_TaggedMessagePtr upb_Message_GetTaggedMessagePtr(
const upb_Message* msg, const upb_MiniTableField* field,
upb_Message* default_val);
UPB_API_INLINE const upb_Array* upb_Message_GetArray(
const upb_Message* msg, const upb_MiniTableField* f);
@ -102,12 +93,18 @@ UPB_API_INLINE int64_t upb_Message_GetInt64(const upb_Message* msg,
UPB_API_INLINE const upb_Map* upb_Message_GetMap(const upb_Message* msg,
const upb_MiniTableField* f);
UPB_API_INLINE const upb_Message* upb_Message_GetMessage(
const upb_Message* msg, const upb_MiniTableField* f);
UPB_API_INLINE upb_Array* upb_Message_GetMutableArray(
upb_Message* msg, const upb_MiniTableField* f);
UPB_API_INLINE upb_Map* upb_Message_GetMutableMap(upb_Message* msg,
const upb_MiniTableField* f);
UPB_API_INLINE upb_Message* upb_Message_GetMutableMessage(
upb_Message* msg, const upb_MiniTableField* f);
UPB_API_INLINE upb_Array* upb_Message_GetOrCreateMutableArray(
upb_Message* msg, const upb_MiniTableField* f, upb_Arena* arena);
@ -155,6 +152,11 @@ UPB_API_INLINE bool upb_Message_SetInt64(upb_Message* msg,
const upb_MiniTableField* f,
int64_t value, upb_Arena* a);
UPB_API_INLINE void upb_Message_SetMessage(upb_Message* msg,
const upb_MiniTable* m,
const upb_MiniTableField* f,
upb_Message* sub_message);
UPB_API_INLINE bool upb_Message_SetString(upb_Message* msg,
const upb_MiniTableField* f,
upb_StringView value, upb_Arena* a);
@ -167,55 +169,6 @@ UPB_API_INLINE bool upb_Message_SetUInt64(upb_Message* msg,
const upb_MiniTableField* f,
uint64_t value, upb_Arena* a);
UPB_API_INLINE upb_TaggedMessagePtr upb_Message_GetTaggedMessagePtr(
const upb_Message* msg, const upb_MiniTableField* field,
upb_Message* default_val) {
UPB_ASSUME(upb_MiniTableField_CType(field) == kUpb_CType_Message);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(field) ==
UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte));
UPB_ASSUME(upb_MiniTableField_IsScalar(field));
upb_TaggedMessagePtr tagged;
_upb_Message_GetNonExtensionField(msg, field, &default_val, &tagged);
return tagged;
}
UPB_API_INLINE const upb_Message* upb_Message_GetMessage(
const upb_Message* msg, const upb_MiniTableField* field) {
upb_TaggedMessagePtr tagged =
upb_Message_GetTaggedMessagePtr(msg, field, NULL);
return upb_TaggedMessagePtr_GetNonEmptyMessage(tagged);
}
UPB_API_INLINE upb_Message* upb_Message_GetMutableMessage(
upb_Message* msg, const upb_MiniTableField* field) {
return (upb_Message*)upb_Message_GetMessage(msg, field);
}
// For internal use only; users cannot set tagged messages because only the
// parser and the message copier are allowed to directly create an empty
// message.
UPB_INLINE void UPB_PRIVATE(_upb_Message_SetTaggedMessagePtr)(
struct upb_Message* msg, const upb_MiniTable* mini_table,
const upb_MiniTableField* f, upb_TaggedMessagePtr sub_message) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Message);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) ==
UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte));
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
upb_Message_SetBaseField(msg, f, &sub_message);
}
// Sets the value of a message-typed field. The `mini_table` and `field`
// parameters belong to `msg`, not `sub_message`. The mini_tables of `msg` and
// `sub_message` must have been linked for this to work correctly.
UPB_API_INLINE void upb_Message_SetMessage(upb_Message* msg,
const upb_MiniTable* mini_table,
const upb_MiniTableField* field,
upb_Message* sub_message) {
UPB_PRIVATE(_upb_Message_SetTaggedMessagePtr)
(msg, mini_table, field,
UPB_PRIVATE(_upb_TaggedMessagePtr_Pack)(sub_message, false));
}
UPB_API_INLINE void* upb_Message_ResizeArrayUninitialized(
upb_Message* msg, const upb_MiniTableField* f, size_t size,
upb_Arena* arena);

View File

@ -215,7 +215,7 @@ upb_Message* _upb_Message_Copy(upb_Message* dst, const upb_Message* src,
return NULL;
}
UPB_PRIVATE(_upb_Message_SetTaggedMessagePtr)
(dst, mini_table, field,
(dst, field,
UPB_PRIVATE(_upb_TaggedMessagePtr_Pack)(dst_sub_message,
is_empty));
}

View File

@ -220,7 +220,6 @@ UPB_INLINE bool UPB_PRIVATE(_upb_MiniTableField_DataIsZero)(
// const upb_MiniTableField* field,
// bool value, upb_Arena* a) {
// UPB_ASSUME(field->UPB_PRIVATE(descriptortype) == kUpb_FieldType_Bool);
// UPB_ASSUME(upb_MiniTableField_IsScalar(field));
// UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(field) ==
// kUpb_FieldRep_1Byte);
// upb_Message_SetField(msg, field, &value, a);
@ -351,8 +350,8 @@ UPB_API_INLINE bool upb_Message_GetBool(const struct upb_Message* msg,
const upb_MiniTableField* f,
bool default_val) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Bool);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_1Byte);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_1Byte);
upb_MessageValue def;
def.bool_val = default_val;
return upb_Message_GetField(msg, f, def).bool_val;
@ -362,8 +361,8 @@ UPB_API_INLINE double upb_Message_GetDouble(const struct upb_Message* msg,
const upb_MiniTableField* f,
double default_val) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Double);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
upb_MessageValue def;
def.double_val = default_val;
@ -374,8 +373,8 @@ UPB_API_INLINE float upb_Message_GetFloat(const struct upb_Message* msg,
const upb_MiniTableField* f,
float default_val) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Float);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
upb_MessageValue def;
def.float_val = default_val;
@ -387,8 +386,8 @@ UPB_API_INLINE int32_t upb_Message_GetInt32(const struct upb_Message* msg,
int32_t default_val) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Int32 ||
upb_MiniTableField_CType(f) == kUpb_CType_Enum);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
upb_MessageValue def;
def.int32_val = default_val;
@ -399,8 +398,8 @@ UPB_API_INLINE int64_t upb_Message_GetInt64(const struct upb_Message* msg,
const upb_MiniTableField* f,
int64_t default_val) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Int64);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
upb_MessageValue def;
def.int64_val = default_val;
@ -429,6 +428,37 @@ UPB_API_INLINE const struct upb_Map* upb_Message_GetMap(
return ret;
}
UPB_API_INLINE uintptr_t upb_Message_GetTaggedMessagePtr(
const struct upb_Message* msg, const upb_MiniTableField* f,
struct upb_Message* default_val) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Message);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) ==
UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte));
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
uintptr_t tagged;
_upb_Message_GetNonExtensionField(msg, f, &default_val, &tagged);
return tagged;
}
// For internal use only; users cannot set tagged messages because only the
// parser and the message copier are allowed to directly create an empty
// message.
UPB_INLINE void UPB_PRIVATE(_upb_Message_SetTaggedMessagePtr)(
struct upb_Message* msg, const upb_MiniTableField* f,
uintptr_t sub_message) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Message);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) ==
UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte));
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
upb_Message_SetBaseField(msg, f, &sub_message);
}
UPB_API_INLINE const struct upb_Message* upb_Message_GetMessage(
const struct upb_Message* msg, const upb_MiniTableField* f) {
uintptr_t tagged = upb_Message_GetTaggedMessagePtr(msg, f, NULL);
return upb_TaggedMessagePtr_GetNonEmptyMessage(tagged);
}
UPB_API_INLINE upb_Array* upb_Message_GetMutableArray(
struct upb_Message* msg, const upb_MiniTableField* f) {
UPB_PRIVATE(_upb_MiniTableField_CheckIsArray)(f);
@ -440,6 +470,11 @@ UPB_API_INLINE struct upb_Map* upb_Message_GetMutableMap(
return (struct upb_Map*)upb_Message_GetMap(msg, f);
}
UPB_API_INLINE struct upb_Message* upb_Message_GetMutableMessage(
struct upb_Message* msg, const upb_MiniTableField* f) {
return (struct upb_Message*)upb_Message_GetMessage(msg, f);
}
UPB_API_INLINE upb_Array* upb_Message_GetOrCreateMutableArray(
struct upb_Message* msg, const upb_MiniTableField* f, upb_Arena* arena) {
UPB_ASSERT(arena);
@ -515,7 +550,6 @@ upb_Message_GetString(const struct upb_Message* msg,
upb_MiniTableField_CType(f) == kUpb_CType_Bytes);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) ==
kUpb_FieldRep_StringView);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
upb_MessageValue def;
def.str_val = default_val;
@ -526,8 +560,8 @@ UPB_API_INLINE uint32_t upb_Message_GetUInt32(const struct upb_Message* msg,
const upb_MiniTableField* f,
uint32_t default_val) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_UInt32);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
upb_MessageValue def;
def.uint32_val = default_val;
@ -538,23 +572,89 @@ UPB_API_INLINE uint64_t upb_Message_GetUInt64(const struct upb_Message* msg,
const upb_MiniTableField* f,
uint64_t default_val) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_UInt64);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
upb_MessageValue def;
def.uint64_val = default_val;
return upb_Message_GetField(msg, f, def).uint64_val;
}
UPB_API_INLINE bool upb_Message_SetBool(struct upb_Message* msg,
const upb_MiniTableField* f, bool value,
upb_Arena* a) {
// BaseField Setters ///////////////////////////////////////////////////////////
UPB_API_INLINE void upb_Message_SetBaseFieldBool(struct upb_Message* msg,
const upb_MiniTableField* f,
bool value) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Bool);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_1Byte);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
upb_MessageValue val;
val.bool_val = value;
return UPB_PRIVATE(_upb_Message_SetField)(msg, f, val, a);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_1Byte);
upb_Message_SetBaseField(msg, f, &value);
}
UPB_API_INLINE void upb_Message_SetBaseFieldDouble(struct upb_Message* msg,
const upb_MiniTableField* f,
double value) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Double);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
upb_Message_SetBaseField(msg, f, &value);
}
UPB_API_INLINE void upb_Message_SetBaseFieldFloat(struct upb_Message* msg,
const upb_MiniTableField* f,
float value) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Float);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
upb_Message_SetBaseField(msg, f, &value);
}
UPB_API_INLINE void upb_Message_SetBaseFieldInt32(struct upb_Message* msg,
const upb_MiniTableField* f,
int32_t value) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Int32 ||
upb_MiniTableField_CType(f) == kUpb_CType_Enum);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
upb_Message_SetBaseField(msg, f, &value);
}
UPB_API_INLINE void upb_Message_SetBaseFieldInt64(struct upb_Message* msg,
const upb_MiniTableField* f,
int64_t value) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Int64);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
upb_Message_SetBaseField(msg, f, &value);
}
UPB_API_INLINE void upb_Message_SetBaseFieldString(struct upb_Message* msg,
const upb_MiniTableField* f,
upb_StringView value) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_String ||
upb_MiniTableField_CType(f) == kUpb_CType_Bytes);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) ==
kUpb_FieldRep_StringView);
upb_Message_SetBaseField(msg, f, &value);
}
UPB_API_INLINE void upb_Message_SetBaseFieldUInt32(struct upb_Message* msg,
const upb_MiniTableField* f,
uint32_t value) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_UInt32);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
upb_Message_SetBaseField(msg, f, &value);
}
UPB_API_INLINE void upb_Message_SetBaseFieldUInt64(struct upb_Message* msg,
const upb_MiniTableField* f,
uint64_t value) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_UInt64);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
upb_Message_SetBaseField(msg, f, &value);
}
UPB_API_INLINE void upb_Message_SetClosedEnum(
@ -562,55 +662,142 @@ UPB_API_INLINE void upb_Message_SetClosedEnum(
const upb_MiniTableField* f, int32_t value) {
UPB_ASSERT(upb_MiniTableField_IsClosedEnum(f));
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
UPB_ASSERT(upb_MiniTableEnum_CheckValue(
upb_MiniTable_GetSubEnumTable(msg_mini_table, f), value));
upb_Message_SetBaseField(msg, f, &value);
}
// Extension Setters ///////////////////////////////////////////////////////////
UPB_API_INLINE bool upb_Message_SetExtensionBool(
struct upb_Message* msg, const upb_MiniTableExtension* e, bool value,
upb_Arena* a) {
UPB_ASSUME(upb_MiniTableExtension_CType(e) == kUpb_CType_Bool);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(e) ==
kUpb_FieldRep_1Byte);
return upb_Message_SetExtension(msg, e, &value, a);
}
UPB_API_INLINE bool upb_Message_SetExtensionDouble(
struct upb_Message* msg, const upb_MiniTableExtension* e, double value,
upb_Arena* a) {
UPB_ASSUME(upb_MiniTableExtension_CType(e) == kUpb_CType_Double);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(e) ==
kUpb_FieldRep_8Byte);
return upb_Message_SetExtension(msg, e, &value, a);
}
UPB_API_INLINE bool upb_Message_SetExtensionFloat(
struct upb_Message* msg, const upb_MiniTableExtension* e, float value,
upb_Arena* a) {
UPB_ASSUME(upb_MiniTableExtension_CType(e) == kUpb_CType_Float);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(e) ==
kUpb_FieldRep_4Byte);
return upb_Message_SetExtension(msg, e, &value, a);
}
UPB_API_INLINE bool upb_Message_SetExtensionInt32(
struct upb_Message* msg, const upb_MiniTableExtension* e, int32_t value,
upb_Arena* a) {
UPB_ASSUME(upb_MiniTableExtension_CType(e) == kUpb_CType_Int32 ||
upb_MiniTableExtension_CType(e) == kUpb_CType_Enum);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(e) ==
kUpb_FieldRep_4Byte);
return upb_Message_SetExtension(msg, e, &value, a);
}
UPB_API_INLINE bool upb_Message_SetExtensionInt64(
struct upb_Message* msg, const upb_MiniTableExtension* e, int64_t value,
upb_Arena* a) {
UPB_ASSUME(upb_MiniTableExtension_CType(e) == kUpb_CType_Int64);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(e) ==
kUpb_FieldRep_8Byte);
return upb_Message_SetExtension(msg, e, &value, a);
}
UPB_API_INLINE bool upb_Message_SetExtensionString(
struct upb_Message* msg, const upb_MiniTableExtension* e,
upb_StringView value, upb_Arena* a) {
UPB_ASSUME(upb_MiniTableExtension_CType(e) == kUpb_CType_String ||
upb_MiniTableExtension_CType(e) == kUpb_CType_Bytes);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(e) ==
kUpb_FieldRep_StringView);
return upb_Message_SetExtension(msg, e, &value, a);
}
UPB_API_INLINE bool upb_Message_SetExtensionUInt32(
struct upb_Message* msg, const upb_MiniTableExtension* e, uint32_t value,
upb_Arena* a) {
UPB_ASSUME(upb_MiniTableExtension_CType(e) == kUpb_CType_UInt32);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(e) ==
kUpb_FieldRep_4Byte);
return upb_Message_SetExtension(msg, e, &value, a);
}
UPB_API_INLINE bool upb_Message_SetExtensionUInt64(
struct upb_Message* msg, const upb_MiniTableExtension* e, uint64_t value,
upb_Arena* a) {
UPB_ASSUME(upb_MiniTableExtension_CType(e) == kUpb_CType_UInt64);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(e) ==
kUpb_FieldRep_8Byte);
return upb_Message_SetExtension(msg, e, &value, a);
}
// Universal Setters ///////////////////////////////////////////////////////////
UPB_API_INLINE bool upb_Message_SetBool(struct upb_Message* msg,
const upb_MiniTableField* f, bool value,
upb_Arena* a) {
return upb_MiniTableField_IsExtension(f)
? upb_Message_SetExtensionBool(
msg, (const upb_MiniTableExtension*)f, value, a)
: (upb_Message_SetBaseFieldBool(msg, f, value), true);
}
UPB_API_INLINE bool upb_Message_SetDouble(struct upb_Message* msg,
const upb_MiniTableField* f,
double value, upb_Arena* a) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Double);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
upb_MessageValue val;
val.double_val = value;
return UPB_PRIVATE(_upb_Message_SetField)(msg, f, val, a);
return upb_MiniTableField_IsExtension(f)
? upb_Message_SetExtensionDouble(
msg, (const upb_MiniTableExtension*)f, value, a)
: (upb_Message_SetBaseFieldDouble(msg, f, value), true);
}
UPB_API_INLINE bool upb_Message_SetFloat(struct upb_Message* msg,
const upb_MiniTableField* f,
float value, upb_Arena* a) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Float);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
upb_MessageValue val;
val.float_val = value;
return UPB_PRIVATE(_upb_Message_SetField)(msg, f, val, a);
return upb_MiniTableField_IsExtension(f)
? upb_Message_SetExtensionFloat(
msg, (const upb_MiniTableExtension*)f, value, a)
: (upb_Message_SetBaseFieldFloat(msg, f, value), true);
}
UPB_API_INLINE bool upb_Message_SetInt32(struct upb_Message* msg,
const upb_MiniTableField* f,
int32_t value, upb_Arena* a) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Int32 ||
upb_MiniTableField_CType(f) == kUpb_CType_Enum);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
upb_MessageValue val;
val.int32_val = value;
return UPB_PRIVATE(_upb_Message_SetField)(msg, f, val, a);
return upb_MiniTableField_IsExtension(f)
? upb_Message_SetExtensionInt32(
msg, (const upb_MiniTableExtension*)f, value, a)
: (upb_Message_SetBaseFieldInt32(msg, f, value), true);
}
UPB_API_INLINE bool upb_Message_SetInt64(struct upb_Message* msg,
const upb_MiniTableField* f,
int64_t value, upb_Arena* a) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_Int64);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
upb_MessageValue val;
val.int64_val = value;
return UPB_PRIVATE(_upb_Message_SetField)(msg, f, val, a);
return upb_MiniTableField_IsExtension(f)
? upb_Message_SetExtensionInt64(
msg, (const upb_MiniTableExtension*)f, value, a)
: (upb_Message_SetBaseFieldInt64(msg, f, value), true);
}
// Sets the value of a message-typed field. The mini_tables of `msg` and
// `sub_message` must have been linked for this to work correctly.
UPB_API_INLINE void upb_Message_SetMessage(struct upb_Message* msg,
const upb_MiniTable* m,
const upb_MiniTableField* f,
struct upb_Message* sub_message) {
UPB_PRIVATE(_upb_Message_SetTaggedMessagePtr)
(msg, f, UPB_PRIVATE(_upb_TaggedMessagePtr_Pack)(sub_message, false));
}
// Sets the value of a `string` or `bytes` field. The bytes of the value are not
@ -620,36 +807,28 @@ UPB_API_INLINE bool upb_Message_SetInt64(struct upb_Message* msg,
UPB_API_INLINE bool upb_Message_SetString(struct upb_Message* msg,
const upb_MiniTableField* f,
upb_StringView value, upb_Arena* a) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_String ||
upb_MiniTableField_CType(f) == kUpb_CType_Bytes);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) ==
kUpb_FieldRep_StringView);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
upb_MessageValue val;
val.str_val = value;
return UPB_PRIVATE(_upb_Message_SetField)(msg, f, val, a);
return upb_MiniTableField_IsExtension(f)
? upb_Message_SetExtensionString(
msg, (const upb_MiniTableExtension*)f, value, a)
: (upb_Message_SetBaseFieldString(msg, f, value), true);
}
UPB_API_INLINE bool upb_Message_SetUInt32(struct upb_Message* msg,
const upb_MiniTableField* f,
uint32_t value, upb_Arena* a) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_UInt32);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_4Byte);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
upb_MessageValue val;
val.uint32_val = value;
return UPB_PRIVATE(_upb_Message_SetField)(msg, f, val, a);
return upb_MiniTableField_IsExtension(f)
? upb_Message_SetExtensionUInt32(
msg, (const upb_MiniTableExtension*)f, value, a)
: (upb_Message_SetBaseFieldUInt32(msg, f, value), true);
}
UPB_API_INLINE bool upb_Message_SetUInt64(struct upb_Message* msg,
const upb_MiniTableField* f,
uint64_t value, upb_Arena* a) {
UPB_ASSUME(upb_MiniTableField_CType(f) == kUpb_CType_UInt64);
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableField_GetRep)(f) == kUpb_FieldRep_8Byte);
UPB_ASSUME(upb_MiniTableField_IsScalar(f));
upb_MessageValue val;
val.uint64_val = value;
return UPB_PRIVATE(_upb_Message_SetField)(msg, f, val, a);
return upb_MiniTableField_IsExtension(f)
? upb_Message_SetExtensionUInt64(
msg, (const upb_MiniTableExtension*)f, value, a)
: (upb_Message_SetBaseFieldUInt64(msg, f, value), true);
}
UPB_API_INLINE void upb_Message_Clear(struct upb_Message* msg,

View File

@ -49,6 +49,11 @@ UPB_API_INLINE void upb_MiniTableExtension_SetSubMessage(
e->UPB_PRIVATE(sub).UPB_PRIVATE(submsg) = m;
}
UPB_INLINE upb_FieldRep UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(
const struct upb_MiniTableExtension* e) {
return UPB_PRIVATE(_upb_MiniTableField_GetRep)(&e->UPB_PRIVATE(field));
}
#ifdef __cplusplus
} /* extern "C" */
#endif