Compare commits
16 Commits
191459a1f4
...
4998f243f4
Author | SHA1 | Date |
---|---|---|
Mike Kruskal | 4998f243f4 | |
Sandy Zhang | 7febb4c48f | |
Protobuf Team Bot | b694cfa441 | |
Protobuf Team Bot | ec126a5069 | |
Protobuf Team Bot | 64580b29c1 | |
Protobuf Team Bot | d5b7d7a87f | |
Brent Shaffer | 01744cccae | |
Sandy Zhang | b77343aa2c | |
Protobuf Team Bot | d8329b68e4 | |
Protobuf Team Bot | 6afb130dca | |
Eric Salo | d923896299 | |
Protobuf Team Bot | 4d3a98c27e | |
Eric Salo | 65821a67d6 | |
Éamonn McManus | 98d5bdd111 | |
Protobuf Team Bot | 5632d8e616 | |
Sandy Zhang | 94cf1e9446 |
|
@ -18,7 +18,7 @@ jobs:
|
|||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
branch: [main, 22.x, 23.x, 24.x, 25.x, 26.x]
|
||||
branch: [main, 25.x, 27.x]
|
||||
os: [{ name: Linux, value: ubuntu-latest}]
|
||||
|
||||
name: Test staleness ${{ matrix.os.name }} ${{ github.head_ref && 'PR' || matrix.branch }}
|
||||
|
|
|
@ -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",
|
||||
],
|
||||
)
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
|
@ -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,
|
||||
|
|
|
@ -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"],
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -469,7 +469,7 @@ class PROTOC_EXPORT CommandLineInterface {
|
|||
// When using --encode, this will be passed to SetSerializationDeterministic.
|
||||
bool deterministic_output_ = false;
|
||||
|
||||
bool opensource_runtime_ = PROTO2_IS_OSS;
|
||||
bool opensource_runtime_ = google::protobuf::internal::IsOss();
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include "google/protobuf/compiler/code_generator.h"
|
||||
#include "google/protobuf/cpp_features.pb.h"
|
||||
#include "google/protobuf/descriptor.pb.h"
|
||||
#include "google/protobuf/port.h"
|
||||
|
||||
// Must be included last.
|
||||
#include "google/protobuf/port_def.inc"
|
||||
|
@ -85,7 +86,7 @@ class PROTOC_EXPORT CppGenerator : public CodeGenerator {
|
|||
using CodeGenerator::GetResolvedSourceFeatures;
|
||||
|
||||
private:
|
||||
bool opensource_runtime_ = PROTO2_IS_OSS;
|
||||
bool opensource_runtime_ = google::protobuf::internal::IsOss();
|
||||
std::string runtime_include_base_;
|
||||
|
||||
absl::Status ValidateFeatures(const FileDescriptor* file) const;
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "google/protobuf/compiler/code_generator.h"
|
||||
#include "google/protobuf/compiler/java/java_features.pb.h"
|
||||
#include "google/protobuf/descriptor.pb.h"
|
||||
#include "google/protobuf/port.h"
|
||||
|
||||
// Must be included last.
|
||||
#include "google/protobuf/port_def.inc"
|
||||
|
@ -62,7 +63,7 @@ class PROTOC_EXPORT JavaGenerator : public CodeGenerator {
|
|||
using CodeGenerator::GetResolvedSourceFeatures;
|
||||
|
||||
private:
|
||||
bool opensource_runtime_ = PROTO2_IS_OSS;
|
||||
bool opensource_runtime_ = google::protobuf::internal::IsOss();
|
||||
};
|
||||
|
||||
} // namespace java
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
#include <string>
|
||||
|
||||
#include "google/protobuf/port_def.inc"
|
||||
#include "google/protobuf/port.h"
|
||||
|
||||
namespace google {
|
||||
namespace protobuf {
|
||||
|
@ -34,7 +34,7 @@ struct Options {
|
|||
// When set, the protoc will generate the current files and all the transitive
|
||||
// dependencies as lite runtime.
|
||||
bool enforce_lite;
|
||||
bool opensource_runtime = PROTO2_IS_OSS;
|
||||
bool opensource_runtime = google::protobuf::internal::IsOss();
|
||||
// If true, we should build .meta files and emit @Generated annotations into
|
||||
// generated code.
|
||||
bool annotate_code;
|
||||
|
@ -53,5 +53,4 @@ struct Options {
|
|||
} // namespace protobuf
|
||||
} // namespace google
|
||||
|
||||
#include "google/protobuf/port_undef.inc"
|
||||
#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_OPTIONS_H__
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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$
|
||||
|
|
|
@ -1897,7 +1897,7 @@ const char descriptor_table_protodef_google_2fprotobuf_2fdescriptor_2eproto[] AB
|
|||
"ive_int_value\030\005 \001(\003\022\024\n\014double_value\030\006 \001("
|
||||
"\001\022\024\n\014string_value\030\007 \001(\014\022\027\n\017aggregate_val"
|
||||
"ue\030\010 \001(\t\0323\n\010NamePart\022\021\n\tname_part\030\001 \002(\t\022"
|
||||
"\024\n\014is_extension\030\002 \002(\010\"\333\t\n\nFeatureSet\022\202\001\n"
|
||||
"\024\n\014is_extension\030\002 \002(\010\"\303\t\n\nFeatureSet\022\202\001\n"
|
||||
"\016field_presence\030\001 \001(\0162).google.protobuf."
|
||||
"FeatureSet.FieldPresenceB\?\210\001\001\230\001\004\230\001\001\242\001\r\022\010"
|
||||
"EXPLICIT\030\346\007\242\001\r\022\010IMPLICIT\030\347\007\242\001\r\022\010EXPLICIT"
|
||||
|
@ -1927,47 +1927,47 @@ const char descriptor_table_protodef_google_2fprotobuf_2fdescriptor_2eproto[] AB
|
|||
"GE_ENCODING_UNKNOWN\020\000\022\023\n\017LENGTH_PREFIXED"
|
||||
"\020\001\022\r\n\tDELIMITED\020\002\"H\n\nJsonFormat\022\027\n\023JSON_"
|
||||
"FORMAT_UNKNOWN\020\000\022\t\n\005ALLOW\020\001\022\026\n\022LEGACY_BE"
|
||||
"ST_EFFORT\020\002*\006\010\350\007\020\351\007*\006\010\351\007\020\352\007*\006\010\352\007\020\353\007*\006\010\206N"
|
||||
"\020\207N*\006\010\213N\020\220N*\006\010\220N\020\221NJ\006\010\347\007\020\350\007\"\202\003\n\022FeatureS"
|
||||
"etDefaults\022N\n\010defaults\030\001 \003(\0132<.google.pr"
|
||||
"otobuf.FeatureSetDefaults.FeatureSetEdit"
|
||||
"ionDefault\0221\n\017minimum_edition\030\004 \001(\0162\030.go"
|
||||
"ogle.protobuf.Edition\0221\n\017maximum_edition"
|
||||
"\030\005 \001(\0162\030.google.protobuf.Edition\032\265\001\n\030Fea"
|
||||
"tureSetEditionDefault\022)\n\007edition\030\003 \001(\0162\030"
|
||||
".google.protobuf.Edition\0229\n\024overridable_"
|
||||
"features\030\004 \001(\0132\033.google.protobuf.Feature"
|
||||
"Set\0223\n\016fixed_features\030\005 \001(\0132\033.google.pro"
|
||||
"tobuf.FeatureSet\"\325\001\n\016SourceCodeInfo\022:\n\010l"
|
||||
"ocation\030\001 \003(\0132(.google.protobuf.SourceCo"
|
||||
"deInfo.Location\032\206\001\n\010Location\022\020\n\004path\030\001 \003"
|
||||
"(\005B\002\020\001\022\020\n\004span\030\002 \003(\005B\002\020\001\022\030\n\020leading_comm"
|
||||
"ents\030\003 \001(\t\022\031\n\021trailing_comments\030\004 \001(\t\022!\n"
|
||||
"\031leading_detached_comments\030\006 \003(\t\"\234\002\n\021Gen"
|
||||
"eratedCodeInfo\022A\n\nannotation\030\001 \003(\0132-.goo"
|
||||
"gle.protobuf.GeneratedCodeInfo.Annotatio"
|
||||
"n\032\303\001\n\nAnnotation\022\020\n\004path\030\001 \003(\005B\002\020\001\022\023\n\013so"
|
||||
"urce_file\030\002 \001(\t\022\r\n\005begin\030\003 \001(\005\022\013\n\003end\030\004 "
|
||||
"\001(\005\022H\n\010semantic\030\005 \001(\01626.google.protobuf."
|
||||
"GeneratedCodeInfo.Annotation.Semantic\"(\n"
|
||||
"\010Semantic\022\010\n\004NONE\020\000\022\007\n\003SET\020\001\022\t\n\005ALIAS\020\002*"
|
||||
"\247\002\n\007Edition\022\023\n\017EDITION_UNKNOWN\020\000\022\023\n\016EDIT"
|
||||
"ION_LEGACY\020\204\007\022\023\n\016EDITION_PROTO2\020\346\007\022\023\n\016ED"
|
||||
"ITION_PROTO3\020\347\007\022\021\n\014EDITION_2023\020\350\007\022\021\n\014ED"
|
||||
"ITION_2024\020\351\007\022\027\n\023EDITION_1_TEST_ONLY\020\001\022\027"
|
||||
"\n\023EDITION_2_TEST_ONLY\020\002\022\035\n\027EDITION_99997"
|
||||
"_TEST_ONLY\020\235\215\006\022\035\n\027EDITION_99998_TEST_ONL"
|
||||
"Y\020\236\215\006\022\035\n\027EDITION_99999_TEST_ONLY\020\237\215\006\022\023\n\013"
|
||||
"EDITION_MAX\020\377\377\377\377\007B~\n\023com.google.protobuf"
|
||||
"B\020DescriptorProtosH\001Z-google.golang.org/"
|
||||
"protobuf/types/descriptorpb\370\001\001\242\002\003GPB\252\002\032G"
|
||||
"oogle.Protobuf.Reflection"
|
||||
"ST_EFFORT\020\002*\006\010\350\007\020\213N*\006\010\213N\020\220N*\006\010\220N\020\221NJ\006\010\347\007"
|
||||
"\020\350\007\"\202\003\n\022FeatureSetDefaults\022N\n\010defaults\030\001"
|
||||
" \003(\0132<.google.protobuf.FeatureSetDefault"
|
||||
"s.FeatureSetEditionDefault\0221\n\017minimum_ed"
|
||||
"ition\030\004 \001(\0162\030.google.protobuf.Edition\0221\n"
|
||||
"\017maximum_edition\030\005 \001(\0162\030.google.protobuf"
|
||||
".Edition\032\265\001\n\030FeatureSetEditionDefault\022)\n"
|
||||
"\007edition\030\003 \001(\0162\030.google.protobuf.Edition"
|
||||
"\0229\n\024overridable_features\030\004 \001(\0132\033.google."
|
||||
"protobuf.FeatureSet\0223\n\016fixed_features\030\005 "
|
||||
"\001(\0132\033.google.protobuf.FeatureSet\"\325\001\n\016Sou"
|
||||
"rceCodeInfo\022:\n\010location\030\001 \003(\0132(.google.p"
|
||||
"rotobuf.SourceCodeInfo.Location\032\206\001\n\010Loca"
|
||||
"tion\022\020\n\004path\030\001 \003(\005B\002\020\001\022\020\n\004span\030\002 \003(\005B\002\020\001"
|
||||
"\022\030\n\020leading_comments\030\003 \001(\t\022\031\n\021trailing_c"
|
||||
"omments\030\004 \001(\t\022!\n\031leading_detached_commen"
|
||||
"ts\030\006 \003(\t\"\234\002\n\021GeneratedCodeInfo\022A\n\nannota"
|
||||
"tion\030\001 \003(\0132-.google.protobuf.GeneratedCo"
|
||||
"deInfo.Annotation\032\303\001\n\nAnnotation\022\020\n\004path"
|
||||
"\030\001 \003(\005B\002\020\001\022\023\n\013source_file\030\002 \001(\t\022\r\n\005begin"
|
||||
"\030\003 \001(\005\022\013\n\003end\030\004 \001(\005\022H\n\010semantic\030\005 \001(\01626."
|
||||
"google.protobuf.GeneratedCodeInfo.Annota"
|
||||
"tion.Semantic\"(\n\010Semantic\022\010\n\004NONE\020\000\022\007\n\003S"
|
||||
"ET\020\001\022\t\n\005ALIAS\020\002*\247\002\n\007Edition\022\023\n\017EDITION_U"
|
||||
"NKNOWN\020\000\022\023\n\016EDITION_LEGACY\020\204\007\022\023\n\016EDITION"
|
||||
"_PROTO2\020\346\007\022\023\n\016EDITION_PROTO3\020\347\007\022\021\n\014EDITI"
|
||||
"ON_2023\020\350\007\022\021\n\014EDITION_2024\020\351\007\022\027\n\023EDITION"
|
||||
"_1_TEST_ONLY\020\001\022\027\n\023EDITION_2_TEST_ONLY\020\002\022"
|
||||
"\035\n\027EDITION_99997_TEST_ONLY\020\235\215\006\022\035\n\027EDITIO"
|
||||
"N_99998_TEST_ONLY\020\236\215\006\022\035\n\027EDITION_99999_T"
|
||||
"EST_ONLY\020\237\215\006\022\023\n\013EDITION_MAX\020\377\377\377\377\007B~\n\023com"
|
||||
".google.protobufB\020DescriptorProtosH\001Z-go"
|
||||
"ogle.golang.org/protobuf/types/descripto"
|
||||
"rpb\370\001\001\242\002\003GPB\252\002\032Google.Protobuf.Reflectio"
|
||||
"n"
|
||||
};
|
||||
static ::absl::once_flag descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_once;
|
||||
PROTOBUF_CONSTINIT const ::_pbi::DescriptorTable descriptor_table_google_2fprotobuf_2fdescriptor_2eproto = {
|
||||
false,
|
||||
false,
|
||||
9985,
|
||||
9961,
|
||||
descriptor_table_protodef_google_2fprotobuf_2fdescriptor_2eproto,
|
||||
"google/protobuf/descriptor.proto",
|
||||
&descriptor_table_google_2fprotobuf_2fdescriptor_2eproto_once,
|
||||
|
|
|
@ -1066,11 +1066,24 @@ message FeatureSet {
|
|||
|
||||
reserved 999;
|
||||
|
||||
extensions 1000; // for Protobuf C++
|
||||
extensions 1001; // for Protobuf Java
|
||||
extensions 1002; // for Protobuf Go
|
||||
|
||||
extensions 9990; // for deprecated Java Proto1
|
||||
extensions 1000 to 9994 [
|
||||
declaration = {
|
||||
number: 1000,
|
||||
full_name: ".pb.cpp",
|
||||
type: ".pb.CppFeatures"
|
||||
},
|
||||
declaration = {
|
||||
number: 1001,
|
||||
full_name: ".pb.java",
|
||||
type: ".pb.JavaFeatures"
|
||||
},
|
||||
declaration = { number: 1002, full_name: ".pb.go", type: ".pb.GoFeatures" },
|
||||
declaration = {
|
||||
number: 9990,
|
||||
full_name: ".pb.proto1",
|
||||
type: ".pb.Proto1Features"
|
||||
}
|
||||
];
|
||||
|
||||
extensions 9995 to 9999; // For internal testing
|
||||
extensions 10000; // for https://github.com/bufbuild/protobuf-es
|
||||
|
|
|
@ -620,6 +620,7 @@ DynamicMessageFactory::~DynamicMessageFactory() {
|
|||
}
|
||||
|
||||
const Message* DynamicMessageFactory::GetPrototype(const Descriptor* type) {
|
||||
ABSL_CHECK(type != nullptr);
|
||||
absl::MutexLock lock(&prototypes_mutex_);
|
||||
return GetPrototypeNoLock(type);
|
||||
}
|
||||
|
|
|
@ -108,8 +108,8 @@ class PROTOBUF_EXPORT DynamicMessageFactory : public MessageFactory {
|
|||
// prototype, so these must be destroyed before the DynamicMessageFactory
|
||||
// is destroyed.
|
||||
//
|
||||
// The given descriptor must outlive the returned message, and hence must
|
||||
// outlive the DynamicMessageFactory.
|
||||
// The given descriptor must be non-null and outlive the returned message, and
|
||||
// hence must outlive the DynamicMessageFactory.
|
||||
//
|
||||
// The method is thread-safe.
|
||||
const Message* GetPrototype(const Descriptor* type) override;
|
||||
|
|
|
@ -314,6 +314,8 @@ inline void PrefetchToLocalCache(const void* ptr) {
|
|||
absl::PrefetchToLocalCache(ptr);
|
||||
}
|
||||
|
||||
constexpr bool IsOss() { return true; }
|
||||
|
||||
} // namespace internal
|
||||
} // namespace protobuf
|
||||
} // namespace google
|
||||
|
|
|
@ -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.
|
||||
|
@ -919,8 +879,6 @@ static_assert(PROTOBUF_ABSL_MIN(20230125, 3),
|
|||
#define PROTOBUF_DEBUG false
|
||||
#endif
|
||||
|
||||
#define PROTO2_IS_OSS true
|
||||
|
||||
#ifdef PROTOBUF_NO_THREADLOCAL
|
||||
#error PROTOBUF_NO_THREADLOCAL was previously defined
|
||||
#endif
|
||||
|
|
|
@ -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,14 +64,12 @@
|
|||
#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
|
||||
#undef PROTOBUF_PREFETCH_WITH_OFFSET
|
||||
#undef PROTOBUF_TC_PARAM_DECL
|
||||
#undef PROTOBUF_DEBUG
|
||||
#undef PROTO2_IS_OSS
|
||||
#undef PROTOBUF_NO_THREADLOCAL
|
||||
|
||||
#ifdef PROTOBUF_FUTURE_BREAKING_CHANGES
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue