Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CodedInputReader and CodedOutputWriter #5888

Closed
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -208,3 +208,6 @@ cmake/cmake-build-debug/
# IntelliJ
.idea
*.iml

# Visual Studio test coverage
*.coverage
15 changes: 14 additions & 1 deletion Makefile.am
Expand Up @@ -87,6 +87,7 @@ csharp_EXTRA_DIST= \
csharp/src/AddressBook/SampleUsage.cs \
csharp/src/Google.Protobuf.Benchmarks/BenchmarkMessage1Proto3.cs \
csharp/src/Google.Protobuf.Benchmarks/Benchmarks.cs \
csharp/src/Google.Protobuf.Benchmarks/GoogleMessageBenchmark.cs \
csharp/src/Google.Protobuf.Benchmarks/Google.Protobuf.Benchmarks.csproj \
csharp/src/Google.Protobuf.Benchmarks/Program.cs \
csharp/src/Google.Protobuf.Benchmarks/SerializationBenchmark.cs \
Expand All @@ -100,9 +101,16 @@ csharp_EXTRA_DIST= \
csharp/src/Google.Protobuf.JsonDump/Google.Protobuf.JsonDump.csproj \
csharp/src/Google.Protobuf.JsonDump/Program.cs \
csharp/src/Google.Protobuf.Test/ByteStringTest.cs \
csharp/src/Google.Protobuf.Test/CodedInputStreamExtensions.cs \
csharp/src/Google.Protobuf.Test/CodedInputExtensions.cs \
csharp/src/Google.Protobuf.Test/CodedInputReaderTest.cs \
csharp/src/Google.Protobuf.Test/CodedInputStreamTest.cs \
csharp/src/Google.Protobuf.Test/CodedInputTestBase.cs \
csharp/src/Google.Protobuf.Test/CodedOutputStreamTest.cs \
csharp/src/Google.Protobuf.Test/CodedOutputWriterTest.cs \
csharp/src/Google.Protobuf.Test/CodedOutputTestBase.cs \
csharp/src/Google.Protobuf.Test/Buffers/ArrayBufferWriter.cs \
csharp/src/Google.Protobuf.Test/Buffers/MaxSizeHintBufferWriter.cs \
csharp/src/Google.Protobuf.Test/Buffers/ReadOnlySequenceFactory.cs \
csharp/src/Google.Protobuf.Test/Collections/MapFieldTest.cs \
csharp/src/Google.Protobuf.Test/Collections/ProtobufEqualityComparersTest.cs \
csharp/src/Google.Protobuf.Test/Collections/RepeatedFieldTest.cs \
Expand All @@ -121,6 +129,7 @@ csharp_EXTRA_DIST= \
csharp/src/Google.Protobuf.Test/JsonFormatterTest.cs \
csharp/src/Google.Protobuf.Test/JsonParserTest.cs \
csharp/src/Google.Protobuf.Test/JsonTokenizerTest.cs \
csharp/src/Google.Protobuf.Test/MessageParsingHelpers.cs \
csharp/src/Google.Protobuf.Test/Reflection/CustomOptionsTest.cs \
csharp/src/Google.Protobuf.Test/Reflection/DescriptorDeclarationTest.cs \
csharp/src/Google.Protobuf.Test/Reflection/DescriptorsTest.cs \
Expand Down Expand Up @@ -160,8 +169,10 @@ csharp_EXTRA_DIST= \
csharp/src/Google.Protobuf/ByteArray.cs \
csharp/src/Google.Protobuf/ByteString.cs \
csharp/src/Google.Protobuf/CodedInputStream.cs \
csharp/src/Google.Protobuf/CodedInputReader.cs \
csharp/src/Google.Protobuf/CodedOutputStream.ComputeSize.cs \
csharp/src/Google.Protobuf/CodedOutputStream.cs \
csharp/src/Google.Protobuf/CodedOutputWriter.cs \
csharp/src/Google.Protobuf/Collections/Lists.cs \
csharp/src/Google.Protobuf/Collections/MapField.cs \
csharp/src/Google.Protobuf/Collections/ProtobufEqualityComparers.cs \
Expand All @@ -179,6 +190,7 @@ csharp_EXTRA_DIST= \
csharp/src/Google.Protobuf/FieldMaskTree.cs \
csharp/src/Google.Protobuf/FrameworkPortability.cs \
csharp/src/Google.Protobuf/Google.Protobuf.csproj \
csharp/src/Google.Protobuf/IBufferMessage.cs \
csharp/src/Google.Protobuf/ICustomDiagnosticMessage.cs \
csharp/src/Google.Protobuf/IDeepCloneable.cs \
csharp/src/Google.Protobuf/IExtendableMessage.cs \
Expand Down Expand Up @@ -225,6 +237,7 @@ csharp_EXTRA_DIST= \
csharp/src/Google.Protobuf/Reflection/ServiceDescriptor.cs \
csharp/src/Google.Protobuf/Reflection/SingleFieldAccessor.cs \
csharp/src/Google.Protobuf/Reflection/TypeRegistry.cs \
csharp/src/Google.Protobuf/SequenceReader.cs \
csharp/src/Google.Protobuf/WellKnownTypes/Any.cs \
csharp/src/Google.Protobuf/WellKnownTypes/AnyPartial.cs \
csharp/src/Google.Protobuf/WellKnownTypes/Api.cs \
Expand Down
1 change: 1 addition & 0 deletions conformance/Makefile.am
Expand Up @@ -343,6 +343,7 @@ test_java_lite: protoc_middleman conformance-test-runner conformance-java-lite

