Sync from Piper @306496510
PROTOBUF_SYNC_PIPER
diff --git a/csharp/src/Google.Protobuf.Benchmarks/SerializationConfig.cs b/csharp/src/Google.Protobuf.Benchmarks/BenchmarkDatasetConfig.cs
similarity index 88%
rename from csharp/src/Google.Protobuf.Benchmarks/SerializationConfig.cs
rename to csharp/src/Google.Protobuf.Benchmarks/BenchmarkDatasetConfig.cs
index 679f16c..c075419 100644
--- a/csharp/src/Google.Protobuf.Benchmarks/SerializationConfig.cs
+++ b/csharp/src/Google.Protobuf.Benchmarks/BenchmarkDatasetConfig.cs
@@ -43,20 +43,20 @@
/// <summary>
/// The configuration for a single serialization test, loaded from a dataset.
/// </summary>
- public class SerializationConfig
+ public class BenchmarkDatasetConfig
{
private static readonly Dictionary<string, MessageParser> parsersByMessageName =
- typeof(SerializationBenchmark).Assembly.GetTypes()
+ typeof(GoogleMessageBenchmark).Assembly.GetTypes()
.Where(t => typeof(IMessage).IsAssignableFrom(t))
.ToDictionary(
t => ((MessageDescriptor) t.GetProperty("Descriptor", BindingFlags.Static | BindingFlags.Public).GetValue(null)).FullName,
t => ((MessageParser) t.GetProperty("Parser", BindingFlags.Static | BindingFlags.Public).GetValue(null)));
public MessageParser Parser { get; }
- public IEnumerable<ByteString> Payloads { get; }
+ public List<byte[]> Payloads { get; }
public string Name { get; }
- public SerializationConfig(string resource)
+ public BenchmarkDatasetConfig(string resource, string shortName = null)
{
var data = LoadData(resource);
var dataset = BenchmarkDataset.Parser.ParseFrom(data);
@@ -66,13 +66,13 @@
throw new ArgumentException($"No parser for message {dataset.MessageName} in this assembly");
}
Parser = parser;
- Payloads = dataset.Payload;
- Name = dataset.Name;
+ Payloads = new List<byte[]>(dataset.Payload.Select(p => p.ToByteArray()));
+ Name = shortName ?? dataset.Name;
}
private static byte[] LoadData(string resource)
{
- using (var stream = typeof(SerializationBenchmark).Assembly.GetManifestResourceStream($"Google.Protobuf.Benchmarks.{resource}"))
+ using (var stream = typeof(GoogleMessageBenchmark).Assembly.GetManifestResourceStream($"Google.Protobuf.Benchmarks.{resource}"))
{
if (stream == null)
{
diff --git a/csharp/src/Google.Protobuf.Benchmarks/SerializationBenchmark.cs b/csharp/src/Google.Protobuf.Benchmarks/GoogleMessageBenchmark.cs
similarity index 74%
rename from csharp/src/Google.Protobuf.Benchmarks/SerializationBenchmark.cs
rename to csharp/src/Google.Protobuf.Benchmarks/GoogleMessageBenchmark.cs
index d8c2ec1..132967e 100644
--- a/csharp/src/Google.Protobuf.Benchmarks/SerializationBenchmark.cs
+++ b/csharp/src/Google.Protobuf.Benchmarks/GoogleMessageBenchmark.cs
@@ -38,23 +38,27 @@
namespace Google.Protobuf.Benchmarks
{
/// <summary>
- /// Benchmark for serializing (to a MemoryStream) and deserializing (from a ByteString).
+ /// Benchmark for serializing and deserializing of standard datasets that are also
+ /// measured by benchmarks in other languages.
/// Over time we may wish to test the various different approaches to serialization and deserialization separately.
+ /// See https://github.com/protocolbuffers/protobuf/blob/master/benchmarks/README.md
+ /// See https://github.com/protocolbuffers/protobuf/blob/master/docs/performance.md
/// </summary>
[MemoryDiagnoser]
- public class SerializationBenchmark
+ public class GoogleMessageBenchmark
{
/// <summary>
- /// All the configurations to be tested. Add more datasets to the array as they're available.
+ /// All the datasets to be tested. Add more datasets to the array as they're available.
/// (When C# supports proto2, this will increase significantly.)
/// </summary>
- public static SerializationConfig[] Configurations => new[]
+ public static BenchmarkDatasetConfig[] DatasetConfigurations => new[]
{
- new SerializationConfig("dataset.google_message1_proto3.pb")
+ // short name is specified to make results table more readable
+ new BenchmarkDatasetConfig("dataset.google_message1_proto3.pb", "goog_msg1_proto3")
};
- [ParamsSource(nameof(Configurations))]
- public SerializationConfig Configuration { get; set; }
+ [ParamsSource(nameof(DatasetConfigurations))]
+ public BenchmarkDatasetConfig Dataset { get; set; }
private MessageParser parser;
/// <summary>
@@ -67,8 +71,8 @@
[GlobalSetup]
public void GlobalSetup()
{
- parser = Configuration.Parser;
- subTests = Configuration.Payloads.Select(p => new SubTest(p, parser.ParseFrom(p))).ToList();
+ parser = Dataset.Parser;
+ subTests = Dataset.Payloads.Select(p => new SubTest(p, parser.ParseFrom(p))).ToList();
}
[Benchmark]
@@ -78,7 +82,7 @@
public void ToByteArray() => subTests.ForEach(item => item.ToByteArray());
[Benchmark]
- public void ParseFromByteString() => subTests.ForEach(item => item.ParseFromByteString(parser));
+ public void ParseFromByteArray() => subTests.ForEach(item => item.ParseFromByteArray(parser));
[Benchmark]
public void ParseFromStream() => subTests.ForEach(item => item.ParseFromStream(parser));
@@ -87,13 +91,13 @@
{
private readonly Stream destinationStream;
private readonly Stream sourceStream;
- private readonly ByteString data;
+ private readonly byte[] data;
private readonly IMessage message;
- public SubTest(ByteString data, IMessage message)
+ public SubTest(byte[] data, IMessage message)
{
destinationStream = new MemoryStream(data.Length);
- sourceStream = new MemoryStream(data.ToByteArray());
+ sourceStream = new MemoryStream(data);
this.data = data;
this.message = message;
}
@@ -108,7 +112,7 @@
public void ToByteArray() => message.ToByteArray();
- public void ParseFromByteString(MessageParser parser) => parser.ParseFrom(data);
+ public void ParseFromByteArray(MessageParser parser) => parser.ParseFrom(data);
public void ParseFromStream(MessageParser parser)
{
diff --git a/csharp/src/Google.Protobuf.Benchmarks/ParseMessagesBenchmark.cs b/csharp/src/Google.Protobuf.Benchmarks/ParseMessagesBenchmark.cs
new file mode 100644
index 0000000..cbc4732
--- /dev/null
+++ b/csharp/src/Google.Protobuf.Benchmarks/ParseMessagesBenchmark.cs
@@ -0,0 +1,170 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2019 Google Inc. All rights reserved.
+// https://github.com/protocolbuffers/protobuf
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#endregion
+
+using BenchmarkDotNet.Attributes;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Buffers;
+using Google.Protobuf.WellKnownTypes;
+
+namespace Google.Protobuf.Benchmarks
+{
+ /// <summary>
+ /// Benchmark that tests parsing performance for various messages.
+ /// </summary>
+ [MemoryDiagnoser]
+ public class ParseMessagesBenchmark
+ {
+ const int MaxMessages = 100;
+
+ SubTest manyWrapperFieldsTest = new SubTest(CreateManyWrapperFieldsMessage(), ManyWrapperFieldsMessage.Parser, () => new ManyWrapperFieldsMessage(), MaxMessages);
+ SubTest manyPrimitiveFieldsTest = new SubTest(CreateManyPrimitiveFieldsMessage(), ManyPrimitiveFieldsMessage.Parser, () => new ManyPrimitiveFieldsMessage(), MaxMessages);
+ SubTest emptyMessageTest = new SubTest(new Empty(), Empty.Parser, () => new Empty(), MaxMessages);
+
+ public IEnumerable<int> MessageCountValues => new[] { 10, 100 };
+
+ [GlobalSetup]
+ public void GlobalSetup()
+ {
+ }
+
+ [Benchmark]
+ public IMessage ManyWrapperFieldsMessage_ParseFromByteArray()
+ {
+ return manyWrapperFieldsTest.ParseFromByteArray();
+ }
+
+ [Benchmark]
+ public IMessage ManyPrimitiveFieldsMessage_ParseFromByteArray()
+ {
+ return manyPrimitiveFieldsTest.ParseFromByteArray();
+ }
+
+ [Benchmark]
+ public IMessage EmptyMessage_ParseFromByteArray()
+ {
+ return emptyMessageTest.ParseFromByteArray();
+ }
+
+ [Benchmark]
+ [ArgumentsSource(nameof(MessageCountValues))]
+ public void ManyWrapperFieldsMessage_ParseDelimitedMessagesFromByteArray(int messageCount)
+ {
+ manyWrapperFieldsTest.ParseDelimitedMessagesFromByteArray(messageCount);
+ }
+
+ [Benchmark]
+ [ArgumentsSource(nameof(MessageCountValues))]
+ public void ManyPrimitiveFieldsMessage_ParseDelimitedMessagesFromByteArray(int messageCount)
+ {
+ manyPrimitiveFieldsTest.ParseDelimitedMessagesFromByteArray(messageCount);
+ }
+
+ private static ManyWrapperFieldsMessage CreateManyWrapperFieldsMessage()
+ {
+ // Example data match data of an internal benchmarks
+ return new ManyWrapperFieldsMessage()
+ {
+ Int64Field19 = 123,
+ Int64Field37 = 1000032,
+ Int64Field26 = 3453524500,
+ DoubleField79 = 1.2,
+ DoubleField25 = 234,
+ DoubleField9 = 123.3,
+ DoubleField28 = 23,
+ DoubleField7 = 234,
+ DoubleField50 = 2.45
+ };
+ }
+
+ private static ManyPrimitiveFieldsMessage CreateManyPrimitiveFieldsMessage()
+ {
+ // Example data match data of an internal benchmarks
+ return new ManyPrimitiveFieldsMessage()
+ {
+ Int64Field19 = 123,
+ Int64Field37 = 1000032,
+ Int64Field26 = 3453524500,
+ DoubleField79 = 1.2,
+ DoubleField25 = 234,
+ DoubleField9 = 123.3,
+ DoubleField28 = 23,
+ DoubleField7 = 234,
+ DoubleField50 = 2.45
+ };
+ }
+
+ private class SubTest
+ {
+ private readonly IMessage message;
+ private readonly MessageParser parser;
+ private readonly Func<IMessage> factory;
+ private readonly byte[] data;
+ private readonly byte[] multipleMessagesData;
+
+ public SubTest(IMessage message, MessageParser parser, Func<IMessage> factory, int maxMessageCount)
+ {
+ this.message = message;
+ this.parser = parser;
+ this.factory = factory;
+ this.data = message.ToByteArray();
+ this.multipleMessagesData = CreateBufferWithMultipleMessages(message, maxMessageCount);
+ }
+
+ public IMessage ParseFromByteArray() => parser.ParseFrom(data);
+
+ public void ParseDelimitedMessagesFromByteArray(int messageCount)
+ {
+ var input = new CodedInputStream(multipleMessagesData);
+ for (int i = 0; i < messageCount; i++)
+ {
+ var msg = factory();
+ input.ReadMessage(msg);
+ }
+ }
+
+ private static byte[] CreateBufferWithMultipleMessages(IMessage msg, int msgCount)
+ {
+ var ms = new MemoryStream();
+ var cos = new CodedOutputStream(ms);
+ for (int i = 0; i < msgCount; i++)
+ {
+ cos.WriteMessage(msg);
+ }
+ cos.Flush();
+ return ms.ToArray();
+ }
+ }
+ }
+}
diff --git a/csharp/src/Google.Protobuf.Benchmarks/WrapperBenchmark.cs b/csharp/src/Google.Protobuf.Benchmarks/WrapperBenchmark.cs
deleted file mode 100644
index ae17c18..0000000
--- a/csharp/src/Google.Protobuf.Benchmarks/WrapperBenchmark.cs
+++ /dev/null
@@ -1,102 +0,0 @@
-#region Copyright notice and license
-// Protocol Buffers - Google's data interchange format
-// Copyright 2019 Google Inc. All rights reserved.
-// https://github.com/protocolbuffers/protobuf
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#endregion
-
-using BenchmarkDotNet.Attributes;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-
-namespace Google.Protobuf.Benchmarks
-{
- /// <summary>
- /// Benchmark that tests serialization/deserialization of wrapper fields.
- /// </summary>
- [MemoryDiagnoser]
- public class WrapperBenchmark
- {
- byte[] manyWrapperFieldsData;
- byte[] manyPrimitiveFieldsData;
-
- [GlobalSetup]
- public void GlobalSetup()
- {
- manyWrapperFieldsData = CreateManyWrapperFieldsMessage().ToByteArray();
- manyPrimitiveFieldsData = CreateManyPrimitiveFieldsMessage().ToByteArray();
- }
-
- [Benchmark]
- public ManyWrapperFieldsMessage ParseWrapperFields()
- {
- return ManyWrapperFieldsMessage.Parser.ParseFrom(manyWrapperFieldsData);
- }
-
- [Benchmark]
- public ManyPrimitiveFieldsMessage ParsePrimitiveFields()
- {
- return ManyPrimitiveFieldsMessage.Parser.ParseFrom(manyPrimitiveFieldsData);
- }
-
- private static ManyWrapperFieldsMessage CreateManyWrapperFieldsMessage()
- {
- // Example data match data of an internal benchmarks
- return new ManyWrapperFieldsMessage()
- {
- Int64Field19 = 123,
- Int64Field37 = 1000032,
- Int64Field26 = 3453524500,
- DoubleField79 = 1.2,
- DoubleField25 = 234,
- DoubleField9 = 123.3,
- DoubleField28 = 23,
- DoubleField7 = 234,
- DoubleField50 = 2.45
- };
- }
-
- private static ManyPrimitiveFieldsMessage CreateManyPrimitiveFieldsMessage()
- {
- // Example data match data of an internal benchmarks
- return new ManyPrimitiveFieldsMessage()
- {
- Int64Field19 = 123,
- Int64Field37 = 1000032,
- Int64Field26 = 3453524500,
- DoubleField79 = 1.2,
- DoubleField25 = 234,
- DoubleField9 = 123.3,
- DoubleField28 = 23,
- DoubleField7 = 234,
- DoubleField50 = 2.45
- };
- }
- }
-}
diff --git a/csharp/src/Google.Protobuf.Test/testprotos.pb b/csharp/src/Google.Protobuf.Test/testprotos.pb
index f5e1bef..424d969 100644
--- a/csharp/src/Google.Protobuf.Test/testprotos.pb
+++ b/csharp/src/Google.Protobuf.Test/testprotos.pb
Binary files differ
diff --git a/csharp/src/Google.Protobuf/Reflection/Descriptor.cs b/csharp/src/Google.Protobuf/Reflection/Descriptor.cs
index 8b39573..c9ba632 100644
--- a/csharp/src/Google.Protobuf/Reflection/Descriptor.cs
+++ b/csharp/src/Google.Protobuf/Reflection/Descriptor.cs
@@ -2074,10 +2074,21 @@
/// If true, this is a proto3 "optional". When a proto3 field is optional, it
/// tracks presence regardless of field type.
///
- /// For message fields this doesn't create any semantic change, since
- /// non-repeated message fields always track presence. However it still
+ /// When proto3_optional is true, this field must be belong to a oneof to
+ /// signal to old proto3 clients that presence is tracked for this field. This
+ /// oneof is known as a "synthetic" oneof, and this field must be its sole
+ /// member (each proto3 optional field gets its own synthetic oneof). Synthetic
+ /// oneofs exist in the descriptor only, and do not generate any API. Synthetic
+ /// oneofs must be ordered after all "real" oneofs.
+ ///
+ /// For message fields, proto3_optional doesn't create any semantic change,
+ /// since non-repeated message fields always track presence. However it still
/// indicates the semantic detail of whether the user wrote "optional" or not.
- /// This can be useful for round-tripping the .proto file.
+ /// This can be useful for round-tripping the .proto file. For consistency we
+ /// give message fields a synthetic oneof also, even though it is not required
+ /// to track presence. This is especially important because the parser can't
+ /// tell if a field is a message or an enum, so it must always create a
+ /// synthetic oneof.
///
/// Proto2 optional fields do not set this flag, because they already indicate
/// optional with `LABEL_OPTIONAL`.
diff --git a/objectivec/DevTools/full_mac_build.sh b/objectivec/DevTools/full_mac_build.sh
index 5584b0a..84ed8e9 100755
--- a/objectivec/DevTools/full_mac_build.sh
+++ b/objectivec/DevTools/full_mac_build.sh
@@ -290,12 +290,9 @@
)
;;
11.*)
+ # Dropped 32bit as Apple doesn't seem support the simulators either.
XCODEBUILD_TEST_BASE_IOS+=(
- -destination "platform=iOS Simulator,name=iPhone 4s,OS=8.1" # 32bit
-destination "platform=iOS Simulator,name=iPhone 8,OS=latest" # 64bit
- # 10.x also seems to often fail running destinations in parallel (with
- # 32bit one include atleast)
- -disable-concurrent-destination-testing
)
;;
* )
diff --git a/objectivec/Tests/GPBMessageTests+Runtime.m b/objectivec/Tests/GPBMessageTests+Runtime.m
index 190ff51..aa5b0db 100644
--- a/objectivec/Tests/GPBMessageTests+Runtime.m
+++ b/objectivec/Tests/GPBMessageTests+Runtime.m
@@ -252,7 +252,7 @@
// build the selector, i.e. - repeatedInt32Array_Count
SEL countSel = NSSelectorFromString(
[NSString stringWithFormat:@"repeated%@Array_Count", name]);
- XCTAssertTrue([Message2 instancesRespondToSelector:countSel], @"field: %@",
+ XCTAssertTrue([Message3 instancesRespondToSelector:countSel], @"field: %@",
name);
}
@@ -264,9 +264,9 @@
NSSelectorFromString([NSString stringWithFormat:@"hasOneof%@", name]);
SEL setHasSel = NSSelectorFromString(
[NSString stringWithFormat:@"setHasOneof%@:", name]);
- XCTAssertFalse([Message2 instancesRespondToSelector:hasSel], @"field: %@",
+ XCTAssertFalse([Message3 instancesRespondToSelector:hasSel], @"field: %@",
name);
- XCTAssertFalse([Message2 instancesRespondToSelector:setHasSel],
+ XCTAssertFalse([Message3 instancesRespondToSelector:setHasSel],
@"field: %@", name);
}
@@ -302,14 +302,14 @@
[NSString stringWithFormat:@"hasMap%@", name]);
SEL setHasSel = NSSelectorFromString(
[NSString stringWithFormat:@"setHasMap%@:", name]);
- XCTAssertFalse([Message2 instancesRespondToSelector:hasSel], @"field: %@",
+ XCTAssertFalse([Message3 instancesRespondToSelector:hasSel], @"field: %@",
name);
- XCTAssertFalse([Message2 instancesRespondToSelector:setHasSel],
+ XCTAssertFalse([Message3 instancesRespondToSelector:setHasSel],
@"field: %@", name);
// build the selector, i.e. - mapInt32Int32Count
SEL countSel = NSSelectorFromString(
[NSString stringWithFormat:@"map%@_Count", name]);
- XCTAssertTrue([Message2 instancesRespondToSelector:countSel], @"field: %@",
+ XCTAssertTrue([Message3 instancesRespondToSelector:countSel], @"field: %@",
name);
}
}
diff --git a/objectivec/Tests/GPBSwiftTests.swift b/objectivec/Tests/GPBSwiftTests.swift
index cedf0e4..03d7510 100644
--- a/objectivec/Tests/GPBSwiftTests.swift
+++ b/objectivec/Tests/GPBSwiftTests.swift
@@ -355,7 +355,7 @@
msg.oneof = nil
XCTAssertEqual(msg.oneof.optionalInt32, Int32(0)) // Default
XCTAssertEqual(msg.oOneOfCase, Message2_O_OneOfCase.gpbUnsetOneOfCase)
-}
+ }
func testProto3OneOfSupport() {
let msg = Message3()
diff --git a/php/src/Google/Protobuf/Internal/FieldDescriptorProto.php b/php/src/Google/Protobuf/Internal/FieldDescriptorProto.php
index e00488e..b43d988 100644
--- a/php/src/Google/Protobuf/Internal/FieldDescriptorProto.php
+++ b/php/src/Google/Protobuf/Internal/FieldDescriptorProto.php
@@ -96,10 +96,20 @@
/**
* If true, this is a proto3 "optional". When a proto3 field is optional, it
* tracks presence regardless of field type.
- * For message fields this doesn't create any semantic change, since
- * non-repeated message fields always track presence. However it still
+ * When proto3_optional is true, this field must be belong to a oneof to
+ * signal to old proto3 clients that presence is tracked for this field. This
+ * oneof is known as a "synthetic" oneof, and this field must be its sole
+ * member (each proto3 optional field gets its own synthetic oneof). Synthetic
+ * oneofs exist in the descriptor only, and do not generate any API. Synthetic
+ * oneofs must be ordered after all "real" oneofs.
+ * For message fields, proto3_optional doesn't create any semantic change,
+ * since non-repeated message fields always track presence. However it still
* indicates the semantic detail of whether the user wrote "optional" or not.
- * This can be useful for round-tripping the .proto file.
+ * This can be useful for round-tripping the .proto file. For consistency we
+ * give message fields a synthetic oneof also, even though it is not required
+ * to track presence. This is especially important because the parser can't
+ * tell if a field is a message or an enum, so it must always create a
+ * synthetic oneof.
* Proto2 optional fields do not set this flag, because they already indicate
* optional with `LABEL_OPTIONAL`.
*
@@ -147,10 +157,20 @@
* @type bool $proto3_optional
* If true, this is a proto3 "optional". When a proto3 field is optional, it
* tracks presence regardless of field type.
- * For message fields this doesn't create any semantic change, since
- * non-repeated message fields always track presence. However it still
+ * When proto3_optional is true, this field must be belong to a oneof to
+ * signal to old proto3 clients that presence is tracked for this field. This
+ * oneof is known as a "synthetic" oneof, and this field must be its sole
+ * member (each proto3 optional field gets its own synthetic oneof). Synthetic
+ * oneofs exist in the descriptor only, and do not generate any API. Synthetic
+ * oneofs must be ordered after all "real" oneofs.
+ * For message fields, proto3_optional doesn't create any semantic change,
+ * since non-repeated message fields always track presence. However it still
* indicates the semantic detail of whether the user wrote "optional" or not.
- * This can be useful for round-tripping the .proto file.
+ * This can be useful for round-tripping the .proto file. For consistency we
+ * give message fields a synthetic oneof also, even though it is not required
+ * to track presence. This is especially important because the parser can't
+ * tell if a field is a message or an enum, so it must always create a
+ * synthetic oneof.
* Proto2 optional fields do not set this flag, because they already indicate
* optional with `LABEL_OPTIONAL`.
* }
@@ -495,10 +515,20 @@
/**
* If true, this is a proto3 "optional". When a proto3 field is optional, it
* tracks presence regardless of field type.
- * For message fields this doesn't create any semantic change, since
- * non-repeated message fields always track presence. However it still
+ * When proto3_optional is true, this field must be belong to a oneof to
+ * signal to old proto3 clients that presence is tracked for this field. This
+ * oneof is known as a "synthetic" oneof, and this field must be its sole
+ * member (each proto3 optional field gets its own synthetic oneof). Synthetic
+ * oneofs exist in the descriptor only, and do not generate any API. Synthetic
+ * oneofs must be ordered after all "real" oneofs.
+ * For message fields, proto3_optional doesn't create any semantic change,
+ * since non-repeated message fields always track presence. However it still
* indicates the semantic detail of whether the user wrote "optional" or not.
- * This can be useful for round-tripping the .proto file.
+ * This can be useful for round-tripping the .proto file. For consistency we
+ * give message fields a synthetic oneof also, even though it is not required
+ * to track presence. This is especially important because the parser can't
+ * tell if a field is a message or an enum, so it must always create a
+ * synthetic oneof.
* Proto2 optional fields do not set this flag, because they already indicate
* optional with `LABEL_OPTIONAL`.
*
@@ -513,10 +543,20 @@
/**
* If true, this is a proto3 "optional". When a proto3 field is optional, it
* tracks presence regardless of field type.
- * For message fields this doesn't create any semantic change, since
- * non-repeated message fields always track presence. However it still
+ * When proto3_optional is true, this field must be belong to a oneof to
+ * signal to old proto3 clients that presence is tracked for this field. This
+ * oneof is known as a "synthetic" oneof, and this field must be its sole
+ * member (each proto3 optional field gets its own synthetic oneof). Synthetic
+ * oneofs exist in the descriptor only, and do not generate any API. Synthetic
+ * oneofs must be ordered after all "real" oneofs.
+ * For message fields, proto3_optional doesn't create any semantic change,
+ * since non-repeated message fields always track presence. However it still
* indicates the semantic detail of whether the user wrote "optional" or not.
- * This can be useful for round-tripping the .proto file.
+ * This can be useful for round-tripping the .proto file. For consistency we
+ * give message fields a synthetic oneof also, even though it is not required
+ * to track presence. This is especially important because the parser can't
+ * tell if a field is a message or an enum, so it must always create a
+ * synthetic oneof.
* Proto2 optional fields do not set this flag, because they already indicate
* optional with `LABEL_OPTIONAL`.
*
diff --git a/ruby/ext/google/protobuf_c/encode_decode.c b/ruby/ext/google/protobuf_c/encode_decode.c
index 8b0a22e..4a1d724 100644
--- a/ruby/ext/google/protobuf_c/encode_decode.c
+++ b/ruby/ext/google/protobuf_c/encode_decode.c
@@ -434,10 +434,8 @@
}
static bool endmap_handler(void *closure, const void *hd) {
- MessageHeader* msg = closure;
- const map_handlerdata_t* mapdata = hd;
- VALUE map_rb = DEREF(msg, mapdata->ofs, VALUE);
- Map_set_frame(map_rb, Qnil);
+ map_parse_frame_t* frame = closure;
+ Map_set_frame(frame->map, Qnil);
return true;
}
@@ -1200,7 +1198,7 @@
upb_sink_startsubmsg(sink, getsel(f, UPB_HANDLER_STARTSUBMSG), &subsink);
putmsg(submsg, subdesc, subsink, depth + 1, emit_defaults, is_json, true);
- upb_sink_endsubmsg(sink, getsel(f, UPB_HANDLER_ENDSUBMSG));
+ upb_sink_endsubmsg(sink, subsink, getsel(f, UPB_HANDLER_ENDSUBMSG));
}
static void putary(VALUE ary, const upb_fielddef* f, upb_sink sink, int depth,
@@ -1345,7 +1343,7 @@
entry_sink, emit_defaults, is_json);
upb_sink_endmsg(entry_sink, &status);
- upb_sink_endsubmsg(subsink, getsel(f, UPB_HANDLER_ENDSUBMSG));
+ upb_sink_endsubmsg(subsink, entry_sink, getsel(f, UPB_HANDLER_ENDSUBMSG));
}
upb_sink_endseq(sink, getsel(f, UPB_HANDLER_ENDSEQ));
diff --git a/ruby/ext/google/protobuf_c/map.c b/ruby/ext/google/protobuf_c/map.c
index 719706b..00d23a7 100644
--- a/ruby/ext/google/protobuf_c/map.c
+++ b/ruby/ext/google/protobuf_c/map.c
@@ -100,11 +100,11 @@
return key;
}
-static VALUE table_key_to_ruby(Map* self, const char* buf, size_t length) {
+static VALUE table_key_to_ruby(Map* self, upb_strview key) {
switch (self->key_type) {
case UPB_TYPE_BYTES:
case UPB_TYPE_STRING: {
- VALUE ret = rb_str_new(buf, length);
+ VALUE ret = rb_str_new(key.data, key.size);
rb_enc_associate(ret,
(self->key_type == UPB_TYPE_BYTES) ?
kRubyString8bitEncoding : kRubyStringUtf8Encoding);
@@ -116,7 +116,7 @@
case UPB_TYPE_INT64:
case UPB_TYPE_UINT32:
case UPB_TYPE_UINT64:
- return native_slot_get(self->key_type, Qnil, buf);
+ return native_slot_get(self->key_type, Qnil, key.data);
default:
assert(false);
@@ -289,9 +289,7 @@
for (upb_strtable_begin(&it, &self->table);
!upb_strtable_done(&it);
upb_strtable_next(&it)) {
-
- VALUE key = table_key_to_ruby(
- self, upb_strtable_iter_key(&it), upb_strtable_iter_keylength(&it));
+ VALUE key = table_key_to_ruby(self, upb_strtable_iter_key(&it));
upb_value v = upb_strtable_iter_value(&it);
void* mem = value_memory(&v);
@@ -319,9 +317,7 @@
for (upb_strtable_begin(&it, &self->table);
!upb_strtable_done(&it);
upb_strtable_next(&it)) {
-
- VALUE key = table_key_to_ruby(
- self, upb_strtable_iter_key(&it), upb_strtable_iter_keylength(&it));
+ VALUE key = table_key_to_ruby(self, upb_strtable_iter_key(&it));
rb_ary_push(ret, key);
}
@@ -526,17 +522,14 @@
for (upb_strtable_begin(&it, &self->table);
!upb_strtable_done(&it);
upb_strtable_next(&it)) {
-
+ upb_strview k = upb_strtable_iter_key(&it);
upb_value v = upb_strtable_iter_value(&it);
void* mem = value_memory(&v);
upb_value dup;
void* dup_mem = value_memory(&dup);
native_slot_dup(self->value_type, dup_mem, mem);
- if (!upb_strtable_insert2(&new_self->table,
- upb_strtable_iter_key(&it),
- upb_strtable_iter_keylength(&it),
- dup)) {
+ if (!upb_strtable_insert2(&new_self->table, k.data, k.size, dup)) {
rb_raise(rb_eRuntimeError, "Error inserting value into new table");
}
}
@@ -554,7 +547,7 @@
for (upb_strtable_begin(&it, &self->table);
!upb_strtable_done(&it);
upb_strtable_next(&it)) {
-
+ upb_strview k = upb_strtable_iter_key(&it);
upb_value v = upb_strtable_iter_value(&it);
void* mem = value_memory(&v);
upb_value dup;
@@ -562,10 +555,7 @@
native_slot_deep_copy(self->value_type, self->value_type_class, dup_mem,
mem);
- if (!upb_strtable_insert2(&new_self->table,
- upb_strtable_iter_key(&it),
- upb_strtable_iter_keylength(&it),
- dup)) {
+ if (!upb_strtable_insert2(&new_self->table, k.data, k.size, dup)) {
rb_raise(rb_eRuntimeError, "Error inserting value into new table");
}
}
@@ -618,16 +608,13 @@
for (upb_strtable_begin(&it, &self->table);
!upb_strtable_done(&it);
upb_strtable_next(&it)) {
-
+ upb_strview k = upb_strtable_iter_key(&it);
upb_value v = upb_strtable_iter_value(&it);
void* mem = value_memory(&v);
upb_value other_v;
void* other_mem = value_memory(&other_v);
- if (!upb_strtable_lookup2(&other->table,
- upb_strtable_iter_key(&it),
- upb_strtable_iter_keylength(&it),
- &other_v)) {
+ if (!upb_strtable_lookup2(&other->table, k.data, k.size, &other_v)) {
// Not present in other map.
return Qfalse;
}
@@ -655,11 +642,9 @@
VALUE hash_sym = rb_intern("hash");
upb_strtable_iter it;
- for (upb_strtable_begin(&it, &self->table);
- !upb_strtable_done(&it);
+ for (upb_strtable_begin(&it, &self->table); !upb_strtable_done(&it);
upb_strtable_next(&it)) {
- VALUE key = table_key_to_ruby(
- self, upb_strtable_iter_key(&it), upb_strtable_iter_keylength(&it));
+ VALUE key = table_key_to_ruby(self, upb_strtable_iter_key(&it));
upb_value v = upb_strtable_iter_value(&it);
void* mem = value_memory(&v);
@@ -687,8 +672,7 @@
for (upb_strtable_begin(&it, &self->table);
!upb_strtable_done(&it);
upb_strtable_next(&it)) {
- VALUE key = table_key_to_ruby(
- self, upb_strtable_iter_key(&it), upb_strtable_iter_keylength(&it));
+ VALUE key = table_key_to_ruby(self, upb_strtable_iter_key(&it));
upb_value v = upb_strtable_iter_value(&it);
void* mem = value_memory(&v);
VALUE value = native_slot_get(self->value_type,
@@ -720,11 +704,9 @@
VALUE inspect_sym = rb_intern("inspect");
upb_strtable_iter it;
- for (upb_strtable_begin(&it, &self->table);
- !upb_strtable_done(&it);
+ for (upb_strtable_begin(&it, &self->table); !upb_strtable_done(&it);
upb_strtable_next(&it)) {
- VALUE key = table_key_to_ruby(
- self, upb_strtable_iter_key(&it), upb_strtable_iter_keylength(&it));
+ VALUE key = table_key_to_ruby(self, upb_strtable_iter_key(&it));
upb_value v = upb_strtable_iter_value(&it);
void* mem = value_memory(&v);
@@ -785,20 +767,15 @@
for (upb_strtable_begin(&it, &other->table);
!upb_strtable_done(&it);
upb_strtable_next(&it)) {
+ upb_strview k = upb_strtable_iter_key(&it);
// Replace any existing value by issuing a 'remove' operation first.
upb_value v;
upb_value oldv;
- upb_strtable_remove2(&self->table,
- upb_strtable_iter_key(&it),
- upb_strtable_iter_keylength(&it),
- &oldv);
+ upb_strtable_remove2(&self->table, k.data, k.size, &oldv);
v = upb_strtable_iter_value(&it);
- upb_strtable_insert2(&self->table,
- upb_strtable_iter_key(&it),
- upb_strtable_iter_keylength(&it),
- v);
+ upb_strtable_insert2(&self->table, k.data, k.size, v);
}
} else {
rb_raise(rb_eArgError, "Unknown type merging into Map");
@@ -822,10 +799,7 @@
}
VALUE Map_iter_key(Map_iter* iter) {
- return table_key_to_ruby(
- iter->self,
- upb_strtable_iter_key(&iter->it),
- upb_strtable_iter_keylength(&iter->it));
+ return table_key_to_ruby(iter->self, upb_strtable_iter_key(&iter->it));
}
VALUE Map_iter_value(Map_iter* iter) {
diff --git a/ruby/ext/google/protobuf_c/upb.c b/ruby/ext/google/protobuf_c/upb.c
index b7d7c16..ffa55fb 100644
--- a/ruby/ext/google/protobuf_c/upb.c
+++ b/ruby/ext/google/protobuf_c/upb.c
@@ -22,9 +22,7 @@
*
* This file is private and must not be included by users!
*/
-#ifndef UINTPTR_MAX
-#error must include stdint.h first
-#endif
+#include <stdint.h>
#if UINTPTR_MAX == 0xffffffff
#define UPB_SIZE(size32, size64) size32
@@ -32,17 +30,21 @@
#define UPB_SIZE(size32, size64) size64
#endif
-#define UPB_FIELD_AT(msg, fieldtype, offset) \
- *(fieldtype*)((const char*)(msg) + offset)
+/* If we always read/write as a consistent type to each address, this shouldn't
+ * violate aliasing.
+ */
+#define UPB_PTR_AT(msg, ofs, type) ((type*)((char*)(msg) + (ofs)))
#define UPB_READ_ONEOF(msg, fieldtype, offset, case_offset, case_val, default) \
- UPB_FIELD_AT(msg, int, case_offset) == case_val \
- ? UPB_FIELD_AT(msg, fieldtype, offset) \
+ *UPB_PTR_AT(msg, case_offset, int) == case_val \
+ ? *UPB_PTR_AT(msg, offset, fieldtype) \
: default
#define UPB_WRITE_ONEOF(msg, fieldtype, offset, value, case_offset, case_val) \
- UPB_FIELD_AT(msg, int, case_offset) = case_val; \
- UPB_FIELD_AT(msg, fieldtype, offset) = value;
+ *UPB_PTR_AT(msg, case_offset, int) = case_val; \
+ *UPB_PTR_AT(msg, offset, fieldtype) = value;
+
+#define UPB_MAPTYPE_STRING 0
/* UPB_INLINE: inline if possible, emit standalone code if required. */
#ifdef __cplusplus
@@ -116,7 +118,7 @@
#ifdef __cplusplus
#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) || \
(defined(_MSC_VER) && _MSC_VER >= 1900)
-// C++11 is present
+/* C++11 is present */
#else
#error upb requires C++11 for C++ support
#endif
@@ -127,6 +129,18 @@
#define UPB_UNUSED(var) (void)var
+/* UPB_ASSUME(): in release mode, we tell the compiler to assume this is true.
+ */
+#ifdef NDEBUG
+#ifdef __GNUC__
+#define UPB_ASSUME(expr) if (!(expr)) __builtin_unreachable()
+#else
+#define UPB_ASSUME(expr) do {} if (false && (expr))
+#endif
+#else
+#define UPB_ASSUME(expr) assert(expr)
+#endif
+
/* UPB_ASSERT(): in release mode, we use the expression without letting it be
* evaluated. This prevents "unused variable" warnings. */
#ifdef NDEBUG
@@ -153,606 +167,572 @@
#define UPB_INFINITY (1.0 / 0.0)
#endif
+#include <setjmp.h>
#include <string.h>
+
/* Maps descriptor type -> upb field type. */
-const uint8_t upb_desctype_to_fieldtype[] = {
- UPB_WIRE_TYPE_END_GROUP, /* ENDGROUP */
- UPB_TYPE_DOUBLE, /* DOUBLE */
- UPB_TYPE_FLOAT, /* FLOAT */
- UPB_TYPE_INT64, /* INT64 */
- UPB_TYPE_UINT64, /* UINT64 */
- UPB_TYPE_INT32, /* INT32 */
- UPB_TYPE_UINT64, /* FIXED64 */
- UPB_TYPE_UINT32, /* FIXED32 */
- UPB_TYPE_BOOL, /* BOOL */
- UPB_TYPE_STRING, /* STRING */
- UPB_TYPE_MESSAGE, /* GROUP */
- UPB_TYPE_MESSAGE, /* MESSAGE */
- UPB_TYPE_BYTES, /* BYTES */
- UPB_TYPE_UINT32, /* UINT32 */
- UPB_TYPE_ENUM, /* ENUM */
- UPB_TYPE_INT32, /* SFIXED32 */
- UPB_TYPE_INT64, /* SFIXED64 */
- UPB_TYPE_INT32, /* SINT32 */
- UPB_TYPE_INT64, /* SINT64 */
+static const uint8_t desctype_to_fieldtype[] = {
+ -1, /* invalid descriptor type */
+ UPB_TYPE_DOUBLE, /* DOUBLE */
+ UPB_TYPE_FLOAT, /* FLOAT */
+ UPB_TYPE_INT64, /* INT64 */
+ UPB_TYPE_UINT64, /* UINT64 */
+ UPB_TYPE_INT32, /* INT32 */
+ UPB_TYPE_UINT64, /* FIXED64 */
+ UPB_TYPE_UINT32, /* FIXED32 */
+ UPB_TYPE_BOOL, /* BOOL */
+ UPB_TYPE_STRING, /* STRING */
+ UPB_TYPE_MESSAGE, /* GROUP */
+ UPB_TYPE_MESSAGE, /* MESSAGE */
+ UPB_TYPE_BYTES, /* BYTES */
+ UPB_TYPE_UINT32, /* UINT32 */
+ UPB_TYPE_ENUM, /* ENUM */
+ UPB_TYPE_INT32, /* SFIXED32 */
+ UPB_TYPE_INT64, /* SFIXED64 */
+ UPB_TYPE_INT32, /* SINT32 */
+ UPB_TYPE_INT64, /* SINT64 */
+};
+
+/* Maps descriptor type -> upb map size. */
+static const uint8_t desctype_to_mapsize[] = {
+ -1, /* invalid descriptor type */
+ 8, /* DOUBLE */
+ 4, /* FLOAT */
+ 8, /* INT64 */
+ 8, /* UINT64 */
+ 4, /* INT32 */
+ 8, /* FIXED64 */
+ 4, /* FIXED32 */
+ 1, /* BOOL */
+ UPB_MAPTYPE_STRING, /* STRING */
+ sizeof(void *), /* GROUP */
+ sizeof(void *), /* MESSAGE */
+ UPB_MAPTYPE_STRING, /* BYTES */
+ 4, /* UINT32 */
+ 4, /* ENUM */
+ 4, /* SFIXED32 */
+ 8, /* SFIXED64 */
+ 4, /* SINT32 */
+ 8, /* SINT64 */
+};
+
+static const unsigned fixed32_ok = (1 << UPB_DTYPE_FLOAT) |
+ (1 << UPB_DTYPE_FIXED32) |
+ (1 << UPB_DTYPE_SFIXED32);
+
+static const unsigned fixed64_ok = (1 << UPB_DTYPE_DOUBLE) |
+ (1 << UPB_DTYPE_FIXED64) |
+ (1 << UPB_DTYPE_SFIXED64);
+
+/* Op: an action to be performed for a wire-type/field-type combination. */
+#define OP_SCALAR_LG2(n) (n)
+#define OP_FIXPCK_LG2(n) (n + 4)
+#define OP_VARPCK_LG2(n) (n + 8)
+#define OP_STRING 4
+#define OP_SUBMSG 5
+
+static const int8_t varint_ops[19] = {
+ -1, /* field not found */
+ -1, /* DOUBLE */
+ -1, /* FLOAT */
+ OP_SCALAR_LG2(3), /* INT64 */
+ OP_SCALAR_LG2(3), /* UINT64 */
+ OP_SCALAR_LG2(2), /* INT32 */
+ -1, /* FIXED64 */
+ -1, /* FIXED32 */
+ OP_SCALAR_LG2(0), /* BOOL */
+ -1, /* STRING */
+ -1, /* GROUP */
+ -1, /* MESSAGE */
+ -1, /* BYTES */
+ OP_SCALAR_LG2(2), /* UINT32 */
+ OP_SCALAR_LG2(2), /* ENUM */
+ -1, /* SFIXED32 */
+ -1, /* SFIXED64 */
+ OP_SCALAR_LG2(2), /* SINT32 */
+ OP_SCALAR_LG2(3), /* SINT64 */
+};
+
+static const int8_t delim_ops[37] = {
+ /* For non-repeated field type. */
+ -1, /* field not found */
+ -1, /* DOUBLE */
+ -1, /* FLOAT */
+ -1, /* INT64 */
+ -1, /* UINT64 */
+ -1, /* INT32 */
+ -1, /* FIXED64 */
+ -1, /* FIXED32 */
+ -1, /* BOOL */
+ OP_STRING, /* STRING */
+ -1, /* GROUP */
+ OP_SUBMSG, /* MESSAGE */
+ OP_STRING, /* BYTES */
+ -1, /* UINT32 */
+ -1, /* ENUM */
+ -1, /* SFIXED32 */
+ -1, /* SFIXED64 */
+ -1, /* SINT32 */
+ -1, /* SINT64 */
+ /* For repeated field type. */
+ OP_FIXPCK_LG2(3), /* REPEATED DOUBLE */
+ OP_FIXPCK_LG2(2), /* REPEATED FLOAT */
+ OP_VARPCK_LG2(3), /* REPEATED INT64 */
+ OP_VARPCK_LG2(3), /* REPEATED UINT64 */
+ OP_VARPCK_LG2(2), /* REPEATED INT32 */
+ OP_FIXPCK_LG2(3), /* REPEATED FIXED64 */
+ OP_FIXPCK_LG2(2), /* REPEATED FIXED32 */
+ OP_VARPCK_LG2(0), /* REPEATED BOOL */
+ OP_STRING, /* REPEATED STRING */
+ OP_SUBMSG, /* REPEATED GROUP */
+ OP_SUBMSG, /* REPEATED MESSAGE */
+ OP_STRING, /* REPEATED BYTES */
+ OP_VARPCK_LG2(2), /* REPEATED UINT32 */
+ OP_VARPCK_LG2(2), /* REPEATED ENUM */
+ OP_FIXPCK_LG2(2), /* REPEATED SFIXED32 */
+ OP_FIXPCK_LG2(3), /* REPEATED SFIXED64 */
+ OP_VARPCK_LG2(2), /* REPEATED SINT32 */
+ OP_VARPCK_LG2(3), /* REPEATED SINT64 */
};
/* Data pertaining to the parse. */
typedef struct {
- const char *ptr; /* Current parsing position. */
- const char *field_start; /* Start of this field. */
- const char *limit; /* End of delimited region or end of buffer. */
+ const char *limit; /* End of delimited region or end of buffer. */
upb_arena *arena;
int depth;
- uint32_t end_group; /* Set to field number of END_GROUP tag, if any. */
+ uint32_t end_group; /* Set to field number of END_GROUP tag, if any. */
+ jmp_buf err;
} upb_decstate;
-/* Data passed by value to each parsing function. */
-typedef struct {
- char *msg;
- const upb_msglayout *layout;
- upb_decstate *state;
-} upb_decframe;
+typedef union {
+ bool bool_val;
+ int32_t int32_val;
+ int64_t int64_val;
+ uint32_t uint32_val;
+ uint64_t uint64_val;
+ upb_strview str_val;
+} wireval;
-#define CHK(x) if (!(x)) { return 0; }
+static const char *decode_msg(upb_decstate *d, const char *ptr, upb_msg *msg,
+ const upb_msglayout *layout);
-static bool upb_skip_unknowngroup(upb_decstate *d, int field_number);
-static bool upb_decode_message(upb_decstate *d, char *msg,
- const upb_msglayout *l);
+UPB_NORETURN static void decode_err(upb_decstate *d) { longjmp(d->err, 1); }
-static bool upb_decode_varint(const char **ptr, const char *limit,
- uint64_t *val) {
+static bool decode_reserve(upb_decstate *d, upb_array *arr, int elem) {
+ bool need_realloc = arr->size - arr->len < elem;
+ if (need_realloc && !_upb_array_realloc(arr, arr->len + elem, d->arena)) {
+ decode_err(d);
+ }
+ return need_realloc;
+}
+
+UPB_NOINLINE
+static const char *decode_longvarint64(upb_decstate *d, const char *ptr,
+ const char *limit, uint64_t *val) {
uint8_t byte;
int bitpos = 0;
- const char *p = *ptr;
- *val = 0;
+ uint64_t out = 0;
do {
- CHK(bitpos < 70 && p < limit);
- byte = *p;
- *val |= (uint64_t)(byte & 0x7F) << bitpos;
- p++;
+ if (bitpos >= 70 || ptr == limit) decode_err(d);
+ byte = *ptr;
+ out |= (uint64_t)(byte & 0x7F) << bitpos;
+ ptr++;
bitpos += 7;
} while (byte & 0x80);
- *ptr = p;
- return true;
+ *val = out;
+ return ptr;
}
-static bool upb_decode_varint32(const char **ptr, const char *limit,
- uint32_t *val) {
+UPB_FORCEINLINE
+static const char *decode_varint64(upb_decstate *d, const char *ptr,
+ const char *limit, uint64_t *val) {
+ if (UPB_LIKELY(ptr < limit && (*ptr & 0x80) == 0)) {
+ *val = (uint8_t)*ptr;
+ return ptr + 1;
+ } else {
+ return decode_longvarint64(d, ptr, limit, val);
+ }
+}
+
+static const char *decode_varint32(upb_decstate *d, const char *ptr,
+ const char *limit, uint32_t *val) {
uint64_t u64;
- CHK(upb_decode_varint(ptr, limit, &u64) && u64 <= UINT32_MAX);
+ ptr = decode_varint64(d, ptr, limit, &u64);
+ if (u64 > UINT32_MAX) decode_err(d);
*val = (uint32_t)u64;
- return true;
+ return ptr;
}
-static bool upb_decode_64bit(const char **ptr, const char *limit,
- uint64_t *val) {
- CHK(limit - *ptr >= 8);
- memcpy(val, *ptr, 8);
- *ptr += 8;
- return true;
-}
-
-static bool upb_decode_32bit(const char **ptr, const char *limit,
- uint32_t *val) {
- CHK(limit - *ptr >= 4);
- memcpy(val, *ptr, 4);
- *ptr += 4;
- return true;
-}
-
-static int32_t upb_zzdecode_32(uint32_t n) {
- return (n >> 1) ^ -(int32_t)(n & 1);
-}
-
-static int64_t upb_zzdecode_64(uint64_t n) {
- return (n >> 1) ^ -(int64_t)(n & 1);
-}
-
-static bool upb_decode_string(const char **ptr, const char *limit,
- int *outlen) {
- uint32_t len;
-
- CHK(upb_decode_varint32(ptr, limit, &len) &&
- len < INT32_MAX &&
- limit - *ptr >= (int32_t)len);
-
- *outlen = len;
- return true;
-}
-
-static void upb_set32(void *msg, size_t ofs, uint32_t val) {
- memcpy((char*)msg + ofs, &val, sizeof(val));
-}
-
-static bool upb_append_unknown(upb_decstate *d, upb_decframe *frame) {
- upb_msg_addunknown(frame->msg, d->field_start, d->ptr - d->field_start,
- d->arena);
- return true;
-}
-
-
-static bool upb_skip_unknownfielddata(upb_decstate *d, uint32_t tag,
- uint32_t group_fieldnum) {
- switch (tag & 7) {
- case UPB_WIRE_TYPE_VARINT: {
- uint64_t val;
- return upb_decode_varint(&d->ptr, d->limit, &val);
- }
- case UPB_WIRE_TYPE_32BIT: {
- uint32_t val;
- return upb_decode_32bit(&d->ptr, d->limit, &val);
- }
- case UPB_WIRE_TYPE_64BIT: {
- uint64_t val;
- return upb_decode_64bit(&d->ptr, d->limit, &val);
- }
- case UPB_WIRE_TYPE_DELIMITED: {
- int len;
- CHK(upb_decode_string(&d->ptr, d->limit, &len));
- d->ptr += len;
- return true;
- }
- case UPB_WIRE_TYPE_START_GROUP:
- return upb_skip_unknowngroup(d, tag >> 3);
- case UPB_WIRE_TYPE_END_GROUP:
- return (tag >> 3) == group_fieldnum;
- }
- return false;
-}
-
-static bool upb_skip_unknowngroup(upb_decstate *d, int field_number) {
- while (d->ptr < d->limit && d->end_group == 0) {
- uint32_t tag = 0;
- CHK(upb_decode_varint32(&d->ptr, d->limit, &tag));
- CHK(upb_skip_unknownfielddata(d, tag, field_number));
- }
-
- CHK(d->end_group == field_number);
- d->end_group = 0;
- return true;
-}
-
-static bool upb_array_grow(upb_array *arr, size_t elements, size_t elem_size,
- upb_arena *arena) {
- size_t needed = arr->len + elements;
- size_t new_size = UPB_MAX(arr->size, 8);
- size_t new_bytes;
- size_t old_bytes;
- void *new_data;
- upb_alloc *alloc = upb_arena_alloc(arena);
-
- while (new_size < needed) {
- new_size *= 2;
- }
-
- old_bytes = arr->len * elem_size;
- new_bytes = new_size * elem_size;
- new_data = upb_realloc(alloc, arr->data, old_bytes, new_bytes);
- CHK(new_data);
-
- arr->data = new_data;
- arr->size = new_size;
- return true;
-}
-
-static void *upb_array_reserve(upb_array *arr, size_t elements,
- size_t elem_size, upb_arena *arena) {
- if (arr->size - arr->len < elements) {
- CHK(upb_array_grow(arr, elements, elem_size, arena));
- }
- return (char*)arr->data + (arr->len * elem_size);
-}
-
-bool upb_array_add(upb_array *arr, size_t elements, size_t elem_size,
- const void *data, upb_arena *arena) {
- void *dest = upb_array_reserve(arr, elements, elem_size, arena);
-
- CHK(dest);
- arr->len += elements;
- memcpy(dest, data, elements * elem_size);
-
- return true;
-}
-
-static upb_array *upb_getarr(upb_decframe *frame,
- const upb_msglayout_field *field) {
- UPB_ASSERT(field->label == UPB_LABEL_REPEATED);
- return *(upb_array**)&frame->msg[field->offset];
-}
-
-static upb_array *upb_getorcreatearr(upb_decframe *frame,
- const upb_msglayout_field *field) {
- upb_array *arr = upb_getarr(frame, field);
-
- if (!arr) {
- arr = upb_array_new(frame->state->arena);
- CHK(arr);
- *(upb_array**)&frame->msg[field->offset] = arr;
- }
-
- return arr;
-}
-
-static upb_msg *upb_getorcreatemsg(upb_decframe *frame,
- const upb_msglayout_field *field,
- const upb_msglayout **subm) {
- upb_msg **submsg = (void*)(frame->msg + field->offset);
- *subm = frame->layout->submsgs[field->submsg_index];
-
- UPB_ASSERT(field->label != UPB_LABEL_REPEATED);
-
- if (!*submsg) {
- *submsg = upb_msg_new(*subm, frame->state->arena);
- CHK(*submsg);
- }
-
- return *submsg;
-}
-
-static upb_msg *upb_addmsg(upb_decframe *frame,
- const upb_msglayout_field *field,
- const upb_msglayout **subm) {
- upb_msg *submsg;
- upb_array *arr = upb_getorcreatearr(frame, field);
-
- *subm = frame->layout->submsgs[field->submsg_index];
- submsg = upb_msg_new(*subm, frame->state->arena);
- CHK(submsg);
- upb_array_add(arr, 1, sizeof(submsg), &submsg, frame->state->arena);
-
- return submsg;
-}
-
-static void upb_sethasbit(upb_decframe *frame,
- const upb_msglayout_field *field) {
- int32_t hasbit = field->presence;
- UPB_ASSERT(field->presence > 0);
- frame->msg[hasbit / 8] |= (1 << (hasbit % 8));
-}
-
-static void upb_setoneofcase(upb_decframe *frame,
- const upb_msglayout_field *field) {
- UPB_ASSERT(field->presence < 0);
- upb_set32(frame->msg, ~field->presence, field->number);
-}
-
-static bool upb_decode_addval(upb_decframe *frame,
- const upb_msglayout_field *field, void *val,
- size_t size) {
- char *field_mem = frame->msg + field->offset;
- upb_array *arr;
-
- if (field->label == UPB_LABEL_REPEATED) {
- arr = upb_getorcreatearr(frame, field);
- CHK(arr);
- field_mem = upb_array_reserve(arr, 1, size, frame->state->arena);
- CHK(field_mem);
- }
-
- memcpy(field_mem, val, size);
- return true;
-}
-
-static void upb_decode_setpresent(upb_decframe *frame,
- const upb_msglayout_field *field) {
- if (field->label == UPB_LABEL_REPEATED) {
- upb_array *arr = upb_getarr(frame, field);
- UPB_ASSERT(arr->len < arr->size);
- arr->len++;
- } else if (field->presence < 0) {
- upb_setoneofcase(frame, field);
- } else if (field->presence > 0) {
- upb_sethasbit(frame, field);
- }
-}
-
-static bool upb_decode_msgfield(upb_decstate *d, upb_msg *msg,
- const upb_msglayout *layout, int limit) {
- const char* saved_limit = d->limit;
- d->limit = d->ptr + limit;
- CHK(--d->depth >= 0);
- upb_decode_message(d, msg, layout);
- d->depth++;
- d->limit = saved_limit;
- CHK(d->end_group == 0);
- return true;
-}
-
-static bool upb_decode_groupfield(upb_decstate *d, upb_msg *msg,
- const upb_msglayout *layout,
- int field_number) {
- CHK(--d->depth >= 0);
- upb_decode_message(d, msg, layout);
- d->depth++;
- CHK(d->end_group == field_number);
- d->end_group = 0;
- return true;
-}
-
-static bool upb_decode_varintfield(upb_decstate *d, upb_decframe *frame,
- const upb_msglayout_field *field) {
- uint64_t val;
- CHK(upb_decode_varint(&d->ptr, d->limit, &val));
-
- switch (field->descriptortype) {
- case UPB_DESCRIPTOR_TYPE_INT64:
- case UPB_DESCRIPTOR_TYPE_UINT64:
- CHK(upb_decode_addval(frame, field, &val, sizeof(val)));
+static void decode_munge(int type, wireval *val) {
+ switch (type) {
+ case UPB_DESCRIPTOR_TYPE_BOOL:
+ val->bool_val = val->uint64_val != 0;
break;
- case UPB_DESCRIPTOR_TYPE_INT32:
- case UPB_DESCRIPTOR_TYPE_UINT32:
- case UPB_DESCRIPTOR_TYPE_ENUM: {
- uint32_t val32 = (uint32_t)val;
- CHK(upb_decode_addval(frame, field, &val32, sizeof(val32)));
- break;
- }
- case UPB_DESCRIPTOR_TYPE_BOOL: {
- bool valbool = val != 0;
- CHK(upb_decode_addval(frame, field, &valbool, sizeof(valbool)));
- break;
- }
case UPB_DESCRIPTOR_TYPE_SINT32: {
- int32_t decoded = upb_zzdecode_32((uint32_t)val);
- CHK(upb_decode_addval(frame, field, &decoded, sizeof(decoded)));
+ uint32_t n = val->uint32_val;
+ val->int32_val = (n >> 1) ^ -(int32_t)(n & 1);
break;
}
case UPB_DESCRIPTOR_TYPE_SINT64: {
- int64_t decoded = upb_zzdecode_64(val);
- CHK(upb_decode_addval(frame, field, &decoded, sizeof(decoded)));
+ uint64_t n = val->uint64_val;
+ val->int64_val = (n >> 1) ^ -(int64_t)(n & 1);
break;
}
- default:
- return upb_append_unknown(d, frame);
- }
-
- upb_decode_setpresent(frame, field);
- return true;
-}
-
-static bool upb_decode_64bitfield(upb_decstate *d, upb_decframe *frame,
- const upb_msglayout_field *field) {
- uint64_t val;
- CHK(upb_decode_64bit(&d->ptr, d->limit, &val));
-
- switch (field->descriptortype) {
- case UPB_DESCRIPTOR_TYPE_DOUBLE:
- case UPB_DESCRIPTOR_TYPE_FIXED64:
- case UPB_DESCRIPTOR_TYPE_SFIXED64:
- CHK(upb_decode_addval(frame, field, &val, sizeof(val)));
- break;
- default:
- return upb_append_unknown(d, frame);
- }
-
- upb_decode_setpresent(frame, field);
- return true;
-}
-
-static bool upb_decode_32bitfield(upb_decstate *d, upb_decframe *frame,
- const upb_msglayout_field *field) {
- uint32_t val;
- CHK(upb_decode_32bit(&d->ptr, d->limit, &val));
-
- switch (field->descriptortype) {
- case UPB_DESCRIPTOR_TYPE_FLOAT:
- case UPB_DESCRIPTOR_TYPE_FIXED32:
- case UPB_DESCRIPTOR_TYPE_SFIXED32:
- CHK(upb_decode_addval(frame, field, &val, sizeof(val)));
- break;
- default:
- return upb_append_unknown(d, frame);
- }
-
- upb_decode_setpresent(frame, field);
- return true;
-}
-
-static bool upb_decode_fixedpacked(upb_decstate *d, upb_array *arr,
- uint32_t len, int elem_size) {
- size_t elements = len / elem_size;
-
- CHK((size_t)(elements * elem_size) == len);
- CHK(upb_array_add(arr, elements, elem_size, d->ptr, d->arena));
- d->ptr += len;
-
- return true;
-}
-
-static upb_strview upb_decode_strfield(upb_decstate *d, uint32_t len) {
- upb_strview ret;
- ret.data = d->ptr;
- ret.size = len;
- d->ptr += len;
- return ret;
-}
-
-static bool upb_decode_toarray(upb_decstate *d, upb_decframe *frame,
- const upb_msglayout_field *field, int len) {
- upb_array *arr = upb_getorcreatearr(frame, field);
- CHK(arr);
-
-#define VARINT_CASE(ctype, decode) \
- VARINT_CASE_EX(ctype, decode, decode)
-
-#define VARINT_CASE_EX(ctype, decode, dtype) \
- { \
- const char *ptr = d->ptr; \
- const char *limit = ptr + len; \
- while (ptr < limit) { \
- uint64_t val; \
- ctype decoded; \
- CHK(upb_decode_varint(&ptr, limit, &val)); \
- decoded = (decode)((dtype)val); \
- CHK(upb_array_add(arr, 1, sizeof(decoded), &decoded, d->arena)); \
- } \
- d->ptr = ptr; \
- return true; \
- }
-
- switch (field->descriptortype) {
- case UPB_DESCRIPTOR_TYPE_STRING:
- case UPB_DESCRIPTOR_TYPE_BYTES: {
- upb_strview str = upb_decode_strfield(d, len);
- return upb_array_add(arr, 1, sizeof(str), &str, d->arena);
- }
- case UPB_DESCRIPTOR_TYPE_FLOAT:
- case UPB_DESCRIPTOR_TYPE_FIXED32:
- case UPB_DESCRIPTOR_TYPE_SFIXED32:
- return upb_decode_fixedpacked(d, arr, len, sizeof(int32_t));
- case UPB_DESCRIPTOR_TYPE_DOUBLE:
- case UPB_DESCRIPTOR_TYPE_FIXED64:
- case UPB_DESCRIPTOR_TYPE_SFIXED64:
- return upb_decode_fixedpacked(d, arr, len, sizeof(int64_t));
- case UPB_DESCRIPTOR_TYPE_INT32:
- case UPB_DESCRIPTOR_TYPE_UINT32:
- case UPB_DESCRIPTOR_TYPE_ENUM:
- VARINT_CASE(uint32_t, uint32_t);
- case UPB_DESCRIPTOR_TYPE_INT64:
- case UPB_DESCRIPTOR_TYPE_UINT64:
- VARINT_CASE(uint64_t, uint64_t);
- case UPB_DESCRIPTOR_TYPE_BOOL:
- VARINT_CASE(bool, bool);
- case UPB_DESCRIPTOR_TYPE_SINT32:
- VARINT_CASE_EX(int32_t, upb_zzdecode_32, uint32_t);
- case UPB_DESCRIPTOR_TYPE_SINT64:
- VARINT_CASE_EX(int64_t, upb_zzdecode_64, uint64_t);
- case UPB_DESCRIPTOR_TYPE_MESSAGE: {
- const upb_msglayout *subm;
- upb_msg *submsg = upb_addmsg(frame, field, &subm);
- CHK(submsg);
- return upb_decode_msgfield(d, submsg, subm, len);
- }
- case UPB_DESCRIPTOR_TYPE_GROUP:
- return upb_append_unknown(d, frame);
- }
-#undef VARINT_CASE
- UPB_UNREACHABLE();
-}
-
-static bool upb_decode_delimitedfield(upb_decstate *d, upb_decframe *frame,
- const upb_msglayout_field *field) {
- int len;
-
- CHK(upb_decode_string(&d->ptr, d->limit, &len));
-
- if (field->label == UPB_LABEL_REPEATED) {
- return upb_decode_toarray(d, frame, field, len);
- } else {
- switch (field->descriptortype) {
- case UPB_DESCRIPTOR_TYPE_STRING:
- case UPB_DESCRIPTOR_TYPE_BYTES: {
- upb_strview str = upb_decode_strfield(d, len);
- CHK(upb_decode_addval(frame, field, &str, sizeof(str)));
- break;
- }
- case UPB_DESCRIPTOR_TYPE_MESSAGE: {
- const upb_msglayout *subm;
- upb_msg *submsg = upb_getorcreatemsg(frame, field, &subm);
- CHK(submsg);
- CHK(upb_decode_msgfield(d, submsg, subm, len));
- break;
- }
- default:
- /* TODO(haberman): should we accept the last element of a packed? */
- d->ptr += len;
- return upb_append_unknown(d, frame);
- }
- upb_decode_setpresent(frame, field);
- return true;
}
}
static const upb_msglayout_field *upb_find_field(const upb_msglayout *l,
uint32_t field_number) {
+ static upb_msglayout_field none = {0};
+
/* Lots of optimization opportunities here. */
int i;
+ if (l == NULL) return &none;
for (i = 0; i < l->field_count; i++) {
if (l->fields[i].number == field_number) {
return &l->fields[i];
}
}
- return NULL; /* Unknown field. */
+ return &none; /* Unknown field. */
}
-static bool upb_decode_field(upb_decstate *d, upb_decframe *frame) {
- uint32_t tag;
- const upb_msglayout_field *field;
- int field_number;
+static upb_msg *decode_newsubmsg(upb_decstate *d, const upb_msglayout *layout,
+ const upb_msglayout_field *field) {
+ const upb_msglayout *subl = layout->submsgs[field->submsg_index];
+ return _upb_msg_new(subl, d->arena);
+}
- d->field_start = d->ptr;
- CHK(upb_decode_varint32(&d->ptr, d->limit, &tag));
- field_number = tag >> 3;
- field = upb_find_field(frame->layout, field_number);
+static void decode_tosubmsg(upb_decstate *d, upb_msg *submsg,
+ const upb_msglayout *layout,
+ const upb_msglayout_field *field, upb_strview val) {
+ const upb_msglayout *subl = layout->submsgs[field->submsg_index];
+ const char *saved_limit = d->limit;
+ if (--d->depth < 0) decode_err(d);
+ d->limit = val.data + val.size;
+ decode_msg(d, val.data, submsg, subl);
+ d->limit = saved_limit;
+ if (d->end_group != 0) decode_err(d);
+ d->depth++;
+}
- if (field) {
- switch (tag & 7) {
- case UPB_WIRE_TYPE_VARINT:
- return upb_decode_varintfield(d, frame, field);
- case UPB_WIRE_TYPE_32BIT:
- return upb_decode_32bitfield(d, frame, field);
- case UPB_WIRE_TYPE_64BIT:
- return upb_decode_64bitfield(d, frame, field);
- case UPB_WIRE_TYPE_DELIMITED:
- return upb_decode_delimitedfield(d, frame, field);
- case UPB_WIRE_TYPE_START_GROUP: {
- const upb_msglayout *layout;
- upb_msg *group;
+static const char *decode_group(upb_decstate *d, const char *ptr,
+ upb_msg *submsg, const upb_msglayout *subl,
+ uint32_t number) {
+ if (--d->depth < 0) decode_err(d);
+ ptr = decode_msg(d, ptr, submsg, subl);
+ if (d->end_group != number) decode_err(d);
+ d->end_group = 0;
+ d->depth++;
+ return ptr;
+}
- if (field->label == UPB_LABEL_REPEATED) {
- group = upb_addmsg(frame, field, &layout);
- } else {
- group = upb_getorcreatemsg(frame, field, &layout);
- }
+static const char *decode_togroup(upb_decstate *d, const char *ptr,
+ upb_msg *submsg, const upb_msglayout *layout,
+ const upb_msglayout_field *field) {
+ const upb_msglayout *subl = layout->submsgs[field->submsg_index];
+ return decode_group(d, ptr, submsg, subl, field->number);
+}
- return upb_decode_groupfield(d, group, layout, field_number);
+static const char *decode_toarray(upb_decstate *d, const char *ptr,
+ upb_msg *msg, const upb_msglayout *layout,
+ const upb_msglayout_field *field, wireval val,
+ int op) {
+ upb_array **arrp = UPB_PTR_AT(msg, field->offset, void);
+ upb_array *arr = *arrp;
+ void *mem;
+
+ if (!arr) {
+ upb_fieldtype_t type = desctype_to_fieldtype[field->descriptortype];
+ arr = _upb_array_new(d->arena, type);
+ if (!arr) decode_err(d);
+ *arrp = arr;
+ }
+
+ decode_reserve(d, arr, 1);
+
+ switch (op) {
+ case OP_SCALAR_LG2(0):
+ case OP_SCALAR_LG2(2):
+ case OP_SCALAR_LG2(3):
+ /* Append scalar value. */
+ mem = UPB_PTR_AT(_upb_array_ptr(arr), arr->len << op, void);
+ arr->len++;
+ memcpy(mem, &val, 1 << op);
+ return ptr;
+ case OP_STRING:
+ /* Append string. */
+ mem =
+ UPB_PTR_AT(_upb_array_ptr(arr), arr->len * sizeof(upb_strview), void);
+ arr->len++;
+ memcpy(mem, &val, sizeof(upb_strview));
+ return ptr;
+ case OP_SUBMSG: {
+ /* Append submessage / group. */
+ upb_msg *submsg = decode_newsubmsg(d, layout, field);
+ *UPB_PTR_AT(_upb_array_ptr(arr), arr->len * sizeof(void *), upb_msg *) =
+ submsg;
+ arr->len++;
+ if (UPB_UNLIKELY(field->descriptortype == UPB_DTYPE_GROUP)) {
+ ptr = decode_togroup(d, ptr, submsg, layout, field);
+ } else {
+ decode_tosubmsg(d, submsg, layout, field, val.str_val);
}
+ return ptr;
+ }
+ case OP_FIXPCK_LG2(2):
+ case OP_FIXPCK_LG2(3): {
+ /* Fixed packed. */
+ int lg2 = op - OP_FIXPCK_LG2(0);
+ int mask = (1 << lg2) - 1;
+ int count = val.str_val.size >> lg2;
+ if ((val.str_val.size & mask) != 0) {
+ decode_err(d); /* Length isn't a round multiple of elem size. */
+ }
+ decode_reserve(d, arr, count);
+ mem = UPB_PTR_AT(_upb_array_ptr(arr), arr->len << lg2, void);
+ arr->len += count;
+ memcpy(mem, val.str_val.data, count << op);
+ return ptr;
+ }
+ case OP_VARPCK_LG2(0):
+ case OP_VARPCK_LG2(2):
+ case OP_VARPCK_LG2(3): {
+ /* Varint packed. */
+ int lg2 = op - OP_VARPCK_LG2(0);
+ int scale = 1 << lg2;
+ const char *ptr = val.str_val.data;
+ const char *end = ptr + val.str_val.size;
+ char *out = UPB_PTR_AT(_upb_array_ptr(arr), arr->len << lg2, void);
+ while (ptr < end) {
+ wireval elem;
+ ptr = decode_varint64(d, ptr, end, &elem.uint64_val);
+ decode_munge(field->descriptortype, &elem);
+ if (decode_reserve(d, arr, 1)) {
+ out = UPB_PTR_AT(_upb_array_ptr(arr), arr->len << lg2, void);
+ }
+ arr->len++;
+ memcpy(out, &elem, scale);
+ out += scale;
+ }
+ if (ptr != end) decode_err(d);
+ return ptr;
+ }
+ default:
+ UPB_UNREACHABLE();
+ }
+}
+
+static void decode_tomap(upb_decstate *d, upb_msg *msg,
+ const upb_msglayout *layout,
+ const upb_msglayout_field *field, wireval val) {
+ upb_map **map_p = UPB_PTR_AT(msg, field->offset, upb_map *);
+ upb_map *map = *map_p;
+ upb_map_entry ent;
+ const upb_msglayout *entry = layout->submsgs[field->submsg_index];
+
+ if (!map) {
+ /* Lazily create map. */
+ const upb_msglayout *entry = layout->submsgs[field->submsg_index];
+ const upb_msglayout_field *key_field = &entry->fields[0];
+ const upb_msglayout_field *val_field = &entry->fields[1];
+ char key_size = desctype_to_mapsize[key_field->descriptortype];
+ char val_size = desctype_to_mapsize[val_field->descriptortype];
+ UPB_ASSERT(key_field->offset == 0);
+ UPB_ASSERT(val_field->offset == sizeof(upb_strview));
+ map = _upb_map_new(d->arena, key_size, val_size);
+ *map_p = map;
+ }
+
+ /* Parse map entry. */
+ memset(&ent, 0, sizeof(ent));
+
+ if (entry->fields[1].descriptortype == UPB_DESCRIPTOR_TYPE_MESSAGE ||
+ entry->fields[1].descriptortype == UPB_DESCRIPTOR_TYPE_GROUP) {
+ /* Create proactively to handle the case where it doesn't appear. */
+ ent.v.val.val = (uint64_t)_upb_msg_new(entry->submsgs[0], d->arena);
+ }
+
+ decode_tosubmsg(d, &ent.k, layout, field, val.str_val);
+
+ /* Insert into map. */
+ _upb_map_set(map, &ent.k, map->key_size, &ent.v, map->val_size, d->arena);
+}
+
+static const char *decode_tomsg(upb_decstate *d, const char *ptr, upb_msg *msg,
+ const upb_msglayout *layout,
+ const upb_msglayout_field *field, wireval val,
+ int op) {
+ void *mem = UPB_PTR_AT(msg, field->offset, void);
+ int type = field->descriptortype;
+
+ /* Set presence if necessary. */
+ if (field->presence < 0) {
+ /* Oneof case */
+ *UPB_PTR_AT(msg, -field->presence, int32_t) = field->number;
+ } else if (field->presence > 0) {
+ /* Hasbit */
+ uint32_t hasbit = field->presence;
+ *UPB_PTR_AT(msg, hasbit / 8, uint8_t) |= (1 << (hasbit % 8));
+ }
+
+ /* Store into message. */
+ switch (op) {
+ case OP_SUBMSG: {
+ upb_msg **submsgp = mem;
+ upb_msg *submsg = *submsgp;
+ if (!submsg) {
+ submsg = decode_newsubmsg(d, layout, field);
+ *submsgp = submsg;
+ }
+ if (UPB_UNLIKELY(type == UPB_DTYPE_GROUP)) {
+ ptr = decode_togroup(d, ptr, submsg, layout, field);
+ } else {
+ decode_tosubmsg(d, submsg, layout, field, val.str_val);
+ }
+ break;
+ }
+ case OP_STRING:
+ memcpy(mem, &val, sizeof(upb_strview));
+ break;
+ case OP_SCALAR_LG2(3):
+ memcpy(mem, &val, 8);
+ break;
+ case OP_SCALAR_LG2(2):
+ memcpy(mem, &val, 4);
+ break;
+ case OP_SCALAR_LG2(0):
+ memcpy(mem, &val, 1);
+ break;
+ default:
+ UPB_UNREACHABLE();
+ }
+
+ return ptr;
+}
+
+static const char *decode_msg(upb_decstate *d, const char *ptr, upb_msg *msg,
+ const upb_msglayout *layout) {
+ while (ptr < d->limit) {
+ uint32_t tag;
+ const upb_msglayout_field *field;
+ int field_number;
+ int wire_type;
+ const char *field_start = ptr;
+ wireval val;
+ int op;
+
+ ptr = decode_varint32(d, ptr, d->limit, &tag);
+ field_number = tag >> 3;
+ wire_type = tag & 7;
+
+ field = upb_find_field(layout, field_number);
+
+ switch (wire_type) {
+ case UPB_WIRE_TYPE_VARINT:
+ ptr = decode_varint64(d, ptr, d->limit, &val.uint64_val);
+ op = varint_ops[field->descriptortype];
+ decode_munge(field->descriptortype, &val);
+ break;
+ case UPB_WIRE_TYPE_32BIT:
+ if (d->limit - ptr < 4) decode_err(d);
+ memcpy(&val, ptr, 4);
+ ptr += 4;
+ op = OP_SCALAR_LG2(2);
+ if (((1 << field->descriptortype) & fixed32_ok) == 0) goto unknown;
+ break;
+ case UPB_WIRE_TYPE_64BIT:
+ if (d->limit - ptr < 8) decode_err(d);
+ memcpy(&val, ptr, 8);
+ ptr += 8;
+ op = OP_SCALAR_LG2(3);
+ if (((1 << field->descriptortype) & fixed64_ok) == 0) goto unknown;
+ break;
+ case UPB_WIRE_TYPE_DELIMITED: {
+ uint32_t size;
+ int ndx = field->descriptortype;
+ if (_upb_isrepeated(field)) ndx += 18;
+ ptr = decode_varint32(d, ptr, d->limit, &size);
+ if (size >= INT32_MAX || (size_t)(d->limit - ptr) < size) {
+ decode_err(d); /* Length overflow. */
+ }
+ val.str_val.data = ptr;
+ val.str_val.size = size;
+ ptr += size;
+ op = delim_ops[ndx];
+ break;
+ }
+ case UPB_WIRE_TYPE_START_GROUP:
+ val.int32_val = field_number;
+ op = OP_SUBMSG;
+ if (field->descriptortype != UPB_DTYPE_GROUP) goto unknown;
+ break;
case UPB_WIRE_TYPE_END_GROUP:
d->end_group = field_number;
- return true;
+ return ptr;
default:
- CHK(false);
+ decode_err(d);
}
- } else {
- CHK(field_number != 0);
- CHK(upb_skip_unknownfielddata(d, tag, -1));
- CHK(upb_append_unknown(d, frame));
- return true;
- }
-}
-static bool upb_decode_message(upb_decstate *d, char *msg, const upb_msglayout *l) {
- upb_decframe frame;
- frame.msg = msg;
- frame.layout = l;
- frame.state = d;
-
- while (d->ptr < d->limit) {
- CHK(upb_decode_field(d, &frame));
+ if (op >= 0) {
+ /* Parse, using op for dispatch. */
+ switch (field->label) {
+ case UPB_LABEL_REPEATED:
+ case _UPB_LABEL_PACKED:
+ ptr = decode_toarray(d, ptr, msg, layout, field, val, op);
+ break;
+ case _UPB_LABEL_MAP:
+ decode_tomap(d, msg, layout, field, val);
+ break;
+ default:
+ ptr = decode_tomsg(d, ptr, msg, layout, field, val, op);
+ break;
+ }
+ } else {
+ unknown:
+ /* Skip unknown field. */
+ if (field_number == 0) decode_err(d);
+ if (wire_type == UPB_WIRE_TYPE_START_GROUP) {
+ ptr = decode_group(d, ptr, NULL, NULL, field_number);
+ }
+ if (msg) {
+ if (!_upb_msg_addunknown(msg, field_start, ptr - field_start,
+ d->arena)) {
+ decode_err(d);
+ }
+ }
+ }
}
- return true;
+ if (ptr != d->limit) decode_err(d);
+ return ptr;
}
bool upb_decode(const char *buf, size_t size, void *msg, const upb_msglayout *l,
upb_arena *arena) {
upb_decstate state;
- state.ptr = buf;
state.limit = buf + size;
state.arena = arena;
state.depth = 64;
state.end_group = 0;
- CHK(upb_decode_message(&state, msg, l));
+ if (setjmp(state.err)) return false;
+
+ if (size == 0) return true;
+ decode_msg(&state, buf, msg, l);
+
return state.end_group == 0;
}
-#undef CHK
+#undef OP_SCALAR_LG2
+#undef OP_FIXPCK_LG2
+#undef OP_VARPCK_LG2
+#undef OP_STRING
+#undef OP_SUBMSG
/* We encode backwards, to avoid pre-computing lengths (one-pass encode). */
@@ -821,6 +801,7 @@
/* Writes the given bytes to the buffer, handling reserve/advance. */
static bool upb_put_bytes(upb_encstate *e, const void *data, size_t len) {
+ if (len == 0) return true;
CHK(upb_encode_reserve(e, len));
memcpy(e->ptr, data, len);
return true;
@@ -863,15 +844,14 @@
static uint32_t upb_readcase(const char *msg, const upb_msglayout_field *f) {
uint32_t ret;
- uint32_t offset = ~f->presence;
- memcpy(&ret, msg + offset, sizeof(ret));
+ memcpy(&ret, msg - f->presence, sizeof(ret));
return ret;
}
static bool upb_readhasbit(const char *msg, const upb_msglayout_field *f) {
uint32_t hasbit = f->presence;
UPB_ASSERT(f->presence > 0);
- return msg[hasbit / 8] & (1 << (hasbit % 8));
+ return (*UPB_PTR_AT(msg, hasbit / 8, uint8_t)) & (1 << (hasbit % 8));
}
static bool upb_put_tag(upb_encstate *e, int field_number, int wire_type) {
@@ -879,116 +859,30 @@
}
static bool upb_put_fixedarray(upb_encstate *e, const upb_array *arr,
- size_t size) {
- size_t bytes = arr->len * size;
- return upb_put_bytes(e, arr->data, bytes) && upb_put_varint(e, bytes);
+ size_t elem_size, uint32_t tag) {
+ size_t bytes = arr->len * elem_size;
+ const char* data = _upb_array_constptr(arr);
+ const char* ptr = data + bytes - elem_size;
+ if (tag) {
+ while (true) {
+ CHK(upb_put_bytes(e, ptr, elem_size) && upb_put_varint(e, tag));
+ if (ptr == data) break;
+ ptr -= elem_size;
+ }
+ return true;
+ } else {
+ return upb_put_bytes(e, data, bytes) && upb_put_varint(e, bytes);
+ }
}
bool upb_encode_message(upb_encstate *e, const char *msg,
const upb_msglayout *m, size_t *size);
-static bool upb_encode_array(upb_encstate *e, const char *field_mem,
- const upb_msglayout *m,
- const upb_msglayout_field *f) {
- const upb_array *arr = *(const upb_array**)field_mem;
-
- if (arr == NULL || arr->len == 0) {
- return true;
- }
-
-#define VARINT_CASE(ctype, encode) { \
- ctype *start = arr->data; \
- ctype *ptr = start + arr->len; \
- size_t pre_len = e->limit - e->ptr; \
- do { \
- ptr--; \
- CHK(upb_put_varint(e, encode)); \
- } while (ptr != start); \
- CHK(upb_put_varint(e, e->limit - e->ptr - pre_len)); \
-} \
-break; \
-do { ; } while(0)
-
- switch (f->descriptortype) {
- case UPB_DESCRIPTOR_TYPE_DOUBLE:
- CHK(upb_put_fixedarray(e, arr, sizeof(double)));
- break;
- case UPB_DESCRIPTOR_TYPE_FLOAT:
- CHK(upb_put_fixedarray(e, arr, sizeof(float)));
- break;
- case UPB_DESCRIPTOR_TYPE_SFIXED64:
- case UPB_DESCRIPTOR_TYPE_FIXED64:
- CHK(upb_put_fixedarray(e, arr, sizeof(uint64_t)));
- break;
- case UPB_DESCRIPTOR_TYPE_FIXED32:
- case UPB_DESCRIPTOR_TYPE_SFIXED32:
- CHK(upb_put_fixedarray(e, arr, sizeof(uint32_t)));
- break;
- case UPB_DESCRIPTOR_TYPE_INT64:
- case UPB_DESCRIPTOR_TYPE_UINT64:
- VARINT_CASE(uint64_t, *ptr);
- case UPB_DESCRIPTOR_TYPE_UINT32:
- VARINT_CASE(uint32_t, *ptr);
- case UPB_DESCRIPTOR_TYPE_INT32:
- case UPB_DESCRIPTOR_TYPE_ENUM:
- VARINT_CASE(int32_t, (int64_t)*ptr);
- case UPB_DESCRIPTOR_TYPE_BOOL:
- VARINT_CASE(bool, *ptr);
- case UPB_DESCRIPTOR_TYPE_SINT32:
- VARINT_CASE(int32_t, upb_zzencode_32(*ptr));
- case UPB_DESCRIPTOR_TYPE_SINT64:
- VARINT_CASE(int64_t, upb_zzencode_64(*ptr));
- case UPB_DESCRIPTOR_TYPE_STRING:
- case UPB_DESCRIPTOR_TYPE_BYTES: {
- upb_strview *start = arr->data;
- upb_strview *ptr = start + arr->len;
- do {
- ptr--;
- CHK(upb_put_bytes(e, ptr->data, ptr->size) &&
- upb_put_varint(e, ptr->size) &&
- upb_put_tag(e, f->number, UPB_WIRE_TYPE_DELIMITED));
- } while (ptr != start);
- return true;
- }
- case UPB_DESCRIPTOR_TYPE_GROUP: {
- void **start = arr->data;
- void **ptr = start + arr->len;
- const upb_msglayout *subm = m->submsgs[f->submsg_index];
- do {
- size_t size;
- ptr--;
- CHK(upb_put_tag(e, f->number, UPB_WIRE_TYPE_END_GROUP) &&
- upb_encode_message(e, *ptr, subm, &size) &&
- upb_put_tag(e, f->number, UPB_WIRE_TYPE_START_GROUP));
- } while (ptr != start);
- return true;
- }
- case UPB_DESCRIPTOR_TYPE_MESSAGE: {
- void **start = arr->data;
- void **ptr = start + arr->len;
- const upb_msglayout *subm = m->submsgs[f->submsg_index];
- do {
- size_t size;
- ptr--;
- CHK(upb_encode_message(e, *ptr, subm, &size) &&
- upb_put_varint(e, size) &&
- upb_put_tag(e, f->number, UPB_WIRE_TYPE_DELIMITED));
- } while (ptr != start);
- return true;
- }
- }
-#undef VARINT_CASE
-
- /* We encode all primitive arrays as packed, regardless of what was specified
- * in the .proto file. Could special case 1-sized arrays. */
- CHK(upb_put_tag(e, f->number, UPB_WIRE_TYPE_DELIMITED));
- return true;
-}
-
-static bool upb_encode_scalarfield(upb_encstate *e, const char *field_mem,
+static bool upb_encode_scalarfield(upb_encstate *e, const void *_field_mem,
const upb_msglayout *m,
const upb_msglayout_field *f,
bool skip_zero_value) {
+ const char *field_mem = _field_mem;
#define CASE(ctype, type, wire_type, encodeval) do { \
ctype val = *(ctype*)field_mem; \
if (skip_zero_value && val == 0) { \
@@ -1060,6 +954,146 @@
UPB_UNREACHABLE();
}
+static bool upb_encode_array(upb_encstate *e, const char *field_mem,
+ const upb_msglayout *m,
+ const upb_msglayout_field *f) {
+ const upb_array *arr = *(const upb_array**)field_mem;
+ bool packed = f->label == _UPB_LABEL_PACKED;
+
+ if (arr == NULL || arr->len == 0) {
+ return true;
+ }
+
+#define VARINT_CASE(ctype, encode) \
+ { \
+ const ctype *start = _upb_array_constptr(arr); \
+ const ctype *ptr = start + arr->len; \
+ size_t pre_len = e->limit - e->ptr; \
+ uint32_t tag = packed ? 0 : (f->number << 3) | UPB_WIRE_TYPE_VARINT; \
+ do { \
+ ptr--; \
+ CHK(upb_put_varint(e, encode)); \
+ if (tag) CHK(upb_put_varint(e, tag)); \
+ } while (ptr != start); \
+ if (!tag) CHK(upb_put_varint(e, e->limit - e->ptr - pre_len)); \
+ } \
+ break; \
+ do { \
+ ; \
+ } while (0)
+
+#define TAG(wire_type) (packed ? 0 : (f->number << 3 | wire_type))
+
+ switch (f->descriptortype) {
+ case UPB_DESCRIPTOR_TYPE_DOUBLE:
+ CHK(upb_put_fixedarray(e, arr, sizeof(double), TAG(UPB_WIRE_TYPE_64BIT)));
+ break;
+ case UPB_DESCRIPTOR_TYPE_FLOAT:
+ CHK(upb_put_fixedarray(e, arr, sizeof(float), TAG(UPB_WIRE_TYPE_32BIT)));
+ break;
+ case UPB_DESCRIPTOR_TYPE_SFIXED64:
+ case UPB_DESCRIPTOR_TYPE_FIXED64:
+ CHK(upb_put_fixedarray(e, arr, sizeof(uint64_t), TAG(UPB_WIRE_TYPE_64BIT)));
+ break;
+ case UPB_DESCRIPTOR_TYPE_FIXED32:
+ case UPB_DESCRIPTOR_TYPE_SFIXED32:
+ CHK(upb_put_fixedarray(e, arr, sizeof(uint32_t), TAG(UPB_WIRE_TYPE_32BIT)));
+ break;
+ case UPB_DESCRIPTOR_TYPE_INT64:
+ case UPB_DESCRIPTOR_TYPE_UINT64:
+ VARINT_CASE(uint64_t, *ptr);
+ case UPB_DESCRIPTOR_TYPE_UINT32:
+ VARINT_CASE(uint32_t, *ptr);
+ case UPB_DESCRIPTOR_TYPE_INT32:
+ case UPB_DESCRIPTOR_TYPE_ENUM:
+ VARINT_CASE(int32_t, (int64_t)*ptr);
+ case UPB_DESCRIPTOR_TYPE_BOOL:
+ VARINT_CASE(bool, *ptr);
+ case UPB_DESCRIPTOR_TYPE_SINT32:
+ VARINT_CASE(int32_t, upb_zzencode_32(*ptr));
+ case UPB_DESCRIPTOR_TYPE_SINT64:
+ VARINT_CASE(int64_t, upb_zzencode_64(*ptr));
+ case UPB_DESCRIPTOR_TYPE_STRING:
+ case UPB_DESCRIPTOR_TYPE_BYTES: {
+ const upb_strview *start = _upb_array_constptr(arr);
+ const upb_strview *ptr = start + arr->len;
+ do {
+ ptr--;
+ CHK(upb_put_bytes(e, ptr->data, ptr->size) &&
+ upb_put_varint(e, ptr->size) &&
+ upb_put_tag(e, f->number, UPB_WIRE_TYPE_DELIMITED));
+ } while (ptr != start);
+ return true;
+ }
+ case UPB_DESCRIPTOR_TYPE_GROUP: {
+ const void *const*start = _upb_array_constptr(arr);
+ const void *const*ptr = start + arr->len;
+ const upb_msglayout *subm = m->submsgs[f->submsg_index];
+ do {
+ size_t size;
+ ptr--;
+ CHK(upb_put_tag(e, f->number, UPB_WIRE_TYPE_END_GROUP) &&
+ upb_encode_message(e, *ptr, subm, &size) &&
+ upb_put_tag(e, f->number, UPB_WIRE_TYPE_START_GROUP));
+ } while (ptr != start);
+ return true;
+ }
+ case UPB_DESCRIPTOR_TYPE_MESSAGE: {
+ const void *const*start = _upb_array_constptr(arr);
+ const void *const*ptr = start + arr->len;
+ const upb_msglayout *subm = m->submsgs[f->submsg_index];
+ do {
+ size_t size;
+ ptr--;
+ CHK(upb_encode_message(e, *ptr, subm, &size) &&
+ upb_put_varint(e, size) &&
+ upb_put_tag(e, f->number, UPB_WIRE_TYPE_DELIMITED));
+ } while (ptr != start);
+ return true;
+ }
+ }
+#undef VARINT_CASE
+
+ if (packed) {
+ CHK(upb_put_tag(e, f->number, UPB_WIRE_TYPE_DELIMITED));
+ }
+ return true;
+}
+
+static bool upb_encode_map(upb_encstate *e, const char *field_mem,
+ const upb_msglayout *m,
+ const upb_msglayout_field *f) {
+ const upb_map *map = *(const upb_map**)field_mem;
+ const upb_msglayout *entry = m->submsgs[f->submsg_index];
+ const upb_msglayout_field *key_field = &entry->fields[0];
+ const upb_msglayout_field *val_field = &entry->fields[1];
+ upb_strtable_iter i;
+ if (map == NULL) {
+ return true;
+ }
+
+ upb_strtable_begin(&i, &map->table);
+ for(; !upb_strtable_done(&i); upb_strtable_next(&i)) {
+ size_t pre_len = e->limit - e->ptr;
+ size_t size;
+ upb_strview key = upb_strtable_iter_key(&i);
+ const upb_value val = upb_strtable_iter_value(&i);
+ const void *keyp =
+ map->key_size == UPB_MAPTYPE_STRING ? (void *)&key : key.data;
+ const void *valp =
+ map->val_size == UPB_MAPTYPE_STRING ? upb_value_getptr(val) : &val;
+
+ CHK(upb_encode_scalarfield(e, valp, entry, val_field, false));
+ CHK(upb_encode_scalarfield(e, keyp, entry, key_field, false));
+ size = (e->limit - e->ptr) - pre_len;
+ CHK(upb_put_varint(e, size));
+ CHK(upb_put_tag(e, f->number, UPB_WIRE_TYPE_DELIMITED));
+ }
+
+ return true;
+}
+
+
bool upb_encode_message(upb_encstate *e, const char *msg,
const upb_msglayout *m, size_t *size) {
int i;
@@ -1067,11 +1101,19 @@
const char *unknown;
size_t unknown_size;
+ unknown = upb_msg_getunknown(msg, &unknown_size);
+
+ if (unknown) {
+ upb_put_bytes(e, unknown, unknown_size);
+ }
+
for (i = m->field_count - 1; i >= 0; i--) {
const upb_msglayout_field *f = &m->fields[i];
- if (f->label == UPB_LABEL_REPEATED) {
+ if (_upb_isrepeated(f)) {
CHK(upb_encode_array(e, msg + f->offset, m, f));
+ } else if (f->label == _UPB_LABEL_MAP) {
+ CHK(upb_encode_map(e, msg + f->offset, m, f));
} else {
bool skip_empty = false;
if (f->presence == 0) {
@@ -1092,12 +1134,6 @@
}
}
- unknown = upb_msg_getunknown(msg, &unknown_size);
-
- if (unknown) {
- upb_put_bytes(e, unknown, unknown_size);
- }
-
*size = (e->limit - e->ptr) - pre_len;
return true;
}
@@ -1131,24 +1167,27 @@
-#define VOIDPTR_AT(msg, ofs) (void*)((char*)msg + (int)ofs)
+/** upb_msg *******************************************************************/
-/* Internal members of a upb_msg. We can change this without breaking binary
- * compatibility. We put these before the user's data. The user's upb_msg*
- * points after the upb_msg_internal. */
+static const char _upb_fieldtype_to_sizelg2[12] = {
+ 0,
+ 0, /* UPB_TYPE_BOOL */
+ 2, /* UPB_TYPE_FLOAT */
+ 2, /* UPB_TYPE_INT32 */
+ 2, /* UPB_TYPE_UINT32 */
+ 2, /* UPB_TYPE_ENUM */
+ UPB_SIZE(2, 3), /* UPB_TYPE_MESSAGE */
+ 3, /* UPB_TYPE_DOUBLE */
+ 3, /* UPB_TYPE_INT64 */
+ 3, /* UPB_TYPE_UINT64 */
+ UPB_SIZE(3, 4), /* UPB_TYPE_STRING */
+ UPB_SIZE(3, 4), /* UPB_TYPE_BYTES */
+};
-/* Used when a message is not extendable. */
-typedef struct {
- char *unknown;
- size_t unknown_len;
- size_t unknown_size;
-} upb_msg_internal;
-
-/* Used when a message is extendable. */
-typedef struct {
- upb_inttable *extdict;
- upb_msg_internal base;
-} upb_msg_internal_withext;
+static uintptr_t tag_arrptr(void* ptr, int elem_size_lg2) {
+ UPB_ASSERT(elem_size_lg2 <= 4);
+ return (uintptr_t)ptr | elem_size_lg2;
+}
static int upb_msg_internalsize(const upb_msglayout *l) {
return sizeof(upb_msg_internal) - l->extendable * sizeof(void *);
@@ -1159,22 +1198,22 @@
}
static upb_msg_internal *upb_msg_getinternal(upb_msg *msg) {
- return VOIDPTR_AT(msg, -sizeof(upb_msg_internal));
+ return UPB_PTR_AT(msg, -sizeof(upb_msg_internal), upb_msg_internal);
}
static const upb_msg_internal *upb_msg_getinternal_const(const upb_msg *msg) {
- return VOIDPTR_AT(msg, -sizeof(upb_msg_internal));
+ return UPB_PTR_AT(msg, -sizeof(upb_msg_internal), upb_msg_internal);
}
static upb_msg_internal_withext *upb_msg_getinternalwithext(
upb_msg *msg, const upb_msglayout *l) {
UPB_ASSERT(l->extendable);
- return VOIDPTR_AT(msg, -sizeof(upb_msg_internal_withext));
+ return UPB_PTR_AT(msg, -sizeof(upb_msg_internal_withext),
+ upb_msg_internal_withext);
}
-upb_msg *upb_msg_new(const upb_msglayout *l, upb_arena *a) {
- upb_alloc *alloc = upb_arena_alloc(a);
- void *mem = upb_malloc(alloc, upb_msg_sizeof(l));
+upb_msg *_upb_msg_new(const upb_msglayout *l, upb_arena *a) {
+ void *mem = upb_arena_malloc(a, upb_msg_sizeof(l));
upb_msg_internal *in;
upb_msg *msg;
@@ -1182,7 +1221,7 @@
return NULL;
}
- msg = VOIDPTR_AT(mem, upb_msg_internalsize(l));
+ msg = UPB_PTR_AT(mem, upb_msg_internalsize(l), upb_msg);
/* Initialize normal members. */
memset(msg, 0, l->size);
@@ -1200,66 +1239,122 @@
return msg;
}
-upb_array *upb_array_new(upb_arena *a) {
- upb_array *ret = upb_arena_malloc(a, sizeof(upb_array));
-
- if (!ret) {
- return NULL;
- }
-
- ret->data = NULL;
- ret->len = 0;
- ret->size = 0;
-
- return ret;
-}
-
-void upb_msg_addunknown(upb_msg *msg, const char *data, size_t len,
- upb_arena *arena) {
+bool _upb_msg_addunknown(upb_msg *msg, const char *data, size_t len,
+ upb_arena *arena) {
upb_msg_internal *in = upb_msg_getinternal(msg);
if (len > in->unknown_size - in->unknown_len) {
upb_alloc *alloc = upb_arena_alloc(arena);
size_t need = in->unknown_size + len;
size_t newsize = UPB_MAX(in->unknown_size * 2, need);
- in->unknown = upb_realloc(alloc, in->unknown, in->unknown_size, newsize);
+ void *mem = upb_realloc(alloc, in->unknown, in->unknown_size, newsize);
+ if (!mem) return false;
+ in->unknown = mem;
in->unknown_size = newsize;
}
memcpy(in->unknown + in->unknown_len, data, len);
in->unknown_len += len;
+ return true;
}
const char *upb_msg_getunknown(const upb_msg *msg, size_t *len) {
- const upb_msg_internal* in = upb_msg_getinternal_const(msg);
+ const upb_msg_internal *in = upb_msg_getinternal_const(msg);
*len = in->unknown_len;
return in->unknown;
}
-#undef VOIDPTR_AT
+/** upb_array *****************************************************************/
+upb_array *_upb_array_new(upb_arena *a, upb_fieldtype_t type) {
+ upb_array *arr = upb_arena_malloc(a, sizeof(upb_array));
-#ifdef UPB_MSVC_VSNPRINTF
-/* Visual C++ earlier than 2015 doesn't have standard C99 snprintf and
- * vsnprintf. To support them, missing functions are manually implemented
- * using the existing secure functions. */
-int msvc_vsnprintf(char* s, size_t n, const char* format, va_list arg) {
- if (!s) {
- return _vscprintf(format, arg);
+ if (!arr) {
+ return NULL;
}
- int ret = _vsnprintf_s(s, n, _TRUNCATE, format, arg);
- if (ret < 0) {
- ret = _vscprintf(format, arg);
- }
- return ret;
+
+ arr->data = tag_arrptr(NULL, _upb_fieldtype_to_sizelg2[type]);
+ arr->len = 0;
+ arr->size = 0;
+
+ return arr;
}
-int msvc_snprintf(char* s, size_t n, const char* format, ...) {
- va_list arg;
- va_start(arg, format);
- int ret = msvc_vsnprintf(s, n, format, arg);
- va_end(arg);
- return ret;
+bool _upb_array_realloc(upb_array *arr, size_t min_size, upb_arena *arena) {
+ size_t new_size = UPB_MAX(arr->size, 4);
+ int elem_size_lg2 = arr->data & 7;
+ size_t old_bytes = arr->size << elem_size_lg2;
+ size_t new_bytes;
+ void* ptr = _upb_array_ptr(arr);
+
+ /* Log2 ceiling of size. */
+ while (new_size < min_size) new_size *= 2;
+
+ new_bytes = new_size << elem_size_lg2;
+ ptr = upb_arena_realloc(arena, ptr, old_bytes, new_bytes);
+
+ if (!ptr) {
+ return false;
+ }
+
+ arr->data = tag_arrptr(ptr, elem_size_lg2);
+ arr->size = new_size;
+ return true;
}
-#endif
+
+static upb_array *getorcreate_array(upb_array **arr_ptr, upb_fieldtype_t type,
+ upb_arena *arena) {
+ upb_array *arr = *arr_ptr;
+ if (!arr) {
+ arr = _upb_array_new(arena, type);
+ if (!arr) return NULL;
+ *arr_ptr = arr;
+ }
+ return arr;
+}
+
+static bool resize_array(upb_array *arr, size_t size, upb_arena *arena) {
+ if (size > arr->size && !_upb_array_realloc(arr, size, arena)) {
+ return false;
+ }
+
+ arr->len = size;
+ return true;
+}
+
+void *_upb_array_resize_fallback(upb_array **arr_ptr, size_t size,
+ upb_fieldtype_t type, upb_arena *arena) {
+ upb_array *arr = getorcreate_array(arr_ptr, type, arena);
+ return arr && resize_array(arr, size, arena) ? _upb_array_ptr(arr) : NULL;
+}
+
+bool _upb_array_append_fallback(upb_array **arr_ptr, const void *value,
+ upb_fieldtype_t type, upb_arena *arena) {
+ upb_array *arr = getorcreate_array(arr_ptr, type, arena);
+ size_t elem = arr->len;
+ int lg2 = _upb_fieldtype_to_sizelg2[type];
+ char *data;
+
+ if (!arr || !resize_array(arr, elem + 1, arena)) return false;
+
+ data = _upb_array_ptr(arr);
+ memcpy(data + (elem << lg2), value, 1 << lg2);
+ return true;
+}
+
+/** upb_map *******************************************************************/
+
+upb_map *_upb_map_new(upb_arena *a, size_t key_size, size_t value_size) {
+ upb_map *map = upb_arena_malloc(a, sizeof(upb_map));
+
+ if (!map) {
+ return NULL;
+ }
+
+ upb_strtable_init2(&map->table, UPB_CTYPE_INT32, upb_arena_alloc(a));
+ map->key_size = key_size;
+ map->val_size = value_size;
+
+ return map;
+}
/*
** upb_table Implementation
**
@@ -1276,12 +1371,6 @@
#define ARRAY_SIZE(x) \
((sizeof(x)/sizeof(0[x])) / ((size_t)(!(sizeof(x) % sizeof(0[x])))))
-static void upb_check_alloc(upb_table *t, upb_alloc *a) {
- UPB_UNUSED(t);
- UPB_UNUSED(a);
- UPB_ASSERT_DEBUGVAR(t->alloc == a);
-}
-
static const double MAX_LOAD = 0.85;
/* The minimum utilization of the array part of a mixed hash/array table. This
@@ -1360,17 +1449,12 @@
}
}
-static bool init(upb_table *t, upb_ctype_t ctype, uint8_t size_lg2,
- upb_alloc *a) {
+static bool init(upb_table *t, uint8_t size_lg2, upb_alloc *a) {
size_t bytes;
t->count = 0;
- t->ctype = ctype;
t->size_lg2 = size_lg2;
t->mask = upb_table_size(t) ? upb_table_size(t) - 1 : 0;
-#ifndef NDEBUG
- t->alloc = a;
-#endif
bytes = upb_table_size(t) * sizeof(upb_tabent);
if (bytes > 0) {
t->entries = upb_malloc(a, bytes);
@@ -1383,7 +1467,6 @@
}
static void uninit(upb_table *t, upb_alloc *a) {
- upb_check_alloc(t, a);
upb_free(a, mutable_entries(t));
}
@@ -1419,7 +1502,7 @@
const upb_tabent *e = findentry(t, key, hash, eql);
if (e) {
if (v) {
- _upb_value_setval(v, e->val.val, t->ctype);
+ _upb_value_setval(v, e->val.val);
}
return true;
} else {
@@ -1435,7 +1518,6 @@
upb_tabent *our_e;
UPB_ASSERT(findentry(t, key, hash, eql) == NULL);
- UPB_ASSERT_DEBUGVAR(val.ctype == t->ctype);
t->count++;
mainpos_e = getentry_mutable(t, hash);
@@ -1481,7 +1563,7 @@
if (eql(chain->key, key)) {
/* Element to remove is at the head of its chain. */
t->count--;
- if (val) _upb_value_setval(val, chain->val.val, t->ctype);
+ if (val) _upb_value_setval(val, chain->val.val);
if (removed) *removed = chain->key;
if (chain->next) {
upb_tabent *move = (upb_tabent*)chain->next;
@@ -1501,7 +1583,7 @@
/* Found element to remove. */
upb_tabent *rm = (upb_tabent*)chain->next;
t->count--;
- if (val) _upb_value_setval(val, chain->next->val.val, t->ctype);
+ if (val) _upb_value_setval(val, chain->next->val.val);
if (removed) *removed = rm->key;
rm->key = 0; /* Make the slot empty. */
chain->next = rm->next;
@@ -1554,7 +1636,13 @@
}
bool upb_strtable_init2(upb_strtable *t, upb_ctype_t ctype, upb_alloc *a) {
- return init(&t->t, ctype, 2, a);
+ return init(&t->t, 2, a);
+}
+
+void upb_strtable_clear(upb_strtable *t) {
+ size_t bytes = upb_table_size(&t->t) * sizeof(upb_tabent);
+ t->t.count = 0;
+ memset((char*)t->t.entries, 0, bytes);
}
void upb_strtable_uninit2(upb_strtable *t, upb_alloc *a) {
@@ -1568,18 +1656,14 @@
upb_strtable new_table;
upb_strtable_iter i;
- upb_check_alloc(&t->t, a);
-
- if (!init(&new_table.t, t->t.ctype, size_lg2, a))
+ if (!init(&new_table.t, size_lg2, a))
return false;
upb_strtable_begin(&i, t);
for ( ; !upb_strtable_done(&i); upb_strtable_next(&i)) {
+ upb_strview key = upb_strtable_iter_key(&i);
upb_strtable_insert3(
- &new_table,
- upb_strtable_iter_key(&i),
- upb_strtable_iter_keylength(&i),
- upb_strtable_iter_value(&i),
- a);
+ &new_table, key.data, key.size,
+ upb_strtable_iter_value(&i), a);
}
upb_strtable_uninit2(t, a);
*t = new_table;
@@ -1592,8 +1676,6 @@
upb_tabkey tabkey;
uint32_t hash;
- upb_check_alloc(&t->t, a);
-
if (isfull(&t->t)) {
/* Need to resize. New table of double the size, add old elements to it. */
if (!upb_strtable_resize(t, t->t.size_lg2 + 1, a)) {
@@ -1621,7 +1703,10 @@
uint32_t hash = upb_murmur_hash2(key, len, 0);
upb_tabkey tabkey;
if (rm(&t->t, strkey2(key, len), val, &tabkey, hash, &streql)) {
- upb_free(alloc, (void*)tabkey);
+ if (alloc) {
+ /* Arena-based allocs don't need to free and won't pass this. */
+ upb_free(alloc, (void*)tabkey);
+ }
return true;
} else {
return false;
@@ -1630,10 +1715,6 @@
/* Iteration */
-static const upb_tabent *str_tabent(const upb_strtable_iter *i) {
- return &i->t->t.entries[i->index];
-}
-
void upb_strtable_begin(upb_strtable_iter *i, const upb_strtable *t) {
i->t = t;
i->index = begin(&t->t);
@@ -1649,21 +1730,18 @@
upb_tabent_isempty(str_tabent(i));
}
-const char *upb_strtable_iter_key(const upb_strtable_iter *i) {
- UPB_ASSERT(!upb_strtable_done(i));
- return upb_tabstr(str_tabent(i)->key, NULL);
-}
-
-size_t upb_strtable_iter_keylength(const upb_strtable_iter *i) {
+upb_strview upb_strtable_iter_key(const upb_strtable_iter *i) {
+ upb_strview key;
uint32_t len;
UPB_ASSERT(!upb_strtable_done(i));
- upb_tabstr(str_tabent(i)->key, &len);
- return len;
+ key.data = upb_tabstr(str_tabent(i)->key, &len);
+ key.size = len;
+ return key;
}
upb_value upb_strtable_iter_value(const upb_strtable_iter *i) {
UPB_ASSERT(!upb_strtable_done(i));
- return _upb_value_val(str_tabent(i)->val.val, i->t->t.ctype);
+ return _upb_value_val(str_tabent(i)->val.val);
}
void upb_strtable_iter_setdone(upb_strtable_iter *i) {
@@ -1729,11 +1807,11 @@
#endif
}
-bool upb_inttable_sizedinit(upb_inttable *t, upb_ctype_t ctype,
- size_t asize, int hsize_lg2, upb_alloc *a) {
+bool upb_inttable_sizedinit(upb_inttable *t, size_t asize, int hsize_lg2,
+ upb_alloc *a) {
size_t array_bytes;
- if (!init(&t->t, ctype, hsize_lg2, a)) return false;
+ if (!init(&t->t, hsize_lg2, a)) return false;
/* Always make the array part at least 1 long, so that we know key 0
* won't be in the hash part, which simplifies things. */
t->array_size = UPB_MAX(1, asize);
@@ -1750,7 +1828,7 @@
}
bool upb_inttable_init2(upb_inttable *t, upb_ctype_t ctype, upb_alloc *a) {
- return upb_inttable_sizedinit(t, ctype, 0, 4, a);
+ return upb_inttable_sizedinit(t, 0, 4, a);
}
void upb_inttable_uninit2(upb_inttable *t, upb_alloc *a) {
@@ -1764,8 +1842,6 @@
tabval.val = val.val;
UPB_ASSERT(upb_arrhas(tabval)); /* This will reject (uint64_t)-1. Fix this. */
- upb_check_alloc(&t->t, a);
-
if (key < t->array_size) {
UPB_ASSERT(!upb_arrhas(t->array[key]));
t->array_count++;
@@ -1776,7 +1852,7 @@
size_t i;
upb_table new_table;
- if (!init(&new_table, t->t.ctype, t->t.size_lg2 + 1, a)) {
+ if (!init(&new_table, t->t.size_lg2 + 1, a)) {
return false;
}
@@ -1785,7 +1861,7 @@
uint32_t hash;
upb_value v;
- _upb_value_setval(&v, e->val.val, t->t.ctype);
+ _upb_value_setval(&v, e->val.val);
hash = upb_inthash(e->key);
insert(&new_table, intkey(e->key), e->key, v, hash, &inthash, &inteql);
}
@@ -1804,7 +1880,7 @@
bool upb_inttable_lookup(const upb_inttable *t, uintptr_t key, upb_value *v) {
const upb_tabval *table_v = inttable_val_const(t, key);
if (!table_v) return false;
- if (v) _upb_value_setval(v, table_v->val, t->t.ctype);
+ if (v) _upb_value_setval(v, table_v->val);
return true;
}
@@ -1822,7 +1898,7 @@
upb_tabval empty = UPB_TABVALUE_EMPTY_INIT;
t->array_count--;
if (val) {
- _upb_value_setval(val, t->array[key].val, t->t.ctype);
+ _upb_value_setval(val, t->array[key].val);
}
mutable_array(t)[key] = empty;
success = true;
@@ -1837,7 +1913,6 @@
}
bool upb_inttable_push2(upb_inttable *t, upb_value val, upb_alloc *a) {
- upb_check_alloc(&t->t, a);
return upb_inttable_insert2(t, upb_inttable_count(t), val, a);
}
@@ -1850,7 +1925,6 @@
bool upb_inttable_insertptr2(upb_inttable *t, const void *key, upb_value val,
upb_alloc *a) {
- upb_check_alloc(&t->t, a);
return upb_inttable_insert2(t, (uintptr_t)key, val, a);
}
@@ -1875,8 +1949,6 @@
int size_lg2;
upb_inttable new_t;
- upb_check_alloc(&t->t, a);
-
upb_inttable_begin(&i, t);
for (; !upb_inttable_done(&i); upb_inttable_next(&i)) {
uintptr_t key = upb_inttable_iter_key(&i);
@@ -1909,7 +1981,7 @@
size_t hash_size = hash_count ? (hash_count / MAX_LOAD) + 1 : 0;
int hashsize_lg2 = log2ceil(hash_size);
- upb_inttable_sizedinit(&new_t, t->t.ctype, arr_size, hashsize_lg2, a);
+ upb_inttable_sizedinit(&new_t, arr_size, hashsize_lg2, a);
upb_inttable_begin(&i, t);
for (; !upb_inttable_done(&i); upb_inttable_next(&i)) {
uintptr_t k = upb_inttable_iter_key(&i);
@@ -1975,8 +2047,7 @@
upb_value upb_inttable_iter_value(const upb_inttable_iter *i) {
UPB_ASSERT(!upb_inttable_done(i));
return _upb_value_val(
- i->array_part ? i->t->array[i->index].val : int_tabent(i)->val.val,
- i->t->t.ctype);
+ i->array_part ? i->t->array[i->index].val : int_tabent(i)->val.val);
}
void upb_inttable_iter_setdone(upb_inttable_iter *i) {
@@ -2016,7 +2087,8 @@
/* Mix 4 bytes at a time into the hash */
const uint8_t * data = (const uint8_t *)key;
while(len >= 4) {
- uint32_t k = *(uint32_t *)data;
+ uint32_t k;
+ memcpy(&k, data, sizeof(k));
k *= m;
k ^= k >> r;
@@ -2181,17 +2253,6 @@
#include <string.h>
-/* Guarantee null-termination and provide ellipsis truncation.
- * It may be tempting to "optimize" this by initializing these final
- * four bytes up-front and then being careful never to overwrite them,
- * this is safer and simpler. */
-static void nullz(upb_status *status) {
- const char *ellipsis = "...";
- size_t len = strlen(ellipsis);
- UPB_ASSERT(sizeof(status->msg) > len);
- memcpy(status->msg + sizeof(status->msg) - len, ellipsis, len);
-}
-
/* upb_status *****************************************************************/
void upb_status_clear(upb_status *status) {
@@ -2207,8 +2268,8 @@
void upb_status_seterrmsg(upb_status *status, const char *msg) {
if (!status) return;
status->ok = false;
- strncpy(status->msg, msg, sizeof(status->msg));
- nullz(status);
+ strncpy(status->msg, msg, UPB_STATUS_MAX_MESSAGE - 1);
+ status->msg[UPB_STATUS_MAX_MESSAGE - 1] = '\0';
}
void upb_status_seterrf(upb_status *status, const char *fmt, ...) {
@@ -2222,7 +2283,7 @@
if (!status) return;
status->ok = false;
_upb_vsnprintf(status->msg, sizeof(status->msg), fmt, args);
- nullz(status);
+ status->msg[UPB_STATUS_MAX_MESSAGE - 1] = '\0';
}
/* upb_alloc ******************************************************************/
@@ -2244,16 +2305,10 @@
/* upb_arena ******************************************************************/
/* Be conservative and choose 16 in case anyone is using SSE. */
-static const size_t maxalign = 16;
-
-static size_t align_up_max(size_t size) {
- return ((size + maxalign - 1) / maxalign) * maxalign;
-}
struct upb_arena {
- /* We implement the allocator interface.
- * This must be the first member of upb_arena! */
- upb_alloc alloc;
+ _upb_arena_head head;
+ char *start;
/* Allocator to allocate arena blocks. We are responsible for freeing these
* when we are destroyed. */
@@ -2272,8 +2327,6 @@
typedef struct mem_block {
struct mem_block *next;
- size_t size;
- size_t used;
bool owned;
/* Data follows. */
} mem_block;
@@ -2288,12 +2341,17 @@
bool owned) {
mem_block *block = ptr;
+ if (a->block_head) {
+ a->bytes_allocated += a->head.ptr - a->start;
+ }
+
block->next = a->block_head;
- block->size = size;
- block->used = align_up_max(sizeof(mem_block));
block->owned = owned;
a->block_head = block;
+ a->start = (char*)block + _upb_arena_alignup(sizeof(mem_block));
+ a->head.ptr = a->start;
+ a->head.end = (char*)block + size;
/* TODO(haberman): ASAN poison. */
}
@@ -2312,39 +2370,31 @@
return block;
}
+void *_upb_arena_slowmalloc(upb_arena *a, size_t size) {
+ mem_block *block = upb_arena_allocblock(a, size);
+ if (!block) return NULL; /* Out of memory. */
+ return upb_arena_malloc(a, size);
+}
+
static void *upb_arena_doalloc(upb_alloc *alloc, void *ptr, size_t oldsize,
size_t size) {
upb_arena *a = (upb_arena*)alloc; /* upb_alloc is initial member. */
- mem_block *block = a->block_head;
void *ret;
if (size == 0) {
return NULL; /* We are an arena, don't need individual frees. */
}
- size = align_up_max(size);
+ ret = upb_arena_malloc(a, size);
+ if (!ret) return NULL;
/* TODO(haberman): special-case if this is a realloc of the last alloc? */
- if (!block || block->size - block->used < size) {
- /* Slow path: have to allocate a new block. */
- block = upb_arena_allocblock(a, size);
-
- if (!block) {
- return NULL; /* Out of memory. */
- }
- }
-
- ret = (char*)block + block->used;
- block->used += size;
-
if (oldsize > 0) {
memcpy(ret, ptr, oldsize); /* Preserve existing data. */
}
/* TODO(haberman): ASAN unpoison. */
-
- a->bytes_allocated += size;
return ret;
}
@@ -2373,7 +2423,10 @@
a = (void*)((char*)mem + n - sizeof(*a));
n -= sizeof(*a);
- a->alloc.func = &upb_arena_doalloc;
+ a->head.alloc.func = &upb_arena_doalloc;
+ a->head.ptr = NULL;
+ a->head.end = NULL;
+ a->start = NULL;
a->block_alloc = &upb_alloc_global;
a->bytes_allocated = 0;
a->next_block_size = 256;
@@ -2413,7 +2466,7 @@
}
bool upb_arena_addcleanup(upb_arena *a, void *ud, upb_cleanup_func *func) {
- cleanup_ent *ent = upb_malloc(&a->alloc, sizeof(cleanup_ent));
+ cleanup_ent *ent = upb_malloc(&a->head.alloc, sizeof(cleanup_ent));
if (!ent) {
return false; /* Out of memory. */
}
@@ -2427,7 +2480,7 @@
}
size_t upb_arena_bytesallocated(const upb_arena *a) {
- return a->bytes_allocated;
+ return a->bytes_allocated + (a->head.ptr - a->start);
}
/* This file was generated by upbc (the upb compiler) from the input
* file:
@@ -2558,23 +2611,24 @@
&google_protobuf_FieldOptions_msginit,
};
-static const upb_msglayout_field google_protobuf_FieldDescriptorProto__fields[10] = {
- {1, UPB_SIZE(32, 32), 5, 0, 9, 1},
- {2, UPB_SIZE(40, 48), 6, 0, 9, 1},
+static const upb_msglayout_field google_protobuf_FieldDescriptorProto__fields[11] = {
+ {1, UPB_SIZE(36, 40), 6, 0, 9, 1},
+ {2, UPB_SIZE(44, 56), 7, 0, 9, 1},
{3, UPB_SIZE(24, 24), 3, 0, 5, 1},
{4, UPB_SIZE(8, 8), 1, 0, 14, 1},
{5, UPB_SIZE(16, 16), 2, 0, 14, 1},
- {6, UPB_SIZE(48, 64), 7, 0, 9, 1},
- {7, UPB_SIZE(56, 80), 8, 0, 9, 1},
- {8, UPB_SIZE(72, 112), 10, 0, 11, 1},
+ {6, UPB_SIZE(52, 72), 8, 0, 9, 1},
+ {7, UPB_SIZE(60, 88), 9, 0, 9, 1},
+ {8, UPB_SIZE(76, 120), 11, 0, 11, 1},
{9, UPB_SIZE(28, 28), 4, 0, 5, 1},
- {10, UPB_SIZE(64, 96), 9, 0, 9, 1},
+ {10, UPB_SIZE(68, 104), 10, 0, 9, 1},
+ {17, UPB_SIZE(32, 32), 5, 0, 8, 1},
};
const upb_msglayout google_protobuf_FieldDescriptorProto_msginit = {
&google_protobuf_FieldDescriptorProto_submsgs[0],
&google_protobuf_FieldDescriptorProto__fields[0],
- UPB_SIZE(80, 128), 10, false,
+ UPB_SIZE(80, 128), 11, false,
};
static const upb_msglayout *const google_protobuf_OneofDescriptorProto_submsgs[1] = {
@@ -2869,8 +2923,8 @@
};
static const upb_msglayout_field google_protobuf_SourceCodeInfo_Location__fields[5] = {
- {1, UPB_SIZE(20, 40), 0, 0, 5, 3},
- {2, UPB_SIZE(24, 48), 0, 0, 5, 3},
+ {1, UPB_SIZE(20, 40), 0, 0, 5, _UPB_LABEL_PACKED},
+ {2, UPB_SIZE(24, 48), 0, 0, 5, _UPB_LABEL_PACKED},
{3, UPB_SIZE(4, 8), 1, 0, 9, 1},
{4, UPB_SIZE(12, 24), 2, 0, 9, 1},
{6, UPB_SIZE(28, 56), 0, 0, 9, 3},
@@ -2897,7 +2951,7 @@
};
static const upb_msglayout_field google_protobuf_GeneratedCodeInfo_Annotation__fields[4] = {
- {1, UPB_SIZE(20, 32), 0, 0, 5, 3},
+ {1, UPB_SIZE(20, 32), 0, 0, 5, _UPB_LABEL_PACKED},
{2, UPB_SIZE(12, 16), 3, 0, 9, 1},
{3, UPB_SIZE(4, 4), 1, 0, 5, 1},
{4, UPB_SIZE(8, 8), 2, 0, 5, 1},
@@ -2936,6 +2990,7 @@
const upb_filedef *file;
const upb_msgdef *msgdef;
const char *full_name;
+ const char *json_name;
union {
int64_t sint;
uint64_t uint;
@@ -2951,16 +3006,19 @@
const google_protobuf_FieldDescriptorProto *unresolved;
} sub;
uint32_t number_;
- uint32_t index_;
+ uint16_t index_;
+ uint16_t layout_index;
uint32_t selector_base; /* Used to index into a upb::Handlers table. */
bool is_extension_;
bool lazy_;
bool packed_;
+ bool proto3_optional_;
upb_descriptortype_t type_;
upb_label_t label_;
};
struct upb_msgdef {
+ const upb_msglayout *layout;
const upb_filedef *file;
const char *full_name;
uint32_t selector_count;
@@ -3024,10 +3082,15 @@
/* Inside a symtab we store tagged pointers to specific def types. */
typedef enum {
- UPB_DEFTYPE_MSG = 0,
- UPB_DEFTYPE_ENUM = 1,
- UPB_DEFTYPE_FIELD = 2,
- UPB_DEFTYPE_ONEOF = 3
+ UPB_DEFTYPE_FIELD = 0,
+
+ /* Only inside symtab table. */
+ UPB_DEFTYPE_MSG = 1,
+ UPB_DEFTYPE_ENUM = 2,
+
+ /* Only inside message table. */
+ UPB_DEFTYPE_ONEOF = 1,
+ UPB_DEFTYPE_FIELD_JSONNAME = 2
} upb_deftype_t;
static const void *unpack_def(upb_value v, upb_deftype_t type) {
@@ -3260,7 +3323,7 @@
}
int upb_enumdef_numvals(const upb_enumdef *e) {
- return upb_strtable_count(&e->ntoi);
+ return (int)upb_strtable_count(&e->ntoi);
}
void upb_enum_begin(upb_enum_iter *i, const upb_enumdef *e) {
@@ -3288,7 +3351,7 @@
}
const char *upb_enum_iter_name(upb_enum_iter *iter) {
- return upb_strtable_iter_key(iter);
+ return upb_strtable_iter_key(iter).data;
}
int32_t upb_enum_iter_number(upb_enum_iter *iter) {
@@ -3369,47 +3432,12 @@
return shortdefname(f->full_name);
}
-uint32_t upb_fielddef_selectorbase(const upb_fielddef *f) {
- return f->selector_base;
+const char *upb_fielddef_jsonname(const upb_fielddef *f) {
+ return f->json_name;
}
-size_t upb_fielddef_getjsonname(const upb_fielddef *f, char *buf, size_t len) {
- const char *name = upb_fielddef_name(f);
- size_t src, dst = 0;
- bool ucase_next = false;
-
-#define WRITE(byte) \
- ++dst; \
- if (dst < len) buf[dst - 1] = byte; \
- else if (dst == len) buf[dst - 1] = '\0'
-
- if (!name) {
- WRITE('\0');
- return 0;
- }
-
- /* Implement the transformation as described in the spec:
- * 1. upper case all letters after an underscore.
- * 2. remove all underscores.
- */
- for (src = 0; name[src]; src++) {
- if (name[src] == '_') {
- ucase_next = true;
- continue;
- }
-
- if (ucase_next) {
- WRITE(toupper(name[src]));
- ucase_next = false;
- } else {
- WRITE(name[src]);
- }
- }
-
- WRITE('\0');
- return dst;
-
-#undef WRITE
+uint32_t upb_fielddef_selectorbase(const upb_fielddef *f) {
+ return f->selector_base;
}
const upb_msgdef *upb_fielddef_containingtype(const upb_fielddef *f) {
@@ -3432,7 +3460,7 @@
int32_t upb_fielddef_defaultint32(const upb_fielddef *f) {
chkdefaulttype(f, UPB_TYPE_INT32);
- return f->defaultval.sint;
+ return (int32_t)f->defaultval.sint;
}
uint64_t upb_fielddef_defaultuint64(const upb_fielddef *f) {
@@ -3442,7 +3470,7 @@
uint32_t upb_fielddef_defaultuint32(const upb_fielddef *f) {
chkdefaulttype(f, UPB_TYPE_UINT32);
- return f->defaultval.uint;
+ return (uint32_t)f->defaultval.uint;
}
bool upb_fielddef_defaultbool(const upb_fielddef *f) {
@@ -3484,6 +3512,10 @@
return f->sub.enumdef;
}
+const upb_msglayout_field *upb_fielddef_layout(const upb_fielddef *f) {
+ return &f->msgdef->layout->fields[f->layout_index];
+}
+
bool upb_fielddef_issubmsg(const upb_fielddef *f) {
return upb_fielddef_type(f) == UPB_TYPE_MESSAGE;
}
@@ -3513,6 +3545,7 @@
bool upb_fielddef_haspresence(const upb_fielddef *f) {
if (upb_fielddef_isseq(f)) return false;
if (upb_fielddef_issubmsg(f)) return true;
+ if (f->proto3_optional_) return true;
return f->file->syntax == UPB_SYNTAX_PROTO2;
}
@@ -3592,18 +3625,39 @@
*o = unpack_def(val, UPB_DEFTYPE_ONEOF);
*f = unpack_def(val, UPB_DEFTYPE_FIELD);
- UPB_ASSERT((*o != NULL) ^ (*f != NULL)); /* Exactly one of the two should be set. */
- return true;
+ return *o || *f; /* False if this was a JSON name. */
+}
+
+const upb_fielddef *upb_msgdef_lookupjsonname(const upb_msgdef *m,
+ const char *name, size_t len) {
+ upb_value val;
+ const upb_fielddef* f;
+
+ if (!upb_strtable_lookup2(&m->ntof, name, len, &val)) {
+ return NULL;
+ }
+
+ f = unpack_def(val, UPB_DEFTYPE_FIELD);
+ if (!f) f = unpack_def(val, UPB_DEFTYPE_FIELD_JSONNAME);
+
+ return f;
}
int upb_msgdef_numfields(const upb_msgdef *m) {
- /* The number table contains only fields. */
- return upb_inttable_count(&m->itof);
+ return m->field_count;
}
int upb_msgdef_numoneofs(const upb_msgdef *m) {
- /* The name table includes oneofs, and the number table does not. */
- return upb_strtable_count(&m->ntof) - upb_inttable_count(&m->itof);
+ return m->oneof_count;
+}
+
+const upb_msglayout *upb_msgdef_layout(const upb_msgdef *m) {
+ return m->layout;
+}
+
+const upb_fielddef *_upb_msgdef_field(const upb_msgdef *m, int i) {
+ if (i >= m->field_count) return NULL;
+ return &m->fields[i];
}
bool upb_msgdef_mapentry(const upb_msgdef *m) {
@@ -3688,13 +3742,23 @@
}
int upb_oneofdef_numfields(const upb_oneofdef *o) {
- return upb_strtable_count(&o->ntof);
+ return (int)upb_strtable_count(&o->ntof);
}
uint32_t upb_oneofdef_index(const upb_oneofdef *o) {
return o->index;
}
+bool upb_oneofdef_synthetic(const upb_oneofdef *o) {
+ upb_inttable_iter iter;
+ const upb_fielddef *f;
+ upb_inttable_begin(&iter, &o->itof);
+ if (upb_oneofdef_numfields(o) != 1) return false;
+ f = upb_value_getptr(upb_inttable_iter_value(&iter));
+ UPB_ASSERT(f);
+ return f->proto3_optional_;
+}
+
const upb_fielddef *upb_oneofdef_ntof(const upb_oneofdef *o,
const char *name, size_t length) {
upb_value val;
@@ -3728,6 +3792,222 @@
upb_inttable_iter_setdone(iter);
}
+/* Dynamic Layout Generation. *************************************************/
+
+static bool is_power_of_two(size_t val) {
+ return (val & (val - 1)) == 0;
+}
+
+/* Align up to the given power of 2. */
+static size_t align_up(size_t val, size_t align) {
+ UPB_ASSERT(is_power_of_two(align));
+ return (val + align - 1) & ~(align - 1);
+}
+
+static size_t div_round_up(size_t n, size_t d) {
+ return (n + d - 1) / d;
+}
+
+static size_t upb_msgval_sizeof(upb_fieldtype_t type) {
+ switch (type) {
+ case UPB_TYPE_DOUBLE:
+ case UPB_TYPE_INT64:
+ case UPB_TYPE_UINT64:
+ return 8;
+ case UPB_TYPE_ENUM:
+ case UPB_TYPE_INT32:
+ case UPB_TYPE_UINT32:
+ case UPB_TYPE_FLOAT:
+ return 4;
+ case UPB_TYPE_BOOL:
+ return 1;
+ case UPB_TYPE_MESSAGE:
+ return sizeof(void*);
+ case UPB_TYPE_BYTES:
+ case UPB_TYPE_STRING:
+ return sizeof(upb_strview);
+ }
+ UPB_UNREACHABLE();
+}
+
+static uint8_t upb_msg_fielddefsize(const upb_fielddef *f) {
+ if (upb_msgdef_mapentry(upb_fielddef_containingtype(f))) {
+ upb_map_entry ent;
+ UPB_ASSERT(sizeof(ent.k) == sizeof(ent.v));
+ return sizeof(ent.k);
+ } else if (upb_fielddef_isseq(f)) {
+ return sizeof(void*);
+ } else {
+ return upb_msgval_sizeof(upb_fielddef_type(f));
+ }
+}
+
+static uint32_t upb_msglayout_place(upb_msglayout *l, size_t size) {
+ uint32_t ret;
+
+ l->size = align_up(l->size, size);
+ ret = l->size;
+ l->size += size;
+ return ret;
+}
+
+/* This function is the dynamic equivalent of message_layout.{cc,h} in upbc.
+ * It computes a dynamic layout for all of the fields in |m|. */
+static bool make_layout(const upb_symtab *symtab, const upb_msgdef *m) {
+ upb_msglayout *l = (upb_msglayout*)m->layout;
+ upb_msg_field_iter it;
+ upb_msg_oneof_iter oit;
+ size_t hasbit;
+ size_t submsg_count = m->submsg_field_count;
+ const upb_msglayout **submsgs;
+ upb_msglayout_field *fields;
+ upb_alloc *alloc = upb_arena_alloc(symtab->arena);
+
+ memset(l, 0, sizeof(*l));
+
+ fields = upb_malloc(alloc, upb_msgdef_numfields(m) * sizeof(*fields));
+ submsgs = upb_malloc(alloc, submsg_count * sizeof(*submsgs));
+
+ if ((!fields && upb_msgdef_numfields(m)) ||
+ (!submsgs && submsg_count)) {
+ /* OOM. */
+ return false;
+ }
+
+ l->field_count = upb_msgdef_numfields(m);
+ l->fields = fields;
+ l->submsgs = submsgs;
+
+ if (upb_msgdef_mapentry(m)) {
+ /* TODO(haberman): refactor this method so this special case is more
+ * elegant. */
+ const upb_fielddef *key = upb_msgdef_itof(m, 1);
+ const upb_fielddef *val = upb_msgdef_itof(m, 2);
+ fields[0].number = 1;
+ fields[1].number = 2;
+ fields[0].label = UPB_LABEL_OPTIONAL;
+ fields[1].label = UPB_LABEL_OPTIONAL;
+ fields[0].presence = 0;
+ fields[1].presence = 0;
+ fields[0].descriptortype = upb_fielddef_descriptortype(key);
+ fields[1].descriptortype = upb_fielddef_descriptortype(val);
+ fields[0].offset = 0;
+ fields[1].offset = sizeof(upb_strview);
+ fields[1].submsg_index = 0;
+
+ if (upb_fielddef_type(val) == UPB_TYPE_MESSAGE) {
+ submsgs[0] = upb_fielddef_msgsubdef(val)->layout;
+ }
+
+ l->field_count = 2;
+ l->size = 2 * sizeof(upb_strview);align_up(l->size, 8);
+ return true;
+ }
+
+ /* Allocate data offsets in three stages:
+ *
+ * 1. hasbits.
+ * 2. regular fields.
+ * 3. oneof fields.
+ *
+ * OPT: There is a lot of room for optimization here to minimize the size.
+ */
+
+ /* Allocate hasbits and set basic field attributes. */
+ submsg_count = 0;
+ for (upb_msg_field_begin(&it, m), hasbit = 0;
+ !upb_msg_field_done(&it);
+ upb_msg_field_next(&it)) {
+ upb_fielddef* f = upb_msg_iter_field(&it);
+ upb_msglayout_field *field = &fields[upb_fielddef_index(f)];
+
+ field->number = upb_fielddef_number(f);
+ field->descriptortype = upb_fielddef_descriptortype(f);
+ field->label = upb_fielddef_label(f);
+
+ if (upb_fielddef_ismap(f)) {
+ field->label = _UPB_LABEL_MAP;
+ } else if (upb_fielddef_packed(f)) {
+ field->label = _UPB_LABEL_PACKED;
+ }
+
+ /* TODO: we probably should sort the fields by field number to match the
+ * output of upbc, and to improve search speed for the table parser. */
+ f->layout_index = f->index_;
+
+ if (upb_fielddef_issubmsg(f)) {
+ const upb_msgdef *subm = upb_fielddef_msgsubdef(f);
+ field->submsg_index = submsg_count++;
+ submsgs[field->submsg_index] = subm->layout;
+ }
+
+ if (upb_fielddef_haspresence(f) && !upb_fielddef_containingoneof(f)) {
+ /* We don't use hasbit 0, so that 0 can indicate "no presence" in the
+ * table. This wastes one hasbit, but we don't worry about it for now. */
+ field->presence = ++hasbit;
+ } else {
+ field->presence = 0;
+ }
+ }
+
+ /* Account for space used by hasbits. */
+ l->size = div_round_up(hasbit, 8);
+
+ /* Allocate non-oneof fields. */
+ for (upb_msg_field_begin(&it, m); !upb_msg_field_done(&it);
+ upb_msg_field_next(&it)) {
+ const upb_fielddef* f = upb_msg_iter_field(&it);
+ size_t field_size = upb_msg_fielddefsize(f);
+ size_t index = upb_fielddef_index(f);
+
+ if (upb_fielddef_containingoneof(f)) {
+ /* Oneofs are handled separately below. */
+ continue;
+ }
+
+ fields[index].offset = upb_msglayout_place(l, field_size);
+ }
+
+ /* Allocate oneof fields. Each oneof field consists of a uint32 for the case
+ * and space for the actual data. */
+ for (upb_msg_oneof_begin(&oit, m); !upb_msg_oneof_done(&oit);
+ upb_msg_oneof_next(&oit)) {
+ const upb_oneofdef* o = upb_msg_iter_oneof(&oit);
+ upb_oneof_iter fit;
+
+ size_t case_size = sizeof(uint32_t); /* Could potentially optimize this. */
+ size_t field_size = 0;
+ uint32_t case_offset;
+ uint32_t data_offset;
+
+ /* Calculate field size: the max of all field sizes. */
+ for (upb_oneof_begin(&fit, o);
+ !upb_oneof_done(&fit);
+ upb_oneof_next(&fit)) {
+ const upb_fielddef* f = upb_oneof_iter_field(&fit);
+ field_size = UPB_MAX(field_size, upb_msg_fielddefsize(f));
+ }
+
+ /* Align and allocate case offset. */
+ case_offset = upb_msglayout_place(l, case_size);
+ data_offset = upb_msglayout_place(l, field_size);
+
+ for (upb_oneof_begin(&fit, o);
+ !upb_oneof_done(&fit);
+ upb_oneof_next(&fit)) {
+ const upb_fielddef* f = upb_oneof_iter_field(&fit);
+ fields[upb_fielddef_index(f)].offset = data_offset;
+ fields[upb_fielddef_index(f)].presence = ~case_offset;
+ }
+ }
+
+ /* Size of the entire structure should be a multiple of its greatest
+ * alignment. TODO: track overall alignment for real? */
+ l->size = align_up(l->size, 8);
+
+ return true;
+}
+
/* Code to build defs from descriptor protos. *********************************/
/* There is a question of how much validation to do here. It will be difficult
@@ -3740,11 +4020,12 @@
typedef struct {
const upb_symtab *symtab;
- upb_filedef *file; /* File we are building. */
- upb_alloc *alloc; /* Allocate defs here. */
- upb_alloc *tmp; /* Alloc for addtab and any other tmp data. */
- upb_strtable *addtab; /* full_name -> packed def ptr for new defs. */
- upb_status *status; /* Record errors here. */
+ upb_filedef *file; /* File we are building. */
+ upb_alloc *alloc; /* Allocate defs here. */
+ upb_alloc *tmp; /* Alloc for addtab and any other tmp data. */
+ upb_strtable *addtab; /* full_name -> packed def ptr for new defs */
+ const upb_msglayout **layouts; /* NULL if we should build layouts. */
+ upb_status *status; /* Record errors here. */
} symtab_addctx;
static char* strviewdup(const symtab_addctx *ctx, upb_strview view) {
@@ -3776,6 +4057,51 @@
}
}
+size_t getjsonname(const char *name, char *buf, size_t len) {
+ size_t src, dst = 0;
+ bool ucase_next = false;
+
+#define WRITE(byte) \
+ ++dst; \
+ if (dst < len) buf[dst - 1] = byte; \
+ else if (dst == len) buf[dst - 1] = '\0'
+
+ if (!name) {
+ WRITE('\0');
+ return 0;
+ }
+
+ /* Implement the transformation as described in the spec:
+ * 1. upper case all letters after an underscore.
+ * 2. remove all underscores.
+ */
+ for (src = 0; name[src]; src++) {
+ if (name[src] == '_') {
+ ucase_next = true;
+ continue;
+ }
+
+ if (ucase_next) {
+ WRITE(toupper(name[src]));
+ ucase_next = false;
+ } else {
+ WRITE(name[src]);
+ }
+ }
+
+ WRITE('\0');
+ return dst;
+
+#undef WRITE
+}
+
+static char* makejsonname(const char* name, upb_alloc *alloc) {
+ size_t size = getjsonname(name, NULL, 0);
+ char* json_name = upb_malloc(alloc, size);
+ getjsonname(name, json_name, size);
+ return json_name;
+}
+
static bool symtab_add(const symtab_addctx *ctx, const char *name,
upb_value v) {
upb_value tmp;
@@ -3899,7 +4225,7 @@
}
case UPB_TYPE_INT64: {
/* XXX: Need to write our own strtoll, since it's not available in c89. */
- long long val = strtol(str, &end, 0);
+ int64_t val = strtol(str, &end, 0);
CHK(val <= INT64_MAX && val >= INT64_MIN && errno != ERANGE && !*end);
f->defaultval.sint = val;
break;
@@ -3912,7 +4238,7 @@
}
case UPB_TYPE_UINT64: {
/* XXX: Need to write our own strtoull, since it's not available in c89. */
- unsigned long long val = strtoul(str, &end, 0);
+ uint64_t val = strtoul(str, &end, 0);
CHK(val <= UINT64_MAX && errno != ERANGE && !*end);
f->defaultval.uint = val;
break;
@@ -3989,6 +4315,7 @@
const google_protobuf_FieldOptions *options;
upb_strview name;
const char *full_name;
+ const char *json_name;
const char *shortname;
uint32_t field_number;
@@ -4002,6 +4329,13 @@
full_name = makefullname(ctx, prefix, name);
shortname = shortdefname(full_name);
+ if (google_protobuf_FieldDescriptorProto_has_json_name(field_proto)) {
+ json_name = strviewdup(
+ ctx, google_protobuf_FieldDescriptorProto_json_name(field_proto));
+ } else {
+ json_name = makejsonname(shortname, ctx->alloc);
+ }
+
field_number = google_protobuf_FieldDescriptorProto_number(field_proto);
if (field_number == 0 || field_number > UPB_MAX_FIELDNUMBER) {
@@ -4011,38 +4345,72 @@
if (m) {
/* direct message field. */
- upb_value v, packed_v;
+ upb_value v, field_v, json_v;
+ size_t json_size;
f = (upb_fielddef*)&m->fields[m->field_count++];
f->msgdef = m;
f->is_extension_ = false;
- packed_v = pack_def(f, UPB_DEFTYPE_FIELD);
- v = upb_value_constptr(f);
-
- if (!upb_strtable_insert3(&m->ntof, name.data, name.size, packed_v, alloc)) {
+ if (upb_strtable_lookup(&m->ntof, shortname, NULL)) {
upb_status_seterrf(ctx->status, "duplicate field name (%s)", shortname);
return false;
}
- if (!upb_inttable_insert2(&m->itof, field_number, v, alloc)) {
+ if (upb_strtable_lookup(&m->ntof, json_name, NULL)) {
+ upb_status_seterrf(ctx->status, "duplicate json_name (%s)", json_name);
+ return false;
+ }
+
+ if (upb_inttable_lookup(&m->itof, field_number, NULL)) {
upb_status_seterrf(ctx->status, "duplicate field number (%u)",
field_number);
return false;
}
+
+ field_v = pack_def(f, UPB_DEFTYPE_FIELD);
+ json_v = pack_def(f, UPB_DEFTYPE_FIELD_JSONNAME);
+ v = upb_value_constptr(f);
+ json_size = strlen(json_name);
+
+ CHK_OOM(
+ upb_strtable_insert3(&m->ntof, name.data, name.size, field_v, alloc));
+ CHK_OOM(upb_inttable_insert2(&m->itof, field_number, v, alloc));
+
+ if (strcmp(shortname, json_name) != 0) {
+ upb_strtable_insert3(&m->ntof, json_name, json_size, json_v, alloc);
+ }
+
+ if (ctx->layouts) {
+ const upb_msglayout_field *fields = m->layout->fields;
+ int count = m->layout->field_count;
+ bool found = false;
+ int i;
+ for (i = 0; i < count; i++) {
+ if (fields[i].number == field_number) {
+ f->layout_index = i;
+ found = true;
+ break;
+ }
+ }
+ UPB_ASSERT(found);
+ }
} else {
/* extension field. */
- f = (upb_fielddef*)&ctx->file->exts[ctx->file->ext_count];
+ f = (upb_fielddef*)&ctx->file->exts[ctx->file->ext_count++];
f->is_extension_ = true;
CHK_OOM(symtab_add(ctx, full_name, pack_def(f, UPB_DEFTYPE_FIELD)));
}
f->full_name = full_name;
+ f->json_name = json_name;
f->file = ctx->file;
f->type_ = (int)google_protobuf_FieldDescriptorProto_type(field_proto);
f->label_ = (int)google_protobuf_FieldDescriptorProto_label(field_proto);
f->number_ = field_number;
f->oneof = NULL;
+ f->proto3_optional_ =
+ google_protobuf_FieldDescriptorProto_proto3_optional(field_proto);
/* We can't resolve the subdef or (in the case of extensions) the containing
* message yet, because it may not have been defined yet. We stash a pointer
@@ -4166,7 +4534,7 @@
return true;
}
-static bool create_msgdef(const symtab_addctx *ctx, const char *prefix,
+static bool create_msgdef(symtab_addctx *ctx, const char *prefix,
const google_protobuf_DescriptorProto *msg_proto) {
upb_msgdef *m;
const google_protobuf_MessageOptions *options;
@@ -4196,6 +4564,14 @@
m->map_entry = google_protobuf_MessageOptions_map_entry(options);
}
+ if (ctx->layouts) {
+ m->layout = *ctx->layouts;
+ ctx->layouts++;
+ } else {
+ /* Allocate now (to allow cross-linking), populate later. */
+ m->layout = upb_malloc(ctx->alloc, sizeof(*m->layout));
+ }
+
oneofs = google_protobuf_DescriptorProto_oneof_decl(msg_proto, &n);
m->oneof_count = 0;
m->oneofs = upb_malloc(ctx->alloc, sizeof(*m->oneofs) * n);
@@ -4342,7 +4718,7 @@
}
static bool build_filedef(
- const symtab_addctx *ctx, upb_filedef *file,
+ symtab_addctx *ctx, upb_filedef *file,
const google_protobuf_FileDescriptorProto *file_proto) {
upb_alloc *alloc = ctx->alloc;
const google_protobuf_FileOptions *file_options_proto;
@@ -4396,7 +4772,8 @@
} else if (streql_view(syntax, "proto3")) {
file->syntax = UPB_SYNTAX_PROTO3;
} else {
- upb_status_seterrf(ctx->status, "Invalid syntax '%s'", syntax);
+ upb_status_seterrf(ctx->status, "Invalid syntax '" UPB_STRVIEW_FORMAT "'",
+ UPB_STRVIEW_ARGS(syntax));
return false;
}
} else {
@@ -4456,7 +4833,7 @@
CHK(create_fielddef(ctx, file->package, NULL, exts[i]));
}
- /* Now that all names are in the table, resolve references. */
+ /* Now that all names are in the table, build layouts and resolve refs. */
for (i = 0; i < file->ext_count; i++) {
CHK(resolve_fielddef(ctx, file->package, (upb_fielddef*)&file->exts[i]));
}
@@ -4469,6 +4846,13 @@
}
}
+ if (!ctx->layouts) {
+ for (i = 0; i < file->msg_count; i++) {
+ const upb_msgdef *m = &file->msgs[i];
+ make_layout(ctx->symtab, m);
+ }
+ }
+
return true;
}
@@ -4483,10 +4867,9 @@
upb_strtable_begin(&iter, ctx->addtab);
for (; !upb_strtable_done(&iter); upb_strtable_next(&iter)) {
- const char *key = upb_strtable_iter_key(&iter);
- size_t keylen = upb_strtable_iter_keylength(&iter);
+ upb_strview key = upb_strtable_iter_key(&iter);
upb_value value = upb_strtable_iter_value(&iter);
- CHK_OOM(upb_strtable_insert3(&s->syms, key, keylen, value, alloc));
+ CHK_OOM(upb_strtable_insert3(&s->syms, key.data, key.size, value, alloc));
}
return true;
@@ -4588,9 +4971,13 @@
: NULL;
}
-const upb_filedef *upb_symtab_addfile(
+int upb_symtab_filecount(const upb_symtab *s) {
+ return (int)upb_strtable_count(&s->files);
+}
+
+static const upb_filedef *_upb_symtab_addfile(
upb_symtab *s, const google_protobuf_FileDescriptorProto *file_proto,
- upb_status *status) {
+ const upb_msglayout **layouts, upb_status *status) {
upb_arena *tmparena = upb_arena_new();
upb_strtable addtab;
upb_alloc *alloc = upb_arena_alloc(s->arena);
@@ -4603,6 +4990,7 @@
ctx.alloc = alloc;
ctx.tmp = upb_arena_alloc(tmparena);
ctx.addtab = &addtab;
+ ctx.layouts = layouts;
ctx.status = status;
ok = file &&
@@ -4614,6 +5002,12 @@
return ok ? file : NULL;
}
+const upb_filedef *upb_symtab_addfile(
+ upb_symtab *s, const google_protobuf_FileDescriptorProto *file_proto,
+ upb_status *status) {
+ return _upb_symtab_addfile(s, file_proto, NULL, status);
+}
+
/* Include here since we want most of this file to be stdio-free. */
#include <stdio.h>
@@ -4649,7 +5043,7 @@
goto err;
}
- if (!upb_symtab_addfile(s, file, &status)) goto err;
+ if (!_upb_symtab_addfile(s, file, init->layouts, &status)) goto err;
upb_arena_free(arena);
return true;
@@ -4665,250 +5059,311 @@
#undef CHK_OOM
+#include <string.h>
-static bool is_power_of_two(size_t val) {
- return (val & (val - 1)) == 0;
+
+static char field_size[] = {
+ 0,/* 0 */
+ 8, /* UPB_DESCRIPTOR_TYPE_DOUBLE */
+ 4, /* UPB_DESCRIPTOR_TYPE_FLOAT */
+ 8, /* UPB_DESCRIPTOR_TYPE_INT64 */
+ 8, /* UPB_DESCRIPTOR_TYPE_UINT64 */
+ 4, /* UPB_DESCRIPTOR_TYPE_INT32 */
+ 8, /* UPB_DESCRIPTOR_TYPE_FIXED64 */
+ 4, /* UPB_DESCRIPTOR_TYPE_FIXED32 */
+ 1, /* UPB_DESCRIPTOR_TYPE_BOOL */
+ sizeof(upb_strview), /* UPB_DESCRIPTOR_TYPE_STRING */
+ sizeof(void*), /* UPB_DESCRIPTOR_TYPE_GROUP */
+ sizeof(void*), /* UPB_DESCRIPTOR_TYPE_MESSAGE */
+ sizeof(upb_strview), /* UPB_DESCRIPTOR_TYPE_BYTES */
+ 4, /* UPB_DESCRIPTOR_TYPE_UINT32 */
+ 4, /* UPB_DESCRIPTOR_TYPE_ENUM */
+ 4, /* UPB_DESCRIPTOR_TYPE_SFIXED32 */
+ 8, /* UPB_DESCRIPTOR_TYPE_SFIXED64 */
+ 4, /* UPB_DESCRIPTOR_TYPE_SINT32 */
+ 8, /* UPB_DESCRIPTOR_TYPE_SINT64 */
+};
+
+/* Strings/bytes are special-cased in maps. */
+static char _upb_fieldtype_to_mapsize[12] = {
+ 0,
+ 1, /* UPB_TYPE_BOOL */
+ 4, /* UPB_TYPE_FLOAT */
+ 4, /* UPB_TYPE_INT32 */
+ 4, /* UPB_TYPE_UINT32 */
+ 4, /* UPB_TYPE_ENUM */
+ sizeof(void*), /* UPB_TYPE_MESSAGE */
+ 8, /* UPB_TYPE_DOUBLE */
+ 8, /* UPB_TYPE_INT64 */
+ 8, /* UPB_TYPE_UINT64 */
+ 0, /* UPB_TYPE_STRING */
+ 0, /* UPB_TYPE_BYTES */
+};
+
+/** upb_msg *******************************************************************/
+
+upb_msg *upb_msg_new(const upb_msgdef *m, upb_arena *a) {
+ return _upb_msg_new(upb_msgdef_layout(m), a);
}
-/* Align up to the given power of 2. */
-static size_t align_up(size_t val, size_t align) {
- UPB_ASSERT(is_power_of_two(align));
- return (val + align - 1) & ~(align - 1);
+static bool in_oneof(const upb_msglayout_field *field) {
+ return field->presence < 0;
}
-static size_t div_round_up(size_t n, size_t d) {
- return (n + d - 1) / d;
+static uint32_t *oneofcase(const upb_msg *msg,
+ const upb_msglayout_field *field) {
+ UPB_ASSERT(in_oneof(field));
+ return UPB_PTR_AT(msg, -field->presence, uint32_t);
}
-static size_t upb_msgval_sizeof2(upb_fieldtype_t type) {
- switch (type) {
- case UPB_TYPE_DOUBLE:
- case UPB_TYPE_INT64:
- case UPB_TYPE_UINT64:
- return 8;
- case UPB_TYPE_ENUM:
- case UPB_TYPE_INT32:
- case UPB_TYPE_UINT32:
- case UPB_TYPE_FLOAT:
- return 4;
- case UPB_TYPE_BOOL:
- return 1;
- case UPB_TYPE_MESSAGE:
- return sizeof(void*);
- case UPB_TYPE_BYTES:
- case UPB_TYPE_STRING:
- return sizeof(upb_strview);
- }
- UPB_UNREACHABLE();
+static upb_msgval _upb_msg_getraw(const upb_msg *msg, const upb_fielddef *f) {
+ const upb_msglayout_field *field = upb_fielddef_layout(f);
+ const char *mem = UPB_PTR_AT(msg, field->offset, char);
+ upb_msgval val = {0};
+ int size = upb_fielddef_isseq(f) ? sizeof(void *)
+ : field_size[field->descriptortype];
+ memcpy(&val, mem, size);
+ return val;
}
-static uint8_t upb_msg_fielddefsize(const upb_fielddef *f) {
- if (upb_fielddef_isseq(f)) {
- return sizeof(void*);
+bool upb_msg_has(const upb_msg *msg, const upb_fielddef *f) {
+ const upb_msglayout_field *field = upb_fielddef_layout(f);
+ if (in_oneof(field)) {
+ return *oneofcase(msg, field) == field->number;
+ } else if (field->presence > 0) {
+ uint32_t hasbit = field->presence;
+ return *UPB_PTR_AT(msg, hasbit / 8, uint8_t) & (1 << (hasbit % 8));
} else {
- return upb_msgval_sizeof2(upb_fielddef_type(f));
+ UPB_ASSERT(field->descriptortype == UPB_DESCRIPTOR_TYPE_MESSAGE ||
+ field->descriptortype == UPB_DESCRIPTOR_TYPE_GROUP);
+ return _upb_msg_getraw(msg, f).msg_val != NULL;
}
}
+bool upb_msg_hasoneof(const upb_msg *msg, const upb_oneofdef *o) {
+ upb_oneof_iter i;
+ const upb_fielddef *f;
+ const upb_msglayout_field *field;
-/** upb_msglayout *************************************************************/
-
-static void upb_msglayout_free(upb_msglayout *l) {
- upb_gfree(l);
+ upb_oneof_begin(&i, o);
+ if (upb_oneof_done(&i)) return false;
+ f = upb_oneof_iter_field(&i);
+ field = upb_fielddef_layout(f);
+ return *oneofcase(msg, field) != 0;
}
-static size_t upb_msglayout_place(upb_msglayout *l, size_t size) {
- size_t ret;
+upb_msgval upb_msg_get(const upb_msg *msg, const upb_fielddef *f) {
+ if (!upb_fielddef_haspresence(f) || upb_msg_has(msg, f)) {
+ return _upb_msg_getraw(msg, f);
+ } else {
+ /* TODO(haberman): change upb_fielddef to not require this switch(). */
+ upb_msgval val = {0};
+ switch (upb_fielddef_type(f)) {
+ case UPB_TYPE_INT32:
+ case UPB_TYPE_ENUM:
+ val.int32_val = upb_fielddef_defaultint32(f);
+ break;
+ case UPB_TYPE_INT64:
+ val.int64_val = upb_fielddef_defaultint64(f);
+ break;
+ case UPB_TYPE_UINT32:
+ val.uint32_val = upb_fielddef_defaultuint32(f);
+ break;
+ case UPB_TYPE_UINT64:
+ val.uint64_val = upb_fielddef_defaultuint64(f);
+ break;
+ case UPB_TYPE_FLOAT:
+ val.float_val = upb_fielddef_defaultfloat(f);
+ break;
+ case UPB_TYPE_DOUBLE:
+ val.double_val = upb_fielddef_defaultdouble(f);
+ break;
+ case UPB_TYPE_BOOL:
+ val.double_val = upb_fielddef_defaultbool(f);
+ break;
+ case UPB_TYPE_STRING:
+ case UPB_TYPE_BYTES:
+ val.str_val.data = upb_fielddef_defaultstr(f, &val.str_val.size);
+ break;
+ case UPB_TYPE_MESSAGE:
+ val.msg_val = NULL;
+ break;
+ }
+ return val;
+ }
+}
- l->size = align_up(l->size, size);
- ret = l->size;
- l->size += size;
+upb_mutmsgval upb_msg_mutable(upb_msg *msg, const upb_fielddef *f,
+ upb_arena *a) {
+ const upb_msglayout_field *field = upb_fielddef_layout(f);
+ upb_mutmsgval ret;
+ char *mem = UPB_PTR_AT(msg, field->offset, char);
+ bool wrong_oneof = in_oneof(field) && *oneofcase(msg, field) != field->number;
+
+ memcpy(&ret, mem, sizeof(void*));
+
+ if (a && (!ret.msg || wrong_oneof)) {
+ if (upb_fielddef_ismap(f)) {
+ const upb_msgdef *entry = upb_fielddef_msgsubdef(f);
+ const upb_fielddef *key = upb_msgdef_itof(entry, UPB_MAPENTRY_KEY);
+ const upb_fielddef *value = upb_msgdef_itof(entry, UPB_MAPENTRY_VALUE);
+ ret.map = upb_map_new(a, upb_fielddef_type(key), upb_fielddef_type(value));
+ } else if (upb_fielddef_isseq(f)) {
+ ret.array = upb_array_new(a, upb_fielddef_type(f));
+ } else {
+ UPB_ASSERT(upb_fielddef_issubmsg(f));
+ ret.msg = upb_msg_new(upb_fielddef_msgsubdef(f), a);
+ }
+
+ memcpy(mem, &ret, sizeof(void*));
+
+ if (wrong_oneof) {
+ *oneofcase(msg, field) = field->number;
+ }
+ }
return ret;
}
-static bool upb_msglayout_init(const upb_msgdef *m,
- upb_msglayout *l,
- upb_msgfactory *factory) {
- upb_msg_field_iter it;
- upb_msg_oneof_iter oit;
- size_t hasbit;
- size_t submsg_count = 0;
- const upb_msglayout **submsgs;
- upb_msglayout_field *fields;
-
- for (upb_msg_field_begin(&it, m);
- !upb_msg_field_done(&it);
- upb_msg_field_next(&it)) {
- const upb_fielddef* f = upb_msg_iter_field(&it);
- if (upb_fielddef_issubmsg(f)) {
- submsg_count++;
- }
+void upb_msg_set(upb_msg *msg, const upb_fielddef *f, upb_msgval val,
+ upb_arena *a) {
+ const upb_msglayout_field *field = upb_fielddef_layout(f);
+ char *mem = UPB_PTR_AT(msg, field->offset, char);
+ int size = upb_fielddef_isseq(f) ? sizeof(void *)
+ : field_size[field->descriptortype];
+ memcpy(mem, &val, size);
+ if (in_oneof(field)) {
+ *oneofcase(msg, field) = field->number;
}
+}
- memset(l, 0, sizeof(*l));
+bool upb_msg_next(const upb_msg *msg, const upb_msgdef *m,
+ const upb_symtab *ext_pool, const upb_fielddef **out_f,
+ upb_msgval *out_val, size_t *iter) {
+ size_t i = *iter;
+ const upb_msgval zero = {0};
+ const upb_fielddef *f;
+ while ((f = _upb_msgdef_field(m, (int)++i)) != NULL) {
+ upb_msgval val = _upb_msg_getraw(msg, f);
- fields = upb_gmalloc(upb_msgdef_numfields(m) * sizeof(*fields));
- submsgs = upb_gmalloc(submsg_count * sizeof(*submsgs));
+ /* Skip field if unset or empty. */
+ if (upb_fielddef_haspresence(f)) {
+ if (!upb_msg_has(msg, f)) continue;
+ } else {
+ upb_msgval test = val;
+ if (upb_fielddef_isstring(f) && !upb_fielddef_isseq(f)) {
+ /* Clear string pointer, only size matters (ptr could be non-NULL). */
+ test.str_val.data = NULL;
+ }
+ /* Continue if NULL or 0. */
+ if (memcmp(&test, &zero, sizeof(test)) == 0) continue;
- if ((!fields && upb_msgdef_numfields(m)) ||
- (!submsgs && submsg_count)) {
- /* OOM. */
- upb_gfree(fields);
- upb_gfree(submsgs);
+ /* Continue on empty array or map. */
+ if (upb_fielddef_ismap(f)) {
+ if (upb_map_size(test.map_val) == 0) continue;
+ } else if (upb_fielddef_isseq(f)) {
+ if (upb_array_size(test.array_val) == 0) continue;
+ }
+ }
+
+ *out_val = val;
+ *out_f = f;
+ *iter = i;
+ return true;
+ }
+ *iter = i;
+ return false;
+}
+
+/** upb_array *****************************************************************/
+
+upb_array *upb_array_new(upb_arena *a, upb_fieldtype_t type) {
+ return _upb_array_new(a, type);
+}
+
+size_t upb_array_size(const upb_array *arr) {
+ return arr->len;
+}
+
+upb_msgval upb_array_get(const upb_array *arr, size_t i) {
+ upb_msgval ret;
+ const char* data = _upb_array_constptr(arr);
+ int lg2 = arr->data & 7;
+ UPB_ASSERT(i < arr->len);
+ memcpy(&ret, data + (i << lg2), 1 << lg2);
+ return ret;
+}
+
+void upb_array_set(upb_array *arr, size_t i, upb_msgval val) {
+ char* data = _upb_array_ptr(arr);
+ int lg2 = arr->data & 7;
+ UPB_ASSERT(i < arr->len);
+ memcpy(data + (i << lg2), &val, 1 << lg2);
+}
+
+bool upb_array_append(upb_array *arr, upb_msgval val, upb_arena *arena) {
+ if (!_upb_array_realloc(arr, arr->len + 1, arena)) {
return false;
}
-
- l->field_count = upb_msgdef_numfields(m);
- l->fields = fields;
- l->submsgs = submsgs;
-
- /* Allocate data offsets in three stages:
- *
- * 1. hasbits.
- * 2. regular fields.
- * 3. oneof fields.
- *
- * OPT: There is a lot of room for optimization here to minimize the size.
- */
-
- /* Allocate hasbits and set basic field attributes. */
- submsg_count = 0;
- for (upb_msg_field_begin(&it, m), hasbit = 0;
- !upb_msg_field_done(&it);
- upb_msg_field_next(&it)) {
- const upb_fielddef* f = upb_msg_iter_field(&it);
- upb_msglayout_field *field = &fields[upb_fielddef_index(f)];
-
- field->number = upb_fielddef_number(f);
- field->descriptortype = upb_fielddef_descriptortype(f);
- field->label = upb_fielddef_label(f);
-
- if (upb_fielddef_issubmsg(f)) {
- const upb_msglayout *sub_layout =
- upb_msgfactory_getlayout(factory, upb_fielddef_msgsubdef(f));
- field->submsg_index = submsg_count++;
- submsgs[field->submsg_index] = sub_layout;
- }
-
- if (upb_fielddef_haspresence(f) && !upb_fielddef_containingoneof(f)) {
- field->presence = (hasbit++);
- } else {
- field->presence = 0;
- }
- }
-
- /* Account for space used by hasbits. */
- l->size = div_round_up(hasbit, 8);
-
- /* Allocate non-oneof fields. */
- for (upb_msg_field_begin(&it, m); !upb_msg_field_done(&it);
- upb_msg_field_next(&it)) {
- const upb_fielddef* f = upb_msg_iter_field(&it);
- size_t field_size = upb_msg_fielddefsize(f);
- size_t index = upb_fielddef_index(f);
-
- if (upb_fielddef_containingoneof(f)) {
- /* Oneofs are handled separately below. */
- continue;
- }
-
- fields[index].offset = upb_msglayout_place(l, field_size);
- }
-
- /* Allocate oneof fields. Each oneof field consists of a uint32 for the case
- * and space for the actual data. */
- for (upb_msg_oneof_begin(&oit, m); !upb_msg_oneof_done(&oit);
- upb_msg_oneof_next(&oit)) {
- const upb_oneofdef* o = upb_msg_iter_oneof(&oit);
- upb_oneof_iter fit;
-
- size_t case_size = sizeof(uint32_t); /* Could potentially optimize this. */
- size_t field_size = 0;
- uint32_t case_offset;
- uint32_t data_offset;
-
- /* Calculate field size: the max of all field sizes. */
- for (upb_oneof_begin(&fit, o);
- !upb_oneof_done(&fit);
- upb_oneof_next(&fit)) {
- const upb_fielddef* f = upb_oneof_iter_field(&fit);
- field_size = UPB_MAX(field_size, upb_msg_fielddefsize(f));
- }
-
- /* Align and allocate case offset. */
- case_offset = upb_msglayout_place(l, case_size);
- data_offset = upb_msglayout_place(l, field_size);
-
- for (upb_oneof_begin(&fit, o);
- !upb_oneof_done(&fit);
- upb_oneof_next(&fit)) {
- const upb_fielddef* f = upb_oneof_iter_field(&fit);
- fields[upb_fielddef_index(f)].offset = data_offset;
- fields[upb_fielddef_index(f)].presence = ~case_offset;
- }
- }
-
- /* Size of the entire structure should be a multiple of its greatest
- * alignment. TODO: track overall alignment for real? */
- l->size = align_up(l->size, 8);
-
+ arr->len++;
+ upb_array_set(arr, arr->len - 1, val);
return true;
}
+/* Resizes the array to the given size, reallocating if necessary, and returns a
+ * pointer to the new array elements. */
+bool upb_array_resize(upb_array *arr, size_t size, upb_arena *arena) {
+ return _upb_array_realloc(arr, size, arena);
+}
-/** upb_msgfactory ************************************************************/
+/** upb_map *******************************************************************/
-struct upb_msgfactory {
- const upb_symtab *symtab; /* We own a ref. */
- upb_inttable layouts;
-};
+upb_map *upb_map_new(upb_arena *a, upb_fieldtype_t key_type,
+ upb_fieldtype_t value_type) {
+ return _upb_map_new(a, _upb_fieldtype_to_mapsize[key_type],
+ _upb_fieldtype_to_mapsize[value_type]);
+}
-upb_msgfactory *upb_msgfactory_new(const upb_symtab *symtab) {
- upb_msgfactory *ret = upb_gmalloc(sizeof(*ret));
+size_t upb_map_size(const upb_map *map) {
+ return _upb_map_size(map);
+}
- ret->symtab = symtab;
- upb_inttable_init(&ret->layouts, UPB_CTYPE_PTR);
+bool upb_map_get(const upb_map *map, upb_msgval key, upb_msgval *val) {
+ return _upb_map_get(map, &key, map->key_size, val, map->val_size);
+}
+bool upb_map_set(upb_map *map, upb_msgval key, upb_msgval val,
+ upb_arena *arena) {
+ return _upb_map_set(map, &key, map->key_size, &val, map->val_size, arena);
+}
+
+bool upb_map_delete(upb_map *map, upb_msgval key) {
+ return _upb_map_delete(map, &key, map->key_size);
+}
+
+bool upb_mapiter_next(const upb_map *map, size_t *iter) {
+ return _upb_map_next(map, iter);
+}
+
+/* Returns the key and value for this entry of the map. */
+upb_msgval upb_mapiter_key(const upb_map *map, size_t iter) {
+ upb_strtable_iter i;
+ upb_msgval ret;
+ i.t = &map->table;
+ i.index = iter;
+ _upb_map_fromkey(upb_strtable_iter_key(&i), &ret, map->key_size);
return ret;
}
-void upb_msgfactory_free(upb_msgfactory *f) {
- upb_inttable_iter i;
- upb_inttable_begin(&i, &f->layouts);
- for(; !upb_inttable_done(&i); upb_inttable_next(&i)) {
- upb_msglayout *l = upb_value_getptr(upb_inttable_iter_value(&i));
- upb_msglayout_free(l);
- }
-
- upb_inttable_uninit(&f->layouts);
- upb_gfree(f);
+upb_msgval upb_mapiter_value(const upb_map *map, size_t iter) {
+ upb_strtable_iter i;
+ upb_msgval ret;
+ i.t = &map->table;
+ i.index = iter;
+ _upb_map_fromvalue(upb_strtable_iter_value(&i), &ret, map->val_size);
+ return ret;
}
-const upb_symtab *upb_msgfactory_symtab(const upb_msgfactory *f) {
- return f->symtab;
-}
-
-const upb_msglayout *upb_msgfactory_getlayout(upb_msgfactory *f,
- const upb_msgdef *m) {
- upb_value v;
- UPB_ASSERT(upb_symtab_lookupmsg(f->symtab, upb_msgdef_fullname(m)) == m);
- UPB_ASSERT(!upb_msgdef_mapentry(m));
-
- if (upb_inttable_lookupptr(&f->layouts, m, &v)) {
- UPB_ASSERT(upb_value_getptr(v));
- return upb_value_getptr(v);
- } else {
- /* In case of circular dependency, layout has to be inserted first. */
- upb_msglayout *l = upb_gmalloc(sizeof(*l));
- upb_msgfactory *mutable_f = (void*)f;
- upb_inttable_insertptr(&mutable_f->layouts, m, upb_value_ptr(l));
- UPB_ASSERT(l);
- if (!upb_msglayout_init(m, l, f)) {
- upb_msglayout_free(l);
- }
- return l;
- }
-}
+/* void upb_mapiter_setvalue(upb_map *map, size_t iter, upb_msgval value); */
/*
** TODO(haberman): it's unclear whether a lot of the consistency checks should
** UPB_ASSERT() or return false.
@@ -5088,7 +5543,8 @@
int extra;
upb_handlers *h;
- extra = sizeof(upb_handlers_tabent) * (upb_msgdef_selectorcount(md) - 1);
+ extra =
+ (int)(sizeof(upb_handlers_tabent) * (upb_msgdef_selectorcount(md) - 1));
h = upb_calloc(arena, sizeof(*h) + extra);
if (!h) return NULL;
@@ -5489,6 +5945,31 @@
}
return ret;
}
+
+
+#ifdef UPB_MSVC_VSNPRINTF
+/* Visual C++ earlier than 2015 doesn't have standard C99 snprintf and
+ * vsnprintf. To support them, missing functions are manually implemented
+ * using the existing secure functions. */
+int msvc_vsnprintf(char* s, size_t n, const char* format, va_list arg) {
+ if (!s) {
+ return _vscprintf(format, arg);
+ }
+ int ret = _vsnprintf_s(s, n, _TRUNCATE, format, arg);
+ if (ret < 0) {
+ ret = _vscprintf(format, arg);
+ }
+ return ret;
+}
+
+int msvc_snprintf(char* s, size_t n, const char* format, ...) {
+ va_list arg;
+ va_start(arg, format);
+ int ret = msvc_vsnprintf(s, n, format, arg);
+ va_end(arg);
+ return ret;
+}
+#endif
/*
** protobuf decoder bytecode compiler
**
@@ -5644,7 +6125,9 @@
UPB_ASSERT(getofs(*instruction) == ofs); /* Would fail in cases of overflow. */
}
-static uint32_t pcofs(compiler *c) { return c->pc - c->group->bytecode; }
+static uint32_t pcofs(compiler *c) {
+ return (uint32_t)(c->pc - c->group->bytecode);
+}
/* Defines a local label at the current PC location. All previous forward
* references are updated to point to this location. The location is noted
@@ -5658,7 +6141,7 @@
codep = (val == EMPTYLABEL) ? NULL : c->group->bytecode + val;
while (codep) {
int ofs = getofs(*codep);
- setofs(codep, c->pc - codep - instruction_len(*codep));
+ setofs(codep, (int32_t)(c->pc - codep - instruction_len(*codep)));
codep = ofs ? codep + ofs : NULL;
}
c->fwd_labels[label] = EMPTYLABEL;
@@ -5680,7 +6163,7 @@
return 0;
} else if (label < 0) {
/* Backward local label. Relative to the next instruction. */
- uint32_t from = (c->pc + 1) - c->group->bytecode;
+ uint32_t from = (uint32_t)((c->pc + 1) - c->group->bytecode);
return c->back_labels[-label] - from;
} else {
/* Forward local label: prepend to (possibly-empty) linked list. */
@@ -5714,7 +6197,7 @@
case OP_SETDISPATCH: {
uintptr_t ptr = (uintptr_t)va_arg(ap, void*);
put32(c, OP_SETDISPATCH);
- put32(c, ptr);
+ put32(c, (uint32_t)ptr);
if (sizeof(uintptr_t) > sizeof(uint32_t))
put32(c, (uint64_t)ptr >> 32);
break;
@@ -5773,7 +6256,7 @@
case OP_TAG2: {
int label = va_arg(ap, int);
uint64_t tag = va_arg(ap, uint64_t);
- uint32_t instruction = op | (tag << 16);
+ uint32_t instruction = (uint32_t)(op | (tag << 16));
UPB_ASSERT(tag <= 0xffff);
setofs(&instruction, labelref(c, label));
put32(c, instruction);
@@ -5785,7 +6268,7 @@
uint32_t instruction = op | (upb_value_size(tag) << 16);
setofs(&instruction, labelref(c, label));
put32(c, instruction);
- put32(c, tag);
+ put32(c, (uint32_t)tag);
put32(c, tag >> 32);
break;
}
@@ -6398,11 +6881,11 @@
} else {
g = mgroup_new(h, c->lazy);
ok = upb_inttable_insertptr(&c->groups, md, upb_value_constptr(g));
- UPB_ASSERT(ok);
+ UPB_ASSUME(ok);
}
ok = upb_inttable_lookupptr(&g->methods, h, &v);
- UPB_ASSERT(ok);
+ UPB_ASSUME(ok);
return upb_value_getptr(v);
}
/*
@@ -6589,7 +7072,7 @@
UPB_ASSERT(d->skip == 0);
if (bytes > delim_remaining(d)) {
seterr(d, "Skipped value extended beyond enclosing submessage.");
- return upb_pbdecoder_suspend(d);
+ return (int32_t)upb_pbdecoder_suspend(d);
} else if (bufleft(d) >= bytes) {
/* Skipped data is all in current buffer, and more is still available. */
advance(d, bytes);
@@ -6602,7 +7085,7 @@
d->bufstart_ofs += (d->end - d->buf);
d->residual_end = d->residual;
switchtobuf(d, d->residual, d->residual_end);
- return d->size_param + d->skip;
+ return (int32_t)(d->size_param + d->skip);
}
}
@@ -6642,7 +7125,7 @@
/* NULL buf is ok if its entire span is covered by the "skip" above, but
* by this point we know that "skip" doesn't cover the buffer. */
seterr(d, "Passed NULL buffer over non-skippable region.");
- return upb_pbdecoder_suspend(d);
+ return (int32_t)upb_pbdecoder_suspend(d);
}
if (d->residual_end > d->residual) {
@@ -6752,9 +7235,9 @@
return DECODE_OK;
} else if (d->data_end == d->delim_end) {
seterr(d, "Submessage ended in the middle of a value or group");
- return upb_pbdecoder_suspend(d);
+ return (int32_t)upb_pbdecoder_suspend(d);
} else {
- return suspend_save(d);
+ return (int32_t)suspend_save(d);
}
}
@@ -6810,7 +7293,7 @@
}
if(bitpos == 70 && (byte & 0x80)) {
seterr(d, kUnterminatedVarint);
- return upb_pbdecoder_suspend(d);
+ return (int32_t)upb_pbdecoder_suspend(d);
}
return DECODE_OK;
}
@@ -6827,7 +7310,7 @@
upb_decoderet r = upb_vdecode_fast(d->ptr);
if (r.p == NULL) {
seterr(d, kUnterminatedVarint);
- return upb_pbdecoder_suspend(d);
+ return (int32_t)upb_pbdecoder_suspend(d);
}
advance(d, r.p - d->ptr);
*u64 = r.val;
@@ -6851,9 +7334,9 @@
* Right now the size_t -> int32_t can overflow and produce negative values.
*/
*u32 = 0;
- return upb_pbdecoder_suspend(d);
+ return (int32_t)upb_pbdecoder_suspend(d);
}
- *u32 = u64;
+ *u32 = (uint32_t)u64;
return DECODE_OK;
}
@@ -6929,7 +7412,7 @@
UPB_ASSERT(ok < 0);
return DECODE_OK;
} else if (read < bytes && memcmp(&data, &expected, read) == 0) {
- return suspend_save(d);
+ return (int32_t)suspend_save(d);
} else {
return DECODE_MISMATCH;
}
@@ -6949,7 +7432,7 @@
have_tag:
if (fieldnum == 0) {
seterr(d, "Saw invalid field number (0)");
- return upb_pbdecoder_suspend(d);
+ return (int32_t)upb_pbdecoder_suspend(d);
}
switch (wire_type) {
@@ -6971,7 +7454,9 @@
break;
}
case UPB_WIRE_TYPE_START_GROUP:
- CHECK_SUSPEND(pushtagdelim(d, -fieldnum));
+ if (!pushtagdelim(d, -fieldnum)) {
+ return (int32_t)upb_pbdecoder_suspend(d);
+ }
break;
case UPB_WIRE_TYPE_END_GROUP:
if (fieldnum == -d->top->groupnum) {
@@ -6980,12 +7465,12 @@
return DECODE_ENDGROUP;
} else {
seterr(d, "Unmatched ENDGROUP tag.");
- return upb_pbdecoder_suspend(d);
+ return (int32_t)upb_pbdecoder_suspend(d);
}
break;
default:
seterr(d, "Invalid wire type");
- return upb_pbdecoder_suspend(d);
+ return (int32_t)upb_pbdecoder_suspend(d);
}
if (d->top->groupnum >= 0) {
@@ -7153,10 +7638,11 @@
CHECK_SUSPEND(upb_sink_startsubmsg(outer->sink, arg, &d->top->sink));
)
VMCASE(OP_ENDSUBMSG,
- CHECK_SUSPEND(upb_sink_endsubmsg(d->top->sink, arg));
+ upb_sink subsink = (d->top + 1)->sink;
+ CHECK_SUSPEND(upb_sink_endsubmsg(d->top->sink, subsink, arg));
)
VMCASE(OP_STARTSTR,
- uint32_t len = delim_remaining(d);
+ uint32_t len = (uint32_t)delim_remaining(d);
upb_pbdecoder_frame *outer = outer_frame(d);
CHECK_SUSPEND(upb_sink_startstr(outer->sink, arg, len, &d->top->sink));
if (len == 0) {
@@ -7164,7 +7650,7 @@
}
)
VMCASE(OP_STRING,
- uint32_t len = curbufleft(d);
+ uint32_t len = (uint32_t)curbufleft(d);
size_t n = upb_sink_putstring(d->top->sink, arg, d->ptr, len, handle);
if (n > len) {
if (n > delim_remaining(d)) {
@@ -7699,7 +8185,7 @@
e->runbegin = e->ptr;
}
- *e->top = e->segptr - e->segbuf;
+ *e->top = (int)(e->segptr - e->segbuf);
e->segptr->seglen = 0;
e->segptr->msglen = 0;
@@ -8819,7 +9305,7 @@
upb_handlertype_t type) {
upb_selector_t sel;
bool ok = upb_handlers_getselector(p->top->f, type, &sel);
- UPB_ASSERT(ok);
+ UPB_ASSUME(ok);
return sel;
}
@@ -8844,7 +9330,7 @@
const upb_json_parsermethod *method;
ok = upb_inttable_lookupptr(&cache->methods, frame->m, &v);
- UPB_ASSERT(ok);
+ UPB_ASSUME(ok);
method = upb_value_getconstptr(v);
frame->name_table = &method->name_table;
@@ -9398,7 +9884,7 @@
} else if (val > INT32_MAX || val < INT32_MIN) {
return false;
} else {
- upb_sink_putint32(p->top->sink, parser_getsel(p), val);
+ upb_sink_putint32(p->top->sink, parser_getsel(p), (int32_t)val);
return true;
}
}
@@ -9409,7 +9895,7 @@
} else if (val > UINT32_MAX || errno == ERANGE) {
return false;
} else {
- upb_sink_putuint32(p->top->sink, parser_getsel(p), val);
+ upb_sink_putuint32(p->top->sink, parser_getsel(p), (uint32_t)val);
return true;
}
}
@@ -9697,7 +10183,7 @@
} else if (upb_fielddef_type(p->top->f) != UPB_TYPE_BOOL &&
upb_fielddef_type(p->top->f) != UPB_TYPE_MESSAGE) {
/* No need to push a frame -- numeric values in quotes remain in the
- * current parser frame. These values must accumulate so we can convert
+ * current parser frame. These values must accmulate so we can convert
* them all at once at the end. */
multipart_startaccum(p);
return true;
@@ -10117,14 +10603,18 @@
capture_begin(p, ptr);
}
+static int div_round_up2(int n, int d) {
+ return (n + d - 1) / d;
+}
+
/* epoch_days(1970, 1, 1) == 1970-01-01 == 0. */
static int epoch_days(int year, int month, int day) {
static const uint16_t month_yday[12] = {0, 31, 59, 90, 120, 151,
181, 212, 243, 273, 304, 334};
int febs_since_0 = month > 2 ? year + 1 : year;
- int leap_days_since_0 = div_round_up(febs_since_0, 4) -
- div_round_up(febs_since_0, 100) +
- div_round_up(febs_since_0, 400);
+ int leap_days_since_0 = div_round_up2(febs_since_0, 4) -
+ div_round_up2(febs_since_0, 100) +
+ div_round_up2(febs_since_0, 400);
int days_since_0 =
365 * year + month_yday[month - 1] + (day - 1) + leap_days_since_0;
@@ -10445,8 +10935,8 @@
/* send ENDSUBMSG in repeated-field-of-mapentries frame. */
p->top--;
ok = upb_handlers_getselector(mapfield, UPB_HANDLER_ENDSUBMSG, &sel);
- UPB_ASSERT(ok);
- upb_sink_endsubmsg(p->top->sink, sel);
+ UPB_ASSUME(ok);
+ upb_sink_endsubmsg(p->top->sink, (p->top + 1)->sink, sel);
}
p->top->f = NULL;
@@ -10560,7 +11050,7 @@
p->top--;
if (!is_unknown) {
sel = getsel_for_handlertype(p, UPB_HANDLER_ENDSUBMSG);
- upb_sink_endsubmsg(p->top->sink, sel);
+ upb_sink_endsubmsg(p->top->sink, (p->top + 1)->sink, sel);
}
}
}
@@ -10999,11 +11489,11 @@
* final state once, when the closing '"' is seen. */
-#line 2794 "upb/json/parser.rl"
+#line 2780 "upb/json/parser.rl"
-#line 2597 "upb/json/parser.c"
+#line 2583 "upb/json/parser.c"
static const char _json_actions[] = {
0, 1, 0, 1, 1, 1, 3, 1,
4, 1, 6, 1, 7, 1, 8, 1,
@@ -11258,7 +11748,7 @@
static const int json_en_main = 1;
-#line 2797 "upb/json/parser.rl"
+#line 2783 "upb/json/parser.rl"
size_t parse(void *closure, const void *hd, const char *buf, size_t size,
const upb_bufhandle *handle) {
@@ -11281,7 +11771,7 @@
capture_resume(parser, buf);
-#line 2875 "upb/json/parser.c"
+#line 2861 "upb/json/parser.c"
{
int _klen;
unsigned int _trans;
@@ -11356,147 +11846,147 @@
switch ( *_acts++ )
{
case 1:
-#line 2602 "upb/json/parser.rl"
+#line 2588 "upb/json/parser.rl"
{ p--; {cs = stack[--top]; goto _again;} }
break;
case 2:
-#line 2604 "upb/json/parser.rl"
+#line 2590 "upb/json/parser.rl"
{ p--; {stack[top++] = cs; cs = 23;goto _again;} }
break;
case 3:
-#line 2608 "upb/json/parser.rl"
+#line 2594 "upb/json/parser.rl"
{ start_text(parser, p); }
break;
case 4:
-#line 2609 "upb/json/parser.rl"
+#line 2595 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_text(parser, p)); }
break;
case 5:
-#line 2615 "upb/json/parser.rl"
+#line 2601 "upb/json/parser.rl"
{ start_hex(parser); }
break;
case 6:
-#line 2616 "upb/json/parser.rl"
+#line 2602 "upb/json/parser.rl"
{ hexdigit(parser, p); }
break;
case 7:
-#line 2617 "upb/json/parser.rl"
+#line 2603 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_hex(parser)); }
break;
case 8:
-#line 2623 "upb/json/parser.rl"
+#line 2609 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(escape(parser, p)); }
break;
case 9:
-#line 2629 "upb/json/parser.rl"
+#line 2615 "upb/json/parser.rl"
{ p--; {cs = stack[--top]; goto _again;} }
break;
case 10:
-#line 2634 "upb/json/parser.rl"
+#line 2620 "upb/json/parser.rl"
{ start_year(parser, p); }
break;
case 11:
-#line 2635 "upb/json/parser.rl"
+#line 2621 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_year(parser, p)); }
break;
case 12:
-#line 2639 "upb/json/parser.rl"
+#line 2625 "upb/json/parser.rl"
{ start_month(parser, p); }
break;
case 13:
-#line 2640 "upb/json/parser.rl"
+#line 2626 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_month(parser, p)); }
break;
case 14:
-#line 2644 "upb/json/parser.rl"
+#line 2630 "upb/json/parser.rl"
{ start_day(parser, p); }
break;
case 15:
-#line 2645 "upb/json/parser.rl"
+#line 2631 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_day(parser, p)); }
break;
case 16:
-#line 2649 "upb/json/parser.rl"
+#line 2635 "upb/json/parser.rl"
{ start_hour(parser, p); }
break;
case 17:
-#line 2650 "upb/json/parser.rl"
+#line 2636 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_hour(parser, p)); }
break;
case 18:
-#line 2654 "upb/json/parser.rl"
+#line 2640 "upb/json/parser.rl"
{ start_minute(parser, p); }
break;
case 19:
-#line 2655 "upb/json/parser.rl"
+#line 2641 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_minute(parser, p)); }
break;
case 20:
-#line 2659 "upb/json/parser.rl"
+#line 2645 "upb/json/parser.rl"
{ start_second(parser, p); }
break;
case 21:
-#line 2660 "upb/json/parser.rl"
+#line 2646 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_second(parser, p)); }
break;
case 22:
-#line 2665 "upb/json/parser.rl"
+#line 2651 "upb/json/parser.rl"
{ start_duration_base(parser, p); }
break;
case 23:
-#line 2666 "upb/json/parser.rl"
+#line 2652 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_duration_base(parser, p)); }
break;
case 24:
-#line 2668 "upb/json/parser.rl"
+#line 2654 "upb/json/parser.rl"
{ p--; {cs = stack[--top]; goto _again;} }
break;
case 25:
-#line 2673 "upb/json/parser.rl"
+#line 2659 "upb/json/parser.rl"
{ start_timestamp_base(parser); }
break;
case 26:
-#line 2675 "upb/json/parser.rl"
+#line 2661 "upb/json/parser.rl"
{ start_timestamp_fraction(parser, p); }
break;
case 27:
-#line 2676 "upb/json/parser.rl"
+#line 2662 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_timestamp_fraction(parser, p)); }
break;
case 28:
-#line 2678 "upb/json/parser.rl"
+#line 2664 "upb/json/parser.rl"
{ start_timestamp_zone(parser, p); }
break;
case 29:
-#line 2679 "upb/json/parser.rl"
+#line 2665 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_timestamp_zone(parser, p)); }
break;
case 30:
-#line 2681 "upb/json/parser.rl"
+#line 2667 "upb/json/parser.rl"
{ p--; {cs = stack[--top]; goto _again;} }
break;
case 31:
-#line 2686 "upb/json/parser.rl"
+#line 2672 "upb/json/parser.rl"
{ start_fieldmask_path_text(parser, p); }
break;
case 32:
-#line 2687 "upb/json/parser.rl"
+#line 2673 "upb/json/parser.rl"
{ end_fieldmask_path_text(parser, p); }
break;
case 33:
-#line 2692 "upb/json/parser.rl"
+#line 2678 "upb/json/parser.rl"
{ start_fieldmask_path(parser); }
break;
case 34:
-#line 2693 "upb/json/parser.rl"
+#line 2679 "upb/json/parser.rl"
{ end_fieldmask_path(parser); }
break;
case 35:
-#line 2699 "upb/json/parser.rl"
+#line 2685 "upb/json/parser.rl"
{ p--; {cs = stack[--top]; goto _again;} }
break;
case 36:
-#line 2704 "upb/json/parser.rl"
+#line 2690 "upb/json/parser.rl"
{
if (is_wellknown_msg(parser, UPB_WELLKNOWN_TIMESTAMP)) {
{stack[top++] = cs; cs = 47;goto _again;}
@@ -11510,11 +12000,11 @@
}
break;
case 37:
-#line 2717 "upb/json/parser.rl"
+#line 2703 "upb/json/parser.rl"
{ p--; {stack[top++] = cs; cs = 78;goto _again;} }
break;
case 38:
-#line 2722 "upb/json/parser.rl"
+#line 2708 "upb/json/parser.rl"
{
if (is_wellknown_msg(parser, UPB_WELLKNOWN_ANY)) {
start_any_member(parser, p);
@@ -11524,11 +12014,11 @@
}
break;
case 39:
-#line 2729 "upb/json/parser.rl"
+#line 2715 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_membername(parser)); }
break;
case 40:
-#line 2732 "upb/json/parser.rl"
+#line 2718 "upb/json/parser.rl"
{
if (is_wellknown_msg(parser, UPB_WELLKNOWN_ANY)) {
end_any_member(parser, p);
@@ -11538,7 +12028,7 @@
}
break;
case 41:
-#line 2743 "upb/json/parser.rl"
+#line 2729 "upb/json/parser.rl"
{
if (is_wellknown_msg(parser, UPB_WELLKNOWN_ANY)) {
start_any_object(parser, p);
@@ -11548,7 +12038,7 @@
}
break;
case 42:
-#line 2752 "upb/json/parser.rl"
+#line 2738 "upb/json/parser.rl"
{
if (is_wellknown_msg(parser, UPB_WELLKNOWN_ANY)) {
CHECK_RETURN_TOP(end_any_object(parser, p));
@@ -11558,54 +12048,54 @@
}
break;
case 43:
-#line 2764 "upb/json/parser.rl"
+#line 2750 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(start_array(parser)); }
break;
case 44:
-#line 2768 "upb/json/parser.rl"
+#line 2754 "upb/json/parser.rl"
{ end_array(parser); }
break;
case 45:
-#line 2773 "upb/json/parser.rl"
+#line 2759 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(start_number(parser, p)); }
break;
case 46:
-#line 2774 "upb/json/parser.rl"
+#line 2760 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_number(parser, p)); }
break;
case 47:
-#line 2776 "upb/json/parser.rl"
+#line 2762 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(start_stringval(parser)); }
break;
case 48:
-#line 2777 "upb/json/parser.rl"
+#line 2763 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_stringval(parser)); }
break;
case 49:
-#line 2779 "upb/json/parser.rl"
+#line 2765 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_bool(parser, true)); }
break;
case 50:
-#line 2781 "upb/json/parser.rl"
+#line 2767 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_bool(parser, false)); }
break;
case 51:
-#line 2783 "upb/json/parser.rl"
+#line 2769 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_null(parser)); }
break;
case 52:
-#line 2785 "upb/json/parser.rl"
+#line 2771 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(start_subobject_full(parser)); }
break;
case 53:
-#line 2786 "upb/json/parser.rl"
+#line 2772 "upb/json/parser.rl"
{ end_subobject_full(parser); }
break;
case 54:
-#line 2791 "upb/json/parser.rl"
+#line 2777 "upb/json/parser.rl"
{ p--; {cs = stack[--top]; goto _again;} }
break;
-#line 3199 "upb/json/parser.c"
+#line 3185 "upb/json/parser.c"
}
}
@@ -11622,32 +12112,32 @@
while ( __nacts-- > 0 ) {
switch ( *__acts++ ) {
case 0:
-#line 2600 "upb/json/parser.rl"
+#line 2586 "upb/json/parser.rl"
{ p--; {cs = stack[--top]; if ( p == pe )
goto _test_eof;
goto _again;} }
break;
case 46:
-#line 2774 "upb/json/parser.rl"
+#line 2760 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_number(parser, p)); }
break;
case 49:
-#line 2779 "upb/json/parser.rl"
+#line 2765 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_bool(parser, true)); }
break;
case 50:
-#line 2781 "upb/json/parser.rl"
+#line 2767 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_bool(parser, false)); }
break;
case 51:
-#line 2783 "upb/json/parser.rl"
+#line 2769 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_null(parser)); }
break;
case 53:
-#line 2786 "upb/json/parser.rl"
+#line 2772 "upb/json/parser.rl"
{ end_subobject_full(parser); }
break;
-#line 3241 "upb/json/parser.c"
+#line 3227 "upb/json/parser.c"
}
}
}
@@ -11655,7 +12145,7 @@
_out: {}
}
-#line 2819 "upb/json/parser.rl"
+#line 2805 "upb/json/parser.rl"
if (p != pe) {
upb_status_seterrf(parser->status, "Parse error at '%.*s'\n", pe - p, p);
@@ -11698,13 +12188,13 @@
/* Emit Ragel initialization of the parser. */
-#line 3292 "upb/json/parser.c"
+#line 3278 "upb/json/parser.c"
{
cs = json_start;
top = 0;
}
-#line 2861 "upb/json/parser.rl"
+#line 2847 "upb/json/parser.rl"
p->current_state = cs;
p->parser_top = top;
accumulate_clear(p);
@@ -11735,15 +12225,13 @@
upb_msg_field_next(&i)) {
const upb_fielddef *f = upb_msg_iter_field(&i);
upb_value v = upb_value_constptr(f);
- char *buf;
+ const char *name;
/* Add an entry for the JSON name. */
- size_t len = upb_fielddef_getjsonname(f, NULL, 0);
- buf = upb_malloc(alloc, len);
- upb_fielddef_getjsonname(f, buf, len);
- upb_strtable_insert3(&m->name_table, buf, strlen(buf), v, alloc);
+ name = upb_fielddef_jsonname(f);
+ upb_strtable_insert3(&m->name_table, name, strlen(name), v, alloc);
- if (strcmp(buf, upb_fielddef_name(f)) != 0) {
+ if (strcmp(name, upb_fielddef_name(f)) != 0) {
/* Since the JSON name is different from the regular field name, add an
* entry for the raw name (compliant proto3 JSON parsers must accept
* both). */
@@ -11869,6 +12357,7 @@
#include <ctype.h>
+#include <inttypes.h>
#include <stdint.h>
#include <string.h>
#include <time.h>
@@ -11926,12 +12415,8 @@
ret->ptr = upb_gstrdup(upb_fielddef_name(f));
ret->len = strlen(ret->ptr);
} else {
- size_t len;
- ret->len = upb_fielddef_getjsonname(f, NULL, 0);
- ret->ptr = upb_gmalloc(ret->len);
- len = upb_fielddef_getjsonname(f, ret->ptr, ret->len);
- UPB_ASSERT(len == ret->len);
- ret->len--; /* NULL */
+ ret->ptr = upb_gstrdup(upb_fielddef_jsonname(f));
+ ret->len = strlen(ret->ptr);
}
upb_handlers_addcleanup(h, ret, freestrpc);
@@ -11950,7 +12435,7 @@
/* ------------ JSON string printing: values, maps, arrays ------------------ */
static void print_data(
- upb_json_printer *p, const char *buf, unsigned int len) {
+ upb_json_printer *p, const char *buf, size_t len) {
/* TODO: Will need to change if we support pushback from the sink. */
size_t n = upb_bytessink_putbuf(p->output_, p->subc_, buf, len, NULL);
UPB_ASSERT(n == len);
@@ -11990,7 +12475,7 @@
/* Write a properly escaped string chunk. The surrounding quotes are *not*
* printed; this is so that the caller has the option of emitting the string
* content in chunks. */
-static void putstring(upb_json_printer *p, const char *buf, unsigned int len) {
+static void putstring(upb_json_printer *p, const char *buf, size_t len) {
const char* unescaped_run = NULL;
unsigned int i;
for (i = 0; i < len; i++) {
@@ -12070,28 +12555,26 @@
return n;
}
-static size_t fmt_int64_as_number(long long val, char* buf, size_t length) {
- size_t n = _upb_snprintf(buf, length, "%lld", val);
+static size_t fmt_int64_as_number(int64_t val, char* buf, size_t length) {
+ size_t n = _upb_snprintf(buf, length, "%" PRId64, val);
CHKLENGTH(n > 0 && n < length);
return n;
}
-static size_t fmt_uint64_as_number(
- unsigned long long val, char* buf, size_t length) {
- size_t n = _upb_snprintf(buf, length, "%llu", val);
+static size_t fmt_uint64_as_number(uint64_t val, char* buf, size_t length) {
+ size_t n = _upb_snprintf(buf, length, "%" PRIu64, val);
CHKLENGTH(n > 0 && n < length);
return n;
}
-static size_t fmt_int64_as_string(long long val, char* buf, size_t length) {
- size_t n = _upb_snprintf(buf, length, "\"%lld\"", val);
+static size_t fmt_int64_as_string(int64_t val, char* buf, size_t length) {
+ size_t n = _upb_snprintf(buf, length, "\"%" PRId64 "\"", val);
CHKLENGTH(n > 0 && n < length);
return n;
}
-static size_t fmt_uint64_as_string(
- unsigned long long val, char* buf, size_t length) {
- size_t n = _upb_snprintf(buf, length, "\"%llu\"", val);
+static size_t fmt_uint64_as_string(uint64_t val, char* buf, size_t length) {
+ size_t n = _upb_snprintf(buf, length, "\"%" PRIu64 "\"", val);
CHKLENGTH(n > 0 && n < length);
return n;
}
@@ -13268,8 +13751,9 @@
}
/* See port_def.inc. This should #undef all macros #defined there. */
+#undef UPB_MAPTYPE_STRING
#undef UPB_SIZE
-#undef UPB_FIELD_AT
+#undef UPB_PTR_AT
#undef UPB_READ_ONEOF
#undef UPB_WRITE_ONEOF
#undef UPB_INLINE
@@ -13279,6 +13763,7 @@
#undef UPB_MAX
#undef UPB_MIN
#undef UPB_UNUSED
+#undef UPB_ASSUME
#undef UPB_ASSERT
#undef UPB_ASSERT_DEBUGVAR
#undef UPB_UNREACHABLE
diff --git a/ruby/ext/google/protobuf_c/upb.h b/ruby/ext/google/protobuf_c/upb.h
index 24943ee..a346379 100644
--- a/ruby/ext/google/protobuf_c/upb.h
+++ b/ruby/ext/google/protobuf_c/upb.h
@@ -21,9 +21,7 @@
*
* This file is private and must not be included by users!
*/
-#ifndef UINTPTR_MAX
-#error must include stdint.h first
-#endif
+#include <stdint.h>
#if UINTPTR_MAX == 0xffffffff
#define UPB_SIZE(size32, size64) size32
@@ -31,17 +29,21 @@
#define UPB_SIZE(size32, size64) size64
#endif
-#define UPB_FIELD_AT(msg, fieldtype, offset) \
- *(fieldtype*)((const char*)(msg) + offset)
+/* If we always read/write as a consistent type to each address, this shouldn't
+ * violate aliasing.
+ */
+#define UPB_PTR_AT(msg, ofs, type) ((type*)((char*)(msg) + (ofs)))
#define UPB_READ_ONEOF(msg, fieldtype, offset, case_offset, case_val, default) \
- UPB_FIELD_AT(msg, int, case_offset) == case_val \
- ? UPB_FIELD_AT(msg, fieldtype, offset) \
+ *UPB_PTR_AT(msg, case_offset, int) == case_val \
+ ? *UPB_PTR_AT(msg, offset, fieldtype) \
: default
#define UPB_WRITE_ONEOF(msg, fieldtype, offset, value, case_offset, case_val) \
- UPB_FIELD_AT(msg, int, case_offset) = case_val; \
- UPB_FIELD_AT(msg, fieldtype, offset) = value;
+ *UPB_PTR_AT(msg, case_offset, int) = case_val; \
+ *UPB_PTR_AT(msg, offset, fieldtype) = value;
+
+#define UPB_MAPTYPE_STRING 0
/* UPB_INLINE: inline if possible, emit standalone code if required. */
#ifdef __cplusplus
@@ -115,7 +117,7 @@
#ifdef __cplusplus
#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) || \
(defined(_MSC_VER) && _MSC_VER >= 1900)
-// C++11 is present
+/* C++11 is present */
#else
#error upb requires C++11 for C++ support
#endif
@@ -126,6 +128,18 @@
#define UPB_UNUSED(var) (void)var
+/* UPB_ASSUME(): in release mode, we tell the compiler to assume this is true.
+ */
+#ifdef NDEBUG
+#ifdef __GNUC__
+#define UPB_ASSUME(expr) if (!(expr)) __builtin_unreachable()
+#else
+#define UPB_ASSUME(expr) do {} if (false && (expr))
+#endif
+#else
+#define UPB_ASSUME(expr) assert(expr)
+#endif
+
/* UPB_ASSERT(): in release mode, we use the expression without letting it be
* evaluated. This prevents "unused variable" warnings. */
#ifdef NDEBUG
@@ -152,6 +166,50 @@
#define UPB_INFINITY (1.0 / 0.0)
#endif
/*
+** upb_decode: parsing into a upb_msg using a upb_msglayout.
+*/
+
+#ifndef UPB_DECODE_H_
+#define UPB_DECODE_H_
+
+/*
+** Our memory representation for parsing tables and messages themselves.
+** Functions in this file are used by generated code and possibly reflection.
+**
+** The definitions in this file are internal to upb.
+**/
+
+#ifndef UPB_MSG_H_
+#define UPB_MSG_H_
+
+#include <stdint.h>
+#include <string.h>
+
+/*
+** upb_table
+**
+** This header is INTERNAL-ONLY! Its interfaces are not public or stable!
+** This file defines very fast int->upb_value (inttable) and string->upb_value
+** (strtable) hash tables.
+**
+** The table uses chained scatter with Brent's variation (inspired by the Lua
+** implementation of hash tables). The hash function for strings is Austin
+** Appleby's "MurmurHash."
+**
+** The inttable uses uintptr_t as its key, which guarantees it can be used to
+** store pointers or integers of at least 32 bits (upb isn't really useful on
+** systems where sizeof(void*) < 4).
+**
+** The table must be homogenous (all values of the same type). In debug
+** mode, we check this on insert and lookup.
+*/
+
+#ifndef UPB_TABLE_H_
+#define UPB_TABLE_H_
+
+#include <stdint.h>
+#include <string.h>
+/*
** This file contains shared definitions that are widely used across upb.
**
** This is a mixed C/C++ interface that offers a full API to both languages.
@@ -361,6 +419,19 @@
extern "C" {
#endif
+typedef struct {
+ /* We implement the allocator interface.
+ * This must be the first member of upb_arena! */
+ upb_alloc alloc;
+
+ char *ptr, *end;
+} _upb_arena_head;
+
+UPB_INLINE size_t _upb_arena_alignup(size_t size) {
+ const size_t maxalign = 16;
+ return ((size + maxalign - 1) / maxalign) * maxalign;
+}
+
/* Creates an arena from the given initial block (if any -- n may be 0).
* Additional blocks will be allocated from |alloc|. If |alloc| is NULL, this
* is a fixed-size arena and cannot grow. */
@@ -368,18 +439,29 @@
void upb_arena_free(upb_arena *a);
bool upb_arena_addcleanup(upb_arena *a, void *ud, upb_cleanup_func *func);
size_t upb_arena_bytesallocated(const upb_arena *a);
+void *_upb_arena_slowmalloc(upb_arena *a, size_t size);
UPB_INLINE upb_alloc *upb_arena_alloc(upb_arena *a) { return (upb_alloc*)a; }
-/* Convenience wrappers around upb_alloc functions. */
-
UPB_INLINE void *upb_arena_malloc(upb_arena *a, size_t size) {
- return upb_malloc(upb_arena_alloc(a), size);
+ _upb_arena_head *h = (_upb_arena_head*)a;
+ size = _upb_arena_alignup(size);
+ if (UPB_LIKELY((size_t)(h->end - h->ptr) >= size)) {
+ void* ret = h->ptr;
+ h->ptr += size;
+ return ret;
+ } else {
+ return _upb_arena_slowmalloc(a, size);
+ }
}
UPB_INLINE void *upb_arena_realloc(upb_arena *a, void *ptr, size_t oldsize,
size_t size) {
- return upb_realloc(upb_arena_alloc(a), ptr, oldsize, size);
+ if (oldsize == 0) {
+ return upb_arena_malloc(a, size);
+ } else {
+ return upb_realloc(upb_arena_alloc(a), ptr, oldsize, size);
+ }
}
UPB_INLINE upb_arena *upb_arena_new(void) {
@@ -470,14 +552,15 @@
UPB_TYPE_INT32 = 3,
UPB_TYPE_UINT32 = 4,
UPB_TYPE_ENUM = 5, /* Enum values are int32. */
- /* Types stored as pointers (probably 4 or 8 bytes). */
- UPB_TYPE_STRING = 6,
- UPB_TYPE_BYTES = 7,
- UPB_TYPE_MESSAGE = 8,
+ /* Types stored as void* (probably 4 or 8 bytes). */
+ UPB_TYPE_MESSAGE = 6,
/* Types stored as 8 bytes. */
- UPB_TYPE_DOUBLE = 9,
- UPB_TYPE_INT64 = 10,
- UPB_TYPE_UINT64 = 11
+ UPB_TYPE_DOUBLE = 7,
+ UPB_TYPE_INT64 = 8,
+ UPB_TYPE_UINT64 = 9,
+ /* Types stored as upb_strview (2 * void*) (probably 8 or 16 bytes). */
+ UPB_TYPE_STRING = 10,
+ UPB_TYPE_BYTES = 11
} upb_fieldtype_t;
/* The repeated-ness of each field; this matches descriptor.proto. */
@@ -489,6 +572,7 @@
/* Descriptor types, as defined in descriptor.proto. */
typedef enum {
+ /* Old (long) names. TODO(haberman): remove */
UPB_DESCRIPTOR_TYPE_DOUBLE = 1,
UPB_DESCRIPTOR_TYPE_FLOAT = 2,
UPB_DESCRIPTOR_TYPE_INT64 = 3,
@@ -506,145 +590,32 @@
UPB_DESCRIPTOR_TYPE_SFIXED32 = 15,
UPB_DESCRIPTOR_TYPE_SFIXED64 = 16,
UPB_DESCRIPTOR_TYPE_SINT32 = 17,
- UPB_DESCRIPTOR_TYPE_SINT64 = 18
+ UPB_DESCRIPTOR_TYPE_SINT64 = 18,
+
+ UPB_DTYPE_DOUBLE = 1,
+ UPB_DTYPE_FLOAT = 2,
+ UPB_DTYPE_INT64 = 3,
+ UPB_DTYPE_UINT64 = 4,
+ UPB_DTYPE_INT32 = 5,
+ UPB_DTYPE_FIXED64 = 6,
+ UPB_DTYPE_FIXED32 = 7,
+ UPB_DTYPE_BOOL = 8,
+ UPB_DTYPE_STRING = 9,
+ UPB_DTYPE_GROUP = 10,
+ UPB_DTYPE_MESSAGE = 11,
+ UPB_DTYPE_BYTES = 12,
+ UPB_DTYPE_UINT32 = 13,
+ UPB_DTYPE_ENUM = 14,
+ UPB_DTYPE_SFIXED32 = 15,
+ UPB_DTYPE_SFIXED64 = 16,
+ UPB_DTYPE_SINT32 = 17,
+ UPB_DTYPE_SINT64 = 18
} upb_descriptortype_t;
-extern const uint8_t upb_desctype_to_fieldtype[];
+#define UPB_MAP_BEGIN -1
#endif /* UPB_H_ */
-/*
-** upb_decode: parsing into a upb_msg using a upb_msglayout.
-*/
-
-#ifndef UPB_DECODE_H_
-#define UPB_DECODE_H_
-
-/*
-** Data structures for message tables, used for parsing and serialization.
-** This are much lighter-weight than full reflection, but they are do not
-** have enough information to convert to text format, JSON, etc.
-**
-** The definitions in this file are internal to upb.
-**/
-
-#ifndef UPB_MSG_H_
-#define UPB_MSG_H_
-
-#include <stdint.h>
-#include <string.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef void upb_msg;
-
-/** upb_msglayout *************************************************************/
-
-/* upb_msglayout represents the memory layout of a given upb_msgdef. The
- * members are public so generated code can initialize them, but users MUST NOT
- * read or write any of its members. */
-
-typedef struct {
- uint32_t number;
- uint16_t offset;
- int16_t presence; /* If >0, hasbit_index+1. If <0, oneof_index+1. */
- uint16_t submsg_index; /* undefined if descriptortype != MESSAGE or GROUP. */
- uint8_t descriptortype;
- uint8_t label;
-} upb_msglayout_field;
-
-typedef struct upb_msglayout {
- const struct upb_msglayout *const* submsgs;
- const upb_msglayout_field *fields;
- /* Must be aligned to sizeof(void*). Doesn't include internal members like
- * unknown fields, extension dict, pointer to msglayout, etc. */
- uint16_t size;
- uint16_t field_count;
- bool extendable;
-} upb_msglayout;
-
-/** Message internal representation *******************************************/
-
-/* Our internal representation for repeated fields. */
-typedef struct {
- void *data; /* Each element is element_size. */
- size_t len; /* Measured in elements. */
- size_t size; /* Measured in elements. */
-} upb_array;
-
-upb_msg *upb_msg_new(const upb_msglayout *l, upb_arena *a);
-upb_msg *upb_msg_new(const upb_msglayout *l, upb_arena *a);
-
-void upb_msg_addunknown(upb_msg *msg, const char *data, size_t len,
- upb_arena *arena);
-const char *upb_msg_getunknown(const upb_msg *msg, size_t *len);
-
-upb_array *upb_array_new(upb_arena *a);
-
-#ifdef __cplusplus
-} /* extern "C" */
-#endif
-
-#endif /* UPB_MSG_H_ */
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-bool upb_decode(const char *buf, size_t size, upb_msg *msg,
- const upb_msglayout *l, upb_arena *arena);
-
-#ifdef __cplusplus
-} /* extern "C" */
-#endif
-
-#endif /* UPB_DECODE_H_ */
-/*
-** upb_encode: parsing into a upb_msg using a upb_msglayout.
-*/
-
-#ifndef UPB_ENCODE_H_
-#define UPB_ENCODE_H_
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-char *upb_encode(const void *msg, const upb_msglayout *l, upb_arena *arena,
- size_t *size);
-
-#ifdef __cplusplus
-} /* extern "C" */
-#endif
-
-#endif /* UPB_ENCODE_H_ */
-/*
-** upb_table
-**
-** This header is INTERNAL-ONLY! Its interfaces are not public or stable!
-** This file defines very fast int->upb_value (inttable) and string->upb_value
-** (strtable) hash tables.
-**
-** The table uses chained scatter with Brent's variation (inspired by the Lua
-** implementation of hash tables). The hash function for strings is Austin
-** Appleby's "MurmurHash."
-**
-** The inttable uses uintptr_t as its key, which guarantees it can be used to
-** store pointers or integers of at least 32 bits (upb isn't really useful on
-** systems where sizeof(void*) < 4).
-**
-** The table must be homogenous (all values of the same type). In debug
-** mode, we check this on insert and lookup.
-*/
-
-#ifndef UPB_TABLE_H_
-#define UPB_TABLE_H_
-
-#include <stdint.h>
-#include <string.h>
#ifdef __cplusplus
@@ -673,19 +644,8 @@
typedef struct {
uint64_t val;
-#ifndef NDEBUG
- /* In debug mode we carry the value type around also so we can check accesses
- * to be sure the right member is being read. */
- upb_ctype_t ctype;
-#endif
} upb_value;
-#ifdef NDEBUG
-#define SET_TYPE(dest, val) UPB_UNUSED(val)
-#else
-#define SET_TYPE(dest, val) dest = val
-#endif
-
/* Like strdup(), which isn't always available since it's not ANSI C. */
char *upb_strdup(const char *s, upb_alloc *a);
/* Variant that works with a length-delimited rather than NULL-delimited string,
@@ -696,15 +656,13 @@
return upb_strdup(s, &upb_alloc_global);
}
-UPB_INLINE void _upb_value_setval(upb_value *v, uint64_t val,
- upb_ctype_t ctype) {
+UPB_INLINE void _upb_value_setval(upb_value *v, uint64_t val) {
v->val = val;
- SET_TYPE(v->ctype, ctype);
}
-UPB_INLINE upb_value _upb_value_val(uint64_t val, upb_ctype_t ctype) {
+UPB_INLINE upb_value _upb_value_val(uint64_t val) {
upb_value ret;
- _upb_value_setval(&ret, val, ctype);
+ _upb_value_setval(&ret, val);
return ret;
}
@@ -719,7 +677,6 @@
#define FUNCS(name, membername, type_t, converter, proto_type) \
UPB_INLINE void upb_value_set ## name(upb_value *val, type_t cval) { \
val->val = (converter)cval; \
- SET_TYPE(val->ctype, proto_type); \
} \
UPB_INLINE upb_value upb_value_ ## name(type_t val) { \
upb_value ret; \
@@ -727,7 +684,6 @@
return ret; \
} \
UPB_INLINE type_t upb_value_get ## name(upb_value val) { \
- UPB_ASSERT_DEBUGVAR(val.ctype == proto_type); \
return (type_t)(converter)val.val; \
}
@@ -745,12 +701,10 @@
UPB_INLINE void upb_value_setfloat(upb_value *val, float cval) {
memcpy(&val->val, &cval, sizeof(cval));
- SET_TYPE(val->ctype, UPB_CTYPE_FLOAT);
}
UPB_INLINE void upb_value_setdouble(upb_value *val, double cval) {
memcpy(&val->val, &cval, sizeof(cval));
- SET_TYPE(val->ctype, UPB_CTYPE_DOUBLE);
}
UPB_INLINE upb_value upb_value_float(float cval) {
@@ -794,7 +748,6 @@
#define UPB_TABVALUE_EMPTY_INIT {-1}
-
/* upb_table ******************************************************************/
typedef struct _upb_tabent {
@@ -811,7 +764,6 @@
typedef struct {
size_t count; /* Number of entries in the hash part. */
size_t mask; /* Mask to turn hash value -> bucket. */
- upb_ctype_t ctype; /* Type of all values. */
uint8_t size_lg2; /* Size of the hashtable part is 2^size_lg2 entries. */
/* Hash table entries.
@@ -821,17 +773,6 @@
* initialize const hash tables. Then we cast away const when we have to.
*/
const upb_tabent *entries;
-
-#ifndef NDEBUG
- /* This table's allocator. We make the user pass it in to every relevant
- * function and only use this to check it in debug mode. We do this solely
- * to keep upb_table as small as possible. This might seem slightly paranoid
- * but the plan is to use upb_table for all map fields and extension sets in
- * a forthcoming message representation, so there could be a lot of these.
- * If this turns out to be too annoying later, we can change it (since this
- * is an internal-only header file). */
- upb_alloc *alloc;
-#endif
} upb_table;
typedef struct {
@@ -845,12 +786,6 @@
size_t array_count; /* Array part number of elements. */
} upb_inttable;
-#define UPB_INTTABLE_INIT(count, mask, ctype, size_lg2, ent, a, asize, acount) \
- {UPB_TABLE_INIT(count, mask, ctype, size_lg2, ent), a, asize, acount}
-
-#define UPB_EMPTY_INTTABLE_INIT(ctype) \
- UPB_INTTABLE_INIT(0, 0, ctype, 0, NULL, NULL, 0, 0)
-
#define UPB_ARRAY_EMPTYENT -1
UPB_INLINE size_t upb_table_size(const upb_table *t) {
@@ -919,6 +854,7 @@
size_t size);
upb_strtable *upb_strtable_pack(const upb_strtable *t, void *p, size_t *ofs,
size_t size);
+void upb_strtable_clear(upb_strtable *t);
/* Inserts the given key into the hashtable with the given value. The key must
* not already exist in the hash table. For string tables, the key must be
@@ -1020,7 +956,7 @@
if (key < t->array_size) {
upb_tabval arrval = t->array[key];
if (upb_arrhas(arrval)) {
- _upb_value_setval(v, arrval.val, t->t.ctype);
+ _upb_value_setval(v, arrval.val);
return true;
} else {
return false;
@@ -1030,7 +966,7 @@
if (t->t.entries == NULL) return false;
for (e = upb_getentry(&t->t, upb_inthash(key)); true; e = e->next) {
if ((uint32_t)e->key == key) {
- _upb_value_setval(v, e->val.val, t->t.ctype);
+ _upb_value_setval(v, e->val.val);
return true;
}
if (e->next == NULL) return false;
@@ -1084,8 +1020,7 @@
void upb_strtable_begin(upb_strtable_iter *i, const upb_strtable *t);
void upb_strtable_next(upb_strtable_iter *i);
bool upb_strtable_done(const upb_strtable_iter *i);
-const char *upb_strtable_iter_key(const upb_strtable_iter *i);
-size_t upb_strtable_iter_keylength(const upb_strtable_iter *i);
+upb_strview upb_strtable_iter_key(const upb_strtable_iter *i);
upb_value upb_strtable_iter_value(const upb_strtable_iter *i);
void upb_strtable_iter_setdone(upb_strtable_iter *i);
bool upb_strtable_iter_isequal(const upb_strtable_iter *i1,
@@ -1109,6 +1044,10 @@
bool array_part;
} upb_inttable_iter;
+UPB_INLINE const upb_tabent *str_tabent(const upb_strtable_iter *i) {
+ return &i->t->t.entries[i->index];
+}
+
void upb_inttable_begin(upb_inttable_iter *i, const upb_inttable *t);
void upb_inttable_next(upb_inttable_iter *i);
bool upb_inttable_done(const upb_inttable_iter *i);
@@ -1125,98 +1064,80 @@
#endif /* UPB_TABLE_H_ */
-/* This file was generated by upbc (the upb compiler) from the input
- * file:
- *
- * google/protobuf/descriptor.proto
- *
- * Do not edit -- your changes will be discarded when the file is
- * regenerated. */
-#ifndef GOOGLE_PROTOBUF_DESCRIPTOR_PROTO_UPB_H_
-#define GOOGLE_PROTOBUF_DESCRIPTOR_PROTO_UPB_H_
-/*
-** Functions for use by generated code. These are not public and users must
-** not call them directly.
-*/
-
-#ifndef UPB_GENERATED_UTIL_H_
-#define UPB_GENERATED_UTIL_H_
-
-#include <stdint.h>
-
+#ifdef __cplusplus
+extern "C" {
+#endif
#define PTR_AT(msg, ofs, type) (type*)((const char*)msg + ofs)
-UPB_INLINE const void *_upb_array_accessor(const void *msg, size_t ofs,
- size_t *size) {
- const upb_array *arr = *PTR_AT(msg, ofs, const upb_array*);
- if (arr) {
- if (size) *size = arr->len;
- return arr->data;
- } else {
- if (size) *size = 0;
- return NULL;
- }
-}
+typedef void upb_msg;
-UPB_INLINE void *_upb_array_mutable_accessor(void *msg, size_t ofs,
- size_t *size) {
- upb_array *arr = *PTR_AT(msg, ofs, upb_array*);
- if (arr) {
- if (size) *size = arr->len;
- return arr->data;
- } else {
- if (size) *size = 0;
- return NULL;
- }
-}
+/** upb_msglayout *************************************************************/
-/* TODO(haberman): this is a mess. It will improve when upb_array no longer
- * carries reflective state (type, elem_size). */
-UPB_INLINE void *_upb_array_resize_accessor(void *msg, size_t ofs, size_t size,
- size_t elem_size,
- upb_fieldtype_t type,
- upb_arena *arena) {
- upb_array *arr = *PTR_AT(msg, ofs, upb_array*);
+/* upb_msglayout represents the memory layout of a given upb_msgdef. The
+ * members are public so generated code can initialize them, but users MUST NOT
+ * read or write any of its members. */
- if (!arr) {
- arr = upb_array_new(arena);
- if (!arr) return NULL;
- *PTR_AT(msg, ofs, upb_array*) = arr;
- }
+/* These aren't real labels according to descriptor.proto, but in the table we
+ * use these for map/packed fields instead of UPB_LABEL_REPEATED. */
+enum {
+ _UPB_LABEL_MAP = 4,
+ _UPB_LABEL_PACKED = 7 /* Low 3 bits are common with UPB_LABEL_REPEATED. */
+};
- if (size > arr->size) {
- size_t new_size = UPB_MAX(arr->size, 4);
- size_t old_bytes = arr->size * elem_size;
- size_t new_bytes;
- while (new_size < size) new_size *= 2;
- new_bytes = new_size * elem_size;
- arr->data = upb_arena_realloc(arena, arr->data, old_bytes, new_bytes);
- if (!arr->data) {
- return NULL;
- }
- arr->size = new_size;
- }
+typedef struct {
+ uint32_t number;
+ uint16_t offset;
+ int16_t presence; /* If >0, hasbit_index. If <0, -oneof_index. */
+ uint16_t submsg_index; /* undefined if descriptortype != MESSAGE or GROUP. */
+ uint8_t descriptortype;
+ uint8_t label;
+} upb_msglayout_field;
- arr->len = size;
- return arr->data;
-}
+typedef struct upb_msglayout {
+ const struct upb_msglayout *const* submsgs;
+ const upb_msglayout_field *fields;
+ /* Must be aligned to sizeof(void*). Doesn't include internal members like
+ * unknown fields, extension dict, pointer to msglayout, etc. */
+ uint16_t size;
+ uint16_t field_count;
+ bool extendable;
+} upb_msglayout;
-UPB_INLINE bool _upb_array_append_accessor(void *msg, size_t ofs,
- size_t elem_size,
- upb_fieldtype_t type,
- const void *value,
- upb_arena *arena) {
- upb_array *arr = *PTR_AT(msg, ofs, upb_array*);
- size_t i = arr ? arr->len : 0;
- void *data =
- _upb_array_resize_accessor(msg, ofs, i + 1, elem_size, type, arena);
- if (!data) return false;
- memcpy(PTR_AT(data, i * elem_size, char), value, elem_size);
- return true;
-}
+/** upb_msg *******************************************************************/
+
+/* Internal members of a upb_msg. We can change this without breaking binary
+ * compatibility. We put these before the user's data. The user's upb_msg*
+ * points after the upb_msg_internal. */
+
+/* Used when a message is not extendable. */
+typedef struct {
+ char *unknown;
+ size_t unknown_len;
+ size_t unknown_size;
+} upb_msg_internal;
+
+/* Used when a message is extendable. */
+typedef struct {
+ upb_inttable *extdict;
+ upb_msg_internal base;
+} upb_msg_internal_withext;
+
+/* Maps upb_fieldtype_t -> memory size. */
+extern char _upb_fieldtype_to_size[12];
+
+/* Creates a new messages with the given layout on the given arena. */
+upb_msg *_upb_msg_new(const upb_msglayout *l, upb_arena *a);
+
+/* Adds unknown data (serialized protobuf data) to the given message. The data
+ * is copied into the message instance. */
+bool _upb_msg_addunknown(upb_msg *msg, const char *data, size_t len,
+ upb_arena *arena);
+
+/* Returns a reference to the message's unknown data. */
+const char *upb_msg_getunknown(const upb_msg *msg, size_t *len);
UPB_INLINE bool _upb_has_field(const void *msg, size_t idx) {
return (*PTR_AT(msg, idx / 8, const char) & (1 << (idx % 8))) != 0;
@@ -1234,10 +1155,349 @@
return *PTR_AT(msg, case_ofs, int32_t) == num;
}
+UPB_INLINE bool _upb_has_submsg_nohasbit(const void *msg, size_t ofs) {
+ return *PTR_AT(msg, ofs, const void*) != NULL;
+}
+
+UPB_INLINE bool _upb_isrepeated(const upb_msglayout_field *field) {
+ return (field->label & 3) == UPB_LABEL_REPEATED;
+}
+
+/** upb_array *****************************************************************/
+
+/* Our internal representation for repeated fields. */
+typedef struct {
+ uintptr_t data; /* Tagged ptr: low 3 bits of ptr are lg2(elem size). */
+ size_t len; /* Measured in elements. */
+ size_t size; /* Measured in elements. */
+} upb_array;
+
+UPB_INLINE const void *_upb_array_constptr(const upb_array *arr) {
+ return (void*)(arr->data & ~(uintptr_t)7);
+}
+
+UPB_INLINE void *_upb_array_ptr(upb_array *arr) {
+ return (void*)_upb_array_constptr(arr);
+}
+
+/* Creates a new array on the given arena. */
+upb_array *_upb_array_new(upb_arena *a, upb_fieldtype_t type);
+
+/* Resizes the capacity of the array to be at least min_size. */
+bool _upb_array_realloc(upb_array *arr, size_t min_size, upb_arena *arena);
+
+/* Fallback functions for when the accessors require a resize. */
+void *_upb_array_resize_fallback(upb_array **arr_ptr, size_t size,
+ upb_fieldtype_t type, upb_arena *arena);
+bool _upb_array_append_fallback(upb_array **arr_ptr, const void *value,
+ upb_fieldtype_t type, upb_arena *arena);
+
+UPB_INLINE const void *_upb_array_accessor(const void *msg, size_t ofs,
+ size_t *size) {
+ const upb_array *arr = *PTR_AT(msg, ofs, const upb_array*);
+ if (arr) {
+ if (size) *size = arr->len;
+ return _upb_array_constptr(arr);
+ } else {
+ if (size) *size = 0;
+ return NULL;
+ }
+}
+
+UPB_INLINE void *_upb_array_mutable_accessor(void *msg, size_t ofs,
+ size_t *size) {
+ upb_array *arr = *PTR_AT(msg, ofs, upb_array*);
+ if (arr) {
+ if (size) *size = arr->len;
+ return _upb_array_ptr(arr);
+ } else {
+ if (size) *size = 0;
+ return NULL;
+ }
+}
+
+UPB_INLINE void *_upb_array_resize_accessor(void *msg, size_t ofs, size_t size,
+ upb_fieldtype_t type,
+ upb_arena *arena) {
+ upb_array **arr_ptr = PTR_AT(msg, ofs, upb_array*);
+ upb_array *arr = *arr_ptr;
+ if (!arr || arr->size < size) {
+ return _upb_array_resize_fallback(arr_ptr, size, type, arena);
+ }
+ arr->len = size;
+ return _upb_array_ptr(arr);
+}
+
+
+UPB_INLINE bool _upb_array_append_accessor(void *msg, size_t ofs,
+ size_t elem_size,
+ upb_fieldtype_t type,
+ const void *value,
+ upb_arena *arena) {
+ upb_array **arr_ptr = PTR_AT(msg, ofs, upb_array*);
+ upb_array *arr = *arr_ptr;
+ void* ptr;
+ if (!arr || arr->len == arr->size) {
+ return _upb_array_append_fallback(arr_ptr, value, type, arena);
+ }
+ ptr = _upb_array_ptr(arr);
+ memcpy(PTR_AT(ptr, arr->len * elem_size, char), value, elem_size);
+ arr->len++;
+ return true;
+}
+
+/** upb_map *******************************************************************/
+
+/* Right now we use strmaps for everything. We'll likely want to use
+ * integer-specific maps for integer-keyed maps.*/
+typedef struct {
+ /* Size of key and val, based on the map type. Strings are represented as '0'
+ * because they must be handled specially. */
+ char key_size;
+ char val_size;
+
+ upb_strtable table;
+} upb_map;
+
+/* Map entries aren't actually stored, they are only used during parsing. For
+ * parsing, it helps a lot if all map entry messages have the same layout.
+ * The compiler and def.c must ensure that all map entries have this layout. */
+typedef struct {
+ upb_msg_internal internal;
+ union {
+ upb_strview str; /* For str/bytes. */
+ upb_value val; /* For all other types. */
+ } k;
+ union {
+ upb_strview str; /* For str/bytes. */
+ upb_value val; /* For all other types. */
+ } v;
+} upb_map_entry;
+
+/* Creates a new map on the given arena with this key/value type. */
+upb_map *_upb_map_new(upb_arena *a, size_t key_size, size_t value_size);
+
+/* Converting between internal table representation and user values.
+ *
+ * _upb_map_tokey() and _upb_map_fromkey() are inverses.
+ * _upb_map_tovalue() and _upb_map_fromvalue() are inverses.
+ *
+ * These functions account for the fact that strings are treated differently
+ * from other types when stored in a map.
+ */
+
+UPB_INLINE upb_strview _upb_map_tokey(const void *key, size_t size) {
+ if (size == UPB_MAPTYPE_STRING) {
+ return *(upb_strview*)key;
+ } else {
+ return upb_strview_make((const char*)key, size);
+ }
+}
+
+UPB_INLINE void _upb_map_fromkey(upb_strview key, void* out, size_t size) {
+ if (size == UPB_MAPTYPE_STRING) {
+ memcpy(out, &key, sizeof(key));
+ } else {
+ memcpy(out, key.data, size);
+ }
+}
+
+UPB_INLINE upb_value _upb_map_tovalue(const void *val, size_t size,
+ upb_arena *a) {
+ upb_value ret = {0};
+ if (size == UPB_MAPTYPE_STRING) {
+ upb_strview *strp = (upb_strview*)upb_arena_malloc(a, sizeof(*strp));
+ *strp = *(upb_strview*)val;
+ memcpy(&ret, &strp, sizeof(strp));
+ } else {
+ memcpy(&ret, val, size);
+ }
+ return ret;
+}
+
+UPB_INLINE void _upb_map_fromvalue(upb_value val, void* out, size_t size) {
+ if (size == UPB_MAPTYPE_STRING) {
+ const upb_strview *strp = (const upb_strview*)upb_value_getptr(val);
+ memcpy(out, strp, sizeof(upb_strview));
+ } else {
+ memcpy(out, &val, size);
+ }
+}
+
+/* Map operations, shared by reflection and generated code. */
+
+UPB_INLINE size_t _upb_map_size(const upb_map *map) {
+ return map->table.t.count;
+}
+
+UPB_INLINE bool _upb_map_get(const upb_map *map, const void *key,
+ size_t key_size, void *val, size_t val_size) {
+ upb_value tabval;
+ upb_strview k = _upb_map_tokey(key, key_size);
+ bool ret = upb_strtable_lookup2(&map->table, k.data, k.size, &tabval);
+ if (ret) {
+ _upb_map_fromvalue(tabval, val, val_size);
+ }
+ return ret;
+}
+
+UPB_INLINE void* _upb_map_next(const upb_map *map, size_t *iter) {
+ upb_strtable_iter it;
+ it.t = &map->table;
+ it.index = *iter;
+ upb_strtable_next(&it);
+ if (upb_strtable_done(&it)) return NULL;
+ *iter = it.index;
+ return (void*)str_tabent(&it);
+}
+
+UPB_INLINE bool _upb_map_set(upb_map *map, const void *key, size_t key_size,
+ void *val, size_t val_size, upb_arena *arena) {
+ upb_strview strkey = _upb_map_tokey(key, key_size);
+ upb_value tabval = _upb_map_tovalue(val, val_size, arena);
+ upb_alloc *a = upb_arena_alloc(arena);
+
+ /* TODO(haberman): add overwrite operation to minimize number of lookups. */
+ upb_strtable_remove3(&map->table, strkey.data, strkey.size, NULL, a);
+ return upb_strtable_insert3(&map->table, strkey.data, strkey.size, tabval, a);
+}
+
+UPB_INLINE bool _upb_map_delete(upb_map *map, const void *key, size_t key_size) {
+ upb_strview k = _upb_map_tokey(key, key_size);
+ return upb_strtable_remove3(&map->table, k.data, k.size, NULL, NULL);
+}
+
+UPB_INLINE void _upb_map_clear(upb_map *map) {
+ upb_strtable_clear(&map->table);
+}
+
+/* Message map operations, these get the map from the message first. */
+
+UPB_INLINE size_t _upb_msg_map_size(const upb_msg *msg, size_t ofs) {
+ upb_map *map = *UPB_PTR_AT(msg, ofs, upb_map *);
+ return map ? _upb_map_size(map) : 0;
+}
+
+UPB_INLINE bool _upb_msg_map_get(const upb_msg *msg, size_t ofs,
+ const void *key, size_t key_size, void *val,
+ size_t val_size) {
+ upb_map *map = *UPB_PTR_AT(msg, ofs, upb_map *);
+ if (!map) return false;
+ return _upb_map_get(map, key, key_size, val, val_size);
+}
+
+UPB_INLINE void *_upb_msg_map_next(const upb_msg *msg, size_t ofs,
+ size_t *iter) {
+ upb_map *map = *UPB_PTR_AT(msg, ofs, upb_map *);
+ if (!map) return NULL;
+ return _upb_map_next(map, iter);
+}
+
+UPB_INLINE bool _upb_msg_map_set(upb_msg *msg, size_t ofs, const void *key,
+ size_t key_size, void *val, size_t val_size,
+ upb_arena *arena) {
+ upb_map **map = PTR_AT(msg, ofs, upb_map *);
+ if (!*map) {
+ *map = _upb_map_new(arena, key_size, val_size);
+ }
+ return _upb_map_set(*map, key, key_size, val, val_size, arena);
+}
+
+UPB_INLINE bool _upb_msg_map_delete(upb_msg *msg, size_t ofs, const void *key,
+ size_t key_size) {
+ upb_map *map = *UPB_PTR_AT(msg, ofs, upb_map *);
+ if (!map) return false;
+ return _upb_map_delete(map, key, key_size);
+}
+
+UPB_INLINE void _upb_msg_map_clear(upb_msg *msg, size_t ofs) {
+ upb_map *map = *UPB_PTR_AT(msg, ofs, upb_map *);
+ if (!map) return;
+ _upb_map_clear(map);
+}
+
+/* Accessing map key/value from a pointer, used by generated code only. */
+
+UPB_INLINE void _upb_msg_map_key(const void* msg, void* key, size_t size) {
+ const upb_tabent *ent = (const upb_tabent*)msg;
+ uint32_t u32len;
+ upb_strview k;
+ k.data = upb_tabstr(ent->key, &u32len);
+ k.size = u32len;
+ _upb_map_fromkey(k, key, size);
+}
+
+UPB_INLINE void _upb_msg_map_value(const void* msg, void* val, size_t size) {
+ const upb_tabent *ent = (const upb_tabent*)msg;
+ upb_value v;
+ _upb_value_setval(&v, ent->val.val);
+ _upb_map_fromvalue(v, val, size);
+}
+
+UPB_INLINE void _upb_msg_map_set_value(void* msg, const void* val, size_t size) {
+ upb_tabent *ent = (upb_tabent*)msg;
+ /* This is like _upb_map_tovalue() except the entry already exists so we can
+ * reuse the allocated upb_strview for string fields. */
+ if (size == UPB_MAPTYPE_STRING) {
+ upb_strview *strp = (upb_strview*)ent->val.val;
+ memcpy(strp, val, sizeof(*strp));
+ } else {
+ memcpy(&ent->val.val, val, size);
+ }
+}
+
#undef PTR_AT
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
-#endif /* UPB_GENERATED_UTIL_H_ */
+
+#endif /* UPB_MSG_H_ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+bool upb_decode(const char *buf, size_t size, upb_msg *msg,
+ const upb_msglayout *l, upb_arena *arena);
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif /* UPB_DECODE_H_ */
+/*
+** upb_encode: parsing into a upb_msg using a upb_msglayout.
+*/
+
+#ifndef UPB_ENCODE_H_
+#define UPB_ENCODE_H_
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+char *upb_encode(const void *msg, const upb_msglayout *l, upb_arena *arena,
+ size_t *size);
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif /* UPB_ENCODE_H_ */
+/* This file was generated by upbc (the upb compiler) from the input
+ * file:
+ *
+ * google/protobuf/descriptor.proto
+ *
+ * Do not edit -- your changes will be discarded when the file is
+ * regenerated. */
+
+#ifndef GOOGLE_PROTOBUF_DESCRIPTOR_PROTO_UPB_H_
+#define GOOGLE_PROTOBUF_DESCRIPTOR_PROTO_UPB_H_
+
#ifdef __cplusplus
@@ -1381,7 +1641,7 @@
/* google.protobuf.FileDescriptorSet */
UPB_INLINE google_protobuf_FileDescriptorSet *google_protobuf_FileDescriptorSet_new(upb_arena *arena) {
- return (google_protobuf_FileDescriptorSet *)upb_msg_new(&google_protobuf_FileDescriptorSet_msginit, arena);
+ return (google_protobuf_FileDescriptorSet *)_upb_msg_new(&google_protobuf_FileDescriptorSet_msginit, arena);
}
UPB_INLINE google_protobuf_FileDescriptorSet *google_protobuf_FileDescriptorSet_parse(const char *buf, size_t size,
upb_arena *arena) {
@@ -1392,16 +1652,17 @@
return upb_encode(msg, &google_protobuf_FileDescriptorSet_msginit, arena, len);
}
+UPB_INLINE bool google_protobuf_FileDescriptorSet_has_file(const google_protobuf_FileDescriptorSet *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(0, 0)); }
UPB_INLINE const google_protobuf_FileDescriptorProto* const* google_protobuf_FileDescriptorSet_file(const google_protobuf_FileDescriptorSet *msg, size_t *len) { return (const google_protobuf_FileDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(0, 0), len); }
UPB_INLINE google_protobuf_FileDescriptorProto** google_protobuf_FileDescriptorSet_mutable_file(google_protobuf_FileDescriptorSet *msg, size_t *len) {
return (google_protobuf_FileDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(0, 0), len);
}
UPB_INLINE google_protobuf_FileDescriptorProto** google_protobuf_FileDescriptorSet_resize_file(google_protobuf_FileDescriptorSet *msg, size_t len, upb_arena *arena) {
- return (google_protobuf_FileDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(0, 0), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
+ return (google_protobuf_FileDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(0, 0), len, UPB_TYPE_MESSAGE, arena);
}
UPB_INLINE struct google_protobuf_FileDescriptorProto* google_protobuf_FileDescriptorSet_add_file(google_protobuf_FileDescriptorSet *msg, upb_arena *arena) {
- struct google_protobuf_FileDescriptorProto* sub = (struct google_protobuf_FileDescriptorProto*)upb_msg_new(&google_protobuf_FileDescriptorProto_msginit, arena);
+ struct google_protobuf_FileDescriptorProto* sub = (struct google_protobuf_FileDescriptorProto*)_upb_msg_new(&google_protobuf_FileDescriptorProto_msginit, arena);
bool ok = _upb_array_append_accessor(
msg, UPB_SIZE(0, 0), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
if (!ok) return NULL;
@@ -1411,7 +1672,7 @@
/* google.protobuf.FileDescriptorProto */
UPB_INLINE google_protobuf_FileDescriptorProto *google_protobuf_FileDescriptorProto_new(upb_arena *arena) {
- return (google_protobuf_FileDescriptorProto *)upb_msg_new(&google_protobuf_FileDescriptorProto_msginit, arena);
+ return (google_protobuf_FileDescriptorProto *)_upb_msg_new(&google_protobuf_FileDescriptorProto_msginit, arena);
}
UPB_INLINE google_protobuf_FileDescriptorProto *google_protobuf_FileDescriptorProto_parse(const char *buf, size_t size,
upb_arena *arena) {
@@ -1423,49 +1684,53 @@
}
UPB_INLINE bool google_protobuf_FileDescriptorProto_has_name(const google_protobuf_FileDescriptorProto *msg) { return _upb_has_field(msg, 1); }
-UPB_INLINE upb_strview google_protobuf_FileDescriptorProto_name(const google_protobuf_FileDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(4, 8)); }
+UPB_INLINE upb_strview google_protobuf_FileDescriptorProto_name(const google_protobuf_FileDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview); }
UPB_INLINE bool google_protobuf_FileDescriptorProto_has_package(const google_protobuf_FileDescriptorProto *msg) { return _upb_has_field(msg, 2); }
-UPB_INLINE upb_strview google_protobuf_FileDescriptorProto_package(const google_protobuf_FileDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(12, 24)); }
+UPB_INLINE upb_strview google_protobuf_FileDescriptorProto_package(const google_protobuf_FileDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(12, 24), upb_strview); }
UPB_INLINE upb_strview const* google_protobuf_FileDescriptorProto_dependency(const google_protobuf_FileDescriptorProto *msg, size_t *len) { return (upb_strview const*)_upb_array_accessor(msg, UPB_SIZE(36, 72), len); }
+UPB_INLINE bool google_protobuf_FileDescriptorProto_has_message_type(const google_protobuf_FileDescriptorProto *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(40, 80)); }
UPB_INLINE const google_protobuf_DescriptorProto* const* google_protobuf_FileDescriptorProto_message_type(const google_protobuf_FileDescriptorProto *msg, size_t *len) { return (const google_protobuf_DescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(40, 80), len); }
+UPB_INLINE bool google_protobuf_FileDescriptorProto_has_enum_type(const google_protobuf_FileDescriptorProto *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(44, 88)); }
UPB_INLINE const google_protobuf_EnumDescriptorProto* const* google_protobuf_FileDescriptorProto_enum_type(const google_protobuf_FileDescriptorProto *msg, size_t *len) { return (const google_protobuf_EnumDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(44, 88), len); }
+UPB_INLINE bool google_protobuf_FileDescriptorProto_has_service(const google_protobuf_FileDescriptorProto *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(48, 96)); }
UPB_INLINE const google_protobuf_ServiceDescriptorProto* const* google_protobuf_FileDescriptorProto_service(const google_protobuf_FileDescriptorProto *msg, size_t *len) { return (const google_protobuf_ServiceDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(48, 96), len); }
+UPB_INLINE bool google_protobuf_FileDescriptorProto_has_extension(const google_protobuf_FileDescriptorProto *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(52, 104)); }
UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_FileDescriptorProto_extension(const google_protobuf_FileDescriptorProto *msg, size_t *len) { return (const google_protobuf_FieldDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(52, 104), len); }
UPB_INLINE bool google_protobuf_FileDescriptorProto_has_options(const google_protobuf_FileDescriptorProto *msg) { return _upb_has_field(msg, 4); }
-UPB_INLINE const google_protobuf_FileOptions* google_protobuf_FileDescriptorProto_options(const google_protobuf_FileDescriptorProto *msg) { return UPB_FIELD_AT(msg, const google_protobuf_FileOptions*, UPB_SIZE(28, 56)); }
+UPB_INLINE const google_protobuf_FileOptions* google_protobuf_FileDescriptorProto_options(const google_protobuf_FileDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(28, 56), const google_protobuf_FileOptions*); }
UPB_INLINE bool google_protobuf_FileDescriptorProto_has_source_code_info(const google_protobuf_FileDescriptorProto *msg) { return _upb_has_field(msg, 5); }
-UPB_INLINE const google_protobuf_SourceCodeInfo* google_protobuf_FileDescriptorProto_source_code_info(const google_protobuf_FileDescriptorProto *msg) { return UPB_FIELD_AT(msg, const google_protobuf_SourceCodeInfo*, UPB_SIZE(32, 64)); }
+UPB_INLINE const google_protobuf_SourceCodeInfo* google_protobuf_FileDescriptorProto_source_code_info(const google_protobuf_FileDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(32, 64), const google_protobuf_SourceCodeInfo*); }
UPB_INLINE int32_t const* google_protobuf_FileDescriptorProto_public_dependency(const google_protobuf_FileDescriptorProto *msg, size_t *len) { return (int32_t const*)_upb_array_accessor(msg, UPB_SIZE(56, 112), len); }
UPB_INLINE int32_t const* google_protobuf_FileDescriptorProto_weak_dependency(const google_protobuf_FileDescriptorProto *msg, size_t *len) { return (int32_t const*)_upb_array_accessor(msg, UPB_SIZE(60, 120), len); }
UPB_INLINE bool google_protobuf_FileDescriptorProto_has_syntax(const google_protobuf_FileDescriptorProto *msg) { return _upb_has_field(msg, 3); }
-UPB_INLINE upb_strview google_protobuf_FileDescriptorProto_syntax(const google_protobuf_FileDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(20, 40)); }
+UPB_INLINE upb_strview google_protobuf_FileDescriptorProto_syntax(const google_protobuf_FileDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(20, 40), upb_strview); }
UPB_INLINE void google_protobuf_FileDescriptorProto_set_name(google_protobuf_FileDescriptorProto *msg, upb_strview value) {
_upb_sethas(msg, 1);
- UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(4, 8)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview) = value;
}
UPB_INLINE void google_protobuf_FileDescriptorProto_set_package(google_protobuf_FileDescriptorProto *msg, upb_strview value) {
_upb_sethas(msg, 2);
- UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(12, 24)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(12, 24), upb_strview) = value;
}
UPB_INLINE upb_strview* google_protobuf_FileDescriptorProto_mutable_dependency(google_protobuf_FileDescriptorProto *msg, size_t *len) {
return (upb_strview*)_upb_array_mutable_accessor(msg, UPB_SIZE(36, 72), len);
}
UPB_INLINE upb_strview* google_protobuf_FileDescriptorProto_resize_dependency(google_protobuf_FileDescriptorProto *msg, size_t len, upb_arena *arena) {
- return (upb_strview*)_upb_array_resize_accessor(msg, UPB_SIZE(36, 72), len, UPB_SIZE(8, 16), UPB_TYPE_STRING, arena);
+ return (upb_strview*)_upb_array_resize_accessor(msg, UPB_SIZE(36, 72), len, UPB_TYPE_STRING, arena);
}
UPB_INLINE bool google_protobuf_FileDescriptorProto_add_dependency(google_protobuf_FileDescriptorProto *msg, upb_strview val, upb_arena *arena) {
- return _upb_array_append_accessor(
- msg, UPB_SIZE(36, 72), UPB_SIZE(8, 16), UPB_TYPE_STRING, &val, arena);
+ return _upb_array_append_accessor(msg, UPB_SIZE(36, 72), UPB_SIZE(8, 16), UPB_TYPE_STRING, &val,
+ arena);
}
UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_FileDescriptorProto_mutable_message_type(google_protobuf_FileDescriptorProto *msg, size_t *len) {
return (google_protobuf_DescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(40, 80), len);
}
UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_FileDescriptorProto_resize_message_type(google_protobuf_FileDescriptorProto *msg, size_t len, upb_arena *arena) {
- return (google_protobuf_DescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(40, 80), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
+ return (google_protobuf_DescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(40, 80), len, UPB_TYPE_MESSAGE, arena);
}
UPB_INLINE struct google_protobuf_DescriptorProto* google_protobuf_FileDescriptorProto_add_message_type(google_protobuf_FileDescriptorProto *msg, upb_arena *arena) {
- struct google_protobuf_DescriptorProto* sub = (struct google_protobuf_DescriptorProto*)upb_msg_new(&google_protobuf_DescriptorProto_msginit, arena);
+ struct google_protobuf_DescriptorProto* sub = (struct google_protobuf_DescriptorProto*)_upb_msg_new(&google_protobuf_DescriptorProto_msginit, arena);
bool ok = _upb_array_append_accessor(
msg, UPB_SIZE(40, 80), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
if (!ok) return NULL;
@@ -1475,10 +1740,10 @@
return (google_protobuf_EnumDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(44, 88), len);
}
UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_FileDescriptorProto_resize_enum_type(google_protobuf_FileDescriptorProto *msg, size_t len, upb_arena *arena) {
- return (google_protobuf_EnumDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(44, 88), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
+ return (google_protobuf_EnumDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(44, 88), len, UPB_TYPE_MESSAGE, arena);
}
UPB_INLINE struct google_protobuf_EnumDescriptorProto* google_protobuf_FileDescriptorProto_add_enum_type(google_protobuf_FileDescriptorProto *msg, upb_arena *arena) {
- struct google_protobuf_EnumDescriptorProto* sub = (struct google_protobuf_EnumDescriptorProto*)upb_msg_new(&google_protobuf_EnumDescriptorProto_msginit, arena);
+ struct google_protobuf_EnumDescriptorProto* sub = (struct google_protobuf_EnumDescriptorProto*)_upb_msg_new(&google_protobuf_EnumDescriptorProto_msginit, arena);
bool ok = _upb_array_append_accessor(
msg, UPB_SIZE(44, 88), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
if (!ok) return NULL;
@@ -1488,10 +1753,10 @@
return (google_protobuf_ServiceDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(48, 96), len);
}
UPB_INLINE google_protobuf_ServiceDescriptorProto** google_protobuf_FileDescriptorProto_resize_service(google_protobuf_FileDescriptorProto *msg, size_t len, upb_arena *arena) {
- return (google_protobuf_ServiceDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(48, 96), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
+ return (google_protobuf_ServiceDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(48, 96), len, UPB_TYPE_MESSAGE, arena);
}
UPB_INLINE struct google_protobuf_ServiceDescriptorProto* google_protobuf_FileDescriptorProto_add_service(google_protobuf_FileDescriptorProto *msg, upb_arena *arena) {
- struct google_protobuf_ServiceDescriptorProto* sub = (struct google_protobuf_ServiceDescriptorProto*)upb_msg_new(&google_protobuf_ServiceDescriptorProto_msginit, arena);
+ struct google_protobuf_ServiceDescriptorProto* sub = (struct google_protobuf_ServiceDescriptorProto*)_upb_msg_new(&google_protobuf_ServiceDescriptorProto_msginit, arena);
bool ok = _upb_array_append_accessor(
msg, UPB_SIZE(48, 96), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
if (!ok) return NULL;
@@ -1501,10 +1766,10 @@
return (google_protobuf_FieldDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(52, 104), len);
}
UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_FileDescriptorProto_resize_extension(google_protobuf_FileDescriptorProto *msg, size_t len, upb_arena *arena) {
- return (google_protobuf_FieldDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(52, 104), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
+ return (google_protobuf_FieldDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(52, 104), len, UPB_TYPE_MESSAGE, arena);
}
UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_FileDescriptorProto_add_extension(google_protobuf_FileDescriptorProto *msg, upb_arena *arena) {
- struct google_protobuf_FieldDescriptorProto* sub = (struct google_protobuf_FieldDescriptorProto*)upb_msg_new(&google_protobuf_FieldDescriptorProto_msginit, arena);
+ struct google_protobuf_FieldDescriptorProto* sub = (struct google_protobuf_FieldDescriptorProto*)_upb_msg_new(&google_protobuf_FieldDescriptorProto_msginit, arena);
bool ok = _upb_array_append_accessor(
msg, UPB_SIZE(52, 104), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
if (!ok) return NULL;
@@ -1512,12 +1777,12 @@
}
UPB_INLINE void google_protobuf_FileDescriptorProto_set_options(google_protobuf_FileDescriptorProto *msg, google_protobuf_FileOptions* value) {
_upb_sethas(msg, 4);
- UPB_FIELD_AT(msg, google_protobuf_FileOptions*, UPB_SIZE(28, 56)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(28, 56), google_protobuf_FileOptions*) = value;
}
UPB_INLINE struct google_protobuf_FileOptions* google_protobuf_FileDescriptorProto_mutable_options(google_protobuf_FileDescriptorProto *msg, upb_arena *arena) {
struct google_protobuf_FileOptions* sub = (struct google_protobuf_FileOptions*)google_protobuf_FileDescriptorProto_options(msg);
if (sub == NULL) {
- sub = (struct google_protobuf_FileOptions*)upb_msg_new(&google_protobuf_FileOptions_msginit, arena);
+ sub = (struct google_protobuf_FileOptions*)_upb_msg_new(&google_protobuf_FileOptions_msginit, arena);
if (!sub) return NULL;
google_protobuf_FileDescriptorProto_set_options(msg, sub);
}
@@ -1525,12 +1790,12 @@
}
UPB_INLINE void google_protobuf_FileDescriptorProto_set_source_code_info(google_protobuf_FileDescriptorProto *msg, google_protobuf_SourceCodeInfo* value) {
_upb_sethas(msg, 5);
- UPB_FIELD_AT(msg, google_protobuf_SourceCodeInfo*, UPB_SIZE(32, 64)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(32, 64), google_protobuf_SourceCodeInfo*) = value;
}
UPB_INLINE struct google_protobuf_SourceCodeInfo* google_protobuf_FileDescriptorProto_mutable_source_code_info(google_protobuf_FileDescriptorProto *msg, upb_arena *arena) {
struct google_protobuf_SourceCodeInfo* sub = (struct google_protobuf_SourceCodeInfo*)google_protobuf_FileDescriptorProto_source_code_info(msg);
if (sub == NULL) {
- sub = (struct google_protobuf_SourceCodeInfo*)upb_msg_new(&google_protobuf_SourceCodeInfo_msginit, arena);
+ sub = (struct google_protobuf_SourceCodeInfo*)_upb_msg_new(&google_protobuf_SourceCodeInfo_msginit, arena);
if (!sub) return NULL;
google_protobuf_FileDescriptorProto_set_source_code_info(msg, sub);
}
@@ -1540,31 +1805,31 @@
return (int32_t*)_upb_array_mutable_accessor(msg, UPB_SIZE(56, 112), len);
}
UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_resize_public_dependency(google_protobuf_FileDescriptorProto *msg, size_t len, upb_arena *arena) {
- return (int32_t*)_upb_array_resize_accessor(msg, UPB_SIZE(56, 112), len, UPB_SIZE(4, 4), UPB_TYPE_INT32, arena);
+ return (int32_t*)_upb_array_resize_accessor(msg, UPB_SIZE(56, 112), len, UPB_TYPE_INT32, arena);
}
UPB_INLINE bool google_protobuf_FileDescriptorProto_add_public_dependency(google_protobuf_FileDescriptorProto *msg, int32_t val, upb_arena *arena) {
- return _upb_array_append_accessor(
- msg, UPB_SIZE(56, 112), UPB_SIZE(4, 4), UPB_TYPE_INT32, &val, arena);
+ return _upb_array_append_accessor(msg, UPB_SIZE(56, 112), UPB_SIZE(4, 4), UPB_TYPE_INT32, &val,
+ arena);
}
UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_mutable_weak_dependency(google_protobuf_FileDescriptorProto *msg, size_t *len) {
return (int32_t*)_upb_array_mutable_accessor(msg, UPB_SIZE(60, 120), len);
}
UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_resize_weak_dependency(google_protobuf_FileDescriptorProto *msg, size_t len, upb_arena *arena) {
- return (int32_t*)_upb_array_resize_accessor(msg, UPB_SIZE(60, 120), len, UPB_SIZE(4, 4), UPB_TYPE_INT32, arena);
+ return (int32_t*)_upb_array_resize_accessor(msg, UPB_SIZE(60, 120), len, UPB_TYPE_INT32, arena);
}
UPB_INLINE bool google_protobuf_FileDescriptorProto_add_weak_dependency(google_protobuf_FileDescriptorProto *msg, int32_t val, upb_arena *arena) {
- return _upb_array_append_accessor(
- msg, UPB_SIZE(60, 120), UPB_SIZE(4, 4), UPB_TYPE_INT32, &val, arena);
+ return _upb_array_append_accessor(msg, UPB_SIZE(60, 120), UPB_SIZE(4, 4), UPB_TYPE_INT32, &val,
+ arena);
}
UPB_INLINE void google_protobuf_FileDescriptorProto_set_syntax(google_protobuf_FileDescriptorProto *msg, upb_strview value) {
_upb_sethas(msg, 3);
- UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(20, 40)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(20, 40), upb_strview) = value;
}
/* google.protobuf.DescriptorProto */
UPB_INLINE google_protobuf_DescriptorProto *google_protobuf_DescriptorProto_new(upb_arena *arena) {
- return (google_protobuf_DescriptorProto *)upb_msg_new(&google_protobuf_DescriptorProto_msginit, arena);
+ return (google_protobuf_DescriptorProto *)_upb_msg_new(&google_protobuf_DescriptorProto_msginit, arena);
}
UPB_INLINE google_protobuf_DescriptorProto *google_protobuf_DescriptorProto_parse(const char *buf, size_t size,
upb_arena *arena) {
@@ -1576,30 +1841,37 @@
}
UPB_INLINE bool google_protobuf_DescriptorProto_has_name(const google_protobuf_DescriptorProto *msg) { return _upb_has_field(msg, 1); }
-UPB_INLINE upb_strview google_protobuf_DescriptorProto_name(const google_protobuf_DescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(4, 8)); }
+UPB_INLINE upb_strview google_protobuf_DescriptorProto_name(const google_protobuf_DescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview); }
+UPB_INLINE bool google_protobuf_DescriptorProto_has_field(const google_protobuf_DescriptorProto *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(16, 32)); }
UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_DescriptorProto_field(const google_protobuf_DescriptorProto *msg, size_t *len) { return (const google_protobuf_FieldDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(16, 32), len); }
+UPB_INLINE bool google_protobuf_DescriptorProto_has_nested_type(const google_protobuf_DescriptorProto *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(20, 40)); }
UPB_INLINE const google_protobuf_DescriptorProto* const* google_protobuf_DescriptorProto_nested_type(const google_protobuf_DescriptorProto *msg, size_t *len) { return (const google_protobuf_DescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(20, 40), len); }
+UPB_INLINE bool google_protobuf_DescriptorProto_has_enum_type(const google_protobuf_DescriptorProto *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(24, 48)); }
UPB_INLINE const google_protobuf_EnumDescriptorProto* const* google_protobuf_DescriptorProto_enum_type(const google_protobuf_DescriptorProto *msg, size_t *len) { return (const google_protobuf_EnumDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(24, 48), len); }
+UPB_INLINE bool google_protobuf_DescriptorProto_has_extension_range(const google_protobuf_DescriptorProto *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(28, 56)); }
UPB_INLINE const google_protobuf_DescriptorProto_ExtensionRange* const* google_protobuf_DescriptorProto_extension_range(const google_protobuf_DescriptorProto *msg, size_t *len) { return (const google_protobuf_DescriptorProto_ExtensionRange* const*)_upb_array_accessor(msg, UPB_SIZE(28, 56), len); }
+UPB_INLINE bool google_protobuf_DescriptorProto_has_extension(const google_protobuf_DescriptorProto *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(32, 64)); }
UPB_INLINE const google_protobuf_FieldDescriptorProto* const* google_protobuf_DescriptorProto_extension(const google_protobuf_DescriptorProto *msg, size_t *len) { return (const google_protobuf_FieldDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(32, 64), len); }
UPB_INLINE bool google_protobuf_DescriptorProto_has_options(const google_protobuf_DescriptorProto *msg) { return _upb_has_field(msg, 2); }
-UPB_INLINE const google_protobuf_MessageOptions* google_protobuf_DescriptorProto_options(const google_protobuf_DescriptorProto *msg) { return UPB_FIELD_AT(msg, const google_protobuf_MessageOptions*, UPB_SIZE(12, 24)); }
+UPB_INLINE const google_protobuf_MessageOptions* google_protobuf_DescriptorProto_options(const google_protobuf_DescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(12, 24), const google_protobuf_MessageOptions*); }
+UPB_INLINE bool google_protobuf_DescriptorProto_has_oneof_decl(const google_protobuf_DescriptorProto *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(36, 72)); }
UPB_INLINE const google_protobuf_OneofDescriptorProto* const* google_protobuf_DescriptorProto_oneof_decl(const google_protobuf_DescriptorProto *msg, size_t *len) { return (const google_protobuf_OneofDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(36, 72), len); }
+UPB_INLINE bool google_protobuf_DescriptorProto_has_reserved_range(const google_protobuf_DescriptorProto *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(40, 80)); }
UPB_INLINE const google_protobuf_DescriptorProto_ReservedRange* const* google_protobuf_DescriptorProto_reserved_range(const google_protobuf_DescriptorProto *msg, size_t *len) { return (const google_protobuf_DescriptorProto_ReservedRange* const*)_upb_array_accessor(msg, UPB_SIZE(40, 80), len); }
UPB_INLINE upb_strview const* google_protobuf_DescriptorProto_reserved_name(const google_protobuf_DescriptorProto *msg, size_t *len) { return (upb_strview const*)_upb_array_accessor(msg, UPB_SIZE(44, 88), len); }
UPB_INLINE void google_protobuf_DescriptorProto_set_name(google_protobuf_DescriptorProto *msg, upb_strview value) {
_upb_sethas(msg, 1);
- UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(4, 8)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview) = value;
}
UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProto_mutable_field(google_protobuf_DescriptorProto *msg, size_t *len) {
return (google_protobuf_FieldDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(16, 32), len);
}
UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProto_resize_field(google_protobuf_DescriptorProto *msg, size_t len, upb_arena *arena) {
- return (google_protobuf_FieldDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(16, 32), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
+ return (google_protobuf_FieldDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(16, 32), len, UPB_TYPE_MESSAGE, arena);
}
UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_DescriptorProto_add_field(google_protobuf_DescriptorProto *msg, upb_arena *arena) {
- struct google_protobuf_FieldDescriptorProto* sub = (struct google_protobuf_FieldDescriptorProto*)upb_msg_new(&google_protobuf_FieldDescriptorProto_msginit, arena);
+ struct google_protobuf_FieldDescriptorProto* sub = (struct google_protobuf_FieldDescriptorProto*)_upb_msg_new(&google_protobuf_FieldDescriptorProto_msginit, arena);
bool ok = _upb_array_append_accessor(
msg, UPB_SIZE(16, 32), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
if (!ok) return NULL;
@@ -1609,10 +1881,10 @@
return (google_protobuf_DescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(20, 40), len);
}
UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_DescriptorProto_resize_nested_type(google_protobuf_DescriptorProto *msg, size_t len, upb_arena *arena) {
- return (google_protobuf_DescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(20, 40), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
+ return (google_protobuf_DescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(20, 40), len, UPB_TYPE_MESSAGE, arena);
}
UPB_INLINE struct google_protobuf_DescriptorProto* google_protobuf_DescriptorProto_add_nested_type(google_protobuf_DescriptorProto *msg, upb_arena *arena) {
- struct google_protobuf_DescriptorProto* sub = (struct google_protobuf_DescriptorProto*)upb_msg_new(&google_protobuf_DescriptorProto_msginit, arena);
+ struct google_protobuf_DescriptorProto* sub = (struct google_protobuf_DescriptorProto*)_upb_msg_new(&google_protobuf_DescriptorProto_msginit, arena);
bool ok = _upb_array_append_accessor(
msg, UPB_SIZE(20, 40), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
if (!ok) return NULL;
@@ -1622,10 +1894,10 @@
return (google_protobuf_EnumDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(24, 48), len);
}
UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_DescriptorProto_resize_enum_type(google_protobuf_DescriptorProto *msg, size_t len, upb_arena *arena) {
- return (google_protobuf_EnumDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(24, 48), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
+ return (google_protobuf_EnumDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(24, 48), len, UPB_TYPE_MESSAGE, arena);
}
UPB_INLINE struct google_protobuf_EnumDescriptorProto* google_protobuf_DescriptorProto_add_enum_type(google_protobuf_DescriptorProto *msg, upb_arena *arena) {
- struct google_protobuf_EnumDescriptorProto* sub = (struct google_protobuf_EnumDescriptorProto*)upb_msg_new(&google_protobuf_EnumDescriptorProto_msginit, arena);
+ struct google_protobuf_EnumDescriptorProto* sub = (struct google_protobuf_EnumDescriptorProto*)_upb_msg_new(&google_protobuf_EnumDescriptorProto_msginit, arena);
bool ok = _upb_array_append_accessor(
msg, UPB_SIZE(24, 48), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
if (!ok) return NULL;
@@ -1635,10 +1907,10 @@
return (google_protobuf_DescriptorProto_ExtensionRange**)_upb_array_mutable_accessor(msg, UPB_SIZE(28, 56), len);
}
UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange** google_protobuf_DescriptorProto_resize_extension_range(google_protobuf_DescriptorProto *msg, size_t len, upb_arena *arena) {
- return (google_protobuf_DescriptorProto_ExtensionRange**)_upb_array_resize_accessor(msg, UPB_SIZE(28, 56), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
+ return (google_protobuf_DescriptorProto_ExtensionRange**)_upb_array_resize_accessor(msg, UPB_SIZE(28, 56), len, UPB_TYPE_MESSAGE, arena);
}
UPB_INLINE struct google_protobuf_DescriptorProto_ExtensionRange* google_protobuf_DescriptorProto_add_extension_range(google_protobuf_DescriptorProto *msg, upb_arena *arena) {
- struct google_protobuf_DescriptorProto_ExtensionRange* sub = (struct google_protobuf_DescriptorProto_ExtensionRange*)upb_msg_new(&google_protobuf_DescriptorProto_ExtensionRange_msginit, arena);
+ struct google_protobuf_DescriptorProto_ExtensionRange* sub = (struct google_protobuf_DescriptorProto_ExtensionRange*)_upb_msg_new(&google_protobuf_DescriptorProto_ExtensionRange_msginit, arena);
bool ok = _upb_array_append_accessor(
msg, UPB_SIZE(28, 56), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
if (!ok) return NULL;
@@ -1648,10 +1920,10 @@
return (google_protobuf_FieldDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(32, 64), len);
}
UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProto_resize_extension(google_protobuf_DescriptorProto *msg, size_t len, upb_arena *arena) {
- return (google_protobuf_FieldDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(32, 64), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
+ return (google_protobuf_FieldDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(32, 64), len, UPB_TYPE_MESSAGE, arena);
}
UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_DescriptorProto_add_extension(google_protobuf_DescriptorProto *msg, upb_arena *arena) {
- struct google_protobuf_FieldDescriptorProto* sub = (struct google_protobuf_FieldDescriptorProto*)upb_msg_new(&google_protobuf_FieldDescriptorProto_msginit, arena);
+ struct google_protobuf_FieldDescriptorProto* sub = (struct google_protobuf_FieldDescriptorProto*)_upb_msg_new(&google_protobuf_FieldDescriptorProto_msginit, arena);
bool ok = _upb_array_append_accessor(
msg, UPB_SIZE(32, 64), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
if (!ok) return NULL;
@@ -1659,12 +1931,12 @@
}
UPB_INLINE void google_protobuf_DescriptorProto_set_options(google_protobuf_DescriptorProto *msg, google_protobuf_MessageOptions* value) {
_upb_sethas(msg, 2);
- UPB_FIELD_AT(msg, google_protobuf_MessageOptions*, UPB_SIZE(12, 24)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(12, 24), google_protobuf_MessageOptions*) = value;
}
UPB_INLINE struct google_protobuf_MessageOptions* google_protobuf_DescriptorProto_mutable_options(google_protobuf_DescriptorProto *msg, upb_arena *arena) {
struct google_protobuf_MessageOptions* sub = (struct google_protobuf_MessageOptions*)google_protobuf_DescriptorProto_options(msg);
if (sub == NULL) {
- sub = (struct google_protobuf_MessageOptions*)upb_msg_new(&google_protobuf_MessageOptions_msginit, arena);
+ sub = (struct google_protobuf_MessageOptions*)_upb_msg_new(&google_protobuf_MessageOptions_msginit, arena);
if (!sub) return NULL;
google_protobuf_DescriptorProto_set_options(msg, sub);
}
@@ -1674,10 +1946,10 @@
return (google_protobuf_OneofDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(36, 72), len);
}
UPB_INLINE google_protobuf_OneofDescriptorProto** google_protobuf_DescriptorProto_resize_oneof_decl(google_protobuf_DescriptorProto *msg, size_t len, upb_arena *arena) {
- return (google_protobuf_OneofDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(36, 72), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
+ return (google_protobuf_OneofDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(36, 72), len, UPB_TYPE_MESSAGE, arena);
}
UPB_INLINE struct google_protobuf_OneofDescriptorProto* google_protobuf_DescriptorProto_add_oneof_decl(google_protobuf_DescriptorProto *msg, upb_arena *arena) {
- struct google_protobuf_OneofDescriptorProto* sub = (struct google_protobuf_OneofDescriptorProto*)upb_msg_new(&google_protobuf_OneofDescriptorProto_msginit, arena);
+ struct google_protobuf_OneofDescriptorProto* sub = (struct google_protobuf_OneofDescriptorProto*)_upb_msg_new(&google_protobuf_OneofDescriptorProto_msginit, arena);
bool ok = _upb_array_append_accessor(
msg, UPB_SIZE(36, 72), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
if (!ok) return NULL;
@@ -1687,10 +1959,10 @@
return (google_protobuf_DescriptorProto_ReservedRange**)_upb_array_mutable_accessor(msg, UPB_SIZE(40, 80), len);
}
UPB_INLINE google_protobuf_DescriptorProto_ReservedRange** google_protobuf_DescriptorProto_resize_reserved_range(google_protobuf_DescriptorProto *msg, size_t len, upb_arena *arena) {
- return (google_protobuf_DescriptorProto_ReservedRange**)_upb_array_resize_accessor(msg, UPB_SIZE(40, 80), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
+ return (google_protobuf_DescriptorProto_ReservedRange**)_upb_array_resize_accessor(msg, UPB_SIZE(40, 80), len, UPB_TYPE_MESSAGE, arena);
}
UPB_INLINE struct google_protobuf_DescriptorProto_ReservedRange* google_protobuf_DescriptorProto_add_reserved_range(google_protobuf_DescriptorProto *msg, upb_arena *arena) {
- struct google_protobuf_DescriptorProto_ReservedRange* sub = (struct google_protobuf_DescriptorProto_ReservedRange*)upb_msg_new(&google_protobuf_DescriptorProto_ReservedRange_msginit, arena);
+ struct google_protobuf_DescriptorProto_ReservedRange* sub = (struct google_protobuf_DescriptorProto_ReservedRange*)_upb_msg_new(&google_protobuf_DescriptorProto_ReservedRange_msginit, arena);
bool ok = _upb_array_append_accessor(
msg, UPB_SIZE(40, 80), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
if (!ok) return NULL;
@@ -1700,17 +1972,17 @@
return (upb_strview*)_upb_array_mutable_accessor(msg, UPB_SIZE(44, 88), len);
}
UPB_INLINE upb_strview* google_protobuf_DescriptorProto_resize_reserved_name(google_protobuf_DescriptorProto *msg, size_t len, upb_arena *arena) {
- return (upb_strview*)_upb_array_resize_accessor(msg, UPB_SIZE(44, 88), len, UPB_SIZE(8, 16), UPB_TYPE_STRING, arena);
+ return (upb_strview*)_upb_array_resize_accessor(msg, UPB_SIZE(44, 88), len, UPB_TYPE_STRING, arena);
}
UPB_INLINE bool google_protobuf_DescriptorProto_add_reserved_name(google_protobuf_DescriptorProto *msg, upb_strview val, upb_arena *arena) {
- return _upb_array_append_accessor(
- msg, UPB_SIZE(44, 88), UPB_SIZE(8, 16), UPB_TYPE_STRING, &val, arena);
+ return _upb_array_append_accessor(msg, UPB_SIZE(44, 88), UPB_SIZE(8, 16), UPB_TYPE_STRING, &val,
+ arena);
}
/* google.protobuf.DescriptorProto.ExtensionRange */
UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange *google_protobuf_DescriptorProto_ExtensionRange_new(upb_arena *arena) {
- return (google_protobuf_DescriptorProto_ExtensionRange *)upb_msg_new(&google_protobuf_DescriptorProto_ExtensionRange_msginit, arena);
+ return (google_protobuf_DescriptorProto_ExtensionRange *)_upb_msg_new(&google_protobuf_DescriptorProto_ExtensionRange_msginit, arena);
}
UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange *google_protobuf_DescriptorProto_ExtensionRange_parse(const char *buf, size_t size,
upb_arena *arena) {
@@ -1722,28 +1994,28 @@
}
UPB_INLINE bool google_protobuf_DescriptorProto_ExtensionRange_has_start(const google_protobuf_DescriptorProto_ExtensionRange *msg) { return _upb_has_field(msg, 1); }
-UPB_INLINE int32_t google_protobuf_DescriptorProto_ExtensionRange_start(const google_protobuf_DescriptorProto_ExtensionRange *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(4, 4)); }
+UPB_INLINE int32_t google_protobuf_DescriptorProto_ExtensionRange_start(const google_protobuf_DescriptorProto_ExtensionRange *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 4), int32_t); }
UPB_INLINE bool google_protobuf_DescriptorProto_ExtensionRange_has_end(const google_protobuf_DescriptorProto_ExtensionRange *msg) { return _upb_has_field(msg, 2); }
-UPB_INLINE int32_t google_protobuf_DescriptorProto_ExtensionRange_end(const google_protobuf_DescriptorProto_ExtensionRange *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)); }
+UPB_INLINE int32_t google_protobuf_DescriptorProto_ExtensionRange_end(const google_protobuf_DescriptorProto_ExtensionRange *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t); }
UPB_INLINE bool google_protobuf_DescriptorProto_ExtensionRange_has_options(const google_protobuf_DescriptorProto_ExtensionRange *msg) { return _upb_has_field(msg, 3); }
-UPB_INLINE const google_protobuf_ExtensionRangeOptions* google_protobuf_DescriptorProto_ExtensionRange_options(const google_protobuf_DescriptorProto_ExtensionRange *msg) { return UPB_FIELD_AT(msg, const google_protobuf_ExtensionRangeOptions*, UPB_SIZE(12, 16)); }
+UPB_INLINE const google_protobuf_ExtensionRangeOptions* google_protobuf_DescriptorProto_ExtensionRange_options(const google_protobuf_DescriptorProto_ExtensionRange *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(12, 16), const google_protobuf_ExtensionRangeOptions*); }
UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_set_start(google_protobuf_DescriptorProto_ExtensionRange *msg, int32_t value) {
_upb_sethas(msg, 1);
- UPB_FIELD_AT(msg, int32_t, UPB_SIZE(4, 4)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(4, 4), int32_t) = value;
}
UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_set_end(google_protobuf_DescriptorProto_ExtensionRange *msg, int32_t value) {
_upb_sethas(msg, 2);
- UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t) = value;
}
UPB_INLINE void google_protobuf_DescriptorProto_ExtensionRange_set_options(google_protobuf_DescriptorProto_ExtensionRange *msg, google_protobuf_ExtensionRangeOptions* value) {
_upb_sethas(msg, 3);
- UPB_FIELD_AT(msg, google_protobuf_ExtensionRangeOptions*, UPB_SIZE(12, 16)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(12, 16), google_protobuf_ExtensionRangeOptions*) = value;
}
UPB_INLINE struct google_protobuf_ExtensionRangeOptions* google_protobuf_DescriptorProto_ExtensionRange_mutable_options(google_protobuf_DescriptorProto_ExtensionRange *msg, upb_arena *arena) {
struct google_protobuf_ExtensionRangeOptions* sub = (struct google_protobuf_ExtensionRangeOptions*)google_protobuf_DescriptorProto_ExtensionRange_options(msg);
if (sub == NULL) {
- sub = (struct google_protobuf_ExtensionRangeOptions*)upb_msg_new(&google_protobuf_ExtensionRangeOptions_msginit, arena);
+ sub = (struct google_protobuf_ExtensionRangeOptions*)_upb_msg_new(&google_protobuf_ExtensionRangeOptions_msginit, arena);
if (!sub) return NULL;
google_protobuf_DescriptorProto_ExtensionRange_set_options(msg, sub);
}
@@ -1753,7 +2025,7 @@
/* google.protobuf.DescriptorProto.ReservedRange */
UPB_INLINE google_protobuf_DescriptorProto_ReservedRange *google_protobuf_DescriptorProto_ReservedRange_new(upb_arena *arena) {
- return (google_protobuf_DescriptorProto_ReservedRange *)upb_msg_new(&google_protobuf_DescriptorProto_ReservedRange_msginit, arena);
+ return (google_protobuf_DescriptorProto_ReservedRange *)_upb_msg_new(&google_protobuf_DescriptorProto_ReservedRange_msginit, arena);
}
UPB_INLINE google_protobuf_DescriptorProto_ReservedRange *google_protobuf_DescriptorProto_ReservedRange_parse(const char *buf, size_t size,
upb_arena *arena) {
@@ -1765,23 +2037,23 @@
}
UPB_INLINE bool google_protobuf_DescriptorProto_ReservedRange_has_start(const google_protobuf_DescriptorProto_ReservedRange *msg) { return _upb_has_field(msg, 1); }
-UPB_INLINE int32_t google_protobuf_DescriptorProto_ReservedRange_start(const google_protobuf_DescriptorProto_ReservedRange *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(4, 4)); }
+UPB_INLINE int32_t google_protobuf_DescriptorProto_ReservedRange_start(const google_protobuf_DescriptorProto_ReservedRange *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 4), int32_t); }
UPB_INLINE bool google_protobuf_DescriptorProto_ReservedRange_has_end(const google_protobuf_DescriptorProto_ReservedRange *msg) { return _upb_has_field(msg, 2); }
-UPB_INLINE int32_t google_protobuf_DescriptorProto_ReservedRange_end(const google_protobuf_DescriptorProto_ReservedRange *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)); }
+UPB_INLINE int32_t google_protobuf_DescriptorProto_ReservedRange_end(const google_protobuf_DescriptorProto_ReservedRange *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t); }
UPB_INLINE void google_protobuf_DescriptorProto_ReservedRange_set_start(google_protobuf_DescriptorProto_ReservedRange *msg, int32_t value) {
_upb_sethas(msg, 1);
- UPB_FIELD_AT(msg, int32_t, UPB_SIZE(4, 4)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(4, 4), int32_t) = value;
}
UPB_INLINE void google_protobuf_DescriptorProto_ReservedRange_set_end(google_protobuf_DescriptorProto_ReservedRange *msg, int32_t value) {
_upb_sethas(msg, 2);
- UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t) = value;
}
/* google.protobuf.ExtensionRangeOptions */
UPB_INLINE google_protobuf_ExtensionRangeOptions *google_protobuf_ExtensionRangeOptions_new(upb_arena *arena) {
- return (google_protobuf_ExtensionRangeOptions *)upb_msg_new(&google_protobuf_ExtensionRangeOptions_msginit, arena);
+ return (google_protobuf_ExtensionRangeOptions *)_upb_msg_new(&google_protobuf_ExtensionRangeOptions_msginit, arena);
}
UPB_INLINE google_protobuf_ExtensionRangeOptions *google_protobuf_ExtensionRangeOptions_parse(const char *buf, size_t size,
upb_arena *arena) {
@@ -1792,16 +2064,17 @@
return upb_encode(msg, &google_protobuf_ExtensionRangeOptions_msginit, arena, len);
}
+UPB_INLINE bool google_protobuf_ExtensionRangeOptions_has_uninterpreted_option(const google_protobuf_ExtensionRangeOptions *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(0, 0)); }
UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_ExtensionRangeOptions_uninterpreted_option(const google_protobuf_ExtensionRangeOptions *msg, size_t *len) { return (const google_protobuf_UninterpretedOption* const*)_upb_array_accessor(msg, UPB_SIZE(0, 0), len); }
UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ExtensionRangeOptions_mutable_uninterpreted_option(google_protobuf_ExtensionRangeOptions *msg, size_t *len) {
return (google_protobuf_UninterpretedOption**)_upb_array_mutable_accessor(msg, UPB_SIZE(0, 0), len);
}
UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ExtensionRangeOptions_resize_uninterpreted_option(google_protobuf_ExtensionRangeOptions *msg, size_t len, upb_arena *arena) {
- return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor(msg, UPB_SIZE(0, 0), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
+ return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor(msg, UPB_SIZE(0, 0), len, UPB_TYPE_MESSAGE, arena);
}
UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_ExtensionRangeOptions_add_uninterpreted_option(google_protobuf_ExtensionRangeOptions *msg, upb_arena *arena) {
- struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena);
+ struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena);
bool ok = _upb_array_append_accessor(
msg, UPB_SIZE(0, 0), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
if (!ok) return NULL;
@@ -1811,7 +2084,7 @@
/* google.protobuf.FieldDescriptorProto */
UPB_INLINE google_protobuf_FieldDescriptorProto *google_protobuf_FieldDescriptorProto_new(upb_arena *arena) {
- return (google_protobuf_FieldDescriptorProto *)upb_msg_new(&google_protobuf_FieldDescriptorProto_msginit, arena);
+ return (google_protobuf_FieldDescriptorProto *)_upb_msg_new(&google_protobuf_FieldDescriptorProto_msginit, arena);
}
UPB_INLINE google_protobuf_FieldDescriptorProto *google_protobuf_FieldDescriptorProto_parse(const char *buf, size_t size,
upb_arena *arena) {
@@ -1822,63 +2095,65 @@
return upb_encode(msg, &google_protobuf_FieldDescriptorProto_msginit, arena, len);
}
-UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_name(const google_protobuf_FieldDescriptorProto *msg) { return _upb_has_field(msg, 5); }
-UPB_INLINE upb_strview google_protobuf_FieldDescriptorProto_name(const google_protobuf_FieldDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(32, 32)); }
-UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_extendee(const google_protobuf_FieldDescriptorProto *msg) { return _upb_has_field(msg, 6); }
-UPB_INLINE upb_strview google_protobuf_FieldDescriptorProto_extendee(const google_protobuf_FieldDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(40, 48)); }
+UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_name(const google_protobuf_FieldDescriptorProto *msg) { return _upb_has_field(msg, 6); }
+UPB_INLINE upb_strview google_protobuf_FieldDescriptorProto_name(const google_protobuf_FieldDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(36, 40), upb_strview); }
+UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_extendee(const google_protobuf_FieldDescriptorProto *msg) { return _upb_has_field(msg, 7); }
+UPB_INLINE upb_strview google_protobuf_FieldDescriptorProto_extendee(const google_protobuf_FieldDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(44, 56), upb_strview); }
UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_number(const google_protobuf_FieldDescriptorProto *msg) { return _upb_has_field(msg, 3); }
-UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_number(const google_protobuf_FieldDescriptorProto *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(24, 24)); }
+UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_number(const google_protobuf_FieldDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(24, 24), int32_t); }
UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_label(const google_protobuf_FieldDescriptorProto *msg) { return _upb_has_field(msg, 1); }
-UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_label(const google_protobuf_FieldDescriptorProto *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)); }
+UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_label(const google_protobuf_FieldDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t); }
UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_type(const google_protobuf_FieldDescriptorProto *msg) { return _upb_has_field(msg, 2); }
-UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_type(const google_protobuf_FieldDescriptorProto *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(16, 16)); }
-UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_type_name(const google_protobuf_FieldDescriptorProto *msg) { return _upb_has_field(msg, 7); }
-UPB_INLINE upb_strview google_protobuf_FieldDescriptorProto_type_name(const google_protobuf_FieldDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(48, 64)); }
-UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_default_value(const google_protobuf_FieldDescriptorProto *msg) { return _upb_has_field(msg, 8); }
-UPB_INLINE upb_strview google_protobuf_FieldDescriptorProto_default_value(const google_protobuf_FieldDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(56, 80)); }
-UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_options(const google_protobuf_FieldDescriptorProto *msg) { return _upb_has_field(msg, 10); }
-UPB_INLINE const google_protobuf_FieldOptions* google_protobuf_FieldDescriptorProto_options(const google_protobuf_FieldDescriptorProto *msg) { return UPB_FIELD_AT(msg, const google_protobuf_FieldOptions*, UPB_SIZE(72, 112)); }
+UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_type(const google_protobuf_FieldDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(16, 16), int32_t); }
+UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_type_name(const google_protobuf_FieldDescriptorProto *msg) { return _upb_has_field(msg, 8); }
+UPB_INLINE upb_strview google_protobuf_FieldDescriptorProto_type_name(const google_protobuf_FieldDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(52, 72), upb_strview); }
+UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_default_value(const google_protobuf_FieldDescriptorProto *msg) { return _upb_has_field(msg, 9); }
+UPB_INLINE upb_strview google_protobuf_FieldDescriptorProto_default_value(const google_protobuf_FieldDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(60, 88), upb_strview); }
+UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_options(const google_protobuf_FieldDescriptorProto *msg) { return _upb_has_field(msg, 11); }
+UPB_INLINE const google_protobuf_FieldOptions* google_protobuf_FieldDescriptorProto_options(const google_protobuf_FieldDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(76, 120), const google_protobuf_FieldOptions*); }
UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_oneof_index(const google_protobuf_FieldDescriptorProto *msg) { return _upb_has_field(msg, 4); }
-UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_oneof_index(const google_protobuf_FieldDescriptorProto *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(28, 28)); }
-UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_json_name(const google_protobuf_FieldDescriptorProto *msg) { return _upb_has_field(msg, 9); }
-UPB_INLINE upb_strview google_protobuf_FieldDescriptorProto_json_name(const google_protobuf_FieldDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(64, 96)); }
+UPB_INLINE int32_t google_protobuf_FieldDescriptorProto_oneof_index(const google_protobuf_FieldDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(28, 28), int32_t); }
+UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_json_name(const google_protobuf_FieldDescriptorProto *msg) { return _upb_has_field(msg, 10); }
+UPB_INLINE upb_strview google_protobuf_FieldDescriptorProto_json_name(const google_protobuf_FieldDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(68, 104), upb_strview); }
+UPB_INLINE bool google_protobuf_FieldDescriptorProto_has_proto3_optional(const google_protobuf_FieldDescriptorProto *msg) { return _upb_has_field(msg, 5); }
+UPB_INLINE bool google_protobuf_FieldDescriptorProto_proto3_optional(const google_protobuf_FieldDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(32, 32), bool); }
UPB_INLINE void google_protobuf_FieldDescriptorProto_set_name(google_protobuf_FieldDescriptorProto *msg, upb_strview value) {
- _upb_sethas(msg, 5);
- UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(32, 32)) = value;
+ _upb_sethas(msg, 6);
+ *UPB_PTR_AT(msg, UPB_SIZE(36, 40), upb_strview) = value;
}
UPB_INLINE void google_protobuf_FieldDescriptorProto_set_extendee(google_protobuf_FieldDescriptorProto *msg, upb_strview value) {
- _upb_sethas(msg, 6);
- UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(40, 48)) = value;
+ _upb_sethas(msg, 7);
+ *UPB_PTR_AT(msg, UPB_SIZE(44, 56), upb_strview) = value;
}
UPB_INLINE void google_protobuf_FieldDescriptorProto_set_number(google_protobuf_FieldDescriptorProto *msg, int32_t value) {
_upb_sethas(msg, 3);
- UPB_FIELD_AT(msg, int32_t, UPB_SIZE(24, 24)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(24, 24), int32_t) = value;
}
UPB_INLINE void google_protobuf_FieldDescriptorProto_set_label(google_protobuf_FieldDescriptorProto *msg, int32_t value) {
_upb_sethas(msg, 1);
- UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t) = value;
}
UPB_INLINE void google_protobuf_FieldDescriptorProto_set_type(google_protobuf_FieldDescriptorProto *msg, int32_t value) {
_upb_sethas(msg, 2);
- UPB_FIELD_AT(msg, int32_t, UPB_SIZE(16, 16)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(16, 16), int32_t) = value;
}
UPB_INLINE void google_protobuf_FieldDescriptorProto_set_type_name(google_protobuf_FieldDescriptorProto *msg, upb_strview value) {
- _upb_sethas(msg, 7);
- UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(48, 64)) = value;
+ _upb_sethas(msg, 8);
+ *UPB_PTR_AT(msg, UPB_SIZE(52, 72), upb_strview) = value;
}
UPB_INLINE void google_protobuf_FieldDescriptorProto_set_default_value(google_protobuf_FieldDescriptorProto *msg, upb_strview value) {
- _upb_sethas(msg, 8);
- UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(56, 80)) = value;
+ _upb_sethas(msg, 9);
+ *UPB_PTR_AT(msg, UPB_SIZE(60, 88), upb_strview) = value;
}
UPB_INLINE void google_protobuf_FieldDescriptorProto_set_options(google_protobuf_FieldDescriptorProto *msg, google_protobuf_FieldOptions* value) {
- _upb_sethas(msg, 10);
- UPB_FIELD_AT(msg, google_protobuf_FieldOptions*, UPB_SIZE(72, 112)) = value;
+ _upb_sethas(msg, 11);
+ *UPB_PTR_AT(msg, UPB_SIZE(76, 120), google_protobuf_FieldOptions*) = value;
}
UPB_INLINE struct google_protobuf_FieldOptions* google_protobuf_FieldDescriptorProto_mutable_options(google_protobuf_FieldDescriptorProto *msg, upb_arena *arena) {
struct google_protobuf_FieldOptions* sub = (struct google_protobuf_FieldOptions*)google_protobuf_FieldDescriptorProto_options(msg);
if (sub == NULL) {
- sub = (struct google_protobuf_FieldOptions*)upb_msg_new(&google_protobuf_FieldOptions_msginit, arena);
+ sub = (struct google_protobuf_FieldOptions*)_upb_msg_new(&google_protobuf_FieldOptions_msginit, arena);
if (!sub) return NULL;
google_protobuf_FieldDescriptorProto_set_options(msg, sub);
}
@@ -1886,17 +2161,21 @@
}
UPB_INLINE void google_protobuf_FieldDescriptorProto_set_oneof_index(google_protobuf_FieldDescriptorProto *msg, int32_t value) {
_upb_sethas(msg, 4);
- UPB_FIELD_AT(msg, int32_t, UPB_SIZE(28, 28)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(28, 28), int32_t) = value;
}
UPB_INLINE void google_protobuf_FieldDescriptorProto_set_json_name(google_protobuf_FieldDescriptorProto *msg, upb_strview value) {
- _upb_sethas(msg, 9);
- UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(64, 96)) = value;
+ _upb_sethas(msg, 10);
+ *UPB_PTR_AT(msg, UPB_SIZE(68, 104), upb_strview) = value;
+}
+UPB_INLINE void google_protobuf_FieldDescriptorProto_set_proto3_optional(google_protobuf_FieldDescriptorProto *msg, bool value) {
+ _upb_sethas(msg, 5);
+ *UPB_PTR_AT(msg, UPB_SIZE(32, 32), bool) = value;
}
/* google.protobuf.OneofDescriptorProto */
UPB_INLINE google_protobuf_OneofDescriptorProto *google_protobuf_OneofDescriptorProto_new(upb_arena *arena) {
- return (google_protobuf_OneofDescriptorProto *)upb_msg_new(&google_protobuf_OneofDescriptorProto_msginit, arena);
+ return (google_protobuf_OneofDescriptorProto *)_upb_msg_new(&google_protobuf_OneofDescriptorProto_msginit, arena);
}
UPB_INLINE google_protobuf_OneofDescriptorProto *google_protobuf_OneofDescriptorProto_parse(const char *buf, size_t size,
upb_arena *arena) {
@@ -1908,22 +2187,22 @@
}
UPB_INLINE bool google_protobuf_OneofDescriptorProto_has_name(const google_protobuf_OneofDescriptorProto *msg) { return _upb_has_field(msg, 1); }
-UPB_INLINE upb_strview google_protobuf_OneofDescriptorProto_name(const google_protobuf_OneofDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(4, 8)); }
+UPB_INLINE upb_strview google_protobuf_OneofDescriptorProto_name(const google_protobuf_OneofDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview); }
UPB_INLINE bool google_protobuf_OneofDescriptorProto_has_options(const google_protobuf_OneofDescriptorProto *msg) { return _upb_has_field(msg, 2); }
-UPB_INLINE const google_protobuf_OneofOptions* google_protobuf_OneofDescriptorProto_options(const google_protobuf_OneofDescriptorProto *msg) { return UPB_FIELD_AT(msg, const google_protobuf_OneofOptions*, UPB_SIZE(12, 24)); }
+UPB_INLINE const google_protobuf_OneofOptions* google_protobuf_OneofDescriptorProto_options(const google_protobuf_OneofDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(12, 24), const google_protobuf_OneofOptions*); }
UPB_INLINE void google_protobuf_OneofDescriptorProto_set_name(google_protobuf_OneofDescriptorProto *msg, upb_strview value) {
_upb_sethas(msg, 1);
- UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(4, 8)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview) = value;
}
UPB_INLINE void google_protobuf_OneofDescriptorProto_set_options(google_protobuf_OneofDescriptorProto *msg, google_protobuf_OneofOptions* value) {
_upb_sethas(msg, 2);
- UPB_FIELD_AT(msg, google_protobuf_OneofOptions*, UPB_SIZE(12, 24)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(12, 24), google_protobuf_OneofOptions*) = value;
}
UPB_INLINE struct google_protobuf_OneofOptions* google_protobuf_OneofDescriptorProto_mutable_options(google_protobuf_OneofDescriptorProto *msg, upb_arena *arena) {
struct google_protobuf_OneofOptions* sub = (struct google_protobuf_OneofOptions*)google_protobuf_OneofDescriptorProto_options(msg);
if (sub == NULL) {
- sub = (struct google_protobuf_OneofOptions*)upb_msg_new(&google_protobuf_OneofOptions_msginit, arena);
+ sub = (struct google_protobuf_OneofOptions*)_upb_msg_new(&google_protobuf_OneofOptions_msginit, arena);
if (!sub) return NULL;
google_protobuf_OneofDescriptorProto_set_options(msg, sub);
}
@@ -1933,7 +2212,7 @@
/* google.protobuf.EnumDescriptorProto */
UPB_INLINE google_protobuf_EnumDescriptorProto *google_protobuf_EnumDescriptorProto_new(upb_arena *arena) {
- return (google_protobuf_EnumDescriptorProto *)upb_msg_new(&google_protobuf_EnumDescriptorProto_msginit, arena);
+ return (google_protobuf_EnumDescriptorProto *)_upb_msg_new(&google_protobuf_EnumDescriptorProto_msginit, arena);
}
UPB_INLINE google_protobuf_EnumDescriptorProto *google_protobuf_EnumDescriptorProto_parse(const char *buf, size_t size,
upb_arena *arena) {
@@ -1945,25 +2224,27 @@
}
UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_name(const google_protobuf_EnumDescriptorProto *msg) { return _upb_has_field(msg, 1); }
-UPB_INLINE upb_strview google_protobuf_EnumDescriptorProto_name(const google_protobuf_EnumDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(4, 8)); }
+UPB_INLINE upb_strview google_protobuf_EnumDescriptorProto_name(const google_protobuf_EnumDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview); }
+UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_value(const google_protobuf_EnumDescriptorProto *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(16, 32)); }
UPB_INLINE const google_protobuf_EnumValueDescriptorProto* const* google_protobuf_EnumDescriptorProto_value(const google_protobuf_EnumDescriptorProto *msg, size_t *len) { return (const google_protobuf_EnumValueDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(16, 32), len); }
UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_options(const google_protobuf_EnumDescriptorProto *msg) { return _upb_has_field(msg, 2); }
-UPB_INLINE const google_protobuf_EnumOptions* google_protobuf_EnumDescriptorProto_options(const google_protobuf_EnumDescriptorProto *msg) { return UPB_FIELD_AT(msg, const google_protobuf_EnumOptions*, UPB_SIZE(12, 24)); }
+UPB_INLINE const google_protobuf_EnumOptions* google_protobuf_EnumDescriptorProto_options(const google_protobuf_EnumDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(12, 24), const google_protobuf_EnumOptions*); }
+UPB_INLINE bool google_protobuf_EnumDescriptorProto_has_reserved_range(const google_protobuf_EnumDescriptorProto *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(20, 40)); }
UPB_INLINE const google_protobuf_EnumDescriptorProto_EnumReservedRange* const* google_protobuf_EnumDescriptorProto_reserved_range(const google_protobuf_EnumDescriptorProto *msg, size_t *len) { return (const google_protobuf_EnumDescriptorProto_EnumReservedRange* const*)_upb_array_accessor(msg, UPB_SIZE(20, 40), len); }
UPB_INLINE upb_strview const* google_protobuf_EnumDescriptorProto_reserved_name(const google_protobuf_EnumDescriptorProto *msg, size_t *len) { return (upb_strview const*)_upb_array_accessor(msg, UPB_SIZE(24, 48), len); }
UPB_INLINE void google_protobuf_EnumDescriptorProto_set_name(google_protobuf_EnumDescriptorProto *msg, upb_strview value) {
_upb_sethas(msg, 1);
- UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(4, 8)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview) = value;
}
UPB_INLINE google_protobuf_EnumValueDescriptorProto** google_protobuf_EnumDescriptorProto_mutable_value(google_protobuf_EnumDescriptorProto *msg, size_t *len) {
return (google_protobuf_EnumValueDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(16, 32), len);
}
UPB_INLINE google_protobuf_EnumValueDescriptorProto** google_protobuf_EnumDescriptorProto_resize_value(google_protobuf_EnumDescriptorProto *msg, size_t len, upb_arena *arena) {
- return (google_protobuf_EnumValueDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(16, 32), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
+ return (google_protobuf_EnumValueDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(16, 32), len, UPB_TYPE_MESSAGE, arena);
}
UPB_INLINE struct google_protobuf_EnumValueDescriptorProto* google_protobuf_EnumDescriptorProto_add_value(google_protobuf_EnumDescriptorProto *msg, upb_arena *arena) {
- struct google_protobuf_EnumValueDescriptorProto* sub = (struct google_protobuf_EnumValueDescriptorProto*)upb_msg_new(&google_protobuf_EnumValueDescriptorProto_msginit, arena);
+ struct google_protobuf_EnumValueDescriptorProto* sub = (struct google_protobuf_EnumValueDescriptorProto*)_upb_msg_new(&google_protobuf_EnumValueDescriptorProto_msginit, arena);
bool ok = _upb_array_append_accessor(
msg, UPB_SIZE(16, 32), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
if (!ok) return NULL;
@@ -1971,12 +2252,12 @@
}
UPB_INLINE void google_protobuf_EnumDescriptorProto_set_options(google_protobuf_EnumDescriptorProto *msg, google_protobuf_EnumOptions* value) {
_upb_sethas(msg, 2);
- UPB_FIELD_AT(msg, google_protobuf_EnumOptions*, UPB_SIZE(12, 24)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(12, 24), google_protobuf_EnumOptions*) = value;
}
UPB_INLINE struct google_protobuf_EnumOptions* google_protobuf_EnumDescriptorProto_mutable_options(google_protobuf_EnumDescriptorProto *msg, upb_arena *arena) {
struct google_protobuf_EnumOptions* sub = (struct google_protobuf_EnumOptions*)google_protobuf_EnumDescriptorProto_options(msg);
if (sub == NULL) {
- sub = (struct google_protobuf_EnumOptions*)upb_msg_new(&google_protobuf_EnumOptions_msginit, arena);
+ sub = (struct google_protobuf_EnumOptions*)_upb_msg_new(&google_protobuf_EnumOptions_msginit, arena);
if (!sub) return NULL;
google_protobuf_EnumDescriptorProto_set_options(msg, sub);
}
@@ -1986,10 +2267,10 @@
return (google_protobuf_EnumDescriptorProto_EnumReservedRange**)_upb_array_mutable_accessor(msg, UPB_SIZE(20, 40), len);
}
UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange** google_protobuf_EnumDescriptorProto_resize_reserved_range(google_protobuf_EnumDescriptorProto *msg, size_t len, upb_arena *arena) {
- return (google_protobuf_EnumDescriptorProto_EnumReservedRange**)_upb_array_resize_accessor(msg, UPB_SIZE(20, 40), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
+ return (google_protobuf_EnumDescriptorProto_EnumReservedRange**)_upb_array_resize_accessor(msg, UPB_SIZE(20, 40), len, UPB_TYPE_MESSAGE, arena);
}
UPB_INLINE struct google_protobuf_EnumDescriptorProto_EnumReservedRange* google_protobuf_EnumDescriptorProto_add_reserved_range(google_protobuf_EnumDescriptorProto *msg, upb_arena *arena) {
- struct google_protobuf_EnumDescriptorProto_EnumReservedRange* sub = (struct google_protobuf_EnumDescriptorProto_EnumReservedRange*)upb_msg_new(&google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, arena);
+ struct google_protobuf_EnumDescriptorProto_EnumReservedRange* sub = (struct google_protobuf_EnumDescriptorProto_EnumReservedRange*)_upb_msg_new(&google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, arena);
bool ok = _upb_array_append_accessor(
msg, UPB_SIZE(20, 40), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
if (!ok) return NULL;
@@ -1999,17 +2280,17 @@
return (upb_strview*)_upb_array_mutable_accessor(msg, UPB_SIZE(24, 48), len);
}
UPB_INLINE upb_strview* google_protobuf_EnumDescriptorProto_resize_reserved_name(google_protobuf_EnumDescriptorProto *msg, size_t len, upb_arena *arena) {
- return (upb_strview*)_upb_array_resize_accessor(msg, UPB_SIZE(24, 48), len, UPB_SIZE(8, 16), UPB_TYPE_STRING, arena);
+ return (upb_strview*)_upb_array_resize_accessor(msg, UPB_SIZE(24, 48), len, UPB_TYPE_STRING, arena);
}
UPB_INLINE bool google_protobuf_EnumDescriptorProto_add_reserved_name(google_protobuf_EnumDescriptorProto *msg, upb_strview val, upb_arena *arena) {
- return _upb_array_append_accessor(
- msg, UPB_SIZE(24, 48), UPB_SIZE(8, 16), UPB_TYPE_STRING, &val, arena);
+ return _upb_array_append_accessor(msg, UPB_SIZE(24, 48), UPB_SIZE(8, 16), UPB_TYPE_STRING, &val,
+ arena);
}
/* google.protobuf.EnumDescriptorProto.EnumReservedRange */
UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange *google_protobuf_EnumDescriptorProto_EnumReservedRange_new(upb_arena *arena) {
- return (google_protobuf_EnumDescriptorProto_EnumReservedRange *)upb_msg_new(&google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, arena);
+ return (google_protobuf_EnumDescriptorProto_EnumReservedRange *)_upb_msg_new(&google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit, arena);
}
UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange *google_protobuf_EnumDescriptorProto_EnumReservedRange_parse(const char *buf, size_t size,
upb_arena *arena) {
@@ -2021,23 +2302,23 @@
}
UPB_INLINE bool google_protobuf_EnumDescriptorProto_EnumReservedRange_has_start(const google_protobuf_EnumDescriptorProto_EnumReservedRange *msg) { return _upb_has_field(msg, 1); }
-UPB_INLINE int32_t google_protobuf_EnumDescriptorProto_EnumReservedRange_start(const google_protobuf_EnumDescriptorProto_EnumReservedRange *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(4, 4)); }
+UPB_INLINE int32_t google_protobuf_EnumDescriptorProto_EnumReservedRange_start(const google_protobuf_EnumDescriptorProto_EnumReservedRange *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 4), int32_t); }
UPB_INLINE bool google_protobuf_EnumDescriptorProto_EnumReservedRange_has_end(const google_protobuf_EnumDescriptorProto_EnumReservedRange *msg) { return _upb_has_field(msg, 2); }
-UPB_INLINE int32_t google_protobuf_EnumDescriptorProto_EnumReservedRange_end(const google_protobuf_EnumDescriptorProto_EnumReservedRange *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)); }
+UPB_INLINE int32_t google_protobuf_EnumDescriptorProto_EnumReservedRange_end(const google_protobuf_EnumDescriptorProto_EnumReservedRange *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t); }
UPB_INLINE void google_protobuf_EnumDescriptorProto_EnumReservedRange_set_start(google_protobuf_EnumDescriptorProto_EnumReservedRange *msg, int32_t value) {
_upb_sethas(msg, 1);
- UPB_FIELD_AT(msg, int32_t, UPB_SIZE(4, 4)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(4, 4), int32_t) = value;
}
UPB_INLINE void google_protobuf_EnumDescriptorProto_EnumReservedRange_set_end(google_protobuf_EnumDescriptorProto_EnumReservedRange *msg, int32_t value) {
_upb_sethas(msg, 2);
- UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t) = value;
}
/* google.protobuf.EnumValueDescriptorProto */
UPB_INLINE google_protobuf_EnumValueDescriptorProto *google_protobuf_EnumValueDescriptorProto_new(upb_arena *arena) {
- return (google_protobuf_EnumValueDescriptorProto *)upb_msg_new(&google_protobuf_EnumValueDescriptorProto_msginit, arena);
+ return (google_protobuf_EnumValueDescriptorProto *)_upb_msg_new(&google_protobuf_EnumValueDescriptorProto_msginit, arena);
}
UPB_INLINE google_protobuf_EnumValueDescriptorProto *google_protobuf_EnumValueDescriptorProto_parse(const char *buf, size_t size,
upb_arena *arena) {
@@ -2049,28 +2330,28 @@
}
UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_name(const google_protobuf_EnumValueDescriptorProto *msg) { return _upb_has_field(msg, 2); }
-UPB_INLINE upb_strview google_protobuf_EnumValueDescriptorProto_name(const google_protobuf_EnumValueDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(8, 8)); }
+UPB_INLINE upb_strview google_protobuf_EnumValueDescriptorProto_name(const google_protobuf_EnumValueDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(8, 8), upb_strview); }
UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_number(const google_protobuf_EnumValueDescriptorProto *msg) { return _upb_has_field(msg, 1); }
-UPB_INLINE int32_t google_protobuf_EnumValueDescriptorProto_number(const google_protobuf_EnumValueDescriptorProto *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(4, 4)); }
+UPB_INLINE int32_t google_protobuf_EnumValueDescriptorProto_number(const google_protobuf_EnumValueDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 4), int32_t); }
UPB_INLINE bool google_protobuf_EnumValueDescriptorProto_has_options(const google_protobuf_EnumValueDescriptorProto *msg) { return _upb_has_field(msg, 3); }
-UPB_INLINE const google_protobuf_EnumValueOptions* google_protobuf_EnumValueDescriptorProto_options(const google_protobuf_EnumValueDescriptorProto *msg) { return UPB_FIELD_AT(msg, const google_protobuf_EnumValueOptions*, UPB_SIZE(16, 24)); }
+UPB_INLINE const google_protobuf_EnumValueOptions* google_protobuf_EnumValueDescriptorProto_options(const google_protobuf_EnumValueDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(16, 24), const google_protobuf_EnumValueOptions*); }
UPB_INLINE void google_protobuf_EnumValueDescriptorProto_set_name(google_protobuf_EnumValueDescriptorProto *msg, upb_strview value) {
_upb_sethas(msg, 2);
- UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(8, 8)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(8, 8), upb_strview) = value;
}
UPB_INLINE void google_protobuf_EnumValueDescriptorProto_set_number(google_protobuf_EnumValueDescriptorProto *msg, int32_t value) {
_upb_sethas(msg, 1);
- UPB_FIELD_AT(msg, int32_t, UPB_SIZE(4, 4)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(4, 4), int32_t) = value;
}
UPB_INLINE void google_protobuf_EnumValueDescriptorProto_set_options(google_protobuf_EnumValueDescriptorProto *msg, google_protobuf_EnumValueOptions* value) {
_upb_sethas(msg, 3);
- UPB_FIELD_AT(msg, google_protobuf_EnumValueOptions*, UPB_SIZE(16, 24)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(16, 24), google_protobuf_EnumValueOptions*) = value;
}
UPB_INLINE struct google_protobuf_EnumValueOptions* google_protobuf_EnumValueDescriptorProto_mutable_options(google_protobuf_EnumValueDescriptorProto *msg, upb_arena *arena) {
struct google_protobuf_EnumValueOptions* sub = (struct google_protobuf_EnumValueOptions*)google_protobuf_EnumValueDescriptorProto_options(msg);
if (sub == NULL) {
- sub = (struct google_protobuf_EnumValueOptions*)upb_msg_new(&google_protobuf_EnumValueOptions_msginit, arena);
+ sub = (struct google_protobuf_EnumValueOptions*)_upb_msg_new(&google_protobuf_EnumValueOptions_msginit, arena);
if (!sub) return NULL;
google_protobuf_EnumValueDescriptorProto_set_options(msg, sub);
}
@@ -2080,7 +2361,7 @@
/* google.protobuf.ServiceDescriptorProto */
UPB_INLINE google_protobuf_ServiceDescriptorProto *google_protobuf_ServiceDescriptorProto_new(upb_arena *arena) {
- return (google_protobuf_ServiceDescriptorProto *)upb_msg_new(&google_protobuf_ServiceDescriptorProto_msginit, arena);
+ return (google_protobuf_ServiceDescriptorProto *)_upb_msg_new(&google_protobuf_ServiceDescriptorProto_msginit, arena);
}
UPB_INLINE google_protobuf_ServiceDescriptorProto *google_protobuf_ServiceDescriptorProto_parse(const char *buf, size_t size,
upb_arena *arena) {
@@ -2092,23 +2373,24 @@
}
UPB_INLINE bool google_protobuf_ServiceDescriptorProto_has_name(const google_protobuf_ServiceDescriptorProto *msg) { return _upb_has_field(msg, 1); }
-UPB_INLINE upb_strview google_protobuf_ServiceDescriptorProto_name(const google_protobuf_ServiceDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(4, 8)); }
+UPB_INLINE upb_strview google_protobuf_ServiceDescriptorProto_name(const google_protobuf_ServiceDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview); }
+UPB_INLINE bool google_protobuf_ServiceDescriptorProto_has_method(const google_protobuf_ServiceDescriptorProto *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(16, 32)); }
UPB_INLINE const google_protobuf_MethodDescriptorProto* const* google_protobuf_ServiceDescriptorProto_method(const google_protobuf_ServiceDescriptorProto *msg, size_t *len) { return (const google_protobuf_MethodDescriptorProto* const*)_upb_array_accessor(msg, UPB_SIZE(16, 32), len); }
UPB_INLINE bool google_protobuf_ServiceDescriptorProto_has_options(const google_protobuf_ServiceDescriptorProto *msg) { return _upb_has_field(msg, 2); }
-UPB_INLINE const google_protobuf_ServiceOptions* google_protobuf_ServiceDescriptorProto_options(const google_protobuf_ServiceDescriptorProto *msg) { return UPB_FIELD_AT(msg, const google_protobuf_ServiceOptions*, UPB_SIZE(12, 24)); }
+UPB_INLINE const google_protobuf_ServiceOptions* google_protobuf_ServiceDescriptorProto_options(const google_protobuf_ServiceDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(12, 24), const google_protobuf_ServiceOptions*); }
UPB_INLINE void google_protobuf_ServiceDescriptorProto_set_name(google_protobuf_ServiceDescriptorProto *msg, upb_strview value) {
_upb_sethas(msg, 1);
- UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(4, 8)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview) = value;
}
UPB_INLINE google_protobuf_MethodDescriptorProto** google_protobuf_ServiceDescriptorProto_mutable_method(google_protobuf_ServiceDescriptorProto *msg, size_t *len) {
return (google_protobuf_MethodDescriptorProto**)_upb_array_mutable_accessor(msg, UPB_SIZE(16, 32), len);
}
UPB_INLINE google_protobuf_MethodDescriptorProto** google_protobuf_ServiceDescriptorProto_resize_method(google_protobuf_ServiceDescriptorProto *msg, size_t len, upb_arena *arena) {
- return (google_protobuf_MethodDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(16, 32), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
+ return (google_protobuf_MethodDescriptorProto**)_upb_array_resize_accessor(msg, UPB_SIZE(16, 32), len, UPB_TYPE_MESSAGE, arena);
}
UPB_INLINE struct google_protobuf_MethodDescriptorProto* google_protobuf_ServiceDescriptorProto_add_method(google_protobuf_ServiceDescriptorProto *msg, upb_arena *arena) {
- struct google_protobuf_MethodDescriptorProto* sub = (struct google_protobuf_MethodDescriptorProto*)upb_msg_new(&google_protobuf_MethodDescriptorProto_msginit, arena);
+ struct google_protobuf_MethodDescriptorProto* sub = (struct google_protobuf_MethodDescriptorProto*)_upb_msg_new(&google_protobuf_MethodDescriptorProto_msginit, arena);
bool ok = _upb_array_append_accessor(
msg, UPB_SIZE(16, 32), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
if (!ok) return NULL;
@@ -2116,12 +2398,12 @@
}
UPB_INLINE void google_protobuf_ServiceDescriptorProto_set_options(google_protobuf_ServiceDescriptorProto *msg, google_protobuf_ServiceOptions* value) {
_upb_sethas(msg, 2);
- UPB_FIELD_AT(msg, google_protobuf_ServiceOptions*, UPB_SIZE(12, 24)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(12, 24), google_protobuf_ServiceOptions*) = value;
}
UPB_INLINE struct google_protobuf_ServiceOptions* google_protobuf_ServiceDescriptorProto_mutable_options(google_protobuf_ServiceDescriptorProto *msg, upb_arena *arena) {
struct google_protobuf_ServiceOptions* sub = (struct google_protobuf_ServiceOptions*)google_protobuf_ServiceDescriptorProto_options(msg);
if (sub == NULL) {
- sub = (struct google_protobuf_ServiceOptions*)upb_msg_new(&google_protobuf_ServiceOptions_msginit, arena);
+ sub = (struct google_protobuf_ServiceOptions*)_upb_msg_new(&google_protobuf_ServiceOptions_msginit, arena);
if (!sub) return NULL;
google_protobuf_ServiceDescriptorProto_set_options(msg, sub);
}
@@ -2131,7 +2413,7 @@
/* google.protobuf.MethodDescriptorProto */
UPB_INLINE google_protobuf_MethodDescriptorProto *google_protobuf_MethodDescriptorProto_new(upb_arena *arena) {
- return (google_protobuf_MethodDescriptorProto *)upb_msg_new(&google_protobuf_MethodDescriptorProto_msginit, arena);
+ return (google_protobuf_MethodDescriptorProto *)_upb_msg_new(&google_protobuf_MethodDescriptorProto_msginit, arena);
}
UPB_INLINE google_protobuf_MethodDescriptorProto *google_protobuf_MethodDescriptorProto_parse(const char *buf, size_t size,
upb_arena *arena) {
@@ -2143,38 +2425,38 @@
}
UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_name(const google_protobuf_MethodDescriptorProto *msg) { return _upb_has_field(msg, 3); }
-UPB_INLINE upb_strview google_protobuf_MethodDescriptorProto_name(const google_protobuf_MethodDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(4, 8)); }
+UPB_INLINE upb_strview google_protobuf_MethodDescriptorProto_name(const google_protobuf_MethodDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview); }
UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_input_type(const google_protobuf_MethodDescriptorProto *msg) { return _upb_has_field(msg, 4); }
-UPB_INLINE upb_strview google_protobuf_MethodDescriptorProto_input_type(const google_protobuf_MethodDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(12, 24)); }
+UPB_INLINE upb_strview google_protobuf_MethodDescriptorProto_input_type(const google_protobuf_MethodDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(12, 24), upb_strview); }
UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_output_type(const google_protobuf_MethodDescriptorProto *msg) { return _upb_has_field(msg, 5); }
-UPB_INLINE upb_strview google_protobuf_MethodDescriptorProto_output_type(const google_protobuf_MethodDescriptorProto *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(20, 40)); }
+UPB_INLINE upb_strview google_protobuf_MethodDescriptorProto_output_type(const google_protobuf_MethodDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(20, 40), upb_strview); }
UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_options(const google_protobuf_MethodDescriptorProto *msg) { return _upb_has_field(msg, 6); }
-UPB_INLINE const google_protobuf_MethodOptions* google_protobuf_MethodDescriptorProto_options(const google_protobuf_MethodDescriptorProto *msg) { return UPB_FIELD_AT(msg, const google_protobuf_MethodOptions*, UPB_SIZE(28, 56)); }
+UPB_INLINE const google_protobuf_MethodOptions* google_protobuf_MethodDescriptorProto_options(const google_protobuf_MethodDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(28, 56), const google_protobuf_MethodOptions*); }
UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_client_streaming(const google_protobuf_MethodDescriptorProto *msg) { return _upb_has_field(msg, 1); }
-UPB_INLINE bool google_protobuf_MethodDescriptorProto_client_streaming(const google_protobuf_MethodDescriptorProto *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)); }
+UPB_INLINE bool google_protobuf_MethodDescriptorProto_client_streaming(const google_protobuf_MethodDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(1, 1), bool); }
UPB_INLINE bool google_protobuf_MethodDescriptorProto_has_server_streaming(const google_protobuf_MethodDescriptorProto *msg) { return _upb_has_field(msg, 2); }
-UPB_INLINE bool google_protobuf_MethodDescriptorProto_server_streaming(const google_protobuf_MethodDescriptorProto *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(2, 2)); }
+UPB_INLINE bool google_protobuf_MethodDescriptorProto_server_streaming(const google_protobuf_MethodDescriptorProto *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(2, 2), bool); }
UPB_INLINE void google_protobuf_MethodDescriptorProto_set_name(google_protobuf_MethodDescriptorProto *msg, upb_strview value) {
_upb_sethas(msg, 3);
- UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(4, 8)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview) = value;
}
UPB_INLINE void google_protobuf_MethodDescriptorProto_set_input_type(google_protobuf_MethodDescriptorProto *msg, upb_strview value) {
_upb_sethas(msg, 4);
- UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(12, 24)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(12, 24), upb_strview) = value;
}
UPB_INLINE void google_protobuf_MethodDescriptorProto_set_output_type(google_protobuf_MethodDescriptorProto *msg, upb_strview value) {
_upb_sethas(msg, 5);
- UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(20, 40)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(20, 40), upb_strview) = value;
}
UPB_INLINE void google_protobuf_MethodDescriptorProto_set_options(google_protobuf_MethodDescriptorProto *msg, google_protobuf_MethodOptions* value) {
_upb_sethas(msg, 6);
- UPB_FIELD_AT(msg, google_protobuf_MethodOptions*, UPB_SIZE(28, 56)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(28, 56), google_protobuf_MethodOptions*) = value;
}
UPB_INLINE struct google_protobuf_MethodOptions* google_protobuf_MethodDescriptorProto_mutable_options(google_protobuf_MethodDescriptorProto *msg, upb_arena *arena) {
struct google_protobuf_MethodOptions* sub = (struct google_protobuf_MethodOptions*)google_protobuf_MethodDescriptorProto_options(msg);
if (sub == NULL) {
- sub = (struct google_protobuf_MethodOptions*)upb_msg_new(&google_protobuf_MethodOptions_msginit, arena);
+ sub = (struct google_protobuf_MethodOptions*)_upb_msg_new(&google_protobuf_MethodOptions_msginit, arena);
if (!sub) return NULL;
google_protobuf_MethodDescriptorProto_set_options(msg, sub);
}
@@ -2182,17 +2464,17 @@
}
UPB_INLINE void google_protobuf_MethodDescriptorProto_set_client_streaming(google_protobuf_MethodDescriptorProto *msg, bool value) {
_upb_sethas(msg, 1);
- UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(1, 1), bool) = value;
}
UPB_INLINE void google_protobuf_MethodDescriptorProto_set_server_streaming(google_protobuf_MethodDescriptorProto *msg, bool value) {
_upb_sethas(msg, 2);
- UPB_FIELD_AT(msg, bool, UPB_SIZE(2, 2)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(2, 2), bool) = value;
}
/* google.protobuf.FileOptions */
UPB_INLINE google_protobuf_FileOptions *google_protobuf_FileOptions_new(upb_arena *arena) {
- return (google_protobuf_FileOptions *)upb_msg_new(&google_protobuf_FileOptions_msginit, arena);
+ return (google_protobuf_FileOptions *)_upb_msg_new(&google_protobuf_FileOptions_msginit, arena);
}
UPB_INLINE google_protobuf_FileOptions *google_protobuf_FileOptions_parse(const char *buf, size_t size,
upb_arena *arena) {
@@ -2204,135 +2486,136 @@
}
UPB_INLINE bool google_protobuf_FileOptions_has_java_package(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 11); }
-UPB_INLINE upb_strview google_protobuf_FileOptions_java_package(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(28, 32)); }
+UPB_INLINE upb_strview google_protobuf_FileOptions_java_package(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(28, 32), upb_strview); }
UPB_INLINE bool google_protobuf_FileOptions_has_java_outer_classname(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 12); }
-UPB_INLINE upb_strview google_protobuf_FileOptions_java_outer_classname(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(36, 48)); }
+UPB_INLINE upb_strview google_protobuf_FileOptions_java_outer_classname(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(36, 48), upb_strview); }
UPB_INLINE bool google_protobuf_FileOptions_has_optimize_for(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 1); }
-UPB_INLINE int32_t google_protobuf_FileOptions_optimize_for(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)); }
+UPB_INLINE int32_t google_protobuf_FileOptions_optimize_for(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t); }
UPB_INLINE bool google_protobuf_FileOptions_has_java_multiple_files(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 2); }
-UPB_INLINE bool google_protobuf_FileOptions_java_multiple_files(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(16, 16)); }
+UPB_INLINE bool google_protobuf_FileOptions_java_multiple_files(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(16, 16), bool); }
UPB_INLINE bool google_protobuf_FileOptions_has_go_package(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 13); }
-UPB_INLINE upb_strview google_protobuf_FileOptions_go_package(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(44, 64)); }
+UPB_INLINE upb_strview google_protobuf_FileOptions_go_package(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(44, 64), upb_strview); }
UPB_INLINE bool google_protobuf_FileOptions_has_cc_generic_services(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 3); }
-UPB_INLINE bool google_protobuf_FileOptions_cc_generic_services(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(17, 17)); }
+UPB_INLINE bool google_protobuf_FileOptions_cc_generic_services(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(17, 17), bool); }
UPB_INLINE bool google_protobuf_FileOptions_has_java_generic_services(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 4); }
-UPB_INLINE bool google_protobuf_FileOptions_java_generic_services(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(18, 18)); }
+UPB_INLINE bool google_protobuf_FileOptions_java_generic_services(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(18, 18), bool); }
UPB_INLINE bool google_protobuf_FileOptions_has_py_generic_services(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 5); }
-UPB_INLINE bool google_protobuf_FileOptions_py_generic_services(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(19, 19)); }
+UPB_INLINE bool google_protobuf_FileOptions_py_generic_services(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(19, 19), bool); }
UPB_INLINE bool google_protobuf_FileOptions_has_java_generate_equals_and_hash(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 6); }
-UPB_INLINE bool google_protobuf_FileOptions_java_generate_equals_and_hash(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(20, 20)); }
+UPB_INLINE bool google_protobuf_FileOptions_java_generate_equals_and_hash(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(20, 20), bool); }
UPB_INLINE bool google_protobuf_FileOptions_has_deprecated(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 7); }
-UPB_INLINE bool google_protobuf_FileOptions_deprecated(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(21, 21)); }
+UPB_INLINE bool google_protobuf_FileOptions_deprecated(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(21, 21), bool); }
UPB_INLINE bool google_protobuf_FileOptions_has_java_string_check_utf8(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 8); }
-UPB_INLINE bool google_protobuf_FileOptions_java_string_check_utf8(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(22, 22)); }
+UPB_INLINE bool google_protobuf_FileOptions_java_string_check_utf8(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(22, 22), bool); }
UPB_INLINE bool google_protobuf_FileOptions_has_cc_enable_arenas(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 9); }
-UPB_INLINE bool google_protobuf_FileOptions_cc_enable_arenas(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(23, 23)); }
+UPB_INLINE bool google_protobuf_FileOptions_cc_enable_arenas(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(23, 23), bool); }
UPB_INLINE bool google_protobuf_FileOptions_has_objc_class_prefix(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 14); }
-UPB_INLINE upb_strview google_protobuf_FileOptions_objc_class_prefix(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(52, 80)); }
+UPB_INLINE upb_strview google_protobuf_FileOptions_objc_class_prefix(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(52, 80), upb_strview); }
UPB_INLINE bool google_protobuf_FileOptions_has_csharp_namespace(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 15); }
-UPB_INLINE upb_strview google_protobuf_FileOptions_csharp_namespace(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(60, 96)); }
+UPB_INLINE upb_strview google_protobuf_FileOptions_csharp_namespace(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(60, 96), upb_strview); }
UPB_INLINE bool google_protobuf_FileOptions_has_swift_prefix(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 16); }
-UPB_INLINE upb_strview google_protobuf_FileOptions_swift_prefix(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(68, 112)); }
+UPB_INLINE upb_strview google_protobuf_FileOptions_swift_prefix(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(68, 112), upb_strview); }
UPB_INLINE bool google_protobuf_FileOptions_has_php_class_prefix(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 17); }
-UPB_INLINE upb_strview google_protobuf_FileOptions_php_class_prefix(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(76, 128)); }
+UPB_INLINE upb_strview google_protobuf_FileOptions_php_class_prefix(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(76, 128), upb_strview); }
UPB_INLINE bool google_protobuf_FileOptions_has_php_namespace(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 18); }
-UPB_INLINE upb_strview google_protobuf_FileOptions_php_namespace(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(84, 144)); }
+UPB_INLINE upb_strview google_protobuf_FileOptions_php_namespace(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(84, 144), upb_strview); }
UPB_INLINE bool google_protobuf_FileOptions_has_php_generic_services(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 10); }
-UPB_INLINE bool google_protobuf_FileOptions_php_generic_services(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(24, 24)); }
+UPB_INLINE bool google_protobuf_FileOptions_php_generic_services(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(24, 24), bool); }
UPB_INLINE bool google_protobuf_FileOptions_has_php_metadata_namespace(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 19); }
-UPB_INLINE upb_strview google_protobuf_FileOptions_php_metadata_namespace(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(92, 160)); }
+UPB_INLINE upb_strview google_protobuf_FileOptions_php_metadata_namespace(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(92, 160), upb_strview); }
UPB_INLINE bool google_protobuf_FileOptions_has_ruby_package(const google_protobuf_FileOptions *msg) { return _upb_has_field(msg, 20); }
-UPB_INLINE upb_strview google_protobuf_FileOptions_ruby_package(const google_protobuf_FileOptions *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(100, 176)); }
+UPB_INLINE upb_strview google_protobuf_FileOptions_ruby_package(const google_protobuf_FileOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(100, 176), upb_strview); }
+UPB_INLINE bool google_protobuf_FileOptions_has_uninterpreted_option(const google_protobuf_FileOptions *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(108, 192)); }
UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_FileOptions_uninterpreted_option(const google_protobuf_FileOptions *msg, size_t *len) { return (const google_protobuf_UninterpretedOption* const*)_upb_array_accessor(msg, UPB_SIZE(108, 192), len); }
UPB_INLINE void google_protobuf_FileOptions_set_java_package(google_protobuf_FileOptions *msg, upb_strview value) {
_upb_sethas(msg, 11);
- UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(28, 32)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(28, 32), upb_strview) = value;
}
UPB_INLINE void google_protobuf_FileOptions_set_java_outer_classname(google_protobuf_FileOptions *msg, upb_strview value) {
_upb_sethas(msg, 12);
- UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(36, 48)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(36, 48), upb_strview) = value;
}
UPB_INLINE void google_protobuf_FileOptions_set_optimize_for(google_protobuf_FileOptions *msg, int32_t value) {
_upb_sethas(msg, 1);
- UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t) = value;
}
UPB_INLINE void google_protobuf_FileOptions_set_java_multiple_files(google_protobuf_FileOptions *msg, bool value) {
_upb_sethas(msg, 2);
- UPB_FIELD_AT(msg, bool, UPB_SIZE(16, 16)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(16, 16), bool) = value;
}
UPB_INLINE void google_protobuf_FileOptions_set_go_package(google_protobuf_FileOptions *msg, upb_strview value) {
_upb_sethas(msg, 13);
- UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(44, 64)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(44, 64), upb_strview) = value;
}
UPB_INLINE void google_protobuf_FileOptions_set_cc_generic_services(google_protobuf_FileOptions *msg, bool value) {
_upb_sethas(msg, 3);
- UPB_FIELD_AT(msg, bool, UPB_SIZE(17, 17)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(17, 17), bool) = value;
}
UPB_INLINE void google_protobuf_FileOptions_set_java_generic_services(google_protobuf_FileOptions *msg, bool value) {
_upb_sethas(msg, 4);
- UPB_FIELD_AT(msg, bool, UPB_SIZE(18, 18)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(18, 18), bool) = value;
}
UPB_INLINE void google_protobuf_FileOptions_set_py_generic_services(google_protobuf_FileOptions *msg, bool value) {
_upb_sethas(msg, 5);
- UPB_FIELD_AT(msg, bool, UPB_SIZE(19, 19)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(19, 19), bool) = value;
}
UPB_INLINE void google_protobuf_FileOptions_set_java_generate_equals_and_hash(google_protobuf_FileOptions *msg, bool value) {
_upb_sethas(msg, 6);
- UPB_FIELD_AT(msg, bool, UPB_SIZE(20, 20)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(20, 20), bool) = value;
}
UPB_INLINE void google_protobuf_FileOptions_set_deprecated(google_protobuf_FileOptions *msg, bool value) {
_upb_sethas(msg, 7);
- UPB_FIELD_AT(msg, bool, UPB_SIZE(21, 21)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(21, 21), bool) = value;
}
UPB_INLINE void google_protobuf_FileOptions_set_java_string_check_utf8(google_protobuf_FileOptions *msg, bool value) {
_upb_sethas(msg, 8);
- UPB_FIELD_AT(msg, bool, UPB_SIZE(22, 22)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(22, 22), bool) = value;
}
UPB_INLINE void google_protobuf_FileOptions_set_cc_enable_arenas(google_protobuf_FileOptions *msg, bool value) {
_upb_sethas(msg, 9);
- UPB_FIELD_AT(msg, bool, UPB_SIZE(23, 23)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(23, 23), bool) = value;
}
UPB_INLINE void google_protobuf_FileOptions_set_objc_class_prefix(google_protobuf_FileOptions *msg, upb_strview value) {
_upb_sethas(msg, 14);
- UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(52, 80)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(52, 80), upb_strview) = value;
}
UPB_INLINE void google_protobuf_FileOptions_set_csharp_namespace(google_protobuf_FileOptions *msg, upb_strview value) {
_upb_sethas(msg, 15);
- UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(60, 96)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(60, 96), upb_strview) = value;
}
UPB_INLINE void google_protobuf_FileOptions_set_swift_prefix(google_protobuf_FileOptions *msg, upb_strview value) {
_upb_sethas(msg, 16);
- UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(68, 112)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(68, 112), upb_strview) = value;
}
UPB_INLINE void google_protobuf_FileOptions_set_php_class_prefix(google_protobuf_FileOptions *msg, upb_strview value) {
_upb_sethas(msg, 17);
- UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(76, 128)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(76, 128), upb_strview) = value;
}
UPB_INLINE void google_protobuf_FileOptions_set_php_namespace(google_protobuf_FileOptions *msg, upb_strview value) {
_upb_sethas(msg, 18);
- UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(84, 144)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(84, 144), upb_strview) = value;
}
UPB_INLINE void google_protobuf_FileOptions_set_php_generic_services(google_protobuf_FileOptions *msg, bool value) {
_upb_sethas(msg, 10);
- UPB_FIELD_AT(msg, bool, UPB_SIZE(24, 24)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(24, 24), bool) = value;
}
UPB_INLINE void google_protobuf_FileOptions_set_php_metadata_namespace(google_protobuf_FileOptions *msg, upb_strview value) {
_upb_sethas(msg, 19);
- UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(92, 160)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(92, 160), upb_strview) = value;
}
UPB_INLINE void google_protobuf_FileOptions_set_ruby_package(google_protobuf_FileOptions *msg, upb_strview value) {
_upb_sethas(msg, 20);
- UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(100, 176)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(100, 176), upb_strview) = value;
}
UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FileOptions_mutable_uninterpreted_option(google_protobuf_FileOptions *msg, size_t *len) {
return (google_protobuf_UninterpretedOption**)_upb_array_mutable_accessor(msg, UPB_SIZE(108, 192), len);
}
UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FileOptions_resize_uninterpreted_option(google_protobuf_FileOptions *msg, size_t len, upb_arena *arena) {
- return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor(msg, UPB_SIZE(108, 192), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
+ return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor(msg, UPB_SIZE(108, 192), len, UPB_TYPE_MESSAGE, arena);
}
UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_FileOptions_add_uninterpreted_option(google_protobuf_FileOptions *msg, upb_arena *arena) {
- struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena);
+ struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena);
bool ok = _upb_array_append_accessor(
msg, UPB_SIZE(108, 192), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
if (!ok) return NULL;
@@ -2342,7 +2625,7 @@
/* google.protobuf.MessageOptions */
UPB_INLINE google_protobuf_MessageOptions *google_protobuf_MessageOptions_new(upb_arena *arena) {
- return (google_protobuf_MessageOptions *)upb_msg_new(&google_protobuf_MessageOptions_msginit, arena);
+ return (google_protobuf_MessageOptions *)_upb_msg_new(&google_protobuf_MessageOptions_msginit, arena);
}
UPB_INLINE google_protobuf_MessageOptions *google_protobuf_MessageOptions_parse(const char *buf, size_t size,
upb_arena *arena) {
@@ -2354,39 +2637,40 @@
}
UPB_INLINE bool google_protobuf_MessageOptions_has_message_set_wire_format(const google_protobuf_MessageOptions *msg) { return _upb_has_field(msg, 1); }
-UPB_INLINE bool google_protobuf_MessageOptions_message_set_wire_format(const google_protobuf_MessageOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)); }
+UPB_INLINE bool google_protobuf_MessageOptions_message_set_wire_format(const google_protobuf_MessageOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(1, 1), bool); }
UPB_INLINE bool google_protobuf_MessageOptions_has_no_standard_descriptor_accessor(const google_protobuf_MessageOptions *msg) { return _upb_has_field(msg, 2); }
-UPB_INLINE bool google_protobuf_MessageOptions_no_standard_descriptor_accessor(const google_protobuf_MessageOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(2, 2)); }
+UPB_INLINE bool google_protobuf_MessageOptions_no_standard_descriptor_accessor(const google_protobuf_MessageOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(2, 2), bool); }
UPB_INLINE bool google_protobuf_MessageOptions_has_deprecated(const google_protobuf_MessageOptions *msg) { return _upb_has_field(msg, 3); }
-UPB_INLINE bool google_protobuf_MessageOptions_deprecated(const google_protobuf_MessageOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(3, 3)); }
+UPB_INLINE bool google_protobuf_MessageOptions_deprecated(const google_protobuf_MessageOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(3, 3), bool); }
UPB_INLINE bool google_protobuf_MessageOptions_has_map_entry(const google_protobuf_MessageOptions *msg) { return _upb_has_field(msg, 4); }
-UPB_INLINE bool google_protobuf_MessageOptions_map_entry(const google_protobuf_MessageOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(4, 4)); }
+UPB_INLINE bool google_protobuf_MessageOptions_map_entry(const google_protobuf_MessageOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 4), bool); }
+UPB_INLINE bool google_protobuf_MessageOptions_has_uninterpreted_option(const google_protobuf_MessageOptions *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(8, 8)); }
UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_MessageOptions_uninterpreted_option(const google_protobuf_MessageOptions *msg, size_t *len) { return (const google_protobuf_UninterpretedOption* const*)_upb_array_accessor(msg, UPB_SIZE(8, 8), len); }
UPB_INLINE void google_protobuf_MessageOptions_set_message_set_wire_format(google_protobuf_MessageOptions *msg, bool value) {
_upb_sethas(msg, 1);
- UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(1, 1), bool) = value;
}
UPB_INLINE void google_protobuf_MessageOptions_set_no_standard_descriptor_accessor(google_protobuf_MessageOptions *msg, bool value) {
_upb_sethas(msg, 2);
- UPB_FIELD_AT(msg, bool, UPB_SIZE(2, 2)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(2, 2), bool) = value;
}
UPB_INLINE void google_protobuf_MessageOptions_set_deprecated(google_protobuf_MessageOptions *msg, bool value) {
_upb_sethas(msg, 3);
- UPB_FIELD_AT(msg, bool, UPB_SIZE(3, 3)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(3, 3), bool) = value;
}
UPB_INLINE void google_protobuf_MessageOptions_set_map_entry(google_protobuf_MessageOptions *msg, bool value) {
_upb_sethas(msg, 4);
- UPB_FIELD_AT(msg, bool, UPB_SIZE(4, 4)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(4, 4), bool) = value;
}
UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MessageOptions_mutable_uninterpreted_option(google_protobuf_MessageOptions *msg, size_t *len) {
return (google_protobuf_UninterpretedOption**)_upb_array_mutable_accessor(msg, UPB_SIZE(8, 8), len);
}
UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MessageOptions_resize_uninterpreted_option(google_protobuf_MessageOptions *msg, size_t len, upb_arena *arena) {
- return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor(msg, UPB_SIZE(8, 8), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
+ return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor(msg, UPB_SIZE(8, 8), len, UPB_TYPE_MESSAGE, arena);
}
UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_MessageOptions_add_uninterpreted_option(google_protobuf_MessageOptions *msg, upb_arena *arena) {
- struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena);
+ struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena);
bool ok = _upb_array_append_accessor(
msg, UPB_SIZE(8, 8), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
if (!ok) return NULL;
@@ -2396,7 +2680,7 @@
/* google.protobuf.FieldOptions */
UPB_INLINE google_protobuf_FieldOptions *google_protobuf_FieldOptions_new(upb_arena *arena) {
- return (google_protobuf_FieldOptions *)upb_msg_new(&google_protobuf_FieldOptions_msginit, arena);
+ return (google_protobuf_FieldOptions *)_upb_msg_new(&google_protobuf_FieldOptions_msginit, arena);
}
UPB_INLINE google_protobuf_FieldOptions *google_protobuf_FieldOptions_parse(const char *buf, size_t size,
upb_arena *arena) {
@@ -2408,51 +2692,52 @@
}
UPB_INLINE bool google_protobuf_FieldOptions_has_ctype(const google_protobuf_FieldOptions *msg) { return _upb_has_field(msg, 1); }
-UPB_INLINE int32_t google_protobuf_FieldOptions_ctype(const google_protobuf_FieldOptions *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)); }
+UPB_INLINE int32_t google_protobuf_FieldOptions_ctype(const google_protobuf_FieldOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t); }
UPB_INLINE bool google_protobuf_FieldOptions_has_packed(const google_protobuf_FieldOptions *msg) { return _upb_has_field(msg, 3); }
-UPB_INLINE bool google_protobuf_FieldOptions_packed(const google_protobuf_FieldOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(24, 24)); }
+UPB_INLINE bool google_protobuf_FieldOptions_packed(const google_protobuf_FieldOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(24, 24), bool); }
UPB_INLINE bool google_protobuf_FieldOptions_has_deprecated(const google_protobuf_FieldOptions *msg) { return _upb_has_field(msg, 4); }
-UPB_INLINE bool google_protobuf_FieldOptions_deprecated(const google_protobuf_FieldOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(25, 25)); }
+UPB_INLINE bool google_protobuf_FieldOptions_deprecated(const google_protobuf_FieldOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(25, 25), bool); }
UPB_INLINE bool google_protobuf_FieldOptions_has_lazy(const google_protobuf_FieldOptions *msg) { return _upb_has_field(msg, 5); }
-UPB_INLINE bool google_protobuf_FieldOptions_lazy(const google_protobuf_FieldOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(26, 26)); }
+UPB_INLINE bool google_protobuf_FieldOptions_lazy(const google_protobuf_FieldOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(26, 26), bool); }
UPB_INLINE bool google_protobuf_FieldOptions_has_jstype(const google_protobuf_FieldOptions *msg) { return _upb_has_field(msg, 2); }
-UPB_INLINE int32_t google_protobuf_FieldOptions_jstype(const google_protobuf_FieldOptions *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(16, 16)); }
+UPB_INLINE int32_t google_protobuf_FieldOptions_jstype(const google_protobuf_FieldOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(16, 16), int32_t); }
UPB_INLINE bool google_protobuf_FieldOptions_has_weak(const google_protobuf_FieldOptions *msg) { return _upb_has_field(msg, 6); }
-UPB_INLINE bool google_protobuf_FieldOptions_weak(const google_protobuf_FieldOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(27, 27)); }
+UPB_INLINE bool google_protobuf_FieldOptions_weak(const google_protobuf_FieldOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(27, 27), bool); }
+UPB_INLINE bool google_protobuf_FieldOptions_has_uninterpreted_option(const google_protobuf_FieldOptions *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(28, 32)); }
UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_FieldOptions_uninterpreted_option(const google_protobuf_FieldOptions *msg, size_t *len) { return (const google_protobuf_UninterpretedOption* const*)_upb_array_accessor(msg, UPB_SIZE(28, 32), len); }
UPB_INLINE void google_protobuf_FieldOptions_set_ctype(google_protobuf_FieldOptions *msg, int32_t value) {
_upb_sethas(msg, 1);
- UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t) = value;
}
UPB_INLINE void google_protobuf_FieldOptions_set_packed(google_protobuf_FieldOptions *msg, bool value) {
_upb_sethas(msg, 3);
- UPB_FIELD_AT(msg, bool, UPB_SIZE(24, 24)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(24, 24), bool) = value;
}
UPB_INLINE void google_protobuf_FieldOptions_set_deprecated(google_protobuf_FieldOptions *msg, bool value) {
_upb_sethas(msg, 4);
- UPB_FIELD_AT(msg, bool, UPB_SIZE(25, 25)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(25, 25), bool) = value;
}
UPB_INLINE void google_protobuf_FieldOptions_set_lazy(google_protobuf_FieldOptions *msg, bool value) {
_upb_sethas(msg, 5);
- UPB_FIELD_AT(msg, bool, UPB_SIZE(26, 26)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(26, 26), bool) = value;
}
UPB_INLINE void google_protobuf_FieldOptions_set_jstype(google_protobuf_FieldOptions *msg, int32_t value) {
_upb_sethas(msg, 2);
- UPB_FIELD_AT(msg, int32_t, UPB_SIZE(16, 16)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(16, 16), int32_t) = value;
}
UPB_INLINE void google_protobuf_FieldOptions_set_weak(google_protobuf_FieldOptions *msg, bool value) {
_upb_sethas(msg, 6);
- UPB_FIELD_AT(msg, bool, UPB_SIZE(27, 27)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(27, 27), bool) = value;
}
UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FieldOptions_mutable_uninterpreted_option(google_protobuf_FieldOptions *msg, size_t *len) {
return (google_protobuf_UninterpretedOption**)_upb_array_mutable_accessor(msg, UPB_SIZE(28, 32), len);
}
UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_FieldOptions_resize_uninterpreted_option(google_protobuf_FieldOptions *msg, size_t len, upb_arena *arena) {
- return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor(msg, UPB_SIZE(28, 32), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
+ return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor(msg, UPB_SIZE(28, 32), len, UPB_TYPE_MESSAGE, arena);
}
UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_FieldOptions_add_uninterpreted_option(google_protobuf_FieldOptions *msg, upb_arena *arena) {
- struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena);
+ struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena);
bool ok = _upb_array_append_accessor(
msg, UPB_SIZE(28, 32), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
if (!ok) return NULL;
@@ -2462,7 +2747,7 @@
/* google.protobuf.OneofOptions */
UPB_INLINE google_protobuf_OneofOptions *google_protobuf_OneofOptions_new(upb_arena *arena) {
- return (google_protobuf_OneofOptions *)upb_msg_new(&google_protobuf_OneofOptions_msginit, arena);
+ return (google_protobuf_OneofOptions *)_upb_msg_new(&google_protobuf_OneofOptions_msginit, arena);
}
UPB_INLINE google_protobuf_OneofOptions *google_protobuf_OneofOptions_parse(const char *buf, size_t size,
upb_arena *arena) {
@@ -2473,16 +2758,17 @@
return upb_encode(msg, &google_protobuf_OneofOptions_msginit, arena, len);
}
+UPB_INLINE bool google_protobuf_OneofOptions_has_uninterpreted_option(const google_protobuf_OneofOptions *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(0, 0)); }
UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_OneofOptions_uninterpreted_option(const google_protobuf_OneofOptions *msg, size_t *len) { return (const google_protobuf_UninterpretedOption* const*)_upb_array_accessor(msg, UPB_SIZE(0, 0), len); }
UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_OneofOptions_mutable_uninterpreted_option(google_protobuf_OneofOptions *msg, size_t *len) {
return (google_protobuf_UninterpretedOption**)_upb_array_mutable_accessor(msg, UPB_SIZE(0, 0), len);
}
UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_OneofOptions_resize_uninterpreted_option(google_protobuf_OneofOptions *msg, size_t len, upb_arena *arena) {
- return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor(msg, UPB_SIZE(0, 0), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
+ return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor(msg, UPB_SIZE(0, 0), len, UPB_TYPE_MESSAGE, arena);
}
UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_OneofOptions_add_uninterpreted_option(google_protobuf_OneofOptions *msg, upb_arena *arena) {
- struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena);
+ struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena);
bool ok = _upb_array_append_accessor(
msg, UPB_SIZE(0, 0), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
if (!ok) return NULL;
@@ -2492,7 +2778,7 @@
/* google.protobuf.EnumOptions */
UPB_INLINE google_protobuf_EnumOptions *google_protobuf_EnumOptions_new(upb_arena *arena) {
- return (google_protobuf_EnumOptions *)upb_msg_new(&google_protobuf_EnumOptions_msginit, arena);
+ return (google_protobuf_EnumOptions *)_upb_msg_new(&google_protobuf_EnumOptions_msginit, arena);
}
UPB_INLINE google_protobuf_EnumOptions *google_protobuf_EnumOptions_parse(const char *buf, size_t size,
upb_arena *arena) {
@@ -2504,27 +2790,28 @@
}
UPB_INLINE bool google_protobuf_EnumOptions_has_allow_alias(const google_protobuf_EnumOptions *msg) { return _upb_has_field(msg, 1); }
-UPB_INLINE bool google_protobuf_EnumOptions_allow_alias(const google_protobuf_EnumOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)); }
+UPB_INLINE bool google_protobuf_EnumOptions_allow_alias(const google_protobuf_EnumOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(1, 1), bool); }
UPB_INLINE bool google_protobuf_EnumOptions_has_deprecated(const google_protobuf_EnumOptions *msg) { return _upb_has_field(msg, 2); }
-UPB_INLINE bool google_protobuf_EnumOptions_deprecated(const google_protobuf_EnumOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(2, 2)); }
+UPB_INLINE bool google_protobuf_EnumOptions_deprecated(const google_protobuf_EnumOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(2, 2), bool); }
+UPB_INLINE bool google_protobuf_EnumOptions_has_uninterpreted_option(const google_protobuf_EnumOptions *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(4, 8)); }
UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_EnumOptions_uninterpreted_option(const google_protobuf_EnumOptions *msg, size_t *len) { return (const google_protobuf_UninterpretedOption* const*)_upb_array_accessor(msg, UPB_SIZE(4, 8), len); }
UPB_INLINE void google_protobuf_EnumOptions_set_allow_alias(google_protobuf_EnumOptions *msg, bool value) {
_upb_sethas(msg, 1);
- UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(1, 1), bool) = value;
}
UPB_INLINE void google_protobuf_EnumOptions_set_deprecated(google_protobuf_EnumOptions *msg, bool value) {
_upb_sethas(msg, 2);
- UPB_FIELD_AT(msg, bool, UPB_SIZE(2, 2)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(2, 2), bool) = value;
}
UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumOptions_mutable_uninterpreted_option(google_protobuf_EnumOptions *msg, size_t *len) {
return (google_protobuf_UninterpretedOption**)_upb_array_mutable_accessor(msg, UPB_SIZE(4, 8), len);
}
UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumOptions_resize_uninterpreted_option(google_protobuf_EnumOptions *msg, size_t len, upb_arena *arena) {
- return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor(msg, UPB_SIZE(4, 8), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
+ return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor(msg, UPB_SIZE(4, 8), len, UPB_TYPE_MESSAGE, arena);
}
UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_EnumOptions_add_uninterpreted_option(google_protobuf_EnumOptions *msg, upb_arena *arena) {
- struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena);
+ struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena);
bool ok = _upb_array_append_accessor(
msg, UPB_SIZE(4, 8), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
if (!ok) return NULL;
@@ -2534,7 +2821,7 @@
/* google.protobuf.EnumValueOptions */
UPB_INLINE google_protobuf_EnumValueOptions *google_protobuf_EnumValueOptions_new(upb_arena *arena) {
- return (google_protobuf_EnumValueOptions *)upb_msg_new(&google_protobuf_EnumValueOptions_msginit, arena);
+ return (google_protobuf_EnumValueOptions *)_upb_msg_new(&google_protobuf_EnumValueOptions_msginit, arena);
}
UPB_INLINE google_protobuf_EnumValueOptions *google_protobuf_EnumValueOptions_parse(const char *buf, size_t size,
upb_arena *arena) {
@@ -2546,21 +2833,22 @@
}
UPB_INLINE bool google_protobuf_EnumValueOptions_has_deprecated(const google_protobuf_EnumValueOptions *msg) { return _upb_has_field(msg, 1); }
-UPB_INLINE bool google_protobuf_EnumValueOptions_deprecated(const google_protobuf_EnumValueOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)); }
+UPB_INLINE bool google_protobuf_EnumValueOptions_deprecated(const google_protobuf_EnumValueOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(1, 1), bool); }
+UPB_INLINE bool google_protobuf_EnumValueOptions_has_uninterpreted_option(const google_protobuf_EnumValueOptions *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(4, 8)); }
UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_EnumValueOptions_uninterpreted_option(const google_protobuf_EnumValueOptions *msg, size_t *len) { return (const google_protobuf_UninterpretedOption* const*)_upb_array_accessor(msg, UPB_SIZE(4, 8), len); }
UPB_INLINE void google_protobuf_EnumValueOptions_set_deprecated(google_protobuf_EnumValueOptions *msg, bool value) {
_upb_sethas(msg, 1);
- UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(1, 1), bool) = value;
}
UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumValueOptions_mutable_uninterpreted_option(google_protobuf_EnumValueOptions *msg, size_t *len) {
return (google_protobuf_UninterpretedOption**)_upb_array_mutable_accessor(msg, UPB_SIZE(4, 8), len);
}
UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_EnumValueOptions_resize_uninterpreted_option(google_protobuf_EnumValueOptions *msg, size_t len, upb_arena *arena) {
- return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor(msg, UPB_SIZE(4, 8), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
+ return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor(msg, UPB_SIZE(4, 8), len, UPB_TYPE_MESSAGE, arena);
}
UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_EnumValueOptions_add_uninterpreted_option(google_protobuf_EnumValueOptions *msg, upb_arena *arena) {
- struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena);
+ struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena);
bool ok = _upb_array_append_accessor(
msg, UPB_SIZE(4, 8), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
if (!ok) return NULL;
@@ -2570,7 +2858,7 @@
/* google.protobuf.ServiceOptions */
UPB_INLINE google_protobuf_ServiceOptions *google_protobuf_ServiceOptions_new(upb_arena *arena) {
- return (google_protobuf_ServiceOptions *)upb_msg_new(&google_protobuf_ServiceOptions_msginit, arena);
+ return (google_protobuf_ServiceOptions *)_upb_msg_new(&google_protobuf_ServiceOptions_msginit, arena);
}
UPB_INLINE google_protobuf_ServiceOptions *google_protobuf_ServiceOptions_parse(const char *buf, size_t size,
upb_arena *arena) {
@@ -2582,21 +2870,22 @@
}
UPB_INLINE bool google_protobuf_ServiceOptions_has_deprecated(const google_protobuf_ServiceOptions *msg) { return _upb_has_field(msg, 1); }
-UPB_INLINE bool google_protobuf_ServiceOptions_deprecated(const google_protobuf_ServiceOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)); }
+UPB_INLINE bool google_protobuf_ServiceOptions_deprecated(const google_protobuf_ServiceOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(1, 1), bool); }
+UPB_INLINE bool google_protobuf_ServiceOptions_has_uninterpreted_option(const google_protobuf_ServiceOptions *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(4, 8)); }
UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_ServiceOptions_uninterpreted_option(const google_protobuf_ServiceOptions *msg, size_t *len) { return (const google_protobuf_UninterpretedOption* const*)_upb_array_accessor(msg, UPB_SIZE(4, 8), len); }
UPB_INLINE void google_protobuf_ServiceOptions_set_deprecated(google_protobuf_ServiceOptions *msg, bool value) {
_upb_sethas(msg, 1);
- UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(1, 1), bool) = value;
}
UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ServiceOptions_mutable_uninterpreted_option(google_protobuf_ServiceOptions *msg, size_t *len) {
return (google_protobuf_UninterpretedOption**)_upb_array_mutable_accessor(msg, UPB_SIZE(4, 8), len);
}
UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_ServiceOptions_resize_uninterpreted_option(google_protobuf_ServiceOptions *msg, size_t len, upb_arena *arena) {
- return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor(msg, UPB_SIZE(4, 8), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
+ return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor(msg, UPB_SIZE(4, 8), len, UPB_TYPE_MESSAGE, arena);
}
UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_ServiceOptions_add_uninterpreted_option(google_protobuf_ServiceOptions *msg, upb_arena *arena) {
- struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena);
+ struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena);
bool ok = _upb_array_append_accessor(
msg, UPB_SIZE(4, 8), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
if (!ok) return NULL;
@@ -2606,7 +2895,7 @@
/* google.protobuf.MethodOptions */
UPB_INLINE google_protobuf_MethodOptions *google_protobuf_MethodOptions_new(upb_arena *arena) {
- return (google_protobuf_MethodOptions *)upb_msg_new(&google_protobuf_MethodOptions_msginit, arena);
+ return (google_protobuf_MethodOptions *)_upb_msg_new(&google_protobuf_MethodOptions_msginit, arena);
}
UPB_INLINE google_protobuf_MethodOptions *google_protobuf_MethodOptions_parse(const char *buf, size_t size,
upb_arena *arena) {
@@ -2618,27 +2907,28 @@
}
UPB_INLINE bool google_protobuf_MethodOptions_has_deprecated(const google_protobuf_MethodOptions *msg) { return _upb_has_field(msg, 2); }
-UPB_INLINE bool google_protobuf_MethodOptions_deprecated(const google_protobuf_MethodOptions *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(16, 16)); }
+UPB_INLINE bool google_protobuf_MethodOptions_deprecated(const google_protobuf_MethodOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(16, 16), bool); }
UPB_INLINE bool google_protobuf_MethodOptions_has_idempotency_level(const google_protobuf_MethodOptions *msg) { return _upb_has_field(msg, 1); }
-UPB_INLINE int32_t google_protobuf_MethodOptions_idempotency_level(const google_protobuf_MethodOptions *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)); }
+UPB_INLINE int32_t google_protobuf_MethodOptions_idempotency_level(const google_protobuf_MethodOptions *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t); }
+UPB_INLINE bool google_protobuf_MethodOptions_has_uninterpreted_option(const google_protobuf_MethodOptions *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(20, 24)); }
UPB_INLINE const google_protobuf_UninterpretedOption* const* google_protobuf_MethodOptions_uninterpreted_option(const google_protobuf_MethodOptions *msg, size_t *len) { return (const google_protobuf_UninterpretedOption* const*)_upb_array_accessor(msg, UPB_SIZE(20, 24), len); }
UPB_INLINE void google_protobuf_MethodOptions_set_deprecated(google_protobuf_MethodOptions *msg, bool value) {
_upb_sethas(msg, 2);
- UPB_FIELD_AT(msg, bool, UPB_SIZE(16, 16)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(16, 16), bool) = value;
}
UPB_INLINE void google_protobuf_MethodOptions_set_idempotency_level(google_protobuf_MethodOptions *msg, int32_t value) {
_upb_sethas(msg, 1);
- UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t) = value;
}
UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MethodOptions_mutable_uninterpreted_option(google_protobuf_MethodOptions *msg, size_t *len) {
return (google_protobuf_UninterpretedOption**)_upb_array_mutable_accessor(msg, UPB_SIZE(20, 24), len);
}
UPB_INLINE google_protobuf_UninterpretedOption** google_protobuf_MethodOptions_resize_uninterpreted_option(google_protobuf_MethodOptions *msg, size_t len, upb_arena *arena) {
- return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor(msg, UPB_SIZE(20, 24), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
+ return (google_protobuf_UninterpretedOption**)_upb_array_resize_accessor(msg, UPB_SIZE(20, 24), len, UPB_TYPE_MESSAGE, arena);
}
UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_MethodOptions_add_uninterpreted_option(google_protobuf_MethodOptions *msg, upb_arena *arena) {
- struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena);
+ struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena);
bool ok = _upb_array_append_accessor(
msg, UPB_SIZE(20, 24), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
if (!ok) return NULL;
@@ -2648,7 +2938,7 @@
/* google.protobuf.UninterpretedOption */
UPB_INLINE google_protobuf_UninterpretedOption *google_protobuf_UninterpretedOption_new(upb_arena *arena) {
- return (google_protobuf_UninterpretedOption *)upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena);
+ return (google_protobuf_UninterpretedOption *)_upb_msg_new(&google_protobuf_UninterpretedOption_msginit, arena);
}
UPB_INLINE google_protobuf_UninterpretedOption *google_protobuf_UninterpretedOption_parse(const char *buf, size_t size,
upb_arena *arena) {
@@ -2659,28 +2949,29 @@
return upb_encode(msg, &google_protobuf_UninterpretedOption_msginit, arena, len);
}
+UPB_INLINE bool google_protobuf_UninterpretedOption_has_name(const google_protobuf_UninterpretedOption *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(56, 80)); }
UPB_INLINE const google_protobuf_UninterpretedOption_NamePart* const* google_protobuf_UninterpretedOption_name(const google_protobuf_UninterpretedOption *msg, size_t *len) { return (const google_protobuf_UninterpretedOption_NamePart* const*)_upb_array_accessor(msg, UPB_SIZE(56, 80), len); }
UPB_INLINE bool google_protobuf_UninterpretedOption_has_identifier_value(const google_protobuf_UninterpretedOption *msg) { return _upb_has_field(msg, 4); }
-UPB_INLINE upb_strview google_protobuf_UninterpretedOption_identifier_value(const google_protobuf_UninterpretedOption *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(32, 32)); }
+UPB_INLINE upb_strview google_protobuf_UninterpretedOption_identifier_value(const google_protobuf_UninterpretedOption *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(32, 32), upb_strview); }
UPB_INLINE bool google_protobuf_UninterpretedOption_has_positive_int_value(const google_protobuf_UninterpretedOption *msg) { return _upb_has_field(msg, 1); }
-UPB_INLINE uint64_t google_protobuf_UninterpretedOption_positive_int_value(const google_protobuf_UninterpretedOption *msg) { return UPB_FIELD_AT(msg, uint64_t, UPB_SIZE(8, 8)); }
+UPB_INLINE uint64_t google_protobuf_UninterpretedOption_positive_int_value(const google_protobuf_UninterpretedOption *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(8, 8), uint64_t); }
UPB_INLINE bool google_protobuf_UninterpretedOption_has_negative_int_value(const google_protobuf_UninterpretedOption *msg) { return _upb_has_field(msg, 2); }
-UPB_INLINE int64_t google_protobuf_UninterpretedOption_negative_int_value(const google_protobuf_UninterpretedOption *msg) { return UPB_FIELD_AT(msg, int64_t, UPB_SIZE(16, 16)); }
+UPB_INLINE int64_t google_protobuf_UninterpretedOption_negative_int_value(const google_protobuf_UninterpretedOption *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(16, 16), int64_t); }
UPB_INLINE bool google_protobuf_UninterpretedOption_has_double_value(const google_protobuf_UninterpretedOption *msg) { return _upb_has_field(msg, 3); }
-UPB_INLINE double google_protobuf_UninterpretedOption_double_value(const google_protobuf_UninterpretedOption *msg) { return UPB_FIELD_AT(msg, double, UPB_SIZE(24, 24)); }
+UPB_INLINE double google_protobuf_UninterpretedOption_double_value(const google_protobuf_UninterpretedOption *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(24, 24), double); }
UPB_INLINE bool google_protobuf_UninterpretedOption_has_string_value(const google_protobuf_UninterpretedOption *msg) { return _upb_has_field(msg, 5); }
-UPB_INLINE upb_strview google_protobuf_UninterpretedOption_string_value(const google_protobuf_UninterpretedOption *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(40, 48)); }
+UPB_INLINE upb_strview google_protobuf_UninterpretedOption_string_value(const google_protobuf_UninterpretedOption *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(40, 48), upb_strview); }
UPB_INLINE bool google_protobuf_UninterpretedOption_has_aggregate_value(const google_protobuf_UninterpretedOption *msg) { return _upb_has_field(msg, 6); }
-UPB_INLINE upb_strview google_protobuf_UninterpretedOption_aggregate_value(const google_protobuf_UninterpretedOption *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(48, 64)); }
+UPB_INLINE upb_strview google_protobuf_UninterpretedOption_aggregate_value(const google_protobuf_UninterpretedOption *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(48, 64), upb_strview); }
UPB_INLINE google_protobuf_UninterpretedOption_NamePart** google_protobuf_UninterpretedOption_mutable_name(google_protobuf_UninterpretedOption *msg, size_t *len) {
return (google_protobuf_UninterpretedOption_NamePart**)_upb_array_mutable_accessor(msg, UPB_SIZE(56, 80), len);
}
UPB_INLINE google_protobuf_UninterpretedOption_NamePart** google_protobuf_UninterpretedOption_resize_name(google_protobuf_UninterpretedOption *msg, size_t len, upb_arena *arena) {
- return (google_protobuf_UninterpretedOption_NamePart**)_upb_array_resize_accessor(msg, UPB_SIZE(56, 80), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
+ return (google_protobuf_UninterpretedOption_NamePart**)_upb_array_resize_accessor(msg, UPB_SIZE(56, 80), len, UPB_TYPE_MESSAGE, arena);
}
UPB_INLINE struct google_protobuf_UninterpretedOption_NamePart* google_protobuf_UninterpretedOption_add_name(google_protobuf_UninterpretedOption *msg, upb_arena *arena) {
- struct google_protobuf_UninterpretedOption_NamePart* sub = (struct google_protobuf_UninterpretedOption_NamePart*)upb_msg_new(&google_protobuf_UninterpretedOption_NamePart_msginit, arena);
+ struct google_protobuf_UninterpretedOption_NamePart* sub = (struct google_protobuf_UninterpretedOption_NamePart*)_upb_msg_new(&google_protobuf_UninterpretedOption_NamePart_msginit, arena);
bool ok = _upb_array_append_accessor(
msg, UPB_SIZE(56, 80), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
if (!ok) return NULL;
@@ -2688,33 +2979,33 @@
}
UPB_INLINE void google_protobuf_UninterpretedOption_set_identifier_value(google_protobuf_UninterpretedOption *msg, upb_strview value) {
_upb_sethas(msg, 4);
- UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(32, 32)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(32, 32), upb_strview) = value;
}
UPB_INLINE void google_protobuf_UninterpretedOption_set_positive_int_value(google_protobuf_UninterpretedOption *msg, uint64_t value) {
_upb_sethas(msg, 1);
- UPB_FIELD_AT(msg, uint64_t, UPB_SIZE(8, 8)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(8, 8), uint64_t) = value;
}
UPB_INLINE void google_protobuf_UninterpretedOption_set_negative_int_value(google_protobuf_UninterpretedOption *msg, int64_t value) {
_upb_sethas(msg, 2);
- UPB_FIELD_AT(msg, int64_t, UPB_SIZE(16, 16)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(16, 16), int64_t) = value;
}
UPB_INLINE void google_protobuf_UninterpretedOption_set_double_value(google_protobuf_UninterpretedOption *msg, double value) {
_upb_sethas(msg, 3);
- UPB_FIELD_AT(msg, double, UPB_SIZE(24, 24)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(24, 24), double) = value;
}
UPB_INLINE void google_protobuf_UninterpretedOption_set_string_value(google_protobuf_UninterpretedOption *msg, upb_strview value) {
_upb_sethas(msg, 5);
- UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(40, 48)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(40, 48), upb_strview) = value;
}
UPB_INLINE void google_protobuf_UninterpretedOption_set_aggregate_value(google_protobuf_UninterpretedOption *msg, upb_strview value) {
_upb_sethas(msg, 6);
- UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(48, 64)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(48, 64), upb_strview) = value;
}
/* google.protobuf.UninterpretedOption.NamePart */
UPB_INLINE google_protobuf_UninterpretedOption_NamePart *google_protobuf_UninterpretedOption_NamePart_new(upb_arena *arena) {
- return (google_protobuf_UninterpretedOption_NamePart *)upb_msg_new(&google_protobuf_UninterpretedOption_NamePart_msginit, arena);
+ return (google_protobuf_UninterpretedOption_NamePart *)_upb_msg_new(&google_protobuf_UninterpretedOption_NamePart_msginit, arena);
}
UPB_INLINE google_protobuf_UninterpretedOption_NamePart *google_protobuf_UninterpretedOption_NamePart_parse(const char *buf, size_t size,
upb_arena *arena) {
@@ -2726,23 +3017,23 @@
}
UPB_INLINE bool google_protobuf_UninterpretedOption_NamePart_has_name_part(const google_protobuf_UninterpretedOption_NamePart *msg) { return _upb_has_field(msg, 2); }
-UPB_INLINE upb_strview google_protobuf_UninterpretedOption_NamePart_name_part(const google_protobuf_UninterpretedOption_NamePart *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(4, 8)); }
+UPB_INLINE upb_strview google_protobuf_UninterpretedOption_NamePart_name_part(const google_protobuf_UninterpretedOption_NamePart *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview); }
UPB_INLINE bool google_protobuf_UninterpretedOption_NamePart_has_is_extension(const google_protobuf_UninterpretedOption_NamePart *msg) { return _upb_has_field(msg, 1); }
-UPB_INLINE bool google_protobuf_UninterpretedOption_NamePart_is_extension(const google_protobuf_UninterpretedOption_NamePart *msg) { return UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)); }
+UPB_INLINE bool google_protobuf_UninterpretedOption_NamePart_is_extension(const google_protobuf_UninterpretedOption_NamePart *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(1, 1), bool); }
UPB_INLINE void google_protobuf_UninterpretedOption_NamePart_set_name_part(google_protobuf_UninterpretedOption_NamePart *msg, upb_strview value) {
_upb_sethas(msg, 2);
- UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(4, 8)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview) = value;
}
UPB_INLINE void google_protobuf_UninterpretedOption_NamePart_set_is_extension(google_protobuf_UninterpretedOption_NamePart *msg, bool value) {
_upb_sethas(msg, 1);
- UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(1, 1), bool) = value;
}
/* google.protobuf.SourceCodeInfo */
UPB_INLINE google_protobuf_SourceCodeInfo *google_protobuf_SourceCodeInfo_new(upb_arena *arena) {
- return (google_protobuf_SourceCodeInfo *)upb_msg_new(&google_protobuf_SourceCodeInfo_msginit, arena);
+ return (google_protobuf_SourceCodeInfo *)_upb_msg_new(&google_protobuf_SourceCodeInfo_msginit, arena);
}
UPB_INLINE google_protobuf_SourceCodeInfo *google_protobuf_SourceCodeInfo_parse(const char *buf, size_t size,
upb_arena *arena) {
@@ -2753,16 +3044,17 @@
return upb_encode(msg, &google_protobuf_SourceCodeInfo_msginit, arena, len);
}
+UPB_INLINE bool google_protobuf_SourceCodeInfo_has_location(const google_protobuf_SourceCodeInfo *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(0, 0)); }
UPB_INLINE const google_protobuf_SourceCodeInfo_Location* const* google_protobuf_SourceCodeInfo_location(const google_protobuf_SourceCodeInfo *msg, size_t *len) { return (const google_protobuf_SourceCodeInfo_Location* const*)_upb_array_accessor(msg, UPB_SIZE(0, 0), len); }
UPB_INLINE google_protobuf_SourceCodeInfo_Location** google_protobuf_SourceCodeInfo_mutable_location(google_protobuf_SourceCodeInfo *msg, size_t *len) {
return (google_protobuf_SourceCodeInfo_Location**)_upb_array_mutable_accessor(msg, UPB_SIZE(0, 0), len);
}
UPB_INLINE google_protobuf_SourceCodeInfo_Location** google_protobuf_SourceCodeInfo_resize_location(google_protobuf_SourceCodeInfo *msg, size_t len, upb_arena *arena) {
- return (google_protobuf_SourceCodeInfo_Location**)_upb_array_resize_accessor(msg, UPB_SIZE(0, 0), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
+ return (google_protobuf_SourceCodeInfo_Location**)_upb_array_resize_accessor(msg, UPB_SIZE(0, 0), len, UPB_TYPE_MESSAGE, arena);
}
UPB_INLINE struct google_protobuf_SourceCodeInfo_Location* google_protobuf_SourceCodeInfo_add_location(google_protobuf_SourceCodeInfo *msg, upb_arena *arena) {
- struct google_protobuf_SourceCodeInfo_Location* sub = (struct google_protobuf_SourceCodeInfo_Location*)upb_msg_new(&google_protobuf_SourceCodeInfo_Location_msginit, arena);
+ struct google_protobuf_SourceCodeInfo_Location* sub = (struct google_protobuf_SourceCodeInfo_Location*)_upb_msg_new(&google_protobuf_SourceCodeInfo_Location_msginit, arena);
bool ok = _upb_array_append_accessor(
msg, UPB_SIZE(0, 0), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
if (!ok) return NULL;
@@ -2772,7 +3064,7 @@
/* google.protobuf.SourceCodeInfo.Location */
UPB_INLINE google_protobuf_SourceCodeInfo_Location *google_protobuf_SourceCodeInfo_Location_new(upb_arena *arena) {
- return (google_protobuf_SourceCodeInfo_Location *)upb_msg_new(&google_protobuf_SourceCodeInfo_Location_msginit, arena);
+ return (google_protobuf_SourceCodeInfo_Location *)_upb_msg_new(&google_protobuf_SourceCodeInfo_Location_msginit, arena);
}
UPB_INLINE google_protobuf_SourceCodeInfo_Location *google_protobuf_SourceCodeInfo_Location_parse(const char *buf, size_t size,
upb_arena *arena) {
@@ -2786,54 +3078,54 @@
UPB_INLINE int32_t const* google_protobuf_SourceCodeInfo_Location_path(const google_protobuf_SourceCodeInfo_Location *msg, size_t *len) { return (int32_t const*)_upb_array_accessor(msg, UPB_SIZE(20, 40), len); }
UPB_INLINE int32_t const* google_protobuf_SourceCodeInfo_Location_span(const google_protobuf_SourceCodeInfo_Location *msg, size_t *len) { return (int32_t const*)_upb_array_accessor(msg, UPB_SIZE(24, 48), len); }
UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_has_leading_comments(const google_protobuf_SourceCodeInfo_Location *msg) { return _upb_has_field(msg, 1); }
-UPB_INLINE upb_strview google_protobuf_SourceCodeInfo_Location_leading_comments(const google_protobuf_SourceCodeInfo_Location *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(4, 8)); }
+UPB_INLINE upb_strview google_protobuf_SourceCodeInfo_Location_leading_comments(const google_protobuf_SourceCodeInfo_Location *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview); }
UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_has_trailing_comments(const google_protobuf_SourceCodeInfo_Location *msg) { return _upb_has_field(msg, 2); }
-UPB_INLINE upb_strview google_protobuf_SourceCodeInfo_Location_trailing_comments(const google_protobuf_SourceCodeInfo_Location *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(12, 24)); }
+UPB_INLINE upb_strview google_protobuf_SourceCodeInfo_Location_trailing_comments(const google_protobuf_SourceCodeInfo_Location *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(12, 24), upb_strview); }
UPB_INLINE upb_strview const* google_protobuf_SourceCodeInfo_Location_leading_detached_comments(const google_protobuf_SourceCodeInfo_Location *msg, size_t *len) { return (upb_strview const*)_upb_array_accessor(msg, UPB_SIZE(28, 56), len); }
UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_mutable_path(google_protobuf_SourceCodeInfo_Location *msg, size_t *len) {
return (int32_t*)_upb_array_mutable_accessor(msg, UPB_SIZE(20, 40), len);
}
UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_resize_path(google_protobuf_SourceCodeInfo_Location *msg, size_t len, upb_arena *arena) {
- return (int32_t*)_upb_array_resize_accessor(msg, UPB_SIZE(20, 40), len, UPB_SIZE(4, 4), UPB_TYPE_INT32, arena);
+ return (int32_t*)_upb_array_resize_accessor(msg, UPB_SIZE(20, 40), len, UPB_TYPE_INT32, arena);
}
UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_path(google_protobuf_SourceCodeInfo_Location *msg, int32_t val, upb_arena *arena) {
- return _upb_array_append_accessor(
- msg, UPB_SIZE(20, 40), UPB_SIZE(4, 4), UPB_TYPE_INT32, &val, arena);
+ return _upb_array_append_accessor(msg, UPB_SIZE(20, 40), UPB_SIZE(4, 4), UPB_TYPE_INT32, &val,
+ arena);
}
UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_mutable_span(google_protobuf_SourceCodeInfo_Location *msg, size_t *len) {
return (int32_t*)_upb_array_mutable_accessor(msg, UPB_SIZE(24, 48), len);
}
UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_resize_span(google_protobuf_SourceCodeInfo_Location *msg, size_t len, upb_arena *arena) {
- return (int32_t*)_upb_array_resize_accessor(msg, UPB_SIZE(24, 48), len, UPB_SIZE(4, 4), UPB_TYPE_INT32, arena);
+ return (int32_t*)_upb_array_resize_accessor(msg, UPB_SIZE(24, 48), len, UPB_TYPE_INT32, arena);
}
UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_span(google_protobuf_SourceCodeInfo_Location *msg, int32_t val, upb_arena *arena) {
- return _upb_array_append_accessor(
- msg, UPB_SIZE(24, 48), UPB_SIZE(4, 4), UPB_TYPE_INT32, &val, arena);
+ return _upb_array_append_accessor(msg, UPB_SIZE(24, 48), UPB_SIZE(4, 4), UPB_TYPE_INT32, &val,
+ arena);
}
UPB_INLINE void google_protobuf_SourceCodeInfo_Location_set_leading_comments(google_protobuf_SourceCodeInfo_Location *msg, upb_strview value) {
_upb_sethas(msg, 1);
- UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(4, 8)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(4, 8), upb_strview) = value;
}
UPB_INLINE void google_protobuf_SourceCodeInfo_Location_set_trailing_comments(google_protobuf_SourceCodeInfo_Location *msg, upb_strview value) {
_upb_sethas(msg, 2);
- UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(12, 24)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(12, 24), upb_strview) = value;
}
UPB_INLINE upb_strview* google_protobuf_SourceCodeInfo_Location_mutable_leading_detached_comments(google_protobuf_SourceCodeInfo_Location *msg, size_t *len) {
return (upb_strview*)_upb_array_mutable_accessor(msg, UPB_SIZE(28, 56), len);
}
UPB_INLINE upb_strview* google_protobuf_SourceCodeInfo_Location_resize_leading_detached_comments(google_protobuf_SourceCodeInfo_Location *msg, size_t len, upb_arena *arena) {
- return (upb_strview*)_upb_array_resize_accessor(msg, UPB_SIZE(28, 56), len, UPB_SIZE(8, 16), UPB_TYPE_STRING, arena);
+ return (upb_strview*)_upb_array_resize_accessor(msg, UPB_SIZE(28, 56), len, UPB_TYPE_STRING, arena);
}
UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_leading_detached_comments(google_protobuf_SourceCodeInfo_Location *msg, upb_strview val, upb_arena *arena) {
- return _upb_array_append_accessor(
- msg, UPB_SIZE(28, 56), UPB_SIZE(8, 16), UPB_TYPE_STRING, &val, arena);
+ return _upb_array_append_accessor(msg, UPB_SIZE(28, 56), UPB_SIZE(8, 16), UPB_TYPE_STRING, &val,
+ arena);
}
/* google.protobuf.GeneratedCodeInfo */
UPB_INLINE google_protobuf_GeneratedCodeInfo *google_protobuf_GeneratedCodeInfo_new(upb_arena *arena) {
- return (google_protobuf_GeneratedCodeInfo *)upb_msg_new(&google_protobuf_GeneratedCodeInfo_msginit, arena);
+ return (google_protobuf_GeneratedCodeInfo *)_upb_msg_new(&google_protobuf_GeneratedCodeInfo_msginit, arena);
}
UPB_INLINE google_protobuf_GeneratedCodeInfo *google_protobuf_GeneratedCodeInfo_parse(const char *buf, size_t size,
upb_arena *arena) {
@@ -2844,16 +3136,17 @@
return upb_encode(msg, &google_protobuf_GeneratedCodeInfo_msginit, arena, len);
}
+UPB_INLINE bool google_protobuf_GeneratedCodeInfo_has_annotation(const google_protobuf_GeneratedCodeInfo *msg) { return _upb_has_submsg_nohasbit(msg, UPB_SIZE(0, 0)); }
UPB_INLINE const google_protobuf_GeneratedCodeInfo_Annotation* const* google_protobuf_GeneratedCodeInfo_annotation(const google_protobuf_GeneratedCodeInfo *msg, size_t *len) { return (const google_protobuf_GeneratedCodeInfo_Annotation* const*)_upb_array_accessor(msg, UPB_SIZE(0, 0), len); }
UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation** google_protobuf_GeneratedCodeInfo_mutable_annotation(google_protobuf_GeneratedCodeInfo *msg, size_t *len) {
return (google_protobuf_GeneratedCodeInfo_Annotation**)_upb_array_mutable_accessor(msg, UPB_SIZE(0, 0), len);
}
UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation** google_protobuf_GeneratedCodeInfo_resize_annotation(google_protobuf_GeneratedCodeInfo *msg, size_t len, upb_arena *arena) {
- return (google_protobuf_GeneratedCodeInfo_Annotation**)_upb_array_resize_accessor(msg, UPB_SIZE(0, 0), len, UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, arena);
+ return (google_protobuf_GeneratedCodeInfo_Annotation**)_upb_array_resize_accessor(msg, UPB_SIZE(0, 0), len, UPB_TYPE_MESSAGE, arena);
}
UPB_INLINE struct google_protobuf_GeneratedCodeInfo_Annotation* google_protobuf_GeneratedCodeInfo_add_annotation(google_protobuf_GeneratedCodeInfo *msg, upb_arena *arena) {
- struct google_protobuf_GeneratedCodeInfo_Annotation* sub = (struct google_protobuf_GeneratedCodeInfo_Annotation*)upb_msg_new(&google_protobuf_GeneratedCodeInfo_Annotation_msginit, arena);
+ struct google_protobuf_GeneratedCodeInfo_Annotation* sub = (struct google_protobuf_GeneratedCodeInfo_Annotation*)_upb_msg_new(&google_protobuf_GeneratedCodeInfo_Annotation_msginit, arena);
bool ok = _upb_array_append_accessor(
msg, UPB_SIZE(0, 0), UPB_SIZE(4, 8), UPB_TYPE_MESSAGE, &sub, arena);
if (!ok) return NULL;
@@ -2863,7 +3156,7 @@
/* google.protobuf.GeneratedCodeInfo.Annotation */
UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation *google_protobuf_GeneratedCodeInfo_Annotation_new(upb_arena *arena) {
- return (google_protobuf_GeneratedCodeInfo_Annotation *)upb_msg_new(&google_protobuf_GeneratedCodeInfo_Annotation_msginit, arena);
+ return (google_protobuf_GeneratedCodeInfo_Annotation *)_upb_msg_new(&google_protobuf_GeneratedCodeInfo_Annotation_msginit, arena);
}
UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation *google_protobuf_GeneratedCodeInfo_Annotation_parse(const char *buf, size_t size,
upb_arena *arena) {
@@ -2876,33 +3169,33 @@
UPB_INLINE int32_t const* google_protobuf_GeneratedCodeInfo_Annotation_path(const google_protobuf_GeneratedCodeInfo_Annotation *msg, size_t *len) { return (int32_t const*)_upb_array_accessor(msg, UPB_SIZE(20, 32), len); }
UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_source_file(const google_protobuf_GeneratedCodeInfo_Annotation *msg) { return _upb_has_field(msg, 3); }
-UPB_INLINE upb_strview google_protobuf_GeneratedCodeInfo_Annotation_source_file(const google_protobuf_GeneratedCodeInfo_Annotation *msg) { return UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(12, 16)); }
+UPB_INLINE upb_strview google_protobuf_GeneratedCodeInfo_Annotation_source_file(const google_protobuf_GeneratedCodeInfo_Annotation *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(12, 16), upb_strview); }
UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_begin(const google_protobuf_GeneratedCodeInfo_Annotation *msg) { return _upb_has_field(msg, 1); }
-UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_begin(const google_protobuf_GeneratedCodeInfo_Annotation *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(4, 4)); }
+UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_begin(const google_protobuf_GeneratedCodeInfo_Annotation *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(4, 4), int32_t); }
UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_has_end(const google_protobuf_GeneratedCodeInfo_Annotation *msg) { return _upb_has_field(msg, 2); }
-UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_end(const google_protobuf_GeneratedCodeInfo_Annotation *msg) { return UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)); }
+UPB_INLINE int32_t google_protobuf_GeneratedCodeInfo_Annotation_end(const google_protobuf_GeneratedCodeInfo_Annotation *msg) { return *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t); }
UPB_INLINE int32_t* google_protobuf_GeneratedCodeInfo_Annotation_mutable_path(google_protobuf_GeneratedCodeInfo_Annotation *msg, size_t *len) {
return (int32_t*)_upb_array_mutable_accessor(msg, UPB_SIZE(20, 32), len);
}
UPB_INLINE int32_t* google_protobuf_GeneratedCodeInfo_Annotation_resize_path(google_protobuf_GeneratedCodeInfo_Annotation *msg, size_t len, upb_arena *arena) {
- return (int32_t*)_upb_array_resize_accessor(msg, UPB_SIZE(20, 32), len, UPB_SIZE(4, 4), UPB_TYPE_INT32, arena);
+ return (int32_t*)_upb_array_resize_accessor(msg, UPB_SIZE(20, 32), len, UPB_TYPE_INT32, arena);
}
UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_add_path(google_protobuf_GeneratedCodeInfo_Annotation *msg, int32_t val, upb_arena *arena) {
- return _upb_array_append_accessor(
- msg, UPB_SIZE(20, 32), UPB_SIZE(4, 4), UPB_TYPE_INT32, &val, arena);
+ return _upb_array_append_accessor(msg, UPB_SIZE(20, 32), UPB_SIZE(4, 4), UPB_TYPE_INT32, &val,
+ arena);
}
UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_source_file(google_protobuf_GeneratedCodeInfo_Annotation *msg, upb_strview value) {
_upb_sethas(msg, 3);
- UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(12, 16)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(12, 16), upb_strview) = value;
}
UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_begin(google_protobuf_GeneratedCodeInfo_Annotation *msg, int32_t value) {
_upb_sethas(msg, 1);
- UPB_FIELD_AT(msg, int32_t, UPB_SIZE(4, 4)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(4, 4), int32_t) = value;
}
UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_end(google_protobuf_GeneratedCodeInfo_Annotation *msg, int32_t value) {
_upb_sethas(msg, 2);
- UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)) = value;
+ *UPB_PTR_AT(msg, UPB_SIZE(8, 8), int32_t) = value;
}
#ifdef __cplusplus
@@ -3008,10 +3301,10 @@
upb_label_t upb_fielddef_label(const upb_fielddef *f);
uint32_t upb_fielddef_number(const upb_fielddef *f);
const char *upb_fielddef_name(const upb_fielddef *f);
+const char *upb_fielddef_jsonname(const upb_fielddef *f);
bool upb_fielddef_isextension(const upb_fielddef *f);
bool upb_fielddef_lazy(const upb_fielddef *f);
bool upb_fielddef_packed(const upb_fielddef *f);
-size_t upb_fielddef_getjsonname(const upb_fielddef *f, char *buf, size_t len);
const upb_msgdef *upb_fielddef_containingtype(const upb_fielddef *f);
const upb_oneofdef *upb_fielddef_containingoneof(const upb_fielddef *f);
uint32_t upb_fielddef_index(const upb_fielddef *f);
@@ -3032,6 +3325,7 @@
bool upb_fielddef_haspresence(const upb_fielddef *f);
const upb_msgdef *upb_fielddef_msgsubdef(const upb_fielddef *f);
const upb_enumdef *upb_fielddef_enumsubdef(const upb_fielddef *f);
+const upb_msglayout_field *upb_fielddef_layout(const upb_fielddef *f);
/* Internal only. */
uint32_t upb_fielddef_selectorbase(const upb_fielddef *f);
@@ -3059,32 +3353,10 @@
Type type() const { return upb_fielddef_type(ptr_); }
Label label() const { return upb_fielddef_label(ptr_); }
const char* name() const { return upb_fielddef_name(ptr_); }
+ const char* json_name() const { return upb_fielddef_jsonname(ptr_); }
uint32_t number() const { return upb_fielddef_number(ptr_); }
bool is_extension() const { return upb_fielddef_isextension(ptr_); }
- /* Copies the JSON name for this field into the given buffer. Returns the
- * actual size of the JSON name, including the NULL terminator. If the
- * return value is 0, the JSON name is unset. If the return value is
- * greater than len, the JSON name was truncated. The buffer is always
- * NULL-terminated if len > 0.
- *
- * The JSON name always defaults to a camelCased version of the regular
- * name. However if the regular name is unset, the JSON name will be unset
- * also.
- */
- size_t GetJsonName(char *buf, size_t len) const {
- return upb_fielddef_getjsonname(ptr_, buf, len);
- }
-
- /* Convenience version of the above function which copies the JSON name
- * into the given string, returning false if the name is not set. */
- template <class T>
- bool GetJsonName(T* str) {
- str->resize(GetJsonName(NULL, 0));
- GetJsonName(&(*str)[0], str->size());
- return str->size() > 0;
- }
-
/* For UPB_TYPE_MESSAGE fields only where is_tag_delimited() == false,
* indicates whether this field should have lazy parsing handlers that yield
* the unparsed string for the submessage.
@@ -3181,6 +3453,7 @@
const upb_msgdef *upb_oneofdef_containingtype(const upb_oneofdef *o);
int upb_oneofdef_numfields(const upb_oneofdef *o);
uint32_t upb_oneofdef_index(const upb_oneofdef *o);
+bool upb_oneofdef_synthetic(const upb_oneofdef *o);
/* Oneof lookups:
* - ntof: look up a field by name.
@@ -3334,6 +3607,8 @@
size_t len);
int upb_msgdef_numfields(const upb_msgdef *m);
int upb_msgdef_numoneofs(const upb_msgdef *m);
+const upb_msglayout *upb_msgdef_layout(const upb_msgdef *m);
+const upb_fielddef *_upb_msgdef_field(const upb_msgdef *m, int i);
UPB_INLINE const upb_oneofdef *upb_msgdef_ntooz(const upb_msgdef *m,
const char *name) {
@@ -3361,6 +3636,10 @@
return upb_msgdef_lookupname(m, name, strlen(name), f, o);
}
+/* Returns a field by either JSON name or regular proto name. */
+const upb_fielddef *upb_msgdef_lookupjsonname(const upb_msgdef *m,
+ const char *name, size_t len);
+
/* Iteration over fields and oneofs. For example:
*
* upb_msg_field_iter i;
@@ -3760,9 +4039,10 @@
/* For generated code only: loads a generated descriptor. */
typedef struct upb_def_init {
- struct upb_def_init **deps;
+ struct upb_def_init **deps; /* Dependencies of this file. */
+ const upb_msglayout **layouts; /* Pre-order layouts of all messages. */
const char *filename;
- upb_strview descriptor;
+ upb_strview descriptor; /* Serialized descriptor. */
} upb_def_init;
bool _upb_symtab_loaddefinit(upb_symtab *s, const upb_def_init *init);
@@ -3816,51 +4096,156 @@
#endif /* UPB_DEF_H_ */
+#ifndef UPB_REFLECTION_H_
+#define UPB_REFLECTION_H_
-#ifndef UPB_MSGFACTORY_H_
-#define UPB_MSGFACTORY_H_
-/** upb_msgfactory ************************************************************/
-struct upb_msgfactory;
-typedef struct upb_msgfactory upb_msgfactory;
+typedef union {
+ bool bool_val;
+ float float_val;
+ double double_val;
+ int32_t int32_val;
+ int64_t int64_val;
+ uint32_t uint32_val;
+ uint64_t uint64_val;
+ const upb_map* map_val;
+ const upb_msg* msg_val;
+ const upb_array* array_val;
+ upb_strview str_val;
+} upb_msgval;
-#ifdef __cplusplus
-extern "C" {
-#endif
+typedef union {
+ upb_map* map;
+ upb_msg* msg;
+ upb_array* array;
+} upb_mutmsgval;
-/* A upb_msgfactory contains a cache of upb_msglayout, upb_handlers, and
- * upb_visitorplan objects. These are the objects necessary to represent,
- * populate, and and visit upb_msg objects.
+/** upb_msg *******************************************************************/
+
+/* Creates a new message of the given type in the given arena. */
+upb_msg *upb_msg_new(const upb_msgdef *m, upb_arena *a);
+
+/* Returns the value associated with this field. */
+upb_msgval upb_msg_get(const upb_msg *msg, const upb_fielddef *f);
+
+/* Returns a mutable pointer to a map, array, or submessage value. If the given
+ * arena is non-NULL this will construct a new object if it was not previously
+ * present. May not be called for primitive fields. */
+upb_mutmsgval upb_msg_mutable(upb_msg *msg, const upb_fielddef *f, upb_arena *a);
+
+/* May only be called for fields where upb_fielddef_haspresence(f) == true. */
+bool upb_msg_has(const upb_msg *msg, const upb_fielddef *f);
+
+/* Returns whether any field is set in the oneof. */
+bool upb_msg_hasoneof(const upb_msg *msg, const upb_oneofdef *o);
+
+/* Sets the given field to the given value. For a msg/array/map/string, the
+ * value must be in the same arena. */
+void upb_msg_set(upb_msg *msg, const upb_fielddef *f, upb_msgval val,
+ upb_arena *a);
+
+/* Clears any field presence and sets the value back to its default. */
+void upb_msg_clearfield(upb_msg *msg, const upb_fielddef *f);
+
+/* Iterate over present fields.
*
- * These caches are all populated by upb_msgdef, and lazily created on demand.
+ * size_t iter = UPB_MSG_BEGIN;
+ * const upb_fielddef *f;
+ * upb_msgval val;
+ * while (upb_msg_next(msg, m, ext_pool, &f, &val, &iter)) {
+ * process_field(f, val);
+ * }
+ *
+ * If ext_pool is NULL, no extensions will be returned. If the given symtab
+ * returns extensions that don't match what is in this message, those extensions
+ * will be skipped.
*/
-/* Creates and destroys a msgfactory, respectively. The messages for this
- * msgfactory must come from |symtab| (which should outlive the msgfactory). */
-upb_msgfactory *upb_msgfactory_new(const upb_symtab *symtab);
-void upb_msgfactory_free(upb_msgfactory *f);
+#define UPB_MSG_BEGIN -1
+bool upb_msg_next(const upb_msg *msg, const upb_msgdef *m,
+ const upb_symtab *ext_pool, const upb_fielddef **f,
+ upb_msgval *val, size_t *iter);
-const upb_symtab *upb_msgfactory_symtab(const upb_msgfactory *f);
+/* Adds unknown data (serialized protobuf data) to the given message. The data
+ * is copied into the message instance. */
+void upb_msg_addunknown(upb_msg *msg, const char *data, size_t len,
+ upb_arena *arena);
-/* The functions to get cached objects, lazily creating them on demand. These
- * all require:
+/* Returns a reference to the message's unknown data. */
+const char *upb_msg_getunknown(const upb_msg *msg, size_t *len);
+
+/** upb_array *****************************************************************/
+
+/* Creates a new array on the given arena that holds elements of this type. */
+upb_array *upb_array_new(upb_arena *a, upb_fieldtype_t type);
+
+/* Returns the size of the array. */
+size_t upb_array_size(const upb_array *arr);
+
+/* Returns the given element, which must be within the array's current size. */
+upb_msgval upb_array_get(const upb_array *arr, size_t i);
+
+/* Sets the given element, which must be within the array's current size. */
+void upb_array_set(upb_array *arr, size_t i, upb_msgval val);
+
+/* Appends an element to the array. Returns false on allocation failure. */
+bool upb_array_append(upb_array *array, upb_msgval val, upb_arena *arena);
+
+/* Changes the size of a vector. New elements are initialized to empty/0.
+ * Returns false on allocation failure. */
+bool upb_array_resize(upb_array *array, size_t size, upb_arena *arena);
+
+/** upb_map *******************************************************************/
+
+/* Creates a new map on the given arena with the given key/value size. */
+upb_map *upb_map_new(upb_arena *a, upb_fieldtype_t key_type,
+ upb_fieldtype_t value_type);
+
+/* Returns the number of entries in the map. */
+size_t upb_map_size(const upb_map *map);
+
+/* Stores a value for the given key into |*val| (or the zero value if the key is
+ * not present). Returns whether the key was present. The |val| pointer may be
+ * NULL, in which case the function tests whether the given key is present. */
+bool upb_map_get(const upb_map *map, upb_msgval key, upb_msgval *val);
+
+/* Removes all entries in the map. */
+void upb_map_clear(upb_map *map);
+
+/* Sets the given key to the given value. Returns true if this was a new key in
+ * the map, or false if an existing key was replaced. */
+bool upb_map_set(upb_map *map, upb_msgval key, upb_msgval val,
+ upb_arena *arena);
+
+/* Deletes this key from the table. Returns true if the key was present. */
+bool upb_map_delete(upb_map *map, upb_msgval key);
+
+/* Map iteration:
*
- * - m is in upb_msgfactory_symtab(f)
- * - upb_msgdef_mapentry(m) == false (since map messages can't have layouts).
+ * size_t iter = UPB_MAP_BEGIN;
+ * while (upb_mapiter_next(map, &iter)) {
+ * upb_msgval key = upb_mapiter_key(map, iter);
+ * upb_msgval val = upb_mapiter_value(map, iter);
*
- * The returned objects will live for as long as the msgfactory does.
- *
- * TODO(haberman): consider making this thread-safe and take a const
- * upb_msgfactory. */
-const upb_msglayout *upb_msgfactory_getlayout(upb_msgfactory *f,
- const upb_msgdef *m);
+ * // If mutating is desired.
+ * upb_mapiter_setvalue(map, iter, value2);
+ * }
+ */
-#ifdef __cplusplus
-} /* extern "C" */
-#endif
+/* Advances to the next entry. Returns false if no more entries are present. */
+bool upb_mapiter_next(const upb_map *map, size_t *iter);
-#endif /* UPB_MSGFACTORY_H_ */
+/* Returns the key and value for this entry of the map. */
+upb_msgval upb_mapiter_key(const upb_map *map, size_t iter);
+upb_msgval upb_mapiter_value(const upb_map *map, size_t iter);
+
+/* Sets the value for this entry. The iterator must not be done, and the
+ * iterator must not have been initialized const. */
+void upb_mapiter_setvalue(upb_map *map, size_t iter, upb_msgval value);
+
+
+#endif /* UPB_REFLECTION_H_ */
/*
** upb::Handlers (upb_handlers)
**
@@ -5693,15 +6078,16 @@
return sub->closure ? true : false;
}
-UPB_INLINE bool upb_sink_endsubmsg(upb_sink s, upb_selector_t sel) {
+UPB_INLINE bool upb_sink_endsubmsg(upb_sink s, upb_sink sub,
+ upb_selector_t sel) {
typedef upb_endfield_handlerfunc func;
func *endsubmsg;
const void *hd;
if (!s.handlers) return true;
endsubmsg = (func*)upb_handlers_gethandler(s.handlers, sel, &hd);
- if (!endsubmsg) return s.closure;
- return endsubmsg(s.closure, hd);
+ if (!endsubmsg) return true;
+ return endsubmsg(sub.closure, hd);
}
#ifdef __cplusplus
@@ -5867,8 +6253,8 @@
return ret;
}
- bool EndSubMessage(HandlersPtr::Selector s) {
- return upb_sink_endsubmsg(sink_, s);
+ bool EndSubMessage(HandlersPtr::Selector s, Sink sub) {
+ return upb_sink_endsubmsg(sink_, sub.sink_, s);
}
/* For repeated fields of any type, the sequence of values must be wrapped in
@@ -6368,7 +6754,7 @@
typedef struct {
/* Space optimization note: we store two pointers here that the JIT
* doesn't need at all; the upb_handlers* inside the sink and
- * the dispatch table pointer. We can optimize so that the JIT uses
+ * the dispatch table pointer. We can optimze so that the JIT uses
* smaller stack frames than the interpreter. The only thing we need
* to guarantee is that the fallback routines can find end_ofs. */
upb_sink sink;
@@ -6445,7 +6831,7 @@
char residual[UPB_DECODER_MAX_RESIDUAL_BYTES];
char *residual_end;
- /* Bytes of data that should be discarded from the input before we start
+ /* Bytes of data that should be discarded from the input beore we start
* parsing again. We set this when we internally determine that we can
* safely skip the next N bytes, but this region extends past the current
* user buffer. */
@@ -6567,21 +6953,22 @@
* descriptor type (upb_descriptortype_t). */
extern const uint8_t upb_pb_native_wire_types[];
-UPB_INLINE uint64_t byteswap64(uint64_t val)
-{
- return ((((val) & 0xff00000000000000ull) >> 56)
- | (((val) & 0x00ff000000000000ull) >> 40)
- | (((val) & 0x0000ff0000000000ull) >> 24)
- | (((val) & 0x000000ff00000000ull) >> 8)
- | (((val) & 0x00000000ff000000ull) << 8)
- | (((val) & 0x0000000000ff0000ull) << 24)
- | (((val) & 0x000000000000ff00ull) << 40)
- | (((val) & 0x00000000000000ffull) << 56));
+UPB_INLINE uint64_t byteswap64(uint64_t val) {
+ uint64_t byte = 0xff;
+ return (val & (byte << 56) >> 56)
+ | (val & (byte << 48) >> 40)
+ | (val & (byte << 40) >> 24)
+ | (val & (byte << 32) >> 8)
+ | (val & (byte << 24) << 8)
+ | (val & (byte << 16) << 24)
+ | (val & (byte << 8) << 40)
+ | (val & (byte << 0) << 56);
}
/* Zig-zag encoding/decoding **************************************************/
-UPB_INLINE int32_t upb_zzdec_32(uint32_t n) {
+UPB_INLINE int32_t upb_zzdec_32(uint64_t _n) {
+ uint32_t n = (uint32_t)_n;
return (n >> 1) ^ -(int32_t)(n & 1);
}
UPB_INLINE int64_t upb_zzdec_64(uint64_t n) {
@@ -7064,8 +7451,9 @@
#endif /* UPB_JSON_TYPED_PRINTER_H_ */
/* See port_def.inc. This should #undef all macros #defined there. */
+#undef UPB_MAPTYPE_STRING
#undef UPB_SIZE
-#undef UPB_FIELD_AT
+#undef UPB_PTR_AT
#undef UPB_READ_ONEOF
#undef UPB_WRITE_ONEOF
#undef UPB_INLINE
@@ -7075,6 +7463,7 @@
#undef UPB_MAX
#undef UPB_MIN
#undef UPB_UNUSED
+#undef UPB_ASSUME
#undef UPB_ASSERT
#undef UPB_ASSERT_DEBUGVAR
#undef UPB_UNREACHABLE
diff --git a/ruby/tests/common_tests.rb b/ruby/tests/common_tests.rb
index 7414aea..6778146 100644
--- a/ruby/tests/common_tests.rb
+++ b/ruby/tests/common_tests.rb
@@ -1723,7 +1723,7 @@
m.duration = Rational(3, 2)
assert_equal Google::Protobuf::Duration.new(seconds: 1, nanos: 500_000_000), m.duration
- m.duration = BigDecimal.new("5")
+ m.duration = BigDecimal("5")
assert_equal Google::Protobuf::Duration.new(seconds: 5, nanos: 0), m.duration
m = proto_module::TimeMessage.new(duration: 1.1)
diff --git a/src/google/protobuf/compiler/cpp/cpp_field.cc b/src/google/protobuf/compiler/cpp/cpp_field.cc
index 6a73ab8..f95e14e 100644
--- a/src/google/protobuf/compiler/cpp/cpp_field.cc
+++ b/src/google/protobuf/compiler/cpp/cpp_field.cc
@@ -156,7 +156,7 @@
default:
return new RepeatedPrimitiveFieldGenerator(field, options);
}
- } else if (InRealOneof(field)) {
+ } else if (field->real_containing_oneof()) {
switch (field->cpp_type()) {
case FieldDescriptor::CPPTYPE_MESSAGE:
return new MessageOneofFieldGenerator(field, options, scc_analyzer);
diff --git a/src/google/protobuf/compiler/cpp/cpp_helpers.cc b/src/google/protobuf/compiler/cpp/cpp_helpers.cc
index 7aeffb0..976823a 100644
--- a/src/google/protobuf/compiler/cpp/cpp_helpers.cc
+++ b/src/google/protobuf/compiler/cpp/cpp_helpers.cc
@@ -1151,7 +1151,7 @@
return UsingImplicitWeakFields(field->file(), options) &&
field->type() == FieldDescriptor::TYPE_MESSAGE &&
!field->is_required() && !field->is_map() && !field->is_extension() &&
- !InRealOneof(field) &&
+ !field->real_containing_oneof() &&
!IsWellKnownMessage(field->message_type()->file()) &&
field->message_type()->file()->name() !=
"net/proto2/proto/descriptor.proto" &&
@@ -1474,7 +1474,7 @@
GetOptimizeFor(field->file(), options_) != FileOptions::LITE_RUNTIME &&
// For now only use arena string for strings with empty defaults.
field->default_value_string().empty() &&
- !IsStringInlined(field, options_) && !InRealOneof(field) &&
+ !IsStringInlined(field, options_) && !field->real_containing_oneof() &&
ctype == FieldOptions::STRING) {
GenerateArenaString(field);
} else {
@@ -1580,7 +1580,7 @@
FieldName(field));
}
} else if (IsLazy(field, options_)) {
- if (InRealOneof(field)) {
+ if (field->real_containing_oneof()) {
format_(
"if (!_internal_has_$1$()) {\n"
" clear_$2$();\n"
@@ -1684,7 +1684,7 @@
field->type() == FieldDescriptor::TYPE_SINT64)) {
zigzag = "ZigZag";
}
- if (field->is_repeated() || InRealOneof(field)) {
+ if (field->is_repeated() || field->real_containing_oneof()) {
std::string prefix = field->is_repeated() ? "add" : "set";
format_(
"_internal_$1$_$2$($pi_ns$::ReadVarint$3$$4$(&ptr));\n"
@@ -1706,7 +1706,7 @@
case WireFormatLite::WIRETYPE_FIXED32:
case WireFormatLite::WIRETYPE_FIXED64: {
std::string type = PrimitiveTypeName(options_, field->cpp_type());
- if (field->is_repeated() || InRealOneof(field)) {
+ if (field->is_repeated() || field->real_containing_oneof()) {
std::string prefix = field->is_repeated() ? "add" : "set";
format_(
"_internal_$1$_$2$($pi_ns$::UnalignedLoad<$3$>(ptr));\n"
diff --git a/src/google/protobuf/compiler/cpp/cpp_helpers.h b/src/google/protobuf/compiler/cpp/cpp_helpers.h
index ec57cb4..988e609 100644
--- a/src/google/protobuf/compiler/cpp/cpp_helpers.h
+++ b/src/google/protobuf/compiler/cpp/cpp_helpers.h
@@ -444,23 +444,6 @@
!field->options().weak();
}
-inline bool InRealOneof(const FieldDescriptor* field) {
- return field->containing_oneof() &&
- !field->containing_oneof()->is_synthetic();
-}
-
-// In practice all synthetic oneofs should be at the end of the list, but we
-// decline to depend on this for correctness of the function.
-inline int RealOneofCount(const Descriptor* descriptor) {
- int count = 0;
- for (int i = 0; i < descriptor->oneof_decl_count(); i++) {
- if (!descriptor->oneof_decl(i)->is_synthetic()) {
- count++;
- }
- }
- return count;
-}
-
// Returns true if 'enum' semantics are such that unknown values are preserved
// in the enum field itself, rather than going to the UnknownFieldSet.
inline bool HasPreservingUnknownEnumSemantics(const FieldDescriptor* field) {
@@ -886,14 +869,6 @@
using value_type = const OneofDescriptor*;
using difference_type = int;
- explicit Iterator(const Descriptor* _descriptor)
- : idx(-1), descriptor(_descriptor) {
- Next();
- }
-
- Iterator(int _idx, const Descriptor* _descriptor)
- : idx(_idx), descriptor(_descriptor) {}
-
value_type operator*() { return descriptor->oneof_decl(idx); }
friend bool operator==(const Iterator& a, const Iterator& b) {
@@ -905,23 +880,18 @@
}
Iterator& operator++() {
- Next();
+ idx++;
return *this;
}
- void Next() {
- do {
- idx++;
- } while (idx < descriptor->oneof_decl_count() &&
- descriptor->oneof_decl(idx)->is_synthetic());
- }
-
int idx;
const Descriptor* descriptor;
};
- Iterator begin() const { return Iterator(descriptor); }
- Iterator end() const { return {descriptor->oneof_decl_count(), descriptor}; }
+ Iterator begin() const { return {0, descriptor}; }
+ Iterator end() const {
+ return {descriptor->real_oneof_decl_count(), descriptor};
+ }
const Descriptor* descriptor;
};
diff --git a/src/google/protobuf/compiler/cpp/cpp_message.cc b/src/google/protobuf/compiler/cpp/cpp_message.cc
index 33be146..1cc0891 100644
--- a/src/google/protobuf/compiler/cpp/cpp_message.cc
+++ b/src/google/protobuf/compiler/cpp/cpp_message.cc
@@ -226,7 +226,7 @@
}
format.Indent();
return true;
- } else if (InRealOneof(field)) {
+ } else if (field->real_containing_oneof()) {
format("if (_internal_has_$name$()) {\n");
format.Indent();
return true;
@@ -282,7 +282,7 @@
bool HasPrivateHasMethod(const FieldDescriptor* field) {
// Only for oneofs in message types with no field presence. has_$name$(),
// based on the oneof case, is still useful internally for generated code.
- return (!HasFieldPresence(field->file()) && InRealOneof(field));
+ return (!HasFieldPresence(field->file()) && field->real_containing_oneof());
}
// TODO(ckennelly): Cull these exclusions if/when these protos do not have
@@ -597,7 +597,7 @@
if (IsWeak(field, options_)) {
num_weak_fields_++;
- } else if (!InRealOneof(field)) {
+ } else if (!field->real_containing_oneof()) {
optimized_order_.push_back(field);
}
}
@@ -677,7 +677,7 @@
void MessageGenerator::GenerateFieldAccessorDeclarations(io::Printer* printer) {
Formatter format(printer, variables_);
// optimized_fields_ does not contain fields where
- // InRealOneof(field) == true
+ // field->real_containing_oneof()
// so we need to iterate over those as well.
//
// We place the non-oneof fields in optimized_order_, as that controls the
@@ -689,7 +689,7 @@
ordered_fields.insert(ordered_fields.begin(), optimized_order_.begin(),
optimized_order_.end());
for (auto field : FieldRange(descriptor_)) {
- if (!InRealOneof(field) && !field->options().weak() &&
+ if (!field->real_containing_oneof() && !field->options().weak() &&
IsFieldUsed(field, options_)) {
continue;
}
@@ -922,7 +922,7 @@
format.Indent();
- if (InRealOneof(field)) {
+ if (field->real_containing_oneof()) {
// Clear this field only if it is the active field in this oneof,
// otherwise ignore
format("if (_internal_has_$name$()) {\n");
@@ -983,7 +983,7 @@
? ".weak"
: "");
}
- } else if (InRealOneof(field)) {
+ } else if (field->real_containing_oneof()) {
format.Set("field_name", UnderscoresToCamelCase(field->name(), true));
format.Set("oneof_name", field->containing_oneof()->name());
format.Set("oneof_index",
@@ -1485,7 +1485,7 @@
for (auto field : FieldRange(descriptor_)) {
// set_has_***() generated in all oneofs.
if (!field->is_repeated() && !field->options().weak() &&
- InRealOneof(field)) {
+ field->real_containing_oneof()) {
format("void set_has_$1$();\n", FieldName(field));
}
}
@@ -1594,12 +1594,11 @@
}
// Generate _oneof_case_.
- int count = RealOneofCount(descriptor_);
- if (count > 0) {
+ if (descriptor_->real_oneof_decl_count() > 0) {
format(
"$uint32$ _oneof_case_[$1$];\n"
"\n",
- count);
+ descriptor_->real_oneof_decl_count());
}
if (num_weak_fields_) {
@@ -1695,7 +1694,7 @@
format("PROTOBUF_FIELD_OFFSET($classtype$, _has_bits_),\n");
}
- if (RealOneofCount(descriptor_) > 0) {
+ if (descriptor_->real_oneof_decl_count() > 0) {
format("PROTOBUF_FIELD_OFFSET($classtype$, _oneof_case_),\n");
} else {
format("-1, // no _oneof_case_\n");
@@ -1755,7 +1754,7 @@
}
}
- if (InRealOneof(field)) {
+ if (field->real_containing_oneof()) {
return internal::FieldMetadata::CalculateType(
type, internal::FieldMetadata::kOneOf);
} else if (field->is_packed()) {
@@ -1764,7 +1763,7 @@
} else if (field->is_repeated()) {
return internal::FieldMetadata::CalculateType(
type, internal::FieldMetadata::kRepeated);
- } else if (HasHasbit(field) || InRealOneof(field) || is_a_map) {
+ } else if (HasHasbit(field) || field->real_containing_oneof() || is_a_map) {
return internal::FieldMetadata::CalculateType(
type, internal::FieldMetadata::kPresence);
} else {
@@ -1859,7 +1858,7 @@
}
std::string classfieldname = FieldName(field);
- if (InRealOneof(field)) {
+ if (field->real_containing_oneof()) {
classfieldname = field->containing_oneof()->name();
}
format.Set("field_name", classfieldname);
@@ -1895,7 +1894,7 @@
type = internal::FieldMetadata::kSpecial;
ptr = "reinterpret_cast<const void*>(::" + variables_["proto_ns"] +
"::internal::LazyFieldSerializer";
- if (InRealOneof(field)) {
+ if (field->real_containing_oneof()) {
ptr += "OneOf";
} else if (!HasHasbit(field)) {
ptr += "NoPresence";
@@ -1912,7 +1911,7 @@
"reinterpret_cast<const "
"void*>(::$proto_ns$::internal::WeakFieldSerializer)},\n",
tag);
- } else if (InRealOneof(field)) {
+ } else if (field->real_containing_oneof()) {
format.Set("oneofoffset",
sizeof(uint32) * field->containing_oneof()->index());
format(
@@ -1972,10 +1971,10 @@
if (!field->is_repeated() && !IsLazy(field, options_) &&
field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE &&
- (!InRealOneof(field) ||
+ (!field->real_containing_oneof() ||
HasDescriptorMethods(descriptor_->file(), options_))) {
std::string name;
- if (InRealOneof(field) || field->options().weak()) {
+ if (field->real_containing_oneof() || field->options().weak()) {
name = "_" + classname_ + "_default_instance_.";
} else {
name =
@@ -2007,7 +2006,7 @@
" $1$::internal_default_instance());\n",
FieldMessageTypeName(field, options_));
}
- } else if (InRealOneof(field) &&
+ } else if (field->real_containing_oneof() &&
HasDescriptorMethods(descriptor_->file(), options_)) {
field_generators_.get(field).GenerateConstructorCode(printer);
}
@@ -2118,7 +2117,7 @@
Formatter::SaveState saver(&format);
std::map<std::string, std::string> vars;
SetCommonFieldVariables(field, &vars, options_);
- if (InRealOneof(field)) {
+ if (field->real_containing_oneof()) {
SetCommonOneofFieldVariables(field, &vars);
}
format.AddMap(vars);
@@ -2129,7 +2128,7 @@
GenerateStructors(printer);
format("\n");
- if (RealOneofCount(descriptor_) > 0) {
+ if (descriptor_->real_oneof_decl_count() > 0) {
GenerateOneofClear(printer);
format("\n");
}
@@ -2258,8 +2257,8 @@
processing_type |= static_cast<unsigned>(
field->is_repeated() ? internal::kRepeatedMask : 0);
- processing_type |=
- static_cast<unsigned>(InRealOneof(field) ? internal::kOneofMask : 0);
+ processing_type |= static_cast<unsigned>(
+ field->real_containing_oneof() ? internal::kOneofMask : 0);
if (field->is_map()) {
processing_type = internal::TYPE_MAP;
@@ -2269,7 +2268,7 @@
WireFormat::TagSize(field->number(), field->type());
std::map<std::string, std::string> vars;
- if (InRealOneof(field)) {
+ if (field->real_containing_oneof()) {
vars["name"] = field->containing_oneof()->name();
vars["presence"] = StrCat(field->containing_oneof()->index());
} else {
@@ -2400,7 +2399,7 @@
} else {
format("~0u, // no _extensions_\n");
}
- if (RealOneofCount(descriptor_) > 0) {
+ if (descriptor_->real_oneof_decl_count() > 0) {
format("PROTOBUF_FIELD_OFFSET($classtype$, _oneof_case_[0]),\n");
} else {
format("~0u, // no _oneof_case_\n");
@@ -2418,13 +2417,13 @@
}
const int kNumGenericOffsets = 5; // the number of fixed offsets above
const size_t offsets = kNumGenericOffsets + descriptor_->field_count() +
- RealOneofCount(descriptor_) - num_stripped;
+ descriptor_->real_oneof_decl_count() - num_stripped;
size_t entries = offsets;
for (auto field : FieldRange(descriptor_)) {
if (!IsFieldUsed(field, options_)) {
continue;
}
- if (InRealOneof(field) || field->options().weak()) {
+ if (field->real_containing_oneof() || field->options().weak()) {
format("offsetof($classtype$DefaultTypeInternal, $1$_)",
FieldName(field));
} else {
@@ -2444,7 +2443,7 @@
format("PROTOBUF_FIELD_OFFSET($classtype$, $1$_),\n", oneof->name());
count++;
}
- GOOGLE_CHECK_EQ(count, RealOneofCount(descriptor_));
+ GOOGLE_CHECK_EQ(count, descriptor_->real_oneof_decl_count());
if (IsMapEntryMessage(descriptor_)) {
entries += 2;
@@ -2656,7 +2655,7 @@
for (auto field : optimized_order_) {
GOOGLE_DCHECK(IsFieldUsed(field, options_));
bool has_arena_constructor = field->is_repeated();
- if (!InRealOneof(field) &&
+ if (!field->real_containing_oneof() &&
(IsLazy(field, options_) || IsStringPiece(field, options_))) {
has_arena_constructor = true;
}
@@ -3122,8 +3121,7 @@
format("swap($1$_, other->$1$_);\n", oneof->name());
}
- int count = RealOneofCount(descriptor_);
- for (int i = 0; i < count; i++) {
+ for (int i = 0; i < descriptor_->real_oneof_decl_count(); i++) {
format("swap(_oneof_case_[$1$], other->_oneof_case_[$1$]);\n", i);
}
@@ -3572,7 +3570,7 @@
if (eager_ || MustFlush(field)) {
Flush();
}
- if (!InRealOneof(field)) {
+ if (!field->real_containing_oneof()) {
// TODO(ckennelly): Defer non-oneof fields similarly to oneof fields.
if (!field->options().weak() && !field->is_repeated() && !eager_) {
@@ -4014,7 +4012,7 @@
} else if (field->options().weak()) {
continue;
} else {
- GOOGLE_CHECK(!InRealOneof(field));
+ GOOGLE_CHECK(!field->real_containing_oneof());
format(
"if (_internal_has_$1$()) {\n"
" if (!$1$_->IsInitialized()) return false;\n"
@@ -4054,7 +4052,7 @@
field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE &&
!ShouldIgnoreRequiredFieldCheck(field, options_) &&
scc_analyzer_->HasRequiredFields(field->message_type())) {
- GOOGLE_CHECK(!(field->options().weak() || !InRealOneof(field)));
+ GOOGLE_CHECK(!(field->options().weak() || !field->real_containing_oneof()));
if (field->options().weak()) {
// Just skip.
} else {
diff --git a/src/google/protobuf/compiler/cpp/cpp_string_field.cc b/src/google/protobuf/compiler/cpp/cpp_string_field.cc
index 43fe860..a21c4c7 100644
--- a/src/google/protobuf/compiler/cpp/cpp_string_field.cc
+++ b/src/google/protobuf/compiler/cpp/cpp_string_field.cc
@@ -501,7 +501,7 @@
void StringFieldGenerator::GenerateMergingCode(io::Printer* printer) const {
Formatter format(printer, variables_);
- if (SupportsArenas(descriptor_) || InRealOneof(descriptor_)) {
+ if (SupportsArenas(descriptor_) || descriptor_->real_containing_oneof()) {
// TODO(gpike): improve this
format("_internal_set_$name$(from._internal_$name$());\n");
} else {
@@ -545,7 +545,7 @@
format.Indent();
- if (SupportsArenas(descriptor_) || InRealOneof(descriptor_)) {
+ if (SupportsArenas(descriptor_) || descriptor_->real_containing_oneof()) {
// TODO(gpike): improve this
format(
"$name$_.Set$lite$($default_variable$, from._internal_$name$(),\n"
diff --git a/src/google/protobuf/compiler/parser.cc b/src/google/protobuf/compiler/parser.cc
index a0f5a2c..d92cd55 100644
--- a/src/google/protobuf/compiler/parser.cc
+++ b/src/google/protobuf/compiler/parser.cc
@@ -783,8 +783,7 @@
}
for (auto& field : *message->mutable_field()) {
- if (field.proto3_optional() &&
- field.type() != FieldDescriptorProto::TYPE_MESSAGE) {
+ if (field.proto3_optional()) {
std::string oneof_name = field.name();
// Prepend 'XXXXX_' until we are no longer conflicting.
diff --git a/src/google/protobuf/descriptor.cc b/src/google/protobuf/descriptor.cc
index b94e925..1ec38c1 100644
--- a/src/google/protobuf/descriptor.cc
+++ b/src/google/protobuf/descriptor.cc
@@ -5500,6 +5500,42 @@
message->field(i);
}
}
+
+ for (int i = 0; i < message->field_count(); i++) {
+ const FieldDescriptor* field = message->field(i);
+ if (field->proto3_optional_) {
+ if (!field->containing_oneof() ||
+ !field->containing_oneof()->is_synthetic()) {
+ AddError(message->full_name(), proto.field(i),
+ DescriptorPool::ErrorCollector::OTHER,
+ "Fields with proto3_optional set must be "
+ "a member of a one-field oneof");
+ }
+ }
+ }
+
+ // Synthetic oneofs must be last.
+ int first_synthetic = -1;
+ for (int i = 0; i < message->oneof_decl_count(); i++) {
+ const OneofDescriptor* oneof = message->oneof_decl(i);
+ if (oneof->is_synthetic()) {
+ if (first_synthetic == -1) {
+ first_synthetic = i;
+ }
+ } else {
+ if (first_synthetic != -1) {
+ AddError(message->full_name(), proto.oneof_decl(i),
+ DescriptorPool::ErrorCollector::OTHER,
+ "Synthetic oneofs must be after all other oneofs");
+ }
+ }
+ }
+
+ if (first_synthetic == -1) {
+ message->real_oneof_decl_count_ = message->oneof_decl_count_;
+ } else {
+ message->real_oneof_decl_count_ = first_synthetic;
+ }
}
void DescriptorBuilder::CrossLinkExtensionRange(
diff --git a/src/google/protobuf/descriptor.h b/src/google/protobuf/descriptor.h
index e84bc3e..322d5a4 100644
--- a/src/google/protobuf/descriptor.h
+++ b/src/google/protobuf/descriptor.h
@@ -337,6 +337,10 @@
// The number of oneofs in this message type.
int oneof_decl_count() const;
+ // The number of oneofs in this message type, excluding synthetic oneofs.
+ // Real oneofs always come first, so iterating up to real_oneof_decl_cout()
+ // will yield all real oneofs.
+ int real_oneof_decl_count() const;
// Get a oneof by index, where 0 <= index < oneof_decl_count().
// These are returned in the order they were defined in the .proto file.
const OneofDescriptor* oneof_decl(int index) const;
@@ -526,6 +530,7 @@
int field_count_;
int oneof_decl_count_;
+ int real_oneof_decl_count_;
int nested_type_count_;
int enum_type_count_;
int extension_range_count_;
@@ -745,6 +750,10 @@
// nullptr.
const OneofDescriptor* containing_oneof() const;
+ // If the field is a member of a non-synthetic oneof, returns the descriptor
+ // for the oneof, otherwise returns nullptr.
+ const OneofDescriptor* real_containing_oneof() const;
+
// If the field is a member of a oneof, returns the index in that oneof.
int index_in_oneof() const;
@@ -1972,6 +1981,7 @@
PROTOBUF_DEFINE_ACCESSOR(Descriptor, field_count, int)
PROTOBUF_DEFINE_ACCESSOR(Descriptor, oneof_decl_count, int)
+PROTOBUF_DEFINE_ACCESSOR(Descriptor, real_oneof_decl_count, int)
PROTOBUF_DEFINE_ACCESSOR(Descriptor, nested_type_count, int)
PROTOBUF_DEFINE_ACCESSOR(Descriptor, enum_type_count, int)
@@ -2166,9 +2176,15 @@
!containing_oneof());
}
+inline const OneofDescriptor* FieldDescriptor::real_containing_oneof() const {
+ return containing_oneof_ && !containing_oneof_->is_synthetic()
+ ? containing_oneof_
+ : nullptr;
+}
+
inline bool FieldDescriptor::is_singular_with_presence() const {
if (is_repeated()) return false;
- if (containing_oneof() && !containing_oneof()->is_synthetic()) return false;
+ if (real_containing_oneof()) return false;
return cpp_type() == CPPTYPE_MESSAGE || proto3_optional_ ||
file()->syntax() == FileDescriptor::SYNTAX_PROTO2;
}
diff --git a/src/google/protobuf/descriptor.proto b/src/google/protobuf/descriptor.proto
index deb8f68..d29fdec 100644
--- a/src/google/protobuf/descriptor.proto
+++ b/src/google/protobuf/descriptor.proto
@@ -217,10 +217,21 @@
// If true, this is a proto3 "optional". When a proto3 field is optional, it
// tracks presence regardless of field type.
//
- // For message fields this doesn't create any semantic change, since
- // non-repeated message fields always track presence. However it still
+ // When proto3_optional is true, this field must be belong to a oneof to
+ // signal to old proto3 clients that presence is tracked for this field. This
+ // oneof is known as a "synthetic" oneof, and this field must be its sole
+ // member (each proto3 optional field gets its own synthetic oneof). Synthetic
+ // oneofs exist in the descriptor only, and do not generate any API. Synthetic
+ // oneofs must be ordered after all "real" oneofs.
+ //
+ // For message fields, proto3_optional doesn't create any semantic change,
+ // since non-repeated message fields always track presence. However it still
// indicates the semantic detail of whether the user wrote "optional" or not.
- // This can be useful for round-tripping the .proto file.
+ // This can be useful for round-tripping the .proto file. For consistency we
+ // give message fields a synthetic oneof also, even though it is not required
+ // to track presence. This is especially important because the parser can't
+ // tell if a field is a message or an enum, so it must always create a
+ // synthetic oneof.
//
// Proto2 optional fields do not set this flag, because they already indicate
// optional with `LABEL_OPTIONAL`.
diff --git a/src/google/protobuf/generated_message_table_driven_lite.h b/src/google/protobuf/generated_message_table_driven_lite.h
index 80f2158..ae13b36 100644
--- a/src/google/protobuf/generated_message_table_driven_lite.h
+++ b/src/google/protobuf/generated_message_table_driven_lite.h
@@ -280,9 +280,13 @@
}
utf8_string_data = field->Get();
} break;
+ default:
+ PROTOBUF_ASSUME(false);
}
break;
}
+ default:
+ PROTOBUF_ASSUME(false);
}
if (kValidateUtf8) {
@@ -322,6 +326,8 @@
SetOneofField(msg, presence, presence_index, offset, field_number,
value);
break;
+ default:
+ PROTOBUF_ASSUME(false);
}
} else {
UnknownFieldHandler::Varint(msg, table, tag, value);
@@ -406,9 +412,6 @@
const unsigned char processing_type = data->processing_type;
if (data->normal_wiretype == static_cast<unsigned char>(wire_type)) {
- // TODO(ckennelly): Use a computed goto on GCC/LLVM or otherwise eliminate
- // the bounds check on processing_type.
-
switch (processing_type) {
#define HANDLE_TYPE(TYPE, CPPTYPE) \
case (WireFormatLite::TYPE_##TYPE): { \
@@ -739,7 +742,7 @@
return true;
}
default:
- break;
+ PROTOBUF_ASSUME(false);
}
} else if (data->packed_wiretype == static_cast<unsigned char>(wire_type)) {
// Non-packable fields have their packed_wiretype masked with
@@ -751,8 +754,6 @@
GOOGLE_DCHECK_NE(TYPE_BYTES_INLINED | kRepeatedMask, processing_type);
GOOGLE_DCHECK_NE(TYPE_STRING_INLINED | kRepeatedMask, processing_type);
- // TODO(ckennelly): Use a computed goto on GCC/LLVM.
- //
// Mask out kRepeatedMask bit, allowing the jump table to be smaller.
switch (static_cast<WireFormatLite::FieldType>(processing_type ^
kRepeatedMask)) {
@@ -825,7 +826,7 @@
GOOGLE_DCHECK(false);
return false;
default:
- break;
+ PROTOBUF_ASSUME(false);
}
} else {
if (wire_type == WireFormatLite::WIRETYPE_END_GROUP) {