Compare commits
20 Commits
14b6ba397c
...
2616826a6f
Author | SHA1 | Date |
---|---|---|
PascalSenn | 2616826a6f | |
Éamonn McManus | 510c1434ed | |
Protobuf Team Bot | dbc2baf5bd | |
Protobuf Team Bot | 13caa08692 | |
Protobuf Team Bot | 1b06cefe33 | |
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 | |
PascalSenn | 775647a7cf | |
Protobuf Team Bot | d8329b68e4 | |
Protobuf Team Bot | 6afb130dca | |
Eric Salo | d923896299 | |
Protobuf Team Bot | 4d3a98c27e | |
Eric Salo | 65821a67d6 | |
Éamonn McManus | 98d5bdd111 | |
PascalSenn | 4a90602b94 |
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -440,13 +440,11 @@ void TextFormatConformanceTestSuiteImpl<MessageType>::RunAllTests() {
|
|||
absl::StrCat("FloatFieldLargerThanUint64", name_suffix), REQUIRED,
|
||||
absl::StrCat("optional_float: 18446744073709551616", suffix));
|
||||
// https://protobuf.dev/reference/protobuf/textformat-spec/#literals says
|
||||
// "-0" is a valid float literal.
|
||||
// TODO: Figure out if this should count as not setting
|
||||
// presence or if -0 should be reflected back.
|
||||
// RunValidTextFormatTestWithExpected(
|
||||
// absl::StrCat("FloatFieldNegativeZero", name_suffix), REQUIRED,
|
||||
// absl::StrCat("optional_float: -0", suffix),
|
||||
// "" /* implicit presence, so zero means unset*/);
|
||||
// "-0" is a valid float literal. -0 should be considered not the same as 0
|
||||
// when considering implicit presence, and so should round trip.
|
||||
RunValidTextFormatTest(absl::StrCat("FloatFieldNegativeZero", name_suffix),
|
||||
REQUIRED,
|
||||
absl::StrCat("optional_float: -0", suffix));
|
||||
// https://protobuf.dev/reference/protobuf/textformat-spec/#literals says
|
||||
// ".123", "-.123", ".123e2" are a valid float literal.
|
||||
RunValidTextFormatTest(absl::StrCat("FloatFieldNoLeadingZero", name_suffix),
|
||||
|
@ -502,6 +500,19 @@ void TextFormatConformanceTestSuiteImpl<MessageType>::RunAllTests() {
|
|||
RunValidTextFormatTestWithExpected(
|
||||
"DoubleFieldOverflowInfinityHugeExponent", REQUIRED,
|
||||
"optional_double: 1e18446744073709551616", "optional_double: inf");
|
||||
RunValidTextFormatTestWithExpected(
|
||||
"DoubleFieldLargeNegativeExponentParsesAsZero", REQUIRED,
|
||||
"optional_double: 1e-18446744073709551616", "");
|
||||
RunValidTextFormatTestWithExpected(
|
||||
"NegDoubleFieldLargeNegativeExponentParsesAsNegZero", REQUIRED,
|
||||
"optional_double: -1e-18446744073709551616", "optional_double: -0");
|
||||
|
||||
RunValidTextFormatTestWithExpected(
|
||||
"FloatFieldLargeNegativeExponentParsesAsZero", REQUIRED,
|
||||
"optional_float: 1e-50", "");
|
||||
RunValidTextFormatTestWithExpected(
|
||||
"NegFloatFieldLargeNegativeExponentParsesAsNegZero", REQUIRED,
|
||||
"optional_float: -1e-50", "optional_float: -0");
|
||||
|
||||
// String literals x {Strings, Bytes}
|
||||
for (const auto& field_type : std::vector<std::string>{"String", "Bytes"}) {
|
||||
|
|
|
@ -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
|
|
@ -77,3 +77,23 @@ Required.Proto3.TextFormatInput.StringLiteralBasicEscapesBytes.ProtobufOutput
|
|||
Required.Proto3.TextFormatInput.StringLiteralBasicEscapesBytes.TextFormatOutput
|
||||
Required.Proto3.TextFormatInput.StringLiteralBasicEscapesString.ProtobufOutput
|
||||
Required.Proto3.TextFormatInput.StringLiteralBasicEscapesString.TextFormatOutput
|
||||
Required.Editions_Proto3.TextFormatInput.FloatFieldNegativeZero.ProtobufOutput
|
||||
Required.Editions_Proto3.TextFormatInput.FloatFieldNegativeZero.TextFormatOutput
|
||||
Required.Editions_Proto3.TextFormatInput.FloatFieldNegativeZero_F.ProtobufOutput
|
||||
Required.Editions_Proto3.TextFormatInput.FloatFieldNegativeZero_F.TextFormatOutput
|
||||
Required.Editions_Proto3.TextFormatInput.FloatFieldNegativeZero_f.ProtobufOutput
|
||||
Required.Editions_Proto3.TextFormatInput.FloatFieldNegativeZero_f.TextFormatOutput
|
||||
Required.Editions_Proto3.TextFormatInput.NegDoubleFieldLargeNegativeExponentParsesAsNegZero.ProtobufOutput
|
||||
Required.Editions_Proto3.TextFormatInput.NegDoubleFieldLargeNegativeExponentParsesAsNegZero.TextFormatOutput
|
||||
Required.Editions_Proto3.TextFormatInput.NegFloatFieldLargeNegativeExponentParsesAsNegZero.ProtobufOutput
|
||||
Required.Editions_Proto3.TextFormatInput.NegFloatFieldLargeNegativeExponentParsesAsNegZero.TextFormatOutput
|
||||
Required.Proto3.TextFormatInput.FloatFieldNegativeZero.ProtobufOutput
|
||||
Required.Proto3.TextFormatInput.FloatFieldNegativeZero.TextFormatOutput
|
||||
Required.Proto3.TextFormatInput.FloatFieldNegativeZero_F.ProtobufOutput
|
||||
Required.Proto3.TextFormatInput.FloatFieldNegativeZero_F.TextFormatOutput
|
||||
Required.Proto3.TextFormatInput.FloatFieldNegativeZero_f.ProtobufOutput
|
||||
Required.Proto3.TextFormatInput.FloatFieldNegativeZero_f.TextFormatOutput
|
||||
Required.Proto3.TextFormatInput.NegDoubleFieldLargeNegativeExponentParsesAsNegZero.ProtobufOutput
|
||||
Required.Proto3.TextFormatInput.NegDoubleFieldLargeNegativeExponentParsesAsNegZero.TextFormatOutput
|
||||
Required.Proto3.TextFormatInput.NegFloatFieldLargeNegativeExponentParsesAsNegZero.ProtobufOutput
|
||||
Required.Proto3.TextFormatInput.NegFloatFieldLargeNegativeExponentParsesAsNegZero.TextFormatOutput
|
||||
|
|
|
@ -28,6 +28,8 @@ Required.Editions_Proto3.TextFormatInput.FloatFieldWithVeryPreciseNumber_F.Proto
|
|||
Required.Editions_Proto3.TextFormatInput.FloatFieldWithVeryPreciseNumber_F.TextFormatOutput
|
||||
Required.Editions_Proto3.TextFormatInput.FloatFieldZero_F.ProtobufOutput
|
||||
Required.Editions_Proto3.TextFormatInput.FloatFieldZero_F.TextFormatOutput
|
||||
Required.Editions_Proto3.TextFormatInput.FloatFieldNegativeZero_F.ProtobufOutput
|
||||
Required.Editions_Proto3.TextFormatInput.FloatFieldNegativeZero_F.TextFormatOutput
|
||||
Required.Editions_Proto3.TextFormatInput.StringLiteralBasicEscapesBytes.ProtobufOutput
|
||||
Required.Editions_Proto3.TextFormatInput.StringLiteralBasicEscapesBytes.TextFormatOutput
|
||||
Required.Editions_Proto3.TextFormatInput.StringLiteralBasicEscapesString.ProtobufOutput
|
||||
|
@ -62,6 +64,8 @@ Required.Proto3.TextFormatInput.FloatFieldWithVeryPreciseNumber_F.ProtobufOutput
|
|||
Required.Proto3.TextFormatInput.FloatFieldWithVeryPreciseNumber_F.TextFormatOutput
|
||||
Required.Proto3.TextFormatInput.FloatFieldZero_F.ProtobufOutput
|
||||
Required.Proto3.TextFormatInput.FloatFieldZero_F.TextFormatOutput
|
||||
Required.Proto3.TextFormatInput.FloatFieldNegativeZero_F.ProtobufOutput
|
||||
Required.Proto3.TextFormatInput.FloatFieldNegativeZero_F.TextFormatOutput
|
||||
Required.Proto3.TextFormatInput.StringLiteralBasicEscapesBytes.ProtobufOutput
|
||||
Required.Proto3.TextFormatInput.StringLiteralBasicEscapesBytes.TextFormatOutput
|
||||
Required.Proto3.TextFormatInput.StringLiteralBasicEscapesString.ProtobufOutput
|
||||
|
|
|
@ -15,6 +15,8 @@ Required.Editions_Proto3.TextFormatInput.FloatFieldNegative_F.ProtobufOutput
|
|||
Required.Editions_Proto3.TextFormatInput.FloatFieldNegative_F.TextFormatOutput
|
||||
Required.Editions_Proto3.TextFormatInput.FloatFieldNegativeNoLeadingZero_F.ProtobufOutput
|
||||
Required.Editions_Proto3.TextFormatInput.FloatFieldNegativeNoLeadingZero_F.TextFormatOutput
|
||||
Required.Editions_Proto3.TextFormatInput.FloatFieldNegativeZero_F.ProtobufOutput
|
||||
Required.Editions_Proto3.TextFormatInput.FloatFieldNegativeZero_F.TextFormatOutput
|
||||
Required.Editions_Proto3.TextFormatInput.FloatFieldNoLeadingZero_F.ProtobufOutput
|
||||
Required.Editions_Proto3.TextFormatInput.FloatFieldNoLeadingZero_F.TextFormatOutput
|
||||
Required.Editions_Proto3.TextFormatInput.FloatFieldNoLeadingZeroWithExponent_F.ProtobufOutput
|
||||
|
@ -49,6 +51,8 @@ Required.Proto3.TextFormatInput.FloatFieldNegative_F.ProtobufOutput
|
|||
Required.Proto3.TextFormatInput.FloatFieldNegative_F.TextFormatOutput
|
||||
Required.Proto3.TextFormatInput.FloatFieldNegativeNoLeadingZero_F.ProtobufOutput
|
||||
Required.Proto3.TextFormatInput.FloatFieldNegativeNoLeadingZero_F.TextFormatOutput
|
||||
Required.Proto3.TextFormatInput.FloatFieldNegativeZero_F.ProtobufOutput
|
||||
Required.Proto3.TextFormatInput.FloatFieldNegativeZero_F.TextFormatOutput
|
||||
Required.Proto3.TextFormatInput.FloatFieldNoLeadingZero_F.ProtobufOutput
|
||||
Required.Proto3.TextFormatInput.FloatFieldNoLeadingZero_F.TextFormatOutput
|
||||
Required.Proto3.TextFormatInput.FloatFieldNoLeadingZeroWithExponent_F.ProtobufOutput
|
||||
|
|
|
@ -877,5 +877,26 @@ namespace Google.Protobuf.Collections
|
|||
Assert.AreEqual(0, list.Count);
|
||||
Assert.AreEqual(8, list.Capacity);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Span_Empty()
|
||||
{
|
||||
var list = new RepeatedField<int>();
|
||||
var span = list.Span;
|
||||
|
||||
Assert.AreEqual(0, span.Length);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Span_Access()
|
||||
{
|
||||
var list = new RepeatedField<int> { 1, 2, 3 };
|
||||
var span = list.Span;
|
||||
|
||||
Assert.AreEqual(3, span.Length);
|
||||
Assert.AreEqual(1, span[0]);
|
||||
Assert.AreEqual(2, span[1]);
|
||||
Assert.AreEqual(3, span[2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,6 +37,19 @@ namespace Google.Protobuf.Collections
|
|||
private T[] array = EmptyArray;
|
||||
private int count = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Provides read-only access to the data of this <see cref="RepeatedField{T}"/>.
|
||||
/// No data is copied so this is the most efficient way of accessing.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Modifying the contents of the <see cref="RepeatedField{T}"/> while using the returned
|
||||
/// <see cref="ReadOnlySpan{T}"/> can lead to undefined behavior.
|
||||
/// </remarks>
|
||||
public ReadOnlySpan<T> Span
|
||||
{
|
||||
get { return array.AsSpan(0, count); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a deep clone of this repeated field.
|
||||
/// </summary>
|
||||
|
@ -355,7 +368,7 @@ namespace Google.Protobuf.Collections
|
|||
if (index == -1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Array.Copy(array, index + 1, array, index, count - index - 1);
|
||||
count--;
|
||||
array[count] = default;
|
||||
|
@ -463,7 +476,7 @@ namespace Google.Protobuf.Collections
|
|||
/// <c>true</c> if the specified <see cref="System.Object" /> is equal to this instance; otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
public override bool Equals(object obj) => Equals(obj as RepeatedField<T>);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Returns an enumerator that iterates through a collection.
|
||||
/// </summary>
|
||||
|
@ -476,7 +489,7 @@ namespace Google.Protobuf.Collections
|
|||
/// Returns a hash code for this instance.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
|
||||
/// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
|
||||
/// </returns>
|
||||
public override int GetHashCode()
|
||||
{
|
||||
|
@ -645,7 +658,7 @@ namespace Google.Protobuf.Collections
|
|||
Remove(t);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
private sealed class RepeatedFieldDebugView
|
||||
{
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -7,11 +7,14 @@
|
|||
|
||||
#include "protos_generator/gen_messages.h"
|
||||
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "google/protobuf/descriptor.pb.h"
|
||||
#include "absl/strings/ascii.h"
|
||||
#include "absl/strings/str_cat.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "google/protobuf/descriptor.h"
|
||||
#include "protos_generator/gen_accessors.h"
|
||||
#include "protos_generator/gen_enums.h"
|
||||
|
@ -120,6 +123,55 @@ void WriteModelAccessDeclaration(const protobuf::Descriptor* descriptor,
|
|||
output("};\n");
|
||||
}
|
||||
|
||||
std::string UnderscoresToCamelCase(absl::string_view input,
|
||||
bool cap_next_letter) {
|
||||
std::string result;
|
||||
|
||||
for (size_t i = 0; i < input.size(); i++) {
|
||||
if (absl::ascii_islower(input[i])) {
|
||||
if (cap_next_letter) {
|
||||
result += absl::ascii_toupper(input[i]);
|
||||
} else {
|
||||
result += input[i];
|
||||
}
|
||||
cap_next_letter = false;
|
||||
} else if (absl::ascii_isupper(input[i])) {
|
||||
// Capital letters are left as-is.
|
||||
result += input[i];
|
||||
cap_next_letter = false;
|
||||
} else if (absl::ascii_isdigit(input[i])) {
|
||||
result += input[i];
|
||||
cap_next_letter = true;
|
||||
} else {
|
||||
cap_next_letter = true;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string FieldConstantName(const protobuf::FieldDescriptor* field) {
|
||||
std::string field_name = UnderscoresToCamelCase(field->name(), true);
|
||||
std::string result = absl::StrCat("k", field_name, "FieldNumber");
|
||||
|
||||
if (!field->is_extension() &&
|
||||
field->containing_type()->FindFieldByCamelcaseName(
|
||||
field->camelcase_name()) != field) {
|
||||
// This field's camelcase name is not unique, add field number to make it
|
||||
// unique.
|
||||
absl::StrAppend(&result, "_", field->number());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void WriteConstFieldNumbers(Output& output,
|
||||
const protobuf::Descriptor* descriptor) {
|
||||
for (auto field : FieldRange(descriptor)) {
|
||||
output("static constexpr ::uint32_t $0 = $1;\n", FieldConstantName(field),
|
||||
field->number());
|
||||
}
|
||||
output("\n\n");
|
||||
}
|
||||
|
||||
void WriteModelPublicDeclaration(
|
||||
const protobuf::Descriptor* descriptor,
|
||||
const std::vector<const protobuf::FieldDescriptor*>& file_exts,
|
||||
|
@ -178,6 +230,7 @@ void WriteModelPublicDeclaration(
|
|||
)cc",
|
||||
ClassName(descriptor));
|
||||
output("\n");
|
||||
WriteConstFieldNumbers(output, descriptor);
|
||||
output(
|
||||
R"cc(
|
||||
private:
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include <limits>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
|
@ -1134,6 +1135,11 @@ TEST(CppGeneratedCode, HasExtensionAndRegistry) {
|
|||
EXPECT_TRUE(::protos::HasExtension(&parsed_model, theme));
|
||||
}
|
||||
|
||||
TEST(CppGeneratedCode, FieldNumberConstants) {
|
||||
static_assert(TestModel::kChildMapFieldNumber == 225);
|
||||
EXPECT_EQ(225, TestModel::kChildMapFieldNumber);
|
||||
}
|
||||
|
||||
// TODO : Add BUILD rule to test failures below.
|
||||
#ifdef TEST_CLEAR_MESSAGE_FAILURE
|
||||
TEST(CppGeneratedCode, ClearConstMessageShouldFail) {
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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", "null", "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:
|
||||
|
|
|
@ -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$
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include "google/protobuf/io/zero_copy_stream_impl_lite.h"
|
||||
#include "google/protobuf/map_lite_test_util.h"
|
||||
#include "google/protobuf/map_lite_unittest.pb.h"
|
||||
#include "google/protobuf/message_lite.h"
|
||||
#include "google/protobuf/parse_context.h"
|
||||
#include "google/protobuf/test_util_lite.h"
|
||||
#include "google/protobuf/unittest_lite.pb.h"
|
||||
|
@ -1325,6 +1326,92 @@ TEST(LiteBasicTest, CodedInputStreamRollback) {
|
|||
}
|
||||
}
|
||||
|
||||
// Two arbitary types
|
||||
using CastType1 = protobuf_unittest::TestAllTypesLite;
|
||||
using CastType2 = protobuf_unittest::TestPackedTypesLite;
|
||||
|
||||
TEST(LiteTest, DynamicCastToGenerated) {
|
||||
CastType1 test_type_1;
|
||||
|
||||
MessageLite* test_type_1_pointer = &test_type_1;
|
||||
EXPECT_EQ(&test_type_1,
|
||||
DynamicCastToGenerated<CastType1>(test_type_1_pointer));
|
||||
EXPECT_EQ(nullptr, DynamicCastToGenerated<CastType2>(test_type_1_pointer));
|
||||
|
||||
const MessageLite* test_type_1_pointer_const = &test_type_1;
|
||||
EXPECT_EQ(&test_type_1,
|
||||
DynamicCastToGenerated<const CastType1>(test_type_1_pointer_const));
|
||||
EXPECT_EQ(nullptr,
|
||||
DynamicCastToGenerated<const CastType2>(test_type_1_pointer_const));
|
||||
|
||||
MessageLite* test_type_1_pointer_nullptr = nullptr;
|
||||
EXPECT_EQ(nullptr,
|
||||
DynamicCastToGenerated<CastType1>(test_type_1_pointer_nullptr));
|
||||
|
||||
MessageLite& test_type_1_pointer_ref = test_type_1;
|
||||
EXPECT_EQ(&test_type_1,
|
||||
&DynamicCastToGenerated<CastType1>(test_type_1_pointer_ref));
|
||||
|
||||
const MessageLite& test_type_1_pointer_const_ref = test_type_1;
|
||||
EXPECT_EQ(&test_type_1,
|
||||
&DynamicCastToGenerated<CastType1>(test_type_1_pointer_const_ref));
|
||||
}
|
||||
|
||||
#if GTEST_HAS_DEATH_TEST
|
||||
TEST(LiteTest, DynamicCastToGeneratedInvalidReferenceType) {
|
||||
CastType1 test_type_1;
|
||||
const MessageLite& test_type_1_pointer_const_ref = test_type_1;
|
||||
ASSERT_DEATH(DynamicCastToGenerated<CastType2>(test_type_1_pointer_const_ref),
|
||||
"Cannot downcast " + test_type_1.GetTypeName() + " to " +
|
||||
CastType2::default_instance().GetTypeName());
|
||||
}
|
||||
#endif // GTEST_HAS_DEATH_TEST
|
||||
|
||||
TEST(LiteTest, DownCastToGeneratedValidType) {
|
||||
CastType1 test_type_1;
|
||||
|
||||
MessageLite* test_type_1_pointer = &test_type_1;
|
||||
EXPECT_EQ(&test_type_1, DownCastToGenerated<CastType1>(test_type_1_pointer));
|
||||
|
||||
const MessageLite* test_type_1_pointer_const = &test_type_1;
|
||||
EXPECT_EQ(&test_type_1,
|
||||
DownCastToGenerated<const CastType1>(test_type_1_pointer_const));
|
||||
|
||||
MessageLite* test_type_1_pointer_nullptr = nullptr;
|
||||
EXPECT_EQ(nullptr,
|
||||
DownCastToGenerated<CastType1>(test_type_1_pointer_nullptr));
|
||||
|
||||
MessageLite& test_type_1_pointer_ref = test_type_1;
|
||||
EXPECT_EQ(&test_type_1,
|
||||
&DownCastToGenerated<CastType1>(test_type_1_pointer_ref));
|
||||
|
||||
const MessageLite& test_type_1_pointer_const_ref = test_type_1;
|
||||
EXPECT_EQ(&test_type_1,
|
||||
&DownCastToGenerated<CastType1>(test_type_1_pointer_const_ref));
|
||||
}
|
||||
|
||||
#if GTEST_HAS_DEATH_TEST
|
||||
TEST(LiteTest, DownCastToGeneratedInvalidPointerType) {
|
||||
CastType1 test_type_1;
|
||||
|
||||
MessageLite* test_type_1_pointer = &test_type_1;
|
||||
|
||||
ASSERT_DEBUG_DEATH(DownCastToGenerated<CastType2>(test_type_1_pointer),
|
||||
"Cannot downcast " + test_type_1.GetTypeName() + " to " +
|
||||
CastType2::default_instance().GetTypeName());
|
||||
}
|
||||
|
||||
TEST(LiteTest, DownCastToGeneratedInvalidReferenceType) {
|
||||
CastType1 test_type_1;
|
||||
|
||||
MessageLite& test_type_1_pointer = test_type_1;
|
||||
|
||||
ASSERT_DEBUG_DEATH(DownCastToGenerated<CastType2>(test_type_1_pointer),
|
||||
"Cannot downcast " + test_type_1.GetTypeName() + " to " +
|
||||
CastType2::default_instance().GetTypeName());
|
||||
}
|
||||
#endif // GTEST_HAS_DEATH_TEST
|
||||
|
||||
} // namespace
|
||||
} // namespace protobuf
|
||||
} // namespace google
|
||||
|
|
|
@ -1424,90 +1424,6 @@ DECLARE_GET_REPEATED_FIELD(bool)
|
|||
|
||||
#undef DECLARE_GET_REPEATED_FIELD
|
||||
|
||||
// Tries to downcast this message to a generated message type. Returns nullptr
|
||||
// if this class is not an instance of T. This works even if RTTI is disabled.
|
||||
//
|
||||
// This also has the effect of creating a strong reference to T that will
|
||||
// prevent the linker from stripping it out at link time. This can be important
|
||||
// if you are using a DynamicMessageFactory that delegates to the generated
|
||||
// factory.
|
||||
template <typename T>
|
||||
const T* DynamicCastToGenerated(const Message* from) {
|
||||
// Compile-time assert that T is a generated type that has a
|
||||
// default_instance() accessor, but avoid actually calling it.
|
||||
const T& (*get_default_instance)() = &T::default_instance;
|
||||
(void)get_default_instance;
|
||||
|
||||
// Compile-time assert that T is a subclass of google::protobuf::Message.
|
||||
const Message* unused = static_cast<T*>(nullptr);
|
||||
(void)unused;
|
||||
|
||||
#if PROTOBUF_RTTI
|
||||
internal::StrongReferenceToType<T>();
|
||||
return dynamic_cast<const T*>(from);
|
||||
#else
|
||||
bool ok = from != nullptr &&
|
||||
T::default_instance().GetReflection() == from->GetReflection();
|
||||
return ok ? internal::DownCast<const T*>(from) : nullptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T* DynamicCastToGenerated(Message* from) {
|
||||
const Message* message_const = from;
|
||||
return const_cast<T*>(DynamicCastToGenerated<T>(message_const));
|
||||
}
|
||||
|
||||
// An overloaded version of DynamicCastToGenerated for downcasting references to
|
||||
// base Message class. If the destination type T if the argument is not an
|
||||
// instance of T and dynamic_cast returns nullptr, it terminates with an error.
|
||||
template <typename T>
|
||||
const T& DynamicCastToGenerated(const Message& from) {
|
||||
const T* destination_message = DynamicCastToGenerated<T>(&from);
|
||||
ABSL_CHECK(destination_message != nullptr)
|
||||
<< "Cannot downcast " << from.GetTypeName() << " to "
|
||||
<< T::default_instance().GetTypeName();
|
||||
return *destination_message;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T& DynamicCastToGenerated(Message& from) {
|
||||
const Message& message_const = from;
|
||||
const T& destination_message = DynamicCastToGenerated<T>(message_const);
|
||||
return const_cast<T&>(destination_message);
|
||||
}
|
||||
|
||||
// A lightweight function for downcasting base Message pointer to derived type.
|
||||
// It should only be used when the caller is certain that the argument is of
|
||||
// instance T and T is a type derived from base Message class.
|
||||
template <typename T>
|
||||
const T* DownCastToGenerated(const Message* from) {
|
||||
internal::StrongReferenceToType<T>();
|
||||
ABSL_DCHECK(DynamicCastToGenerated<T>(from) == from)
|
||||
<< "Cannot downcast " << from->GetTypeName() << " to "
|
||||
<< T::default_instance().GetTypeName();
|
||||
|
||||
return static_cast<const T*>(from);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T* DownCastToGenerated(Message* from) {
|
||||
const Message* message_const = from;
|
||||
return const_cast<T*>(DownCastToGenerated<T>(message_const));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
const T& DownCastToGenerated(const Message& from) {
|
||||
return *DownCastToGenerated<T>(&from);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T& DownCastToGenerated(Message& from) {
|
||||
const Message& message_const = from;
|
||||
const T& destination_message = DownCastToGenerated<T>(message_const);
|
||||
return const_cast<T&>(destination_message);
|
||||
}
|
||||
|
||||
// Call this function to ensure that this message's reflection is linked into
|
||||
// the binary:
|
||||
//
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include <cstdint>
|
||||
#include <iosfwd>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
|
||||
#include "absl/base/attributes.h"
|
||||
#include "absl/log/absl_check.h"
|
||||
|
@ -53,6 +54,7 @@ class FastReflectionStringSetter;
|
|||
class Reflection;
|
||||
class Descriptor;
|
||||
class AssignDescriptorsHelper;
|
||||
class MessageLite;
|
||||
|
||||
namespace io {
|
||||
|
||||
|
@ -120,6 +122,9 @@ class PROTOBUF_EXPORT CachedSize {
|
|||
#endif
|
||||
};
|
||||
|
||||
// For MessageLite to friend.
|
||||
class TypeId;
|
||||
|
||||
class SwapFieldHelper;
|
||||
|
||||
// See parse_context.h for explanation
|
||||
|
@ -638,6 +643,15 @@ class PROTOBUF_EXPORT MessageLite {
|
|||
// return a default table instead of a unique one.
|
||||
virtual const ClassData* GetClassData() const = 0;
|
||||
|
||||
template <typename T>
|
||||
static auto GetClassDataGenerated() {
|
||||
// We could speed this up if needed by avoiding the function call.
|
||||
// In LTO this is likely inlined, so it might not matter.
|
||||
static_assert(
|
||||
std::is_same<const T&, decltype(T::default_instance())>::value, "");
|
||||
return T::default_instance().T::GetClassData();
|
||||
}
|
||||
|
||||
internal::InternalMetadata _internal_metadata_;
|
||||
|
||||
// Return the cached size object as described by
|
||||
|
@ -682,6 +696,7 @@ class PROTOBUF_EXPORT MessageLite {
|
|||
friend class internal::LazyField;
|
||||
friend class internal::SwapFieldHelper;
|
||||
friend class internal::TcParser;
|
||||
friend class internal::TypeId;
|
||||
friend class internal::WeakFieldMap;
|
||||
friend class internal::WireFormatLite;
|
||||
|
||||
|
@ -717,6 +732,32 @@ class PROTOBUF_EXPORT MessageLite {
|
|||
|
||||
namespace internal {
|
||||
|
||||
// A typeinfo equivalent for protobuf message types. Used for
|
||||
// DynamicCastToGenerated.
|
||||
// We might make this class public later on to have an alternative to
|
||||
// `std::type_info` that works when RTTI is disabled.
|
||||
class TypeId {
|
||||
public:
|
||||
constexpr explicit TypeId(const MessageLite::ClassData* data) : data_(data) {}
|
||||
|
||||
friend constexpr bool operator==(TypeId a, TypeId b) {
|
||||
return a.data_ == b.data_;
|
||||
}
|
||||
friend constexpr bool operator!=(TypeId a, TypeId b) { return !(a == b); }
|
||||
|
||||
static TypeId Get(const MessageLite& msg) {
|
||||
return TypeId(msg.GetClassData());
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static TypeId Get() {
|
||||
return TypeId(MessageLite::GetClassDataGenerated<T>());
|
||||
}
|
||||
|
||||
private:
|
||||
const MessageLite::ClassData* data_;
|
||||
};
|
||||
|
||||
template <bool alias>
|
||||
bool MergeFromImpl(absl::string_view input, MessageLite* msg,
|
||||
const internal::TcParseTableBase* tc_table,
|
||||
|
@ -820,6 +861,83 @@ T* OnShutdownDelete(T* p) {
|
|||
std::string ShortFormat(const MessageLite& message_lite);
|
||||
std::string Utf8Format(const MessageLite& message_lite);
|
||||
|
||||
// Tries to downcast this message to a generated message type. Returns nullptr
|
||||
// if this class is not an instance of T. This works even if RTTI is disabled.
|
||||
//
|
||||
// This also has the effect of creating a strong reference to T that will
|
||||
// prevent the linker from stripping it out at link time. This can be important
|
||||
// if you are using a DynamicMessageFactory that delegates to the generated
|
||||
// factory.
|
||||
template <typename T>
|
||||
const T* DynamicCastToGenerated(const MessageLite* from) {
|
||||
static_assert(std::is_base_of<MessageLite, T>::value, "");
|
||||
|
||||
internal::StrongReferenceToType<T>();
|
||||
// We might avoid the call to T::GetClassData() altogether if T were to
|
||||
// expose the class data pointer.
|
||||
if (from == nullptr ||
|
||||
internal::TypeId::Get<T>() != internal::TypeId::Get(*from)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return static_cast<const T*>(from);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
const T* DynamicCastToGenerated(const MessageLite* from);
|
||||
|
||||
template <typename T>
|
||||
T* DynamicCastToGenerated(MessageLite* from) {
|
||||
return const_cast<T*>(
|
||||
DynamicCastToGenerated<T>(static_cast<const MessageLite*>(from)));
|
||||
}
|
||||
|
||||
// An overloaded version of DynamicCastToGenerated for downcasting references to
|
||||
// base Message class. If the argument is not an instance of T, it terminates
|
||||
// with an error.
|
||||
template <typename T>
|
||||
const T& DynamicCastToGenerated(const MessageLite& from) {
|
||||
const T* destination_message = DynamicCastToGenerated<T>(&from);
|
||||
ABSL_CHECK(destination_message != nullptr)
|
||||
<< "Cannot downcast " << from.GetTypeName() << " to "
|
||||
<< T::default_instance().GetTypeName();
|
||||
return *destination_message;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T& DynamicCastToGenerated(MessageLite& from) {
|
||||
return const_cast<T&>(
|
||||
DynamicCastToGenerated<T>(static_cast<const MessageLite&>(from)));
|
||||
}
|
||||
|
||||
// A lightweight function for downcasting base MessageLite pointer to derived
|
||||
// type. It should only be used when the caller is certain that the argument is
|
||||
// of instance T and T is a generated message type.
|
||||
template <typename T>
|
||||
const T* DownCastToGenerated(const MessageLite* from) {
|
||||
internal::StrongReferenceToType<T>();
|
||||
ABSL_DCHECK(DynamicCastToGenerated<T>(from) == from)
|
||||
<< "Cannot downcast " << from->GetTypeName() << " to "
|
||||
<< T::default_instance().GetTypeName();
|
||||
return static_cast<const T*>(from);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T* DownCastToGenerated(MessageLite* from) {
|
||||
return const_cast<T*>(
|
||||
DownCastToGenerated<T>(static_cast<const MessageLite*>(from)));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
const T& DownCastToGenerated(const MessageLite& from) {
|
||||
return *DownCastToGenerated<T>(&from);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T& DownCastToGenerated(MessageLite& from) {
|
||||
return *DownCastToGenerated<T>(&from);
|
||||
}
|
||||
|
||||
} // namespace protobuf
|
||||
} // namespace google
|
||||
|
||||
|
|
|
@ -753,35 +753,35 @@ TEST(MESSAGE_TEST_NAME, InitializationErrorString) {
|
|||
TEST(MESSAGE_TEST_NAME, DynamicCastToGenerated) {
|
||||
UNITTEST::TestAllTypes test_all_types;
|
||||
|
||||
Message* test_all_types_pointer = &test_all_types;
|
||||
MessageLite* test_all_types_pointer = &test_all_types;
|
||||
EXPECT_EQ(&test_all_types, DynamicCastToGenerated<UNITTEST::TestAllTypes>(
|
||||
test_all_types_pointer));
|
||||
EXPECT_EQ(nullptr, DynamicCastToGenerated<UNITTEST::TestRequired>(
|
||||
test_all_types_pointer));
|
||||
|
||||
const Message* test_all_types_pointer_const = &test_all_types;
|
||||
const MessageLite* test_all_types_pointer_const = &test_all_types;
|
||||
EXPECT_EQ(&test_all_types,
|
||||
DynamicCastToGenerated<const UNITTEST::TestAllTypes>(
|
||||
test_all_types_pointer_const));
|
||||
EXPECT_EQ(nullptr, DynamicCastToGenerated<const UNITTEST::TestRequired>(
|
||||
test_all_types_pointer_const));
|
||||
|
||||
Message* test_all_types_pointer_nullptr = nullptr;
|
||||
MessageLite* test_all_types_pointer_nullptr = nullptr;
|
||||
EXPECT_EQ(nullptr, DynamicCastToGenerated<UNITTEST::TestAllTypes>(
|
||||
test_all_types_pointer_nullptr));
|
||||
|
||||
Message& test_all_types_pointer_ref = test_all_types;
|
||||
MessageLite& test_all_types_pointer_ref = test_all_types;
|
||||
EXPECT_EQ(&test_all_types, &DynamicCastToGenerated<UNITTEST::TestAllTypes>(
|
||||
test_all_types_pointer_ref));
|
||||
|
||||
const Message& test_all_types_pointer_const_ref = test_all_types;
|
||||
const MessageLite& test_all_types_pointer_const_ref = test_all_types;
|
||||
EXPECT_EQ(&test_all_types, &DynamicCastToGenerated<UNITTEST::TestAllTypes>(
|
||||
test_all_types_pointer_const_ref));
|
||||
}
|
||||
|
||||
TEST(MESSAGE_TEST_NAME, DynamicCastToGeneratedInvalidReferenceType) {
|
||||
UNITTEST::TestAllTypes test_all_types;
|
||||
const Message& test_all_types_pointer_const_ref = test_all_types;
|
||||
const MessageLite& test_all_types_pointer_const_ref = test_all_types;
|
||||
ASSERT_DEATH(DynamicCastToGenerated<UNITTEST::TestRequired>(
|
||||
test_all_types_pointer_const_ref),
|
||||
"Cannot downcast " + test_all_types.GetTypeName() + " to " +
|
||||
|
@ -791,23 +791,23 @@ TEST(MESSAGE_TEST_NAME, DynamicCastToGeneratedInvalidReferenceType) {
|
|||
TEST(MESSAGE_TEST_NAME, DownCastToGeneratedValidType) {
|
||||
UNITTEST::TestAllTypes test_all_types;
|
||||
|
||||
Message* test_all_types_pointer = &test_all_types;
|
||||
MessageLite* test_all_types_pointer = &test_all_types;
|
||||
EXPECT_EQ(&test_all_types, DownCastToGenerated<UNITTEST::TestAllTypes>(
|
||||
test_all_types_pointer));
|
||||
|
||||
const Message* test_all_types_pointer_const = &test_all_types;
|
||||
const MessageLite* test_all_types_pointer_const = &test_all_types;
|
||||
EXPECT_EQ(&test_all_types, DownCastToGenerated<const UNITTEST::TestAllTypes>(
|
||||
test_all_types_pointer_const));
|
||||
|
||||
Message* test_all_types_pointer_nullptr = nullptr;
|
||||
MessageLite* test_all_types_pointer_nullptr = nullptr;
|
||||
EXPECT_EQ(nullptr, DownCastToGenerated<UNITTEST::TestAllTypes>(
|
||||
test_all_types_pointer_nullptr));
|
||||
|
||||
Message& test_all_types_pointer_ref = test_all_types;
|
||||
MessageLite& test_all_types_pointer_ref = test_all_types;
|
||||
EXPECT_EQ(&test_all_types, &DownCastToGenerated<UNITTEST::TestAllTypes>(
|
||||
test_all_types_pointer_ref));
|
||||
|
||||
const Message& test_all_types_pointer_const_ref = test_all_types;
|
||||
const MessageLite& test_all_types_pointer_const_ref = test_all_types;
|
||||
EXPECT_EQ(&test_all_types, &DownCastToGenerated<UNITTEST::TestAllTypes>(
|
||||
test_all_types_pointer_const_ref));
|
||||
}
|
||||
|
@ -815,7 +815,7 @@ TEST(MESSAGE_TEST_NAME, DownCastToGeneratedValidType) {
|
|||
TEST(MESSAGE_TEST_NAME, DownCastToGeneratedInvalidPointerType) {
|
||||
UNITTEST::TestAllTypes test_all_types;
|
||||
|
||||
Message* test_all_types_pointer = &test_all_types;
|
||||
MessageLite* test_all_types_pointer = &test_all_types;
|
||||
|
||||
ASSERT_DEBUG_DEATH(
|
||||
DownCastToGenerated<UNITTEST::TestRequired>(test_all_types_pointer),
|
||||
|
@ -826,7 +826,7 @@ TEST(MESSAGE_TEST_NAME, DownCastToGeneratedInvalidPointerType) {
|
|||
TEST(MESSAGE_TEST_NAME, DownCastToGeneratedInvalidReferenceType) {
|
||||
UNITTEST::TestAllTypes test_all_types;
|
||||
|
||||
Message& test_all_types_pointer = test_all_types;
|
||||
MessageLite& test_all_types_pointer = test_all_types;
|
||||
|
||||
ASSERT_DEBUG_DEATH(
|
||||
DownCastToGenerated<UNITTEST::TestRequired>(test_all_types_pointer),
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -50,7 +50,6 @@
|
|||
#undef PROTOBUF_ASSUME
|
||||
#undef PROTOBUF_EXPORT_TEMPLATE_DECLARE
|
||||
#undef PROTOBUF_EXPORT_TEMPLATE_DEFINE
|
||||
#undef PROTOBUF_ALIGNAS
|
||||
#undef PROTOBUF_THREAD_LOCAL
|
||||
#undef PROTOBUF_CONSTINIT
|
||||
#undef PROTOBUF_CONSTEXPR
|
||||
|
@ -65,7 +64,6 @@
|
|||
#undef PROTOBUF_MSAN
|
||||
#undef PROTOBUF_TSAN
|
||||
#undef PROTOBUF_TSAN_DECLARE_MEMBER
|
||||
#undef PROTOBUF_USE_TABLE_PARSER_ON_REFLECTION
|
||||
#undef PROTOBUF_BUILTIN_CONSTANT_P
|
||||
#undef PROTOBUF_DESCRIPTOR_WEAK_MESSAGES_ALLOWED
|
||||
#undef PROTOBUF_PREFETCH_PARSE_TABLE
|
||||
|
|
|
@ -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