Skip to content

Commit

Permalink
Merge pull request #628 from jtattermusch/csharp_addressbook_update
Browse files Browse the repository at this point in the history
C# addressbook update
  • Loading branch information
jtattermusch committed Jul 21, 2015
2 parents bd3367c + 43b1737 commit c792db5
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 47 deletions.
4 changes: 2 additions & 2 deletions csharp/src/AddressBook/AddPerson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private static Person PromptForAddress(TextReader input, TextWriter output)
break;
}

person.Phone.Add(phoneNumber);
person.Phones.Add(phoneNumber);
}
return person;
}
Expand Down Expand Up @@ -119,7 +119,7 @@ public static int Main(string[] args)
}

// Add an address.
addressBook.Person.Add(PromptForAddress(Console.In, Console.Out));
addressBook.People.Add(PromptForAddress(Console.In, Console.Out));

// Write the new address book back to disk.
using (Stream output = File.OpenWrite(args[0]))
Expand Down
78 changes: 39 additions & 39 deletions csharp/src/AddressBook/Addressbook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,27 @@ public static partial class Addressbook {
static Addressbook() {
byte[] descriptorData = global::System.Convert.FromBase64String(
string.Concat(
"ChFhZGRyZXNzYm9vay5wcm90bxIIdHV0b3JpYWwi1AEKBlBlcnNvbhIMCgRu",
"YW1lGAEgASgJEgoKAmlkGAIgASgFEg0KBWVtYWlsGAMgASgJEisKBXBob25l",
"GAQgAygLMhwudHV0b3JpYWwuUGVyc29uLlBob25lTnVtYmVyGkcKC1Bob25l",
"TnVtYmVyEg4KBm51bWJlchgBIAEoCRIoCgR0eXBlGAIgASgOMhoudHV0b3Jp",
"YWwuUGVyc29uLlBob25lVHlwZSIrCglQaG9uZVR5cGUSCgoGTU9CSUxFEAAS",
"CAoESE9NRRABEggKBFdPUksQAiIvCgtBZGRyZXNzQm9vaxIgCgZwZXJzb24Y",
"ASADKAsyEC50dXRvcmlhbC5QZXJzb25CUAoUY29tLmV4YW1wbGUudHV0b3Jp",
"YWxCEUFkZHJlc3NCb29rUHJvdG9zqgIkR29vZ2xlLlByb3RvYnVmLkV4YW1w",
"bGVzLkFkZHJlc3NCb29rYgZwcm90bzM="));
"ChFhZGRyZXNzYm9vay5wcm90bxIIdHV0b3JpYWwi1QEKBlBlcnNvbhIMCgRu",
"YW1lGAEgASgJEgoKAmlkGAIgASgFEg0KBWVtYWlsGAMgASgJEiwKBnBob25l",
"cxgEIAMoCzIcLnR1dG9yaWFsLlBlcnNvbi5QaG9uZU51bWJlchpHCgtQaG9u",
"ZU51bWJlchIOCgZudW1iZXIYASABKAkSKAoEdHlwZRgCIAEoDjIaLnR1dG9y",
"aWFsLlBlcnNvbi5QaG9uZVR5cGUiKwoJUGhvbmVUeXBlEgoKBk1PQklMRRAA",
"EggKBEhPTUUQARIICgRXT1JLEAIiLwoLQWRkcmVzc0Jvb2sSIAoGcGVvcGxl",
"GAEgAygLMhAudHV0b3JpYWwuUGVyc29uQlAKFGNvbS5leGFtcGxlLnR1dG9y",
"aWFsQhFBZGRyZXNzQm9va1Byb3Rvc6oCJEdvb2dsZS5Qcm90b2J1Zi5FeGFt",
"cGxlcy5BZGRyZXNzQm9va2IGcHJvdG8z"));
descriptor = pbr::FileDescriptor.InternalBuildGeneratedFileFrom(descriptorData,
new pbr::FileDescriptor[] {
});
internal__static_tutorial_Person__FieldAccessorTable =
new pbr::FieldAccessorTable(typeof(global::Google.Protobuf.Examples.AddressBook.Person), descriptor.MessageTypes[0],
new string[] { "Name", "Id", "Email", "Phone", }, new string[] { });
new string[] { "Name", "Id", "Email", "Phones", }, new string[] { });
internal__static_tutorial_Person_PhoneNumber__FieldAccessorTable =
new pbr::FieldAccessorTable(typeof(global::Google.Protobuf.Examples.AddressBook.Person.Types.PhoneNumber), descriptor.MessageTypes[0].NestedTypes[0],
new string[] { "Number", "Type", }, new string[] { });
internal__static_tutorial_AddressBook__FieldAccessorTable =
new pbr::FieldAccessorTable(typeof(global::Google.Protobuf.Examples.AddressBook.AddressBook), descriptor.MessageTypes[1],
new string[] { "Person", }, new string[] { });
new string[] { "People", }, new string[] { });
}
#endregion