test_csharp: protoc_middleman conformance-test-runner conformance-csharp
./conformance-test-runner --enforce_recommended --failure_list failure_list_csharp.txt --text_format_failure_list text_format_failure_list_csharp.txt ./conformance-csharp
./conformance-test-runner --enforce_recommended --failure_list failure_list_csharp.txt --text_format_failure_list text_format_failure_list_csharp.txt ./conformance-csharp --use_buffer_serialization

test_ruby: protoc_middleman conformance-test-runner $(other_language_protoc_outputs)
RUBYLIB=../ruby/lib:. ./conformance-test-runner --enforce_recommended --failure_list failure_list_ruby.txt --text_format_failure_list text_format_failure_list_ruby.txt ./conformance_ruby.rb
Expand Down
11 changes: 8 additions & 3 deletions csharp/generate_protos.sh
Expand Up @@ -27,7 +27,7 @@ fi

# descriptor.proto and well-known types
$PROTOC -Isrc --csharp_out=csharp/src/Google.Protobuf \
--csharp_opt=base_namespace=Google.Protobuf \
--csharp_opt=base_namespace=Google.Protobuf,use_buffer_serialization \
src/google/protobuf/descriptor.proto \
src/google/protobuf/any.proto \
src/google/protobuf/api.proto \
Expand All @@ -46,6 +46,7 @@ $PROTOC -Isrc --csharp_out=csharp/src/Google.Protobuf \
# of protoc.
$PROTOC -Isrc -Icsharp/protos \
--csharp_out=csharp/src/Google.Protobuf.Test.TestProtos \
--csharp_opt=use_buffer_serialization \
--descriptor_set_out=csharp/src/Google.Protobuf.Test/testprotos.pb \
--include_source_info \
--include_imports \
Expand All @@ -67,18 +68,22 @@ $PROTOC -Isrc -Icsharp/protos \

# AddressBook sample protos
$PROTOC -Iexamples -Isrc --csharp_out=csharp/src/AddressBook \
--csharp_opt=use_buffer_serialization \
examples/addressbook.proto

$PROTOC -Iconformance -Isrc --csharp_out=csharp/src/Google.Protobuf.Conformance \
--csharp_opt=use_buffer_serialization \
conformance/conformance.proto

