Skip to content

Instantly share code, notes, and snippets.

@swankjesse
Created August 23, 2013 20:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save swankjesse/6323830 to your computer and use it in GitHub Desktop.
Save swankjesse/6323830 to your computer and use it in GitHub Desktop.
Protocol Buffers from Wire 1.0.0.
// Code generated by Wire protocol buffer compiler, do not edit.
// Source file: /Users/jwilson/Square/wire/wire-runtime/src/test/proto/person.proto
package com.squareup.wire.protos.person;
import com.squareup.wire.Message;
import com.squareup.wire.ProtoEnum;
import com.squareup.wire.ProtoField;
import java.util.Collections;
import java.util.List;
import static com.squareup.wire.Message.Datatype.ENUM;
import static com.squareup.wire.Message.Datatype.INT32;
import static com.squareup.wire.Message.Datatype.STRING;
import static com.squareup.wire.Message.Label.REPEATED;
import static com.squareup.wire.Message.Label.REQUIRED;
public final class Person extends Message {
public static final String DEFAULT_NAME = "";
public static final Integer DEFAULT_ID = 0;
public static final String DEFAULT_EMAIL = "";
public static final List<PhoneNumber> DEFAULT_PHONE = Collections.emptyList();
/**
* The customer's full name.
*/
@ProtoField(tag = 1, type = STRING, label = REQUIRED)
public final String name;
/**
* The customer's ID number.
*/
@ProtoField(tag = 2, type = INT32, label = REQUIRED)
public final Integer id;
/**
* Email address for the customer.
*/
@ProtoField(tag = 3, type = STRING)
public final String email;
/**
* A list of the user's phone numbers.
*/
@ProtoField(tag = 4, label = REPEATED)
public final List<PhoneNumber> phone;
private Person(Builder builder) {
super(builder);
this.name = builder.name;
this.id = builder.id;
this.email = builder.email;
this.phone = immutableCopyOf(builder.phone);
}
@Override
public boolean equals(Object other) {
if (!(other instanceof Person)) return false;
Person o = (Person) other;
return equals(name, o.name)
&& equals(id, o.id)
&& equals(email, o.email)
&& equals(phone, o.phone);
}
@Override
public int hashCode() {
int result = hashCode;
if (result == 0) {
result = name != null ? name.hashCode() : 0;
result = result * 37 + (id != null ? id.hashCode() : 0);
result = result * 37 + (email != null ? email.hashCode() : 0);
result = result * 37 + (phone != null ? phone.hashCode() : 0);
hashCode = result;
}
return result;
}
public static final class Builder extends Message.Builder<Person> {
public String name;
public Integer id;
public String email;
public List<PhoneNumber> phone;
public Builder() {
}
public Builder(Person message) {
super(message);
if (message == null) return;
this.name = message.name;
this.id = message.id;
this.email = message.email;
this.phone = copyOf(message.phone);
}
public Builder name(String name) {
this.name = name;
return this;
}
public Builder id(Integer id) {
this.id = id;
return this;
}
public Builder email(String email) {
this.email = email;
return this;
}
public Builder phone(List<PhoneNumber> phone) {
this.phone = phone;
return this;
}
@Override
public Person build() {
checkRequiredFields();
return new Person(this);
}
}
public enum PhoneType {
@ProtoEnum(0)
MOBILE,
@ProtoEnum(1)
HOME,
@ProtoEnum(2)
WORK,
}
public static final class PhoneNumber extends Message {
public static final String DEFAULT_NUMBER = "";
public static final PhoneType DEFAULT_TYPE = PhoneType.HOME;
/**
* The user's phone number.
*/
@ProtoField(tag = 1, type = STRING, label = REQUIRED)
public final String number;
/**
* The type of phone stored here.
*/
@ProtoField(tag = 2, type = ENUM)
public final PhoneType type;
private PhoneNumber(Builder builder) {
super(builder);
this.number = builder.number;
this.type = builder.type;
}
@Override
public boolean equals(Object other) {
if (!(other instanceof PhoneNumber)) return false;
PhoneNumber o = (PhoneNumber) other;
return equals(number, o.number)
&& equals(type, o.type);
}
@Override
public int hashCode() {
int result = hashCode;
if (result == 0) {
result = number != null ? number.hashCode() : 0;
result = result * 37 + (type != null ? type.hashCode() : 0);
hashCode = result;
}
return result;
}
public static final class Builder extends Message.Builder<PhoneNumber> {
public String number;
public PhoneType type;
public Builder() {
}
public Builder(PhoneNumber message) {
super(message);
if (message == null) return;
this.number = message.number;
this.type = message.type;
}
public Builder number(String number) {
this.number = number;
return this;
}
public Builder type(PhoneType type) {
this.type = type;
return this;
}
@Override
public PhoneNumber build() {
checkRequiredFields();
return new PhoneNumber(this);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment