diff --git a/src/DotNetty.Codecs.Protobuf/ProtobufDecoder.cs b/src/DotNetty.Codecs.Protobuf/ProtobufDecoder.cs index 5b1f992a9..d052eae49 100644 --- a/src/DotNetty.Codecs.Protobuf/ProtobufDecoder.cs +++ b/src/DotNetty.Codecs.Protobuf/ProtobufDecoder.cs @@ -29,10 +29,6 @@ protected override void Decode(IChannelHandlerContext context, IByteBuffer messa Contract.Requires(output != null); int length = message.ReadableBytes; - if (length <= 0) - { - return; - } Stream inputStream = null; try diff --git a/src/DotNetty.Codecs.Protobuf/ProtobufEncoder.cs b/src/DotNetty.Codecs.Protobuf/ProtobufEncoder.cs index 16550ae06..c561a8f72 100644 --- a/src/DotNetty.Codecs.Protobuf/ProtobufEncoder.cs +++ b/src/DotNetty.Codecs.Protobuf/ProtobufEncoder.cs @@ -22,11 +22,6 @@ protected override void Encode(IChannelHandlerContext context, IMessage message, try { - int size = message.CalculateSize(); - if (size == 0) - { - return; - } //todo: Implement ByteBufferStream to avoid allocations. buffer = Unpooled.WrappedBuffer(message.ToByteArray()); output.Add(buffer); diff --git a/src/DotNetty.Codecs.ProtocolBuffers/ProtobufDecoder.cs b/src/DotNetty.Codecs.ProtocolBuffers/ProtobufDecoder.cs index 68ab3d3cc..c95fde907 100644 --- a/src/DotNetty.Codecs.ProtocolBuffers/ProtobufDecoder.cs +++ b/src/DotNetty.Codecs.ProtocolBuffers/ProtobufDecoder.cs @@ -31,10 +31,6 @@ protected override void Decode(IChannelHandlerContext context, IByteBuffer messa Contract.Requires(output != null); int length = message.ReadableBytes; - if (length <= 0) - { - return; - } Stream inputStream = null; try diff --git a/src/DotNetty.Codecs.ProtocolBuffers/ProtobufEncoder.cs b/src/DotNetty.Codecs.ProtocolBuffers/ProtobufEncoder.cs index c7cf8e093..ce2ac773f 100644 --- a/src/DotNetty.Codecs.ProtocolBuffers/ProtobufEncoder.cs +++ b/src/DotNetty.Codecs.ProtocolBuffers/ProtobufEncoder.cs @@ -22,10 +22,6 @@ protected override void Encode(IChannelHandlerContext context, IMessageLite mess try { int size = message.SerializedSize; - if (size <= 0) - { - return; - } buffer = context.Allocator.Buffer(size); ArraySegment data = buffer.GetIoBuffer(buffer.WriterIndex, size); diff --git a/test/DotNetty.Codecs.Protobuf.Tests/Addressbook.cs b/test/DotNetty.Codecs.Protobuf.Tests/Addressbook.cs index 5723860f0..08761cc67 100644 --- a/test/DotNetty.Codecs.Protobuf.Tests/Addressbook.cs +++ b/test/DotNetty.Codecs.Protobuf.Tests/Addressbook.cs @@ -1,5 +1,5 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: addressbook.proto +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: Addressbook.proto #pragma warning disable 1591, 0612, 3021 #region Designer generated code @@ -7,612 +7,603 @@ using pbc = global::Google.Protobuf.Collections; using pbr = global::Google.Protobuf.Reflection; using scg = global::System.Collections.Generic; -namespace Google.Protobuf.Examples.AddressBook -{ - - /// Holder for reflection information generated from addressbook.proto - public static partial class AddressbookReflection - { - - #region Descriptor - /// File descriptor for addressbook.proto - public static pbr::FileDescriptor Descriptor - { - get { return descriptor; } - } - private static pbr::FileDescriptor descriptor; - - static AddressbookReflection() - { - byte[] descriptorData = global::System.Convert.FromBase64String( - string.Concat( - "ChFhZGRyZXNzYm9vay5wcm90bxIIdHV0b3JpYWwi1QEKBlBlcnNvbhIMCgRu", - "YW1lGAEgASgJEgoKAmlkGAIgASgFEg0KBWVtYWlsGAMgASgJEiwKBnBob25l", - "cxgEIAMoCzIcLnR1dG9yaWFsLlBlcnNvbi5QaG9uZU51bWJlchpHCgtQaG9u", - "ZU51bWJlchIOCgZudW1iZXIYASABKAkSKAoEdHlwZRgCIAEoDjIaLnR1dG9y", - "aWFsLlBlcnNvbi5QaG9uZVR5cGUiKwoJUGhvbmVUeXBlEgoKBk1PQklMRRAA", - "EggKBEhPTUUQARIICgRXT1JLEAIiLwoLQWRkcmVzc0Jvb2sSIAoGcGVvcGxl", - "GAEgAygLMhAudHV0b3JpYWwuUGVyc29uQlAKFGNvbS5leGFtcGxlLnR1dG9y", - "aWFsQhFBZGRyZXNzQm9va1Byb3Rvc6oCJEdvb2dsZS5Qcm90b2J1Zi5FeGFt", - "cGxlcy5BZGRyZXNzQm9va2IGcHJvdG8z")); - descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, - new pbr::FileDescriptor[] { }, - new pbr::GeneratedClrTypeInfo(null, new pbr::GeneratedClrTypeInfo[] { +namespace Google.Protobuf.Examples.AddressBook { + + /// Holder for reflection information generated from Addressbook.proto + public static partial class AddressbookReflection { + + #region Descriptor + /// File descriptor for Addressbook.proto + public static pbr::FileDescriptor Descriptor { + get { return descriptor; } + } + private static pbr::FileDescriptor descriptor; + + static AddressbookReflection() { + byte[] descriptorData = global::System.Convert.FromBase64String( + string.Concat( + "ChFBZGRyZXNzYm9vay5wcm90bxIkR29vZ2xlLlByb3RvYnVmLkV4YW1wbGVz", + "LkFkZHJlc3NCb29rIo0CCgZQZXJzb24SDAoEbmFtZRgBIAEoCRIKCgJpZBgC", + "IAEoBRINCgVlbWFpbBgDIAEoCRJICgZwaG9uZXMYBCADKAsyOC5Hb29nbGUu", + "UHJvdG9idWYuRXhhbXBsZXMuQWRkcmVzc0Jvb2suUGVyc29uLlBob25lTnVt", + "YmVyGmMKC1Bob25lTnVtYmVyEg4KBm51bWJlchgBIAEoCRJECgR0eXBlGAIg", + "ASgOMjYuR29vZ2xlLlByb3RvYnVmLkV4YW1wbGVzLkFkZHJlc3NCb29rLlBl", + "cnNvbi5QaG9uZVR5cGUiKwoJUGhvbmVUeXBlEgoKBk1PQklMRRAAEggKBEhP", + "TUUQARIICgRXT1JLEAIiSwoLQWRkcmVzc0Jvb2sSPAoGcGVvcGxlGAEgAygL", + "MiwuR29vZ2xlLlByb3RvYnVmLkV4YW1wbGVzLkFkZHJlc3NCb29rLlBlcnNv", + "biIOCgxFbXB0eU1lc3NhZ2ViBnByb3RvMw==")); + descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, + new pbr::FileDescriptor[] { }, + new pbr::GeneratedClrTypeInfo(null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Examples.AddressBook.Person), global::Google.Protobuf.Examples.AddressBook.Person.Parser, new[]{ "Name", "Id", "Email", "Phones" }, null, new[]{ typeof(global::Google.Protobuf.Examples.AddressBook.Person.Types.PhoneType) }, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Examples.AddressBook.Person.Types.PhoneNumber), global::Google.Protobuf.Examples.AddressBook.Person.Types.PhoneNumber.Parser, new[]{ "Number", "Type" }, null, null, null)}), - new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Examples.AddressBook.AddressBook), global::Google.Protobuf.Examples.AddressBook.AddressBook.Parser, new[]{ "People" }, null, null, null) - })); - } - #endregion + new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Examples.AddressBook.AddressBook), global::Google.Protobuf.Examples.AddressBook.AddressBook.Parser, new[]{ "People" }, null, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::Google.Protobuf.Examples.AddressBook.EmptyMessage), global::Google.Protobuf.Examples.AddressBook.EmptyMessage.Parser, null, null, null, null) + })); + } + #endregion + } + #region Messages + /// + /// [START messages] + /// + public sealed partial class Person : pb::IMessage { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Person()); + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::Google.Protobuf.Examples.AddressBook.AddressbookReflection.Descriptor.MessageTypes[0]; } } - #region Messages + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Person() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Person(Person other) : this() { + name_ = other.name_; + id_ = other.id_; + email_ = other.email_; + phones_ = other.phones_.Clone(); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Person Clone() { + return new Person(this); + } + + /// Field number for the "name" field. + public const int NameFieldNumber = 1; + private string name_ = ""; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string Name { + get { return name_; } + set { + name_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "id" field. + public const int IdFieldNumber = 2; + private int id_; /// - /// [START messages] + /// Unique ID number for this person. /// - public sealed partial class Person : pb::IMessage - { - private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Person()); + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int Id { + get { return id_; } + set { + id_ = value; + } + } + + /// Field number for the "email" field. + public const int EmailFieldNumber = 3; + private string email_ = ""; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string Email { + get { return email_; } + set { + email_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "phones" field. + public const int PhonesFieldNumber = 4; + private static readonly pb::FieldCodec _repeated_phones_codec + = pb::FieldCodec.ForMessage(34, global::Google.Protobuf.Examples.AddressBook.Person.Types.PhoneNumber.Parser); + private readonly pbc::RepeatedField phones_ = new pbc::RepeatedField(); + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::RepeatedField Phones { + get { return phones_; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as Person); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(Person other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (Name != other.Name) return false; + if (Id != other.Id) return false; + if (Email != other.Email) return false; + if(!phones_.Equals(other.phones_)) return false; + return true; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + if (Name.Length != 0) hash ^= Name.GetHashCode(); + if (Id != 0) hash ^= Id.GetHashCode(); + if (Email.Length != 0) hash ^= Email.GetHashCode(); + hash ^= phones_.GetHashCode(); + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream 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(output, _repeated_phones_codec); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + if (Name.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(Name); + } + if (Id != 0) { + size += 1 + pb::CodedOutputStream.ComputeInt32Size(Id); + } + if (Email.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(Email); + } + size += phones_.CalculateSize(_repeated_phones_codec); + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(Person other) { + if (other == null) { + return; + } + if (other.Name.Length != 0) { + Name = other.Name; + } + if (other.Id != 0) { + Id = other.Id; + } + if (other.Email.Length != 0) { + Email = other.Email; + } + phones_.Add(other.phones_); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + input.SkipLastField(); + break; + case 10: { + Name = input.ReadString(); + break; + } + case 16: { + Id = input.ReadInt32(); + break; + } + case 26: { + Email = input.ReadString(); + break; + } + case 34: { + phones_.AddEntriesFrom(input, _repeated_phones_codec); + break; + } + } + } + } + + #region Nested types + /// Container for nested types declared in the Person message type. + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static partial class Types { + public enum PhoneType { + [pbr::OriginalName("MOBILE")] Mobile = 0, + [pbr::OriginalName("HOME")] Home = 1, + [pbr::OriginalName("WORK")] Work = 2, + } + + public sealed partial class PhoneNumber : pb::IMessage { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new PhoneNumber()); [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public static pb::MessageParser Parser { get { return _parser; } } + public static pb::MessageParser Parser { get { return _parser; } } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public static pbr::MessageDescriptor Descriptor - { - get { return global::Google.Protobuf.Examples.AddressBook.AddressbookReflection.Descriptor.MessageTypes[0]; } + public static pbr::MessageDescriptor Descriptor { + get { return global::Google.Protobuf.Examples.AddressBook.Person.Descriptor.NestedTypes[0]; } } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - pbr::MessageDescriptor pb::IMessage.Descriptor - { - get { return Descriptor; } + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public Person() - { - OnConstruction(); + public PhoneNumber() { + OnConstruction(); } partial void OnConstruction(); [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public Person(Person other) : this() - { - name_ = other.name_; - id_ = other.id_; - email_ = other.email_; - phones_ = other.phones_.Clone(); + public PhoneNumber(PhoneNumber other) : this() { + number_ = other.number_; + type_ = other.type_; } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public Person Clone() - { - return new Person(this); + public PhoneNumber Clone() { + return new PhoneNumber(this); } - /// Field number for the "name" field. - public const int NameFieldNumber = 1; - private string name_ = ""; + /// Field number for the "number" field. + public const int NumberFieldNumber = 1; + private string number_ = ""; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public string Name - { - get { return name_; } - set - { - name_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); - } + public string Number { + get { return number_; } + set { + number_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } } - /// Field number for the "id" field. - public const int IdFieldNumber = 2; - private int id_; - /// - /// Unique ID number for this person. - /// + /// Field number for the "type" field. + public const int TypeFieldNumber = 2; + private global::Google.Protobuf.Examples.AddressBook.Person.Types.PhoneType type_ = 0; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public int Id - { - get { return id_; } - set - { - id_ = value; - } + public global::Google.Protobuf.Examples.AddressBook.Person.Types.PhoneType Type { + get { return type_; } + set { + type_ = value; + } } - /// Field number for the "email" field. - public const int EmailFieldNumber = 3; - private string email_ = ""; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public string Email - { - get { return email_; } - set - { - email_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); - } + public override bool Equals(object other) { + return Equals(other as PhoneNumber); } - /// Field number for the "phones" field. - public const int PhonesFieldNumber = 4; - private static readonly pb::FieldCodec _repeated_phones_codec - = pb::FieldCodec.ForMessage(34, global::Google.Protobuf.Examples.AddressBook.Person.Types.PhoneNumber.Parser); - private readonly pbc::RepeatedField phones_ = new pbc::RepeatedField(); [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public pbc::RepeatedField Phones - { - get { return phones_; } + public bool Equals(PhoneNumber other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (Number != other.Number) return false; + if (Type != other.Type) return false; + return true; } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public override bool Equals(object other) - { - return Equals(other as Person); + public override int GetHashCode() { + int hash = 1; + if (Number.Length != 0) hash ^= Number.GetHashCode(); + if (Type != 0) hash ^= Type.GetHashCode(); + return hash; } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public bool Equals(Person other) - { - if (ReferenceEquals(other, null)) - { - return false; - } - if (ReferenceEquals(other, this)) - { - return true; - } - if (Name != other.Name) return false; - if (Id != other.Id) return false; - if (Email != other.Email) return false; - if (!phones_.Equals(other.phones_)) return false; - return true; + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public override int GetHashCode() - { - int hash = 1; - if (Name.Length != 0) hash ^= Name.GetHashCode(); - if (Id != 0) hash ^= Id.GetHashCode(); - if (Email.Length != 0) hash ^= Email.GetHashCode(); - hash ^= phones_.GetHashCode(); - return hash; + public void WriteTo(pb::CodedOutputStream output) { + if (Number.Length != 0) { + output.WriteRawTag(10); + output.WriteString(Number); + } + if (Type != 0) { + output.WriteRawTag(16); + output.WriteEnum((int) Type); + } } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public override string ToString() - { - return pb::JsonFormatter.ToDiagnosticString(this); + public int CalculateSize() { + int size = 0; + if (Number.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(Number); + } + if (Type != 0) { + size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) Type); + } + return size; } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void WriteTo(pb::CodedOutputStream 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(output, _repeated_phones_codec); + public void MergeFrom(PhoneNumber other) { + if (other == null) { + return; + } + if (other.Number.Length != 0) { + Number = other.Number; + } + if (other.Type != 0) { + Type = other.Type; + } } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public int CalculateSize() - { - int size = 0; - if (Name.Length != 0) - { - size += 1 + pb::CodedOutputStream.ComputeStringSize(Name); - } - if (Id != 0) - { - size += 1 + pb::CodedOutputStream.ComputeInt32Size(Id); + public void MergeFrom(pb::CodedInputStream input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + input.SkipLastField(); + break; + case 10: { + Number = input.ReadString(); + break; + } + case 16: { + type_ = (global::Google.Protobuf.Examples.AddressBook.Person.Types.PhoneType) input.ReadEnum(); + break; + } } - if (Email.Length != 0) - { - size += 1 + pb::CodedOutputStream.ComputeStringSize(Email); - } - size += phones_.CalculateSize(_repeated_phones_codec); - return size; + } } - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void MergeFrom(Person other) - { - if (other == null) - { - return; - } - if (other.Name.Length != 0) - { - Name = other.Name; - } - if (other.Id != 0) - { - Id = other.Id; - } - if (other.Email.Length != 0) - { - Email = other.Email; - } - phones_.Add(other.phones_); - } + } - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void MergeFrom(pb::CodedInputStream input) - { - uint tag; - while ((tag = input.ReadTag()) != 0) - { - switch (tag) - { - default: - input.SkipLastField(); - break; - case 10: - { - Name = input.ReadString(); - break; - } - case 16: - { - Id = input.ReadInt32(); - break; - } - case 26: - { - Email = input.ReadString(); - break; - } - case 34: - { - phones_.AddEntriesFrom(input, _repeated_phones_codec); - break; - } - } - } - } + } + #endregion - #region Nested types - /// Container for nested types declared in the Person message type. - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public static partial class Types - { - public enum PhoneType - { - [pbr::OriginalName("MOBILE")] - Mobile = 0, - [pbr::OriginalName("HOME")] - Home = 1, - [pbr::OriginalName("WORK")] - Work = 2, - } + } - public sealed partial class PhoneNumber : pb::IMessage - { - private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new PhoneNumber()); - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public static pb::MessageParser Parser { get { return _parser; } } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public static pbr::MessageDescriptor Descriptor - { - get { return global::Google.Protobuf.Examples.AddressBook.Person.Descriptor.NestedTypes[0]; } - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - pbr::MessageDescriptor pb::IMessage.Descriptor - { - get { return Descriptor; } - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public PhoneNumber() - { - OnConstruction(); - } - - partial void OnConstruction(); - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public PhoneNumber(PhoneNumber other) : this() - { - number_ = other.number_; - type_ = other.type_; - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public PhoneNumber Clone() - { - return new PhoneNumber(this); - } - - /// Field number for the "number" field. - public const int NumberFieldNumber = 1; - private string number_ = ""; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public string Number - { - get { return number_; } - set - { - number_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); - } - } - - /// Field number for the "type" field. - public const int TypeFieldNumber = 2; - private global::Google.Protobuf.Examples.AddressBook.Person.Types.PhoneType type_ = 0; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public global::Google.Protobuf.Examples.AddressBook.Person.Types.PhoneType Type - { - get { return type_; } - set - { - type_ = value; - } - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public override bool Equals(object other) - { - return Equals(other as PhoneNumber); - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public bool Equals(PhoneNumber other) - { - if (ReferenceEquals(other, null)) - { - return false; - } - if (ReferenceEquals(other, this)) - { - return true; - } - if (Number != other.Number) return false; - if (Type != other.Type) return false; - return true; - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public override int GetHashCode() - { - int hash = 1; - if (Number.Length != 0) hash ^= Number.GetHashCode(); - if (Type != 0) hash ^= Type.GetHashCode(); - return hash; - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public override string ToString() - { - return pb::JsonFormatter.ToDiagnosticString(this); - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void WriteTo(pb::CodedOutputStream output) - { - if (Number.Length != 0) - { - output.WriteRawTag(10); - output.WriteString(Number); - } - if (Type != 0) - { - output.WriteRawTag(16); - output.WriteEnum((int)Type); - } - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public int CalculateSize() - { - int size = 0; - if (Number.Length != 0) - { - size += 1 + pb::CodedOutputStream.ComputeStringSize(Number); - } - if (Type != 0) - { - size += 1 + pb::CodedOutputStream.ComputeEnumSize((int)Type); - } - return size; - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void MergeFrom(PhoneNumber other) - { - if (other == null) - { - return; - } - if (other.Number.Length != 0) - { - Number = other.Number; - } - if (other.Type != 0) - { - Type = other.Type; - } - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void MergeFrom(pb::CodedInputStream input) - { - uint tag; - while ((tag = input.ReadTag()) != 0) - { - switch (tag) - { - default: - input.SkipLastField(); - break; - case 10: - { - Number = input.ReadString(); - break; - } - case 16: - { - type_ = (global::Google.Protobuf.Examples.AddressBook.Person.Types.PhoneType)input.ReadEnum(); - break; - } - } - } - } + /// + /// Our address book file is just one of these. + /// + public sealed partial class AddressBook : pb::IMessage { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new AddressBook()); + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } - } + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::Google.Protobuf.Examples.AddressBook.AddressbookReflection.Descriptor.MessageTypes[1]; } + } - } - #endregion + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public AddressBook() { + OnConstruction(); } - /// - /// Our address book file is just one of these. - /// - public sealed partial class AddressBook : pb::IMessage - { - private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new AddressBook()); - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public static pb::MessageParser Parser { get { return _parser; } } + partial void OnConstruction(); - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public static pbr::MessageDescriptor Descriptor - { - get { return global::Google.Protobuf.Examples.AddressBook.AddressbookReflection.Descriptor.MessageTypes[1]; } - } + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public AddressBook(AddressBook other) : this() { + people_ = other.people_.Clone(); + } - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - pbr::MessageDescriptor pb::IMessage.Descriptor - { - get { return Descriptor; } - } + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public AddressBook Clone() { + return new AddressBook(this); + } - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public AddressBook() - { - OnConstruction(); - } + /// Field number for the "people" field. + public const int PeopleFieldNumber = 1; + private static readonly pb::FieldCodec _repeated_people_codec + = pb::FieldCodec.ForMessage(10, global::Google.Protobuf.Examples.AddressBook.Person.Parser); + private readonly pbc::RepeatedField people_ = new pbc::RepeatedField(); + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::RepeatedField People { + get { return people_; } + } - partial void OnConstruction(); + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as AddressBook); + } - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public AddressBook(AddressBook other) : this() - { - people_ = other.people_.Clone(); - } + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(AddressBook other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if(!people_.Equals(other.people_)) return false; + return true; + } - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public AddressBook Clone() - { - return new AddressBook(this); - } + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + hash ^= people_.GetHashCode(); + return hash; + } - /// Field number for the "people" field. - public const int PeopleFieldNumber = 1; - private static readonly pb::FieldCodec _repeated_people_codec - = pb::FieldCodec.ForMessage(10, global::Google.Protobuf.Examples.AddressBook.Person.Parser); - private readonly pbc::RepeatedField people_ = new pbc::RepeatedField(); - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public pbc::RepeatedField People - { - get { return people_; } - } + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public override bool Equals(object other) - { - return Equals(other as AddressBook); - } + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + people_.WriteTo(output, _repeated_people_codec); + } - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public bool Equals(AddressBook other) - { - if (ReferenceEquals(other, null)) - { - return false; - } - if (ReferenceEquals(other, this)) - { - return true; - } - if (!people_.Equals(other.people_)) return false; - return true; - } + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + size += people_.CalculateSize(_repeated_people_codec); + return size; + } - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public override int GetHashCode() - { - int hash = 1; - hash ^= people_.GetHashCode(); - return hash; - } + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(AddressBook other) { + if (other == null) { + return; + } + people_.Add(other.people_); + } - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public override string ToString() - { - return pb::JsonFormatter.ToDiagnosticString(this); - } + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + input.SkipLastField(); + break; + case 10: { + people_.AddEntriesFrom(input, _repeated_people_codec); + break; + } + } + } + } - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void WriteTo(pb::CodedOutputStream output) - { - people_.WriteTo(output, _repeated_people_codec); - } + } - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public int CalculateSize() - { - int size = 0; - size += people_.CalculateSize(_repeated_people_codec); - return size; - } + public sealed partial class EmptyMessage : pb::IMessage { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new EmptyMessage()); + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void MergeFrom(AddressBook other) - { - if (other == null) - { - return; - } - people_.Add(other.people_); - } + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::Google.Protobuf.Examples.AddressBook.AddressbookReflection.Descriptor.MessageTypes[2]; } + } - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void MergeFrom(pb::CodedInputStream input) - { - uint tag; - while ((tag = input.ReadTag()) != 0) - { - switch (tag) - { - default: - input.SkipLastField(); - break; - case 10: - { - people_.AddEntriesFrom(input, _repeated_people_codec); - break; - } - } - } - } + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public EmptyMessage() { + OnConstruction(); } - #endregion + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public EmptyMessage(EmptyMessage other) : this() { + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public EmptyMessage Clone() { + return new EmptyMessage(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as EmptyMessage); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(EmptyMessage other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + return true; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(EmptyMessage other) { + if (other == null) { + return; + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + input.SkipLastField(); + break; + } + } + } + + } + + #endregion } -#endregion Designer generated code \ No newline at end of file +#endregion Designer generated code diff --git a/test/DotNetty.Codecs.Protobuf.Tests/Addressbook.proto b/test/DotNetty.Codecs.Protobuf.Tests/Addressbook.proto index 71e280127..7c814e22d 100644 --- a/test/DotNetty.Codecs.Protobuf.Tests/Addressbook.proto +++ b/test/DotNetty.Codecs.Protobuf.Tests/Addressbook.proto @@ -24,4 +24,6 @@ message Person { // Our address book file is just one of these. message AddressBook { repeated Person people = 1; -} \ No newline at end of file +} + +message EmptyMessage {} \ No newline at end of file diff --git a/test/DotNetty.Codecs.Protobuf.Tests/RoundTripTests.cs b/test/DotNetty.Codecs.Protobuf.Tests/RoundTripTests.cs index 611ed187d..69c44930a 100644 --- a/test/DotNetty.Codecs.Protobuf.Tests/RoundTripTests.cs +++ b/test/DotNetty.Codecs.Protobuf.Tests/RoundTripTests.cs @@ -295,5 +295,33 @@ public void Run2(Person.Types.PhoneType phoneType, string number, bool isComposi Assert.False(channel.Finish()); } + + [Fact] + public void EmptyTest() + { + var channel = new EmbeddedChannel( + new ProtobufVarint32FrameDecoder(), + new ProtobufDecoder(EmptyMessage.Parser), + new ProtobufVarint32LengthFieldPrepender(), + new ProtobufEncoder()); + + Assert.True(channel.WriteOutbound(new EmptyMessage())); + var buffer = channel.ReadOutbound(); + Assert.NotNull(buffer); + Assert.True(buffer.ReadableBytes > 0); + + var data = new byte[buffer.ReadableBytes]; + buffer.ReadBytes(data); + + IByteBuffer inputBuffer = Unpooled.WrappedBuffer(data); + + Assert.True(channel.WriteInbound(inputBuffer)); + + var message = channel.ReadInbound(); + Assert.NotNull(message); + Assert.IsType(message); + + Assert.False(channel.Finish()); + } } } diff --git a/test/DotNetty.Codecs.ProtocolBuffers.Tests/AddressBook.proto b/test/DotNetty.Codecs.ProtocolBuffers.Tests/AddressBook.proto index 648c516ce..855cebb44 100644 --- a/test/DotNetty.Codecs.ProtocolBuffers.Tests/AddressBook.proto +++ b/test/DotNetty.Codecs.ProtocolBuffers.Tests/AddressBook.proto @@ -20,4 +20,6 @@ message Person { // Our address book file is just one of these. message AddressBook { repeated Person person = 1; -} \ No newline at end of file +} + +message EmptyMessage {} \ No newline at end of file diff --git a/test/DotNetty.Codecs.ProtocolBuffers.Tests/Addressbook.cs b/test/DotNetty.Codecs.ProtocolBuffers.Tests/Addressbook.cs index e5ee50e6f..d7e25007c 100644 --- a/test/DotNetty.Codecs.ProtocolBuffers.Tests/Addressbook.cs +++ b/test/DotNetty.Codecs.ProtocolBuffers.Tests/Addressbook.cs @@ -8,61 +8,71 @@ using scg = global::System.Collections.Generic; namespace DotNetty.Codecs.ProtocolBuffers { - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - public static partial class Addressbook { - - #region Extension registration - public static void RegisterAllExtensions(pb::ExtensionRegistry registry) { - } - #endregion - #region Static variables - internal static pbd::MessageDescriptor internal__static_DotNetty_Codecs_ProtocolBuffers_Person__Descriptor; - internal static pb::FieldAccess.FieldAccessorTable internal__static_DotNetty_Codecs_ProtocolBuffers_Person__FieldAccessorTable; - internal static pbd::MessageDescriptor internal__static_DotNetty_Codecs_ProtocolBuffers_Person_PhoneNumber__Descriptor; - internal static pb::FieldAccess.FieldAccessorTable internal__static_DotNetty_Codecs_ProtocolBuffers_Person_PhoneNumber__FieldAccessorTable; - internal static pbd::MessageDescriptor internal__static_DotNetty_Codecs_ProtocolBuffers_AddressBook__Descriptor; - internal static pb::FieldAccess.FieldAccessorTable internal__static_DotNetty_Codecs_ProtocolBuffers_AddressBook__FieldAccessorTable; - #endregion - #region Descriptor - public static pbd::FileDescriptor Descriptor { - get { return descriptor; } - } - private static pbd::FileDescriptor descriptor; + namespace Proto { - static Addressbook() { - byte[] descriptorData = global::System.Convert.FromBase64String( - string.Concat( - "ChFhZGRyZXNzYm9vay5wcm90bxIfRG90TmV0dHkuQ29kZWNzLlByb3RvY29s", - "QnVmZmVycyKIAgoGUGVyc29uEgwKBG5hbWUYASACKAkSCgoCaWQYAiACKAUS", - "DQoFZW1haWwYAyABKAkSQgoFcGhvbmUYBCADKAsyMy5Eb3ROZXR0eS5Db2Rl", - "Y3MuUHJvdG9jb2xCdWZmZXJzLlBlcnNvbi5QaG9uZU51bWJlchpkCgtQaG9u", - "ZU51bWJlchIOCgZudW1iZXIYASACKAkSRQoEdHlwZRgCIAEoDjIxLkRvdE5l", - "dHR5LkNvZGVjcy5Qcm90b2NvbEJ1ZmZlcnMuUGVyc29uLlBob25lVHlwZToE", - "SE9NRSIrCglQaG9uZVR5cGUSCgoGTU9CSUxFEAASCAoESE9NRRABEggKBFdP", - "UksQAiJGCgtBZGRyZXNzQm9vaxI3CgZwZXJzb24YASADKAsyJy5Eb3ROZXR0", - "eS5Db2RlY3MuUHJvdG9jb2xCdWZmZXJzLlBlcnNvbkICSAE=")); - pbd::FileDescriptor.InternalDescriptorAssigner assigner = delegate(pbd::FileDescriptor root) { - descriptor = root; - internal__static_DotNetty_Codecs_ProtocolBuffers_Person__Descriptor = Descriptor.MessageTypes[0]; - internal__static_DotNetty_Codecs_ProtocolBuffers_Person__FieldAccessorTable = - new pb::FieldAccess.FieldAccessorTable(internal__static_DotNetty_Codecs_ProtocolBuffers_Person__Descriptor, - new string[] { "Name", "Id", "Email", "Phone", }); - internal__static_DotNetty_Codecs_ProtocolBuffers_Person_PhoneNumber__Descriptor = internal__static_DotNetty_Codecs_ProtocolBuffers_Person__Descriptor.NestedTypes[0]; - internal__static_DotNetty_Codecs_ProtocolBuffers_Person_PhoneNumber__FieldAccessorTable = - new pb::FieldAccess.FieldAccessorTable(internal__static_DotNetty_Codecs_ProtocolBuffers_Person_PhoneNumber__Descriptor, - new string[] { "Number", "Type", }); - internal__static_DotNetty_Codecs_ProtocolBuffers_AddressBook__Descriptor = Descriptor.MessageTypes[1]; - internal__static_DotNetty_Codecs_ProtocolBuffers_AddressBook__FieldAccessorTable = - new pb::FieldAccess.FieldAccessorTable(internal__static_DotNetty_Codecs_ProtocolBuffers_AddressBook__Descriptor, - new string[] { "Person", }); - return null; - }; - pbd::FileDescriptor.InternalBuildGeneratedFileFrom(descriptorData, - new pbd::FileDescriptor[] { - }, assigner); - } - #endregion + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + public static partial class AddressBook { + #region Extension registration + public static void RegisterAllExtensions(pb::ExtensionRegistry registry) { + } + #endregion + #region Static variables + internal static pbd::MessageDescriptor internal__static_Google_Protobuf_Examples_AddressBook_Person__Descriptor; + internal static pb::FieldAccess.FieldAccessorTable internal__static_Google_Protobuf_Examples_AddressBook_Person__FieldAccessorTable; + internal static pbd::MessageDescriptor internal__static_Google_Protobuf_Examples_AddressBook_Person_PhoneNumber__Descriptor; + internal static pb::FieldAccess.FieldAccessorTable internal__static_Google_Protobuf_Examples_AddressBook_Person_PhoneNumber__FieldAccessorTable; + internal static pbd::MessageDescriptor internal__static_Google_Protobuf_Examples_AddressBook_AddressBook__Descriptor; + internal static pb::FieldAccess.FieldAccessorTable internal__static_Google_Protobuf_Examples_AddressBook_AddressBook__FieldAccessorTable; + internal static pbd::MessageDescriptor internal__static_Google_Protobuf_Examples_AddressBook_EmptyMessage__Descriptor; + internal static pb::FieldAccess.FieldAccessorTable internal__static_Google_Protobuf_Examples_AddressBook_EmptyMessage__FieldAccessorTable; + #endregion + #region Descriptor + public static pbd::FileDescriptor Descriptor { + get { return descriptor; } + } + private static pbd::FileDescriptor descriptor; + + static AddressBook() { + byte[] descriptorData = global::System.Convert.FromBase64String( + string.Concat( + "ChFBZGRyZXNzQm9vay5wcm90bxIkR29vZ2xlLlByb3RvYnVmLkV4YW1wbGVz", + "LkFkZHJlc3NCb29rIpICCgZQZXJzb24SDAoEbmFtZRgBIAIoCRIKCgJpZBgC", + "IAIoBRINCgVlbWFpbBgDIAEoCRJHCgVwaG9uZRgEIAMoCzI4Lkdvb2dsZS5Q", + "cm90b2J1Zi5FeGFtcGxlcy5BZGRyZXNzQm9vay5QZXJzb24uUGhvbmVOdW1i", + "ZXIaaQoLUGhvbmVOdW1iZXISDgoGbnVtYmVyGAEgAigJEkoKBHR5cGUYAiAB", + "KA4yNi5Hb29nbGUuUHJvdG9idWYuRXhhbXBsZXMuQWRkcmVzc0Jvb2suUGVy", + "c29uLlBob25lVHlwZToESE9NRSIrCglQaG9uZVR5cGUSCgoGTU9CSUxFEAAS", + "CAoESE9NRRABEggKBFdPUksQAiJLCgtBZGRyZXNzQm9vaxI8CgZwZXJzb24Y", + "ASADKAsyLC5Hb29nbGUuUHJvdG9idWYuRXhhbXBsZXMuQWRkcmVzc0Jvb2su", + "UGVyc29uIg4KDEVtcHR5TWVzc2FnZQ==")); + pbd::FileDescriptor.InternalDescriptorAssigner assigner = delegate(pbd::FileDescriptor root) { + descriptor = root; + internal__static_Google_Protobuf_Examples_AddressBook_Person__Descriptor = Descriptor.MessageTypes[0]; + internal__static_Google_Protobuf_Examples_AddressBook_Person__FieldAccessorTable = + new pb::FieldAccess.FieldAccessorTable(internal__static_Google_Protobuf_Examples_AddressBook_Person__Descriptor, + new string[] { "Name", "Id", "Email", "Phone", }); + internal__static_Google_Protobuf_Examples_AddressBook_Person_PhoneNumber__Descriptor = internal__static_Google_Protobuf_Examples_AddressBook_Person__Descriptor.NestedTypes[0]; + internal__static_Google_Protobuf_Examples_AddressBook_Person_PhoneNumber__FieldAccessorTable = + new pb::FieldAccess.FieldAccessorTable(internal__static_Google_Protobuf_Examples_AddressBook_Person_PhoneNumber__Descriptor, + new string[] { "Number", "Type", }); + internal__static_Google_Protobuf_Examples_AddressBook_AddressBook__Descriptor = Descriptor.MessageTypes[1]; + internal__static_Google_Protobuf_Examples_AddressBook_AddressBook__FieldAccessorTable = + new pb::FieldAccess.FieldAccessorTable(internal__static_Google_Protobuf_Examples_AddressBook_AddressBook__Descriptor, + new string[] { "Person", }); + internal__static_Google_Protobuf_Examples_AddressBook_EmptyMessage__Descriptor = Descriptor.MessageTypes[2]; + internal__static_Google_Protobuf_Examples_AddressBook_EmptyMessage__FieldAccessorTable = + new pb::FieldAccess.FieldAccessorTable(internal__static_Google_Protobuf_Examples_AddressBook_EmptyMessage__Descriptor, + new string[] { }); + return null; + }; + pbd::FileDescriptor.InternalBuildGeneratedFileFrom(descriptorData, + new pbd::FileDescriptor[] { + }, assigner); + } + #endregion + + } } #region Messages [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] @@ -84,11 +94,11 @@ protected override Person ThisMessage { } public static pbd::MessageDescriptor Descriptor { - get { return global::DotNetty.Codecs.ProtocolBuffers.Addressbook.internal__static_DotNetty_Codecs_ProtocolBuffers_Person__Descriptor; } + get { return global::DotNetty.Codecs.ProtocolBuffers.Proto.AddressBook.internal__static_Google_Protobuf_Examples_AddressBook_Person__Descriptor; } } protected override pb::FieldAccess.FieldAccessorTable InternalFieldAccessors { - get { return global::DotNetty.Codecs.ProtocolBuffers.Addressbook.internal__static_DotNetty_Codecs_ProtocolBuffers_Person__FieldAccessorTable; } + get { return global::DotNetty.Codecs.ProtocolBuffers.Proto.AddressBook.internal__static_Google_Protobuf_Examples_AddressBook_Person__FieldAccessorTable; } } #region Nested types @@ -119,11 +129,11 @@ protected override PhoneNumber ThisMessage { } public static pbd::MessageDescriptor Descriptor { - get { return global::DotNetty.Codecs.ProtocolBuffers.Addressbook.internal__static_DotNetty_Codecs_ProtocolBuffers_Person_PhoneNumber__Descriptor; } + get { return global::DotNetty.Codecs.ProtocolBuffers.Proto.AddressBook.internal__static_Google_Protobuf_Examples_AddressBook_Person_PhoneNumber__Descriptor; } } protected override pb::FieldAccess.FieldAccessorTable InternalFieldAccessors { - get { return global::DotNetty.Codecs.ProtocolBuffers.Addressbook.internal__static_DotNetty_Codecs_ProtocolBuffers_Person_PhoneNumber__FieldAccessorTable; } + get { return global::DotNetty.Codecs.ProtocolBuffers.Proto.AddressBook.internal__static_Google_Protobuf_Examples_AddressBook_Person_PhoneNumber__FieldAccessorTable; } } public const int NumberFieldNumber = 1; @@ -424,7 +434,7 @@ public Builder ClearType() { } } static PhoneNumber() { - object.ReferenceEquals(global::DotNetty.Codecs.ProtocolBuffers.Addressbook.Descriptor, null); + object.ReferenceEquals(global::DotNetty.Codecs.ProtocolBuffers.Proto.AddressBook.Descriptor, null); } } @@ -839,7 +849,7 @@ public Builder ClearPhone() { } } static Person() { - object.ReferenceEquals(global::DotNetty.Codecs.ProtocolBuffers.Addressbook.Descriptor, null); + object.ReferenceEquals(global::DotNetty.Codecs.ProtocolBuffers.Proto.AddressBook.Descriptor, null); } } @@ -862,11 +872,11 @@ protected override AddressBook ThisMessage { } public static pbd::MessageDescriptor Descriptor { - get { return global::DotNetty.Codecs.ProtocolBuffers.Addressbook.internal__static_DotNetty_Codecs_ProtocolBuffers_AddressBook__Descriptor; } + get { return global::DotNetty.Codecs.ProtocolBuffers.Proto.AddressBook.internal__static_Google_Protobuf_Examples_AddressBook_AddressBook__Descriptor; } } protected override pb::FieldAccess.FieldAccessorTable InternalFieldAccessors { - get { return global::DotNetty.Codecs.ProtocolBuffers.Addressbook.internal__static_DotNetty_Codecs_ProtocolBuffers_AddressBook__FieldAccessorTable; } + get { return global::DotNetty.Codecs.ProtocolBuffers.Proto.AddressBook.internal__static_Google_Protobuf_Examples_AddressBook_AddressBook__FieldAccessorTable; } } public const int PersonFieldNumber = 1; @@ -1144,7 +1154,239 @@ public Builder ClearPerson() { } } static AddressBook() { - object.ReferenceEquals(global::DotNetty.Codecs.ProtocolBuffers.Addressbook.Descriptor, null); + object.ReferenceEquals(global::DotNetty.Codecs.ProtocolBuffers.Proto.AddressBook.Descriptor, null); + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + public sealed partial class EmptyMessage : pb::GeneratedMessage { + private EmptyMessage() { } + private static readonly EmptyMessage defaultInstance = new EmptyMessage().MakeReadOnly(); + private static readonly string[] _emptyMessageFieldNames = new string[] { }; + private static readonly uint[] _emptyMessageFieldTags = new uint[] { }; + public static EmptyMessage DefaultInstance { + get { return defaultInstance; } + } + + public override EmptyMessage DefaultInstanceForType { + get { return DefaultInstance; } + } + + protected override EmptyMessage ThisMessage { + get { return this; } + } + + public static pbd::MessageDescriptor Descriptor { + get { return global::DotNetty.Codecs.ProtocolBuffers.Proto.AddressBook.internal__static_Google_Protobuf_Examples_AddressBook_EmptyMessage__Descriptor; } + } + + protected override pb::FieldAccess.FieldAccessorTable InternalFieldAccessors { + get { return global::DotNetty.Codecs.ProtocolBuffers.Proto.AddressBook.internal__static_Google_Protobuf_Examples_AddressBook_EmptyMessage__FieldAccessorTable; } + } + + public override bool IsInitialized { + get { + return true; + } + } + + public override void WriteTo(pb::ICodedOutputStream output) { + CalcSerializedSize(); + string[] field_names = _emptyMessageFieldNames; + UnknownFields.WriteTo(output); + } + + private int memoizedSerializedSize = -1; + public override int SerializedSize { + get { + int size = memoizedSerializedSize; + if (size != -1) return size; + return CalcSerializedSize(); + } + } + + private int CalcSerializedSize() { + int size = memoizedSerializedSize; + if (size != -1) return size; + + size = 0; + size += UnknownFields.SerializedSize; + memoizedSerializedSize = size; + return size; + } + public static EmptyMessage ParseFrom(pb::ByteString data) { + return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed(); + } + public static EmptyMessage ParseFrom(pb::ByteString data, pb::ExtensionRegistry extensionRegistry) { + return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed(); + } + public static EmptyMessage ParseFrom(byte[] data) { + return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed(); + } + public static EmptyMessage ParseFrom(byte[] data, pb::ExtensionRegistry extensionRegistry) { + return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed(); + } + public static EmptyMessage ParseFrom(global::System.IO.Stream input) { + return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed(); + } + public static EmptyMessage ParseFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) { + return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed(); + } + public static EmptyMessage ParseDelimitedFrom(global::System.IO.Stream input) { + return CreateBuilder().MergeDelimitedFrom(input).BuildParsed(); + } + public static EmptyMessage ParseDelimitedFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) { + return CreateBuilder().MergeDelimitedFrom(input, extensionRegistry).BuildParsed(); + } + public static EmptyMessage ParseFrom(pb::ICodedInputStream input) { + return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed(); + } + public static EmptyMessage ParseFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed(); + } + private EmptyMessage MakeReadOnly() { + return this; + } + + public static Builder CreateBuilder() { return new Builder(); } + public override Builder ToBuilder() { return CreateBuilder(this); } + public override Builder CreateBuilderForType() { return new Builder(); } + public static Builder CreateBuilder(EmptyMessage prototype) { + return new Builder(prototype); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + public sealed partial class Builder : pb::GeneratedBuilder { + protected override Builder ThisBuilder { + get { return this; } + } + public Builder() { + result = DefaultInstance; + resultIsReadOnly = true; + } + internal Builder(EmptyMessage cloneFrom) { + result = cloneFrom; + resultIsReadOnly = true; + } + + private bool resultIsReadOnly; + private EmptyMessage result; + + private EmptyMessage PrepareBuilder() { + if (resultIsReadOnly) { + EmptyMessage original = result; + result = new EmptyMessage(); + resultIsReadOnly = false; + MergeFrom(original); + } + return result; + } + + public override bool IsInitialized { + get { return result.IsInitialized; } + } + + protected override EmptyMessage MessageBeingBuilt { + get { return PrepareBuilder(); } + } + + public override Builder Clear() { + result = DefaultInstance; + resultIsReadOnly = true; + return this; + } + + public override Builder Clone() { + if (resultIsReadOnly) { + return new Builder(result); + } else { + return new Builder().MergeFrom(result); + } + } + + public override pbd::MessageDescriptor DescriptorForType { + get { return global::DotNetty.Codecs.ProtocolBuffers.EmptyMessage.Descriptor; } + } + + public override EmptyMessage DefaultInstanceForType { + get { return global::DotNetty.Codecs.ProtocolBuffers.EmptyMessage.DefaultInstance; } + } + + public override EmptyMessage BuildPartial() { + if (resultIsReadOnly) { + return result; + } + resultIsReadOnly = true; + return result.MakeReadOnly(); + } + + public override Builder MergeFrom(pb::IMessage other) { + if (other is EmptyMessage) { + return MergeFrom((EmptyMessage) other); + } else { + base.MergeFrom(other); + return this; + } + } + + public override Builder MergeFrom(EmptyMessage other) { + if (other == global::DotNetty.Codecs.ProtocolBuffers.EmptyMessage.DefaultInstance) return this; + PrepareBuilder(); + this.MergeUnknownFields(other.UnknownFields); + return this; + } + + public override Builder MergeFrom(pb::ICodedInputStream input) { + return MergeFrom(input, pb::ExtensionRegistry.Empty); + } + + public override Builder MergeFrom(pb::ICodedInputStream input, pb::ExtensionRegistry extensionRegistry) { + PrepareBuilder(); + pb::UnknownFieldSet.Builder unknownFields = null; + uint tag; + string field_name; + while (input.ReadTag(out tag, out field_name)) { + if(tag == 0 && field_name != null) { + int field_ordinal = global::System.Array.BinarySearch(_emptyMessageFieldNames, field_name, global::System.StringComparer.Ordinal); + if(field_ordinal >= 0) + tag = _emptyMessageFieldTags[field_ordinal]; + else { + if (unknownFields == null) { + unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields); + } + ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name); + continue; + } + } + switch (tag) { + case 0: { + throw pb::InvalidProtocolBufferException.InvalidTag(); + } + default: { + if (pb::WireFormat.IsEndGroupTag(tag)) { + if (unknownFields != null) { + this.UnknownFields = unknownFields.Build(); + } + return this; + } + if (unknownFields == null) { + unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields); + } + ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name); + break; + } + } + } + + if (unknownFields != null) { + this.UnknownFields = unknownFields.Build(); + } + return this; + } + + } + static EmptyMessage() { + object.ReferenceEquals(global::DotNetty.Codecs.ProtocolBuffers.Proto.AddressBook.Descriptor, null); } } diff --git a/test/DotNetty.Codecs.ProtocolBuffers.Tests/RoundTripTests.cs b/test/DotNetty.Codecs.ProtocolBuffers.Tests/RoundTripTests.cs index 72e3cd4cb..686501793 100644 --- a/test/DotNetty.Codecs.ProtocolBuffers.Tests/RoundTripTests.cs +++ b/test/DotNetty.Codecs.ProtocolBuffers.Tests/RoundTripTests.cs @@ -205,5 +205,36 @@ public void Run2(Person.Types.PhoneType phoneType, string number, bool isComposi Assert.Equal(phoneNumber.Type, roundTripped.Type); Assert.Equal(phoneNumber.Number, roundTripped.Number); } + + [Fact] + public void EmptyTest() + { + var builder = new EmptyMessage.Builder(); + + IMessageLite protoType = builder.DefaultInstanceForType; + var channel = new EmbeddedChannel( + new ProtobufVarint32FrameDecoder(), + new ProtobufDecoder(protoType, null), + new ProtobufVarint32LengthFieldPrepender(), + new ProtobufEncoder()); + + Assert.True(channel.WriteOutbound(builder.Build())); + var buffer = channel.ReadOutbound(); + Assert.NotNull(buffer); + Assert.True(buffer.ReadableBytes > 0); + + var data = new byte[buffer.ReadableBytes]; + buffer.ReadBytes(data); + + IByteBuffer inputBuffer = Unpooled.WrappedBuffer(data); + + Assert.True(channel.WriteInbound(inputBuffer)); + + var message = channel.ReadInbound(); + Assert.NotNull(message); + Assert.IsType(message); + + Assert.False(channel.Finish()); + } } }