Expand All @@ -57,7 +57,7 @@ public sealed partial class Person : pb::IMessage<Person> {
private static readonly pb::MessageParser<Person> _parser = new pb::MessageParser<Person>(() => new Person());
public static pb::MessageParser<Person> Parser { get { return _parser; } }

private static readonly string[] _fieldNames = new string[] { "email", "id", "name", "phone" };
private static readonly string[] _fieldNames = new string[] { "email", "id", "name", "phones" };
private static readonly uint[] _fieldTags = new uint[] { 26, 16, 10, 34 };
public static pbr::MessageDescriptor Descriptor {
get { return global::Google.Protobuf.Examples.AddressBook.Addressbook.Descriptor.MessageTypes[0]; }
Expand All @@ -80,7 +80,7 @@ public Person(Person other) : this() {
name_ = other.name_;
id_ = other.id_;
email_ = other.email_;
phone_ = other.phone_.Clone();
phones_ = other.phones_.Clone();
}

public Person Clone() {
Expand All @@ -92,7 +92,7 @@ public void Freeze() {
return;
}
_frozen = true;
phone_.Freeze();
phones_.Freeze();
}

public const int NameFieldNumber = 1;
Expand Down Expand Up @@ -125,12 +125,12 @@ public string Email {
}
}

public const int PhoneFieldNumber = 4;
private static readonly pb::FieldCodec<global::Google.Protobuf.Examples.AddressBook.Person.Types.PhoneNumber> _repeated_phone_codec
public const int PhonesFieldNumber = 4;
private static readonly pb::FieldCodec<global::Google.Protobuf.Examples.AddressBook.Person.Types.PhoneNumber> _repeated_phones_codec
= pb::FieldCodec.ForMessage(34, global::Google.Protobuf.Examples.AddressBook.Person.Types.PhoneNumber.Parser);
private readonly pbc::RepeatedField<global::Google.Protobuf.Examples.AddressBook.Person.Types.PhoneNumber> phone_ = new pbc::RepeatedField<global::Google.Protobuf.Examples.AddressBook.Person.Types.PhoneNumber>();
public pbc::RepeatedField<global::Google.Protobuf.Examples.AddressBook.Person.Types.PhoneNumber> Phone {
get { return phone_; }
private readonly pbc::RepeatedField<global::Google.Protobuf.Examples.AddressBook.Person.Types.PhoneNumber> phones_ = new pbc::RepeatedField<global::Google.Protobuf.Examples.AddressBook.Person.Types.PhoneNumber>();
public pbc::RepeatedField<global::Google.Protobuf.Examples.AddressBook.Person.Types.PhoneNumber> Phones {
get { return phones_; }
}

public override bool Equals(object other) {
Expand All @@ -147,7 +147,7 @@ public bool Equals(Person other) {
if (Name != other.Name) return false;
if (Id != other.Id) return false;
if (Email != other.Email) return false;
if(!phone_.Equals(other.phone_)) return false;
if(!phones_.Equals(other.phones_)) return false;
return true;
}

Expand All @@ -156,7 +156,7 @@ public override int GetHashCode() {
if (Name.Length != 0) hash ^= Name.GetHashCode();
if (Id != 0) hash ^= Id.GetHashCode();
if (Email.Length != 0) hash ^= Email.GetHashCode();
hash ^= phone_.GetHashCode();
hash ^= phones_.GetHashCode();
return hash;
}

Expand All @@ -177,7 +177,7 @@ public void WriteTo(pb::CodedOutputStream output) {
output.WriteRawTag(26);
output.WriteString(Email);
}
phone_.WriteTo(output, _repeated_phone_codec);
phones_.WriteTo(output, _repeated_phones_codec);
}

public int CalculateSize() {
Expand All @@ -191,7 +191,7 @@ public int CalculateSize() {
if (Email.Length != 0) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(Email);
}
size += phone_.CalculateSize(_repeated_phone_codec);
size += phones_.CalculateSize(_repeated_phones_codec);
return size;
}

Expand All @@ -208,7 +208,7 @@ public void MergeFrom(Person other) {
if (other.Email.Length != 0) {
Email = other.Email;
}
phone_.Add(other.phone_);
phones_.Add(other.phones_);
}

public void MergeFrom(pb::CodedInputStream input) {
Expand All @@ -235,7 +235,7 @@ public void MergeFrom(pb::CodedInputStream input) {
break;
}
case 34: {
phone_.AddEntriesFrom(input, _repeated_phone_codec);
phones_.AddEntriesFrom(input, _repeated_phones_codec);
break;
}
}
Expand Down Expand Up @@ -407,7 +407,7 @@ public sealed partial class AddressBook : pb::IMessage<AddressBook> {
private static readonly pb::MessageParser<AddressBook> _parser = new pb::MessageParser<AddressBook>(() => new AddressBook());
public static pb::MessageParser<AddressBook> Parser { get { return _parser; } }

private static readonly string[] _fieldNames = new string[] { "person" };
private static readonly string[] _fieldNames = new string[] { "people" };
private static readonly uint[] _fieldTags = new uint[] { 10 };
public static pbr::MessageDescriptor Descriptor {
get { return global::Google.Protobuf.Examples.AddressBook.Addressbook.Descriptor.MessageTypes[1]; }
Expand All @@ -427,7 +427,7 @@ public AddressBook() {
partial void OnConstruction();

public AddressBook(AddressBook other) : this() {
person_ = other.person_.Clone();
people_ = other.people_.Clone();
}

public AddressBook Clone() {
Expand All @@ -439,15 +439,15 @@ public void Freeze() {
return;
}
_frozen = true;
person_.Freeze();
people_.Freeze();
}

public const int PersonFieldNumber = 1;
private static readonly pb::FieldCodec<global::Google.Protobuf.Examples.AddressBook.Person> _repeated_person_codec
public const int PeopleFieldNumber = 1;
private static readonly pb::FieldCodec<global::Google.Protobuf.Examples.AddressBook.Person> _repeated_people_codec
= pb::FieldCodec.ForMessage(10, global::Google.Protobuf.Examples.AddressBook.Person.Parser);
private readonly pbc::RepeatedField<global::Google.Protobuf.Examples.AddressBook.Person> person_ = new pbc::RepeatedField<global::Google.Protobuf.Examples.AddressBook.Person>();
public pbc::RepeatedField<global::Google.Protobuf.Examples.AddressBook.Person> Person {
get { return person_; }
private readonly pbc::RepeatedField<global::Google.Protobuf.Examples.AddressBook.Person> people_ = new pbc::RepeatedField<global::Google.Protobuf.Examples.AddressBook.Person>();
public pbc::RepeatedField<global::Google.Protobuf.Examples.AddressBook.Person> People {
get { return people_; }
}

public override bool Equals(object other) {
Expand All @@ -461,13 +461,13 @@ public bool Equals(AddressBook other) {
if (ReferenceEquals(other, this)) {
return true;
}
if(!person_.Equals(other.person_)) return false;
if(!people_.Equals(other.people_)) return false;
return true;
}

public override int GetHashCode() {
int hash = 1;
hash ^= person_.GetHashCode();
hash ^= people_.GetHashCode();
return hash;
}

Expand All @@ -476,20 +476,20 @@ public override string ToString() {
}

public void WriteTo(pb::CodedOutputStream output) {
person_.WriteTo(output, _repeated_person_codec);
people_.WriteTo(output, _repeated_people_codec);
}

public int CalculateSize() {
int size = 0;
size += person_.CalculateSize(_repeated_person_codec);
size += people_.CalculateSize(_repeated_people_codec);
return size;
}

public void MergeFrom(AddressBook other) {
if (other == null) {
return;
}
person_.Add(other.person_);
people_.Add(other.people_);
}

public void MergeFrom(pb::CodedInputStream input) {
Expand All @@ -504,7 +504,7 @@ public void MergeFrom(pb::CodedInputStream input) {
}
break;
case 10: {
person_.AddEntriesFrom(input, _repeated_person_codec);
people_.AddEntriesFrom(input, _repeated_people_codec);
break;
}
}
Expand Down
4 changes: 2 additions & 2 deletions csharp/src/AddressBook/ListPeople.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ internal class ListPeople
/// </summary>
private static void Print(AddressBook addressBook)
{
foreach (Person person in addressBook.Person)
foreach (Person person in addressBook.People)
{
Console.WriteLine("Person ID: {0}", person.Id);
Console.WriteLine(" Name: {0}", person.Name);
Expand All @@ -51,7 +51,7 @@ private static void Print(AddressBook addressBook)
Console.WriteLine(" E-mail address: {0}", person.Email);
}

foreach (Person.Types.PhoneNumber phoneNumber in person.Phone)
foreach (Person.Types.PhoneNumber phoneNumber in person.Phones)
{
switch (phoneNumber.Type)
{
Expand Down
4 changes: 2 additions & 2 deletions csharp/src/AddressBook/SampleUsage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private static void Main()
Id = 1,
Name = "Foo",
Email = "foo@bar",
Phone = { new Person.Types.PhoneNumber { Number = "555-1212" } }
Phones = { new Person.Types.PhoneNumber { Number = "555-1212" } }
};
using (MemoryStream stream = new MemoryStream())
{
Expand All @@ -61,7 +61,7 @@ private static void Main()
// And read the address book back again
AddressBook restored = AddressBook.Parser.ParseFrom(bytes);
// The message performs a deep-comparison on equality:
if (restored.Person.Count != 1 || !person.Equals(restored.Person[0]))
if (restored.People.Count != 1 || !person.Equals(restored.People[0]))
{
throw new ApplicationException("There is a bad person in here!");
}
Expand Down
4 changes: 2 additions & 2 deletions examples/addressbook.proto
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ message Person {
PhoneType type = 2;
}

repeated PhoneNumber phone = 4;
repeated PhoneNumber phones = 4;
}

// Our address book file is just one of these.
message AddressBook {
repeated Person person = 1;
repeated Person people = 1;
}

0 comments on commit c792db5

Please sign in to comment.