# Benchmark protos
$PROTOC -Ibenchmarks \
benchmarks/datasets/google_message1/proto3/*.proto \
benchmarks/benchmarks.proto \
--csharp_out=csharp/src/Google.Protobuf.Benchmarks
--csharp_out=csharp/src/Google.Protobuf.Benchmarks \
--csharp_opt=use_buffer_serialization

# C# only benchmark protos
$PROTOC -Isrc -Icsharp/src/Google.Protobuf.Benchmarks \
csharp/src/Google.Protobuf.Benchmarks/*.proto \
--csharp_out=csharp/src/Google.Protobuf.Benchmarks
--csharp_out=csharp/src/Google.Protobuf.Benchmarks \
--csharp_opt=use_buffer_serialization
154 changes: 151 additions & 3 deletions csharp/src/AddressBook/Addressbook.cs
Expand Up @@ -49,7 +49,11 @@ public static partial class AddressbookReflection {
/// <summary>
/// [START messages]
/// </summary>
public sealed partial class Person : pb::IMessage<Person> {
public sealed partial class Person : pb::IMessage<Person>
#if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION
, pb::IBufferMessage
#endif
{
private static readonly pb::MessageParser<Person> _parser = new pb::MessageParser<Person>(() => new Person());
private pb::UnknownFieldSet _unknownFields;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
Expand Down Expand Up @@ -208,6 +212,33 @@ public sealed partial class Person : pb::IMessage<Person> {
}
}


#if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(ref pb::CodedOutputWriter output) {
if (Name.Length != 0) {
output.WriteRawTag(10);
output.WriteString(Name);
}
if (Id != 0) {
output.WriteRawTag(16);
output.WriteInt32(Id);
}
if (Email.Length != 0) {
output.WriteRawTag(26);
output.WriteString(Email);
}
phones_.WriteTo(ref output, _repeated_phones_codec);
if (lastUpdated_ != null) {
output.WriteRawTag(42);
output.WriteMessage(LastUpdated);
}
if (_unknownFields != null) {
_unknownFields.WriteTo(ref output);
}
}
#endif

[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
int size = 0;
Expand Down Expand Up @@ -289,6 +320,44 @@ public sealed partial class Person : pb::IMessage<Person> {
}
}


#if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void MergeFrom(ref pb::CodedInputReader input) {
uint tag;
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
break;
case 10: {
Name = input.ReadString();
break;
}
case 16: {
Id = input.ReadInt32();
break;
}
case 26: {
Email = input.ReadString();
break;
}
case 34: {
phones_.AddEntriesFrom(ref input, _repeated_phones_codec);
break;
}
case 42: {
if (lastUpdated_ == null) {
LastUpdated = new global::Google.Protobuf.WellKnownTypes.Timestamp();
}
input.ReadMessage(LastUpdated);
break;
}
}
}
}
#endif

#region Nested types
/// <summary>Container for nested types declared in the Person message type.</summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
Expand All @@ -299,7 +368,11 @@ public enum PhoneType {
[pbr::OriginalName("WORK")] Work = 2,
}

public sealed partial class PhoneNumber : pb::IMessage<PhoneNumber> {
public sealed partial class PhoneNumber : pb::IMessage<PhoneNumber>
#if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION
, pb::IBufferMessage
#endif
{
private static readonly pb::MessageParser<PhoneNumber> _parser = new pb::MessageParser<PhoneNumber>(() => new PhoneNumber());
private pb::UnknownFieldSet _unknownFields;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
Expand Down Expand Up @@ -405,6 +478,24 @@ public sealed partial class PhoneNumber : pb::IMessage<PhoneNumber> {
}
}


#if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(ref pb::CodedOutputWriter output) {
if (Number.Length != 0) {
output.WriteRawTag(10);
output.WriteString(Number);
}
if (Type != global::Google.Protobuf.Examples.AddressBook.Person.Types.PhoneType.Mobile) {
output.WriteRawTag(16);
output.WriteEnum((int) Type);
}
if (_unknownFields != null) {
_unknownFields.WriteTo(ref output);
}
}
#endif

[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
int size = 0;
Expand Down Expand Up @@ -454,6 +545,29 @@ public sealed partial class PhoneNumber : pb::IMessage<PhoneNumber> {
}
}


#if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void MergeFrom(ref pb::CodedInputReader input) {
uint tag;
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
break;
case 10: {
Number = input.ReadString();
break;
}
case 16: {
Type = (global::Google.Protobuf.Examples.AddressBook.Person.Types.PhoneType) input.ReadEnum();
break;
}
}
}
}
#endif

}

}
Expand All @@ -464,7 +578,11 @@ public sealed partial class PhoneNumber : pb::IMessage<PhoneNumber> {
/// <summary>
/// Our address book file is just one of these.
/// </summary>
public sealed partial class AddressBook : pb::IMessage<AddressBook> {
public sealed partial class AddressBook : pb::IMessage<AddressBook>
#if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION
, pb::IBufferMessage
#endif
{
private static readonly pb::MessageParser<AddressBook> _parser = new pb::MessageParser<AddressBook>(() => new AddressBook());
private pb::UnknownFieldSet _unknownFields;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
Expand Down Expand Up @@ -548,6 +666,17 @@ public sealed partial class AddressBook : pb::IMessage<AddressBook> {
}
}


#if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(ref pb::CodedOutputWriter output) {
people_.WriteTo(ref output, _repeated_people_codec);
if (_unknownFields != null) {
_unknownFields.WriteTo(ref output);
}
}
#endif

[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
int size = 0;
Expand Down Expand Up @@ -583,6 +712,25 @@ public sealed partial class AddressBook : pb::IMessage<AddressBook> {
}
}


#if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void MergeFrom(ref pb::CodedInputReader input) {
uint tag;
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
break;
case 10: {
people_.AddEntriesFrom(ref input, _repeated_people_codec);
break;
}
}
}
}
#endif

}

#endregion
Expand Down