diff --git a/protobuf/codec.h b/protobuf/codec.h index a42130d..09ebf7e 100644 --- a/protobuf/codec.h +++ b/protobuf/codec.h @@ -49,7 +49,7 @@ inline std::string encode(const google::protobuf::Message& message) if (succeed) { const char* begin = result.c_str() + kHeaderLen; - int32_t checkSum = adler32(0, reinterpret_cast(begin), result.size()-kHeaderLen); + int32_t checkSum = adler32(1, reinterpret_cast(begin), result.size()-kHeaderLen); int32_t be32 = ::htonl(checkSum); result.append(reinterpret_cast(&be32), sizeof be32); @@ -105,7 +105,7 @@ inline google::protobuf::Message* decode(const std::string& buf) { int32_t expectedCheckSum = asInt32(buf.c_str() + buf.size() - kHeaderLen); const char* begin = buf.c_str(); - int32_t checkSum = adler32(0, reinterpret_cast(begin), len-kHeaderLen); + int32_t checkSum = adler32(1, reinterpret_cast(begin), len-kHeaderLen); if (checkSum == expectedCheckSum) { int32_t nameLen = asInt32(buf.c_str()); diff --git a/protobuf/query.proto b/protobuf/query.proto index d2cfced..98dfac9 100644 --- a/protobuf/query.proto +++ b/protobuf/query.proto @@ -1,6 +1,7 @@ package muduo; -option java_outer_classname = "Proto"; +option java_package = "muduo.codec.tests"; +option java_outer_classname = "QueryProtos"; message Query { required int64 id = 1; diff --git a/protorpc/muduo/codec/ProtobufDecoder.java b/protorpc/muduo/codec/ProtobufDecoder.java new file mode 100644 index 0000000..65451d3 --- /dev/null +++ b/protorpc/muduo/codec/ProtobufDecoder.java @@ -0,0 +1,58 @@ +package muduo.codec; + +import java.nio.charset.Charset; +import java.util.HashMap; +import java.util.Map; +import java.util.zip.Adler32; + +import org.jboss.netty.buffer.ChannelBuffer; +import org.jboss.netty.channel.Channel; +import org.jboss.netty.channel.ChannelHandler.Sharable; +import org.jboss.netty.channel.ChannelHandlerContext; +import org.jboss.netty.handler.codec.oneone.OneToOneDecoder; + +import com.google.protobuf.Message; + +@Sharable +public class ProtobufDecoder extends OneToOneDecoder { + + private Map knownTypes = new HashMap(); + + @Override + public Object decode(ChannelHandlerContext ctx, Channel channel, Object obj) + throws Exception { + if (!(obj instanceof ChannelBuffer)) { + return obj; + } + ChannelBuffer buffer = (ChannelBuffer) obj; + if (buffer.readableBytes() >= 10 && checksum(buffer)) { + int nameLen = buffer.readInt(); + String typeName = buffer.toString(buffer.readerIndex(), nameLen - 1, + Charset.defaultCharset()); + buffer.readerIndex(buffer.readerIndex() + nameLen); + Message prototype = knownTypes.get(typeName); + if (prototype != null) { + return prototype.newBuilderForType().mergeFrom(buffer.array(), + buffer.arrayOffset() + buffer.readerIndex(), + buffer.readableBytes() - 4).build(); + } + } + return obj; + } + + private boolean checksum(ChannelBuffer buffer) { + Adler32 adler32 = new Adler32(); + adler32.update(buffer.array(), + buffer.arrayOffset() + buffer.readerIndex(), + buffer.readableBytes() - 4); + buffer.markReaderIndex(); + buffer.readerIndex(buffer.writerIndex() - 4); + int checksum = buffer.readInt(); + buffer.resetReaderIndex(); + return checksum == (int) adler32.getValue(); + } + + public void addMessageType(Message message) { + knownTypes.put(message.getDescriptorForType().getFullName(), message); + } +} diff --git a/protorpc/muduo/codec/ProtobufEncoder.java b/protorpc/muduo/codec/ProtobufEncoder.java new file mode 100644 index 0000000..2b61f6f --- /dev/null +++ b/protorpc/muduo/codec/ProtobufEncoder.java @@ -0,0 +1,42 @@ +package muduo.codec; + +import java.util.zip.Adler32; + +import org.jboss.netty.buffer.BigEndianHeapChannelBuffer; +import org.jboss.netty.buffer.ChannelBuffer; +import org.jboss.netty.channel.Channel; +import org.jboss.netty.channel.ChannelHandler.Sharable; +import org.jboss.netty.channel.ChannelHandlerContext; +import org.jboss.netty.handler.codec.oneone.OneToOneEncoder; + +import com.google.protobuf.Message; + +@Sharable +public class ProtobufEncoder extends OneToOneEncoder { + + public ProtobufEncoder() { + super(); + } + + @Override + public Object encode(ChannelHandlerContext ctx, Channel channel, Object obj) + throws Exception { + if (!(obj instanceof Message)) { + return obj; + } + Message message = (Message) obj; + String name = message.getDescriptorForType().getFullName(); + int size = message.getSerializedSize(); + ChannelBuffer buffer = new BigEndianHeapChannelBuffer(4 + name.length() + 1 + size + 4); + buffer.writeInt(name.length() + 1); + buffer.writeBytes(name.getBytes()); + buffer.writeZero(1); + buffer.writeBytes(message.toByteArray()); + + Adler32 checksum = new Adler32(); + checksum.update(buffer.array(), buffer.arrayOffset(), buffer.readableBytes()); + buffer.writeInt((int) checksum.getValue()); + + return buffer; + } +} diff --git a/protorpc/muduo/codec/tests/CodecTest.java b/protorpc/muduo/codec/tests/CodecTest.java new file mode 100644 index 0000000..47758fe --- /dev/null +++ b/protorpc/muduo/codec/tests/CodecTest.java @@ -0,0 +1,71 @@ +package muduo.codec.tests; + +import static org.junit.Assert.assertEquals; +import muduo.codec.ProtobufDecoder; +import muduo.codec.ProtobufEncoder; +import muduo.codec.tests.QueryProtos.Empty; +import muduo.codec.tests.QueryProtos.Query; + +import org.jboss.netty.buffer.BigEndianHeapChannelBuffer; +import org.jboss.netty.buffer.ChannelBuffer; +import org.junit.Test; + +import com.google.protobuf.Message; + +public class CodecTest { + + @Test + public void testEncoderEmpty() throws Exception { + ProtobufEncoder encoder = new ProtobufEncoder(); + Empty empty = Empty.getDefaultInstance(); + encoder.encode(null, null, empty); + } + + @Test + public void testDecodeEmpty() throws Exception { + ProtobufEncoder encoder = new ProtobufEncoder(); + Empty empty = Empty.getDefaultInstance(); + ChannelBuffer buf = (ChannelBuffer) encoder.encode(null, null, empty); + + ProtobufDecoder decoder = new ProtobufDecoder(); + decoder.addMessageType(Empty.getDefaultInstance()); + Message message = (Message) decoder.decode(null, null, buf); + assertEquals(empty, message); + } + + @Test + public void testQuery() throws Exception { + ProtobufEncoder encoder = new ProtobufEncoder(); + Query query = Query.newBuilder() + .setId(1) + .setQuestioner("Chen Shuo") + .addQuestion("Running?") + .build(); + ChannelBuffer buf = (ChannelBuffer) encoder.encode(null, null, query); + + ProtobufDecoder decoder = new ProtobufDecoder(); + decoder.addMessageType(Query.getDefaultInstance()); + Message message = (Message) decoder.decode(null, null, buf); + assertEquals(query, message); + } + + @Test + public void testQuery2() throws Exception { + ProtobufEncoder encoder = new ProtobufEncoder(); + Query query = Query.newBuilder() + .setId(1) + .setQuestioner("Chen Shuo") + .addQuestion("Running?") + .build(); + ChannelBuffer buf = (ChannelBuffer) encoder.encode(null, null, query); + ChannelBuffer buf2 = new BigEndianHeapChannelBuffer(buf.readableBytes() + 8); + buf2.writeInt(123); + buf2.writeBytes(buf); + + buf2.readInt(); + ProtobufDecoder decoder = new ProtobufDecoder(); + decoder.addMessageType(Query.getDefaultInstance()); + Message message = (Message) decoder.decode(null, null, buf2); + assertEquals(query, message); + } +} diff --git a/protorpc/muduo/codec/tests/QueryProtos.java b/protorpc/muduo/codec/tests/QueryProtos.java new file mode 100644 index 0000000..e25e78f --- /dev/null +++ b/protorpc/muduo/codec/tests/QueryProtos.java @@ -0,0 +1,1633 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: query.proto + +package muduo.codec.tests; + +public final class QueryProtos { + private QueryProtos() {} + public static void registerAllExtensions( + com.google.protobuf.ExtensionRegistry registry) { + } + public interface QueryOrBuilder + extends com.google.protobuf.MessageOrBuilder { + + // required int64 id = 1; + boolean hasId(); + long getId(); + + // required string questioner = 2; + boolean hasQuestioner(); + String getQuestioner(); + + // repeated string question = 3; + java.util.List getQuestionList(); + int getQuestionCount(); + String getQuestion(int index); + } + public static final class Query extends + com.google.protobuf.GeneratedMessage + implements QueryOrBuilder { + // Use Query.newBuilder() to construct. + private Query(Builder builder) { + super(builder); + } + private Query(boolean noInit) {} + + private static final Query defaultInstance; + public static Query getDefaultInstance() { + return defaultInstance; + } + + public Query getDefaultInstanceForType() { + return defaultInstance; + } + + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return muduo.codec.tests.QueryProtos.internal_static_muduo_Query_descriptor; + } + + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return muduo.codec.tests.QueryProtos.internal_static_muduo_Query_fieldAccessorTable; + } + + private int bitField0_; + // required int64 id = 1; + public static final int ID_FIELD_NUMBER = 1; + private long id_; + public boolean hasId() { + return ((bitField0_ & 0x00000001) == 0x00000001); + } + public long getId() { + return id_; + } + + // required string questioner = 2; + public static final int QUESTIONER_FIELD_NUMBER = 2; + private Object questioner_; + public boolean hasQuestioner() { + return ((bitField0_ & 0x00000002) == 0x00000002); + } + public String getQuestioner() { + Object ref = questioner_; + if (ref instanceof String) { + return (String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + String s = bs.toStringUtf8(); + if (com.google.protobuf.Internal.isValidUtf8(bs)) { + questioner_ = s; + } + return s; + } + } + private com.google.protobuf.ByteString getQuestionerBytes() { + Object ref = questioner_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((String) ref); + questioner_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + // repeated string question = 3; + public static final int QUESTION_FIELD_NUMBER = 3; + private com.google.protobuf.LazyStringList question_; + public java.util.List + getQuestionList() { + return question_; + } + public int getQuestionCount() { + return question_.size(); + } + public String getQuestion(int index) { + return question_.get(index); + } + + private void initFields() { + id_ = 0L; + questioner_ = ""; + question_ = com.google.protobuf.LazyStringArrayList.EMPTY; + } + private byte memoizedIsInitialized = -1; + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized != -1) return isInitialized == 1; + + if (!hasId()) { + memoizedIsInitialized = 0; + return false; + } + if (!hasQuestioner()) { + memoizedIsInitialized = 0; + return false; + } + memoizedIsInitialized = 1; + return true; + } + + public void writeTo(com.google.protobuf.CodedOutputStream output) + throws java.io.IOException { + getSerializedSize(); + if (((bitField0_ & 0x00000001) == 0x00000001)) { + output.writeInt64(1, id_); + } + if (((bitField0_ & 0x00000002) == 0x00000002)) { + output.writeBytes(2, getQuestionerBytes()); + } + for (int i = 0; i < question_.size(); i++) { + output.writeBytes(3, question_.getByteString(i)); + } + getUnknownFields().writeTo(output); + } + + private int memoizedSerializedSize = -1; + public int getSerializedSize() { + int size = memoizedSerializedSize; + if (size != -1) return size; + + size = 0; + if (((bitField0_ & 0x00000001) == 0x00000001)) { + size += com.google.protobuf.CodedOutputStream + .computeInt64Size(1, id_); + } + if (((bitField0_ & 0x00000002) == 0x00000002)) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(2, getQuestionerBytes()); + } + { + int dataSize = 0; + for (int i = 0; i < question_.size(); i++) { + dataSize += com.google.protobuf.CodedOutputStream + .computeBytesSizeNoTag(question_.getByteString(i)); + } + size += dataSize; + size += 1 * getQuestionList().size(); + } + size += getUnknownFields().getSerializedSize(); + memoizedSerializedSize = size; + return size; + } + + @java.lang.Override + protected Object writeReplace() throws java.io.ObjectStreamException { + return super.writeReplace(); + } + + public static muduo.codec.tests.QueryProtos.Query parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return newBuilder().mergeFrom(data).buildParsed(); + } + public static muduo.codec.tests.QueryProtos.Query parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return newBuilder().mergeFrom(data, extensionRegistry) + .buildParsed(); + } + public static muduo.codec.tests.QueryProtos.Query parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return newBuilder().mergeFrom(data).buildParsed(); + } + public static muduo.codec.tests.QueryProtos.Query parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return newBuilder().mergeFrom(data, extensionRegistry) + .buildParsed(); + } + public static muduo.codec.tests.QueryProtos.Query parseFrom(java.io.InputStream input) + throws java.io.IOException { + return newBuilder().mergeFrom(input).buildParsed(); + } + public static muduo.codec.tests.QueryProtos.Query parseFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return newBuilder().mergeFrom(input, extensionRegistry) + .buildParsed(); + } + public static muduo.codec.tests.QueryProtos.Query parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + Builder builder = newBuilder(); + if (builder.mergeDelimitedFrom(input)) { + return builder.buildParsed(); + } else { + return null; + } + } + public static muduo.codec.tests.QueryProtos.Query parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + Builder builder = newBuilder(); + if (builder.mergeDelimitedFrom(input, extensionRegistry)) { + return builder.buildParsed(); + } else { + return null; + } + } + public static muduo.codec.tests.QueryProtos.Query parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return newBuilder().mergeFrom(input).buildParsed(); + } + public static muduo.codec.tests.QueryProtos.Query parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return newBuilder().mergeFrom(input, extensionRegistry) + .buildParsed(); + } + + public static Builder newBuilder() { return Builder.create(); } + public Builder newBuilderForType() { return newBuilder(); } + public static Builder newBuilder(muduo.codec.tests.QueryProtos.Query prototype) { + return newBuilder().mergeFrom(prototype); + } + public Builder toBuilder() { return newBuilder(this); } + + @java.lang.Override + protected Builder newBuilderForType( + com.google.protobuf.GeneratedMessage.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + public static final class Builder extends + com.google.protobuf.GeneratedMessage.Builder + implements muduo.codec.tests.QueryProtos.QueryOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return muduo.codec.tests.QueryProtos.internal_static_muduo_Query_descriptor; + } + + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return muduo.codec.tests.QueryProtos.internal_static_muduo_Query_fieldAccessorTable; + } + + // Construct using muduo.codec.tests.QueryProtos.Query.newBuilder() + private Builder() { + maybeForceBuilderInitialization(); + } + + private Builder(BuilderParent parent) { + super(parent); + maybeForceBuilderInitialization(); + } + private void maybeForceBuilderInitialization() { + if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { + } + } + private static Builder create() { + return new Builder(); + } + + public Builder clear() { + super.clear(); + id_ = 0L; + bitField0_ = (bitField0_ & ~0x00000001); + questioner_ = ""; + bitField0_ = (bitField0_ & ~0x00000002); + question_ = com.google.protobuf.LazyStringArrayList.EMPTY; + bitField0_ = (bitField0_ & ~0x00000004); + return this; + } + + public Builder clone() { + return create().mergeFrom(buildPartial()); + } + + public com.google.protobuf.Descriptors.Descriptor + getDescriptorForType() { + return muduo.codec.tests.QueryProtos.Query.getDescriptor(); + } + + public muduo.codec.tests.QueryProtos.Query getDefaultInstanceForType() { + return muduo.codec.tests.QueryProtos.Query.getDefaultInstance(); + } + + public muduo.codec.tests.QueryProtos.Query build() { + muduo.codec.tests.QueryProtos.Query result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + private muduo.codec.tests.QueryProtos.Query buildParsed() + throws com.google.protobuf.InvalidProtocolBufferException { + muduo.codec.tests.QueryProtos.Query result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException( + result).asInvalidProtocolBufferException(); + } + return result; + } + + public muduo.codec.tests.QueryProtos.Query buildPartial() { + muduo.codec.tests.QueryProtos.Query result = new muduo.codec.tests.QueryProtos.Query(this); + int from_bitField0_ = bitField0_; + int to_bitField0_ = 0; + if (((from_bitField0_ & 0x00000001) == 0x00000001)) { + to_bitField0_ |= 0x00000001; + } + result.id_ = id_; + if (((from_bitField0_ & 0x00000002) == 0x00000002)) { + to_bitField0_ |= 0x00000002; + } + result.questioner_ = questioner_; + if (((bitField0_ & 0x00000004) == 0x00000004)) { + question_ = new com.google.protobuf.UnmodifiableLazyStringList( + question_); + bitField0_ = (bitField0_ & ~0x00000004); + } + result.question_ = question_; + result.bitField0_ = to_bitField0_; + onBuilt(); + return result; + } + + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof muduo.codec.tests.QueryProtos.Query) { + return mergeFrom((muduo.codec.tests.QueryProtos.Query)other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(muduo.codec.tests.QueryProtos.Query other) { + if (other == muduo.codec.tests.QueryProtos.Query.getDefaultInstance()) return this; + if (other.hasId()) { + setId(other.getId()); + } + if (other.hasQuestioner()) { + setQuestioner(other.getQuestioner()); + } + if (!other.question_.isEmpty()) { + if (question_.isEmpty()) { + question_ = other.question_; + bitField0_ = (bitField0_ & ~0x00000004); + } else { + ensureQuestionIsMutable(); + question_.addAll(other.question_); + } + onChanged(); + } + this.mergeUnknownFields(other.getUnknownFields()); + return this; + } + + public final boolean isInitialized() { + if (!hasId()) { + + return false; + } + if (!hasQuestioner()) { + + return false; + } + return true; + } + + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + com.google.protobuf.UnknownFieldSet.Builder unknownFields = + com.google.protobuf.UnknownFieldSet.newBuilder( + this.getUnknownFields()); + while (true) { + int tag = input.readTag(); + switch (tag) { + case 0: + this.setUnknownFields(unknownFields.build()); + onChanged(); + return this; + default: { + if (!parseUnknownField(input, unknownFields, + extensionRegistry, tag)) { + this.setUnknownFields(unknownFields.build()); + onChanged(); + return this; + } + break; + } + case 8: { + bitField0_ |= 0x00000001; + id_ = input.readInt64(); + break; + } + case 18: { + bitField0_ |= 0x00000002; + questioner_ = input.readBytes(); + break; + } + case 26: { + ensureQuestionIsMutable(); + question_.add(input.readBytes()); + break; + } + } + } + } + + private int bitField0_; + + // required int64 id = 1; + private long id_ ; + public boolean hasId() { + return ((bitField0_ & 0x00000001) == 0x00000001); + } + public long getId() { + return id_; + } + public Builder setId(long value) { + bitField0_ |= 0x00000001; + id_ = value; + onChanged(); + return this; + } + public Builder clearId() { + bitField0_ = (bitField0_ & ~0x00000001); + id_ = 0L; + onChanged(); + return this; + } + + // required string questioner = 2; + private Object questioner_ = ""; + public boolean hasQuestioner() { + return ((bitField0_ & 0x00000002) == 0x00000002); + } + public String getQuestioner() { + Object ref = questioner_; + if (!(ref instanceof String)) { + String s = ((com.google.protobuf.ByteString) ref).toStringUtf8(); + questioner_ = s; + return s; + } else { + return (String) ref; + } + } + public Builder setQuestioner(String value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000002; + questioner_ = value; + onChanged(); + return this; + } + public Builder clearQuestioner() { + bitField0_ = (bitField0_ & ~0x00000002); + questioner_ = getDefaultInstance().getQuestioner(); + onChanged(); + return this; + } + void setQuestioner(com.google.protobuf.ByteString value) { + bitField0_ |= 0x00000002; + questioner_ = value; + onChanged(); + } + + // repeated string question = 3; + private com.google.protobuf.LazyStringList question_ = com.google.protobuf.LazyStringArrayList.EMPTY; + private void ensureQuestionIsMutable() { + if (!((bitField0_ & 0x00000004) == 0x00000004)) { + question_ = new com.google.protobuf.LazyStringArrayList(question_); + bitField0_ |= 0x00000004; + } + } + public java.util.List + getQuestionList() { + return java.util.Collections.unmodifiableList(question_); + } + public int getQuestionCount() { + return question_.size(); + } + public String getQuestion(int index) { + return question_.get(index); + } + public Builder setQuestion( + int index, String value) { + if (value == null) { + throw new NullPointerException(); + } + ensureQuestionIsMutable(); + question_.set(index, value); + onChanged(); + return this; + } + public Builder addQuestion(String value) { + if (value == null) { + throw new NullPointerException(); + } + ensureQuestionIsMutable(); + question_.add(value); + onChanged(); + return this; + } + public Builder addAllQuestion( + java.lang.Iterable values) { + ensureQuestionIsMutable(); + super.addAll(values, question_); + onChanged(); + return this; + } + public Builder clearQuestion() { + question_ = com.google.protobuf.LazyStringArrayList.EMPTY; + bitField0_ = (bitField0_ & ~0x00000004); + onChanged(); + return this; + } + void addQuestion(com.google.protobuf.ByteString value) { + ensureQuestionIsMutable(); + question_.add(value); + onChanged(); + } + + // @@protoc_insertion_point(builder_scope:muduo.Query) + } + + static { + defaultInstance = new Query(true); + defaultInstance.initFields(); + } + + // @@protoc_insertion_point(class_scope:muduo.Query) + } + + public interface AnswerOrBuilder + extends com.google.protobuf.MessageOrBuilder { + + // required int64 id = 1; + boolean hasId(); + long getId(); + + // required string questioner = 2; + boolean hasQuestioner(); + String getQuestioner(); + + // required string answerer = 3; + boolean hasAnswerer(); + String getAnswerer(); + + // repeated string solution = 4; + java.util.List getSolutionList(); + int getSolutionCount(); + String getSolution(int index); + } + public static final class Answer extends + com.google.protobuf.GeneratedMessage + implements AnswerOrBuilder { + // Use Answer.newBuilder() to construct. + private Answer(Builder builder) { + super(builder); + } + private Answer(boolean noInit) {} + + private static final Answer defaultInstance; + public static Answer getDefaultInstance() { + return defaultInstance; + } + + public Answer getDefaultInstanceForType() { + return defaultInstance; + } + + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return muduo.codec.tests.QueryProtos.internal_static_muduo_Answer_descriptor; + } + + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return muduo.codec.tests.QueryProtos.internal_static_muduo_Answer_fieldAccessorTable; + } + + private int bitField0_; + // required int64 id = 1; + public static final int ID_FIELD_NUMBER = 1; + private long id_; + public boolean hasId() { + return ((bitField0_ & 0x00000001) == 0x00000001); + } + public long getId() { + return id_; + } + + // required string questioner = 2; + public static final int QUESTIONER_FIELD_NUMBER = 2; + private Object questioner_; + public boolean hasQuestioner() { + return ((bitField0_ & 0x00000002) == 0x00000002); + } + public String getQuestioner() { + Object ref = questioner_; + if (ref instanceof String) { + return (String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + String s = bs.toStringUtf8(); + if (com.google.protobuf.Internal.isValidUtf8(bs)) { + questioner_ = s; + } + return s; + } + } + private com.google.protobuf.ByteString getQuestionerBytes() { + Object ref = questioner_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((String) ref); + questioner_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + // required string answerer = 3; + public static final int ANSWERER_FIELD_NUMBER = 3; + private Object answerer_; + public boolean hasAnswerer() { + return ((bitField0_ & 0x00000004) == 0x00000004); + } + public String getAnswerer() { + Object ref = answerer_; + if (ref instanceof String) { + return (String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + String s = bs.toStringUtf8(); + if (com.google.protobuf.Internal.isValidUtf8(bs)) { + answerer_ = s; + } + return s; + } + } + private com.google.protobuf.ByteString getAnswererBytes() { + Object ref = answerer_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((String) ref); + answerer_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + // repeated string solution = 4; + public static final int SOLUTION_FIELD_NUMBER = 4; + private com.google.protobuf.LazyStringList solution_; + public java.util.List + getSolutionList() { + return solution_; + } + public int getSolutionCount() { + return solution_.size(); + } + public String getSolution(int index) { + return solution_.get(index); + } + + private void initFields() { + id_ = 0L; + questioner_ = ""; + answerer_ = ""; + solution_ = com.google.protobuf.LazyStringArrayList.EMPTY; + } + private byte memoizedIsInitialized = -1; + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized != -1) return isInitialized == 1; + + if (!hasId()) { + memoizedIsInitialized = 0; + return false; + } + if (!hasQuestioner()) { + memoizedIsInitialized = 0; + return false; + } + if (!hasAnswerer()) { + memoizedIsInitialized = 0; + return false; + } + memoizedIsInitialized = 1; + return true; + } + + public void writeTo(com.google.protobuf.CodedOutputStream output) + throws java.io.IOException { + getSerializedSize(); + if (((bitField0_ & 0x00000001) == 0x00000001)) { + output.writeInt64(1, id_); + } + if (((bitField0_ & 0x00000002) == 0x00000002)) { + output.writeBytes(2, getQuestionerBytes()); + } + if (((bitField0_ & 0x00000004) == 0x00000004)) { + output.writeBytes(3, getAnswererBytes()); + } + for (int i = 0; i < solution_.size(); i++) { + output.writeBytes(4, solution_.getByteString(i)); + } + getUnknownFields().writeTo(output); + } + + private int memoizedSerializedSize = -1; + public int getSerializedSize() { + int size = memoizedSerializedSize; + if (size != -1) return size; + + size = 0; + if (((bitField0_ & 0x00000001) == 0x00000001)) { + size += com.google.protobuf.CodedOutputStream + .computeInt64Size(1, id_); + } + if (((bitField0_ & 0x00000002) == 0x00000002)) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(2, getQuestionerBytes()); + } + if (((bitField0_ & 0x00000004) == 0x00000004)) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(3, getAnswererBytes()); + } + { + int dataSize = 0; + for (int i = 0; i < solution_.size(); i++) { + dataSize += com.google.protobuf.CodedOutputStream + .computeBytesSizeNoTag(solution_.getByteString(i)); + } + size += dataSize; + size += 1 * getSolutionList().size(); + } + size += getUnknownFields().getSerializedSize(); + memoizedSerializedSize = size; + return size; + } + + @java.lang.Override + protected Object writeReplace() throws java.io.ObjectStreamException { + return super.writeReplace(); + } + + public static muduo.codec.tests.QueryProtos.Answer parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return newBuilder().mergeFrom(data).buildParsed(); + } + public static muduo.codec.tests.QueryProtos.Answer parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return newBuilder().mergeFrom(data, extensionRegistry) + .buildParsed(); + } + public static muduo.codec.tests.QueryProtos.Answer parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return newBuilder().mergeFrom(data).buildParsed(); + } + public static muduo.codec.tests.QueryProtos.Answer parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return newBuilder().mergeFrom(data, extensionRegistry) + .buildParsed(); + } + public static muduo.codec.tests.QueryProtos.Answer parseFrom(java.io.InputStream input) + throws java.io.IOException { + return newBuilder().mergeFrom(input).buildParsed(); + } + public static muduo.codec.tests.QueryProtos.Answer parseFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return newBuilder().mergeFrom(input, extensionRegistry) + .buildParsed(); + } + public static muduo.codec.tests.QueryProtos.Answer parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + Builder builder = newBuilder(); + if (builder.mergeDelimitedFrom(input)) { + return builder.buildParsed(); + } else { + return null; + } + } + public static muduo.codec.tests.QueryProtos.Answer parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + Builder builder = newBuilder(); + if (builder.mergeDelimitedFrom(input, extensionRegistry)) { + return builder.buildParsed(); + } else { + return null; + } + } + public static muduo.codec.tests.QueryProtos.Answer parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return newBuilder().mergeFrom(input).buildParsed(); + } + public static muduo.codec.tests.QueryProtos.Answer parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return newBuilder().mergeFrom(input, extensionRegistry) + .buildParsed(); + } + + public static Builder newBuilder() { return Builder.create(); } + public Builder newBuilderForType() { return newBuilder(); } + public static Builder newBuilder(muduo.codec.tests.QueryProtos.Answer prototype) { + return newBuilder().mergeFrom(prototype); + } + public Builder toBuilder() { return newBuilder(this); } + + @java.lang.Override + protected Builder newBuilderForType( + com.google.protobuf.GeneratedMessage.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + public static final class Builder extends + com.google.protobuf.GeneratedMessage.Builder + implements muduo.codec.tests.QueryProtos.AnswerOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return muduo.codec.tests.QueryProtos.internal_static_muduo_Answer_descriptor; + } + + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return muduo.codec.tests.QueryProtos.internal_static_muduo_Answer_fieldAccessorTable; + } + + // Construct using muduo.codec.tests.QueryProtos.Answer.newBuilder() + private Builder() { + maybeForceBuilderInitialization(); + } + + private Builder(BuilderParent parent) { + super(parent); + maybeForceBuilderInitialization(); + } + private void maybeForceBuilderInitialization() { + if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { + } + } + private static Builder create() { + return new Builder(); + } + + public Builder clear() { + super.clear(); + id_ = 0L; + bitField0_ = (bitField0_ & ~0x00000001); + questioner_ = ""; + bitField0_ = (bitField0_ & ~0x00000002); + answerer_ = ""; + bitField0_ = (bitField0_ & ~0x00000004); + solution_ = com.google.protobuf.LazyStringArrayList.EMPTY; + bitField0_ = (bitField0_ & ~0x00000008); + return this; + } + + public Builder clone() { + return create().mergeFrom(buildPartial()); + } + + public com.google.protobuf.Descriptors.Descriptor + getDescriptorForType() { + return muduo.codec.tests.QueryProtos.Answer.getDescriptor(); + } + + public muduo.codec.tests.QueryProtos.Answer getDefaultInstanceForType() { + return muduo.codec.tests.QueryProtos.Answer.getDefaultInstance(); + } + + public muduo.codec.tests.QueryProtos.Answer build() { + muduo.codec.tests.QueryProtos.Answer result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + private muduo.codec.tests.QueryProtos.Answer buildParsed() + throws com.google.protobuf.InvalidProtocolBufferException { + muduo.codec.tests.QueryProtos.Answer result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException( + result).asInvalidProtocolBufferException(); + } + return result; + } + + public muduo.codec.tests.QueryProtos.Answer buildPartial() { + muduo.codec.tests.QueryProtos.Answer result = new muduo.codec.tests.QueryProtos.Answer(this); + int from_bitField0_ = bitField0_; + int to_bitField0_ = 0; + if (((from_bitField0_ & 0x00000001) == 0x00000001)) { + to_bitField0_ |= 0x00000001; + } + result.id_ = id_; + if (((from_bitField0_ & 0x00000002) == 0x00000002)) { + to_bitField0_ |= 0x00000002; + } + result.questioner_ = questioner_; + if (((from_bitField0_ & 0x00000004) == 0x00000004)) { + to_bitField0_ |= 0x00000004; + } + result.answerer_ = answerer_; + if (((bitField0_ & 0x00000008) == 0x00000008)) { + solution_ = new com.google.protobuf.UnmodifiableLazyStringList( + solution_); + bitField0_ = (bitField0_ & ~0x00000008); + } + result.solution_ = solution_; + result.bitField0_ = to_bitField0_; + onBuilt(); + return result; + } + + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof muduo.codec.tests.QueryProtos.Answer) { + return mergeFrom((muduo.codec.tests.QueryProtos.Answer)other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(muduo.codec.tests.QueryProtos.Answer other) { + if (other == muduo.codec.tests.QueryProtos.Answer.getDefaultInstance()) return this; + if (other.hasId()) { + setId(other.getId()); + } + if (other.hasQuestioner()) { + setQuestioner(other.getQuestioner()); + } + if (other.hasAnswerer()) { + setAnswerer(other.getAnswerer()); + } + if (!other.solution_.isEmpty()) { + if (solution_.isEmpty()) { + solution_ = other.solution_; + bitField0_ = (bitField0_ & ~0x00000008); + } else { + ensureSolutionIsMutable(); + solution_.addAll(other.solution_); + } + onChanged(); + } + this.mergeUnknownFields(other.getUnknownFields()); + return this; + } + + public final boolean isInitialized() { + if (!hasId()) { + + return false; + } + if (!hasQuestioner()) { + + return false; + } + if (!hasAnswerer()) { + + return false; + } + return true; + } + + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + com.google.protobuf.UnknownFieldSet.Builder unknownFields = + com.google.protobuf.UnknownFieldSet.newBuilder( + this.getUnknownFields()); + while (true) { + int tag = input.readTag(); + switch (tag) { + case 0: + this.setUnknownFields(unknownFields.build()); + onChanged(); + return this; + default: { + if (!parseUnknownField(input, unknownFields, + extensionRegistry, tag)) { + this.setUnknownFields(unknownFields.build()); + onChanged(); + return this; + } + break; + } + case 8: { + bitField0_ |= 0x00000001; + id_ = input.readInt64(); + break; + } + case 18: { + bitField0_ |= 0x00000002; + questioner_ = input.readBytes(); + break; + } + case 26: { + bitField0_ |= 0x00000004; + answerer_ = input.readBytes(); + break; + } + case 34: { + ensureSolutionIsMutable(); + solution_.add(input.readBytes()); + break; + } + } + } + } + + private int bitField0_; + + // required int64 id = 1; + private long id_ ; + public boolean hasId() { + return ((bitField0_ & 0x00000001) == 0x00000001); + } + public long getId() { + return id_; + } + public Builder setId(long value) { + bitField0_ |= 0x00000001; + id_ = value; + onChanged(); + return this; + } + public Builder clearId() { + bitField0_ = (bitField0_ & ~0x00000001); + id_ = 0L; + onChanged(); + return this; + } + + // required string questioner = 2; + private Object questioner_ = ""; + public boolean hasQuestioner() { + return ((bitField0_ & 0x00000002) == 0x00000002); + } + public String getQuestioner() { + Object ref = questioner_; + if (!(ref instanceof String)) { + String s = ((com.google.protobuf.ByteString) ref).toStringUtf8(); + questioner_ = s; + return s; + } else { + return (String) ref; + } + } + public Builder setQuestioner(String value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000002; + questioner_ = value; + onChanged(); + return this; + } + public Builder clearQuestioner() { + bitField0_ = (bitField0_ & ~0x00000002); + questioner_ = getDefaultInstance().getQuestioner(); + onChanged(); + return this; + } + void setQuestioner(com.google.protobuf.ByteString value) { + bitField0_ |= 0x00000002; + questioner_ = value; + onChanged(); + } + + // required string answerer = 3; + private Object answerer_ = ""; + public boolean hasAnswerer() { + return ((bitField0_ & 0x00000004) == 0x00000004); + } + public String getAnswerer() { + Object ref = answerer_; + if (!(ref instanceof String)) { + String s = ((com.google.protobuf.ByteString) ref).toStringUtf8(); + answerer_ = s; + return s; + } else { + return (String) ref; + } + } + public Builder setAnswerer(String value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000004; + answerer_ = value; + onChanged(); + return this; + } + public Builder clearAnswerer() { + bitField0_ = (bitField0_ & ~0x00000004); + answerer_ = getDefaultInstance().getAnswerer(); + onChanged(); + return this; + } + void setAnswerer(com.google.protobuf.ByteString value) { + bitField0_ |= 0x00000004; + answerer_ = value; + onChanged(); + } + + // repeated string solution = 4; + private com.google.protobuf.LazyStringList solution_ = com.google.protobuf.LazyStringArrayList.EMPTY; + private void ensureSolutionIsMutable() { + if (!((bitField0_ & 0x00000008) == 0x00000008)) { + solution_ = new com.google.protobuf.LazyStringArrayList(solution_); + bitField0_ |= 0x00000008; + } + } + public java.util.List + getSolutionList() { + return java.util.Collections.unmodifiableList(solution_); + } + public int getSolutionCount() { + return solution_.size(); + } + public String getSolution(int index) { + return solution_.get(index); + } + public Builder setSolution( + int index, String value) { + if (value == null) { + throw new NullPointerException(); + } + ensureSolutionIsMutable(); + solution_.set(index, value); + onChanged(); + return this; + } + public Builder addSolution(String value) { + if (value == null) { + throw new NullPointerException(); + } + ensureSolutionIsMutable(); + solution_.add(value); + onChanged(); + return this; + } + public Builder addAllSolution( + java.lang.Iterable values) { + ensureSolutionIsMutable(); + super.addAll(values, solution_); + onChanged(); + return this; + } + public Builder clearSolution() { + solution_ = com.google.protobuf.LazyStringArrayList.EMPTY; + bitField0_ = (bitField0_ & ~0x00000008); + onChanged(); + return this; + } + void addSolution(com.google.protobuf.ByteString value) { + ensureSolutionIsMutable(); + solution_.add(value); + onChanged(); + } + + // @@protoc_insertion_point(builder_scope:muduo.Answer) + } + + static { + defaultInstance = new Answer(true); + defaultInstance.initFields(); + } + + // @@protoc_insertion_point(class_scope:muduo.Answer) + } + + public interface EmptyOrBuilder + extends com.google.protobuf.MessageOrBuilder { + + // optional int32 id = 1; + boolean hasId(); + int getId(); + } + public static final class Empty extends + com.google.protobuf.GeneratedMessage + implements EmptyOrBuilder { + // Use Empty.newBuilder() to construct. + private Empty(Builder builder) { + super(builder); + } + private Empty(boolean noInit) {} + + private static final Empty defaultInstance; + public static Empty getDefaultInstance() { + return defaultInstance; + } + + public Empty getDefaultInstanceForType() { + return defaultInstance; + } + + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return muduo.codec.tests.QueryProtos.internal_static_muduo_Empty_descriptor; + } + + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return muduo.codec.tests.QueryProtos.internal_static_muduo_Empty_fieldAccessorTable; + } + + private int bitField0_; + // optional int32 id = 1; + public static final int ID_FIELD_NUMBER = 1; + private int id_; + public boolean hasId() { + return ((bitField0_ & 0x00000001) == 0x00000001); + } + public int getId() { + return id_; + } + + private void initFields() { + id_ = 0; + } + private byte memoizedIsInitialized = -1; + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized != -1) return isInitialized == 1; + + memoizedIsInitialized = 1; + return true; + } + + public void writeTo(com.google.protobuf.CodedOutputStream output) + throws java.io.IOException { + getSerializedSize(); + if (((bitField0_ & 0x00000001) == 0x00000001)) { + output.writeInt32(1, id_); + } + getUnknownFields().writeTo(output); + } + + private int memoizedSerializedSize = -1; + public int getSerializedSize() { + int size = memoizedSerializedSize; + if (size != -1) return size; + + size = 0; + if (((bitField0_ & 0x00000001) == 0x00000001)) { + size += com.google.protobuf.CodedOutputStream + .computeInt32Size(1, id_); + } + size += getUnknownFields().getSerializedSize(); + memoizedSerializedSize = size; + return size; + } + + @java.lang.Override + protected Object writeReplace() throws java.io.ObjectStreamException { + return super.writeReplace(); + } + + public static muduo.codec.tests.QueryProtos.Empty parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return newBuilder().mergeFrom(data).buildParsed(); + } + public static muduo.codec.tests.QueryProtos.Empty parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return newBuilder().mergeFrom(data, extensionRegistry) + .buildParsed(); + } + public static muduo.codec.tests.QueryProtos.Empty parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return newBuilder().mergeFrom(data).buildParsed(); + } + public static muduo.codec.tests.QueryProtos.Empty parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return newBuilder().mergeFrom(data, extensionRegistry) + .buildParsed(); + } + public static muduo.codec.tests.QueryProtos.Empty parseFrom(java.io.InputStream input) + throws java.io.IOException { + return newBuilder().mergeFrom(input).buildParsed(); + } + public static muduo.codec.tests.QueryProtos.Empty parseFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return newBuilder().mergeFrom(input, extensionRegistry) + .buildParsed(); + } + public static muduo.codec.tests.QueryProtos.Empty parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + Builder builder = newBuilder(); + if (builder.mergeDelimitedFrom(input)) { + return builder.buildParsed(); + } else { + return null; + } + } + public static muduo.codec.tests.QueryProtos.Empty parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + Builder builder = newBuilder(); + if (builder.mergeDelimitedFrom(input, extensionRegistry)) { + return builder.buildParsed(); + } else { + return null; + } + } + public static muduo.codec.tests.QueryProtos.Empty parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return newBuilder().mergeFrom(input).buildParsed(); + } + public static muduo.codec.tests.QueryProtos.Empty parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return newBuilder().mergeFrom(input, extensionRegistry) + .buildParsed(); + } + + public static Builder newBuilder() { return Builder.create(); } + public Builder newBuilderForType() { return newBuilder(); } + public static Builder newBuilder(muduo.codec.tests.QueryProtos.Empty prototype) { + return newBuilder().mergeFrom(prototype); + } + public Builder toBuilder() { return newBuilder(this); } + + @java.lang.Override + protected Builder newBuilderForType( + com.google.protobuf.GeneratedMessage.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + public static final class Builder extends + com.google.protobuf.GeneratedMessage.Builder + implements muduo.codec.tests.QueryProtos.EmptyOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return muduo.codec.tests.QueryProtos.internal_static_muduo_Empty_descriptor; + } + + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return muduo.codec.tests.QueryProtos.internal_static_muduo_Empty_fieldAccessorTable; + } + + // Construct using muduo.codec.tests.QueryProtos.Empty.newBuilder() + private Builder() { + maybeForceBuilderInitialization(); + } + + private Builder(BuilderParent parent) { + super(parent); + maybeForceBuilderInitialization(); + } + private void maybeForceBuilderInitialization() { + if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { + } + } + private static Builder create() { + return new Builder(); + } + + public Builder clear() { + super.clear(); + id_ = 0; + bitField0_ = (bitField0_ & ~0x00000001); + return this; + } + + public Builder clone() { + return create().mergeFrom(buildPartial()); + } + + public com.google.protobuf.Descriptors.Descriptor + getDescriptorForType() { + return muduo.codec.tests.QueryProtos.Empty.getDescriptor(); + } + + public muduo.codec.tests.QueryProtos.Empty getDefaultInstanceForType() { + return muduo.codec.tests.QueryProtos.Empty.getDefaultInstance(); + } + + public muduo.codec.tests.QueryProtos.Empty build() { + muduo.codec.tests.QueryProtos.Empty result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + private muduo.codec.tests.QueryProtos.Empty buildParsed() + throws com.google.protobuf.InvalidProtocolBufferException { + muduo.codec.tests.QueryProtos.Empty result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException( + result).asInvalidProtocolBufferException(); + } + return result; + } + + public muduo.codec.tests.QueryProtos.Empty buildPartial() { + muduo.codec.tests.QueryProtos.Empty result = new muduo.codec.tests.QueryProtos.Empty(this); + int from_bitField0_ = bitField0_; + int to_bitField0_ = 0; + if (((from_bitField0_ & 0x00000001) == 0x00000001)) { + to_bitField0_ |= 0x00000001; + } + result.id_ = id_; + result.bitField0_ = to_bitField0_; + onBuilt(); + return result; + } + + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof muduo.codec.tests.QueryProtos.Empty) { + return mergeFrom((muduo.codec.tests.QueryProtos.Empty)other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(muduo.codec.tests.QueryProtos.Empty other) { + if (other == muduo.codec.tests.QueryProtos.Empty.getDefaultInstance()) return this; + if (other.hasId()) { + setId(other.getId()); + } + this.mergeUnknownFields(other.getUnknownFields()); + return this; + } + + public final boolean isInitialized() { + return true; + } + + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + com.google.protobuf.UnknownFieldSet.Builder unknownFields = + com.google.protobuf.UnknownFieldSet.newBuilder( + this.getUnknownFields()); + while (true) { + int tag = input.readTag(); + switch (tag) { + case 0: + this.setUnknownFields(unknownFields.build()); + onChanged(); + return this; + default: { + if (!parseUnknownField(input, unknownFields, + extensionRegistry, tag)) { + this.setUnknownFields(unknownFields.build()); + onChanged(); + return this; + } + break; + } + case 8: { + bitField0_ |= 0x00000001; + id_ = input.readInt32(); + break; + } + } + } + } + + private int bitField0_; + + // optional int32 id = 1; + private int id_ ; + public boolean hasId() { + return ((bitField0_ & 0x00000001) == 0x00000001); + } + public int getId() { + return id_; + } + public Builder setId(int value) { + bitField0_ |= 0x00000001; + id_ = value; + onChanged(); + return this; + } + public Builder clearId() { + bitField0_ = (bitField0_ & ~0x00000001); + id_ = 0; + onChanged(); + return this; + } + + // @@protoc_insertion_point(builder_scope:muduo.Empty) + } + + static { + defaultInstance = new Empty(true); + defaultInstance.initFields(); + } + + // @@protoc_insertion_point(class_scope:muduo.Empty) + } + + private static com.google.protobuf.Descriptors.Descriptor + internal_static_muduo_Query_descriptor; + private static + com.google.protobuf.GeneratedMessage.FieldAccessorTable + internal_static_muduo_Query_fieldAccessorTable; + private static com.google.protobuf.Descriptors.Descriptor + internal_static_muduo_Answer_descriptor; + private static + com.google.protobuf.GeneratedMessage.FieldAccessorTable + internal_static_muduo_Answer_fieldAccessorTable; + private static com.google.protobuf.Descriptors.Descriptor + internal_static_muduo_Empty_descriptor; + private static + com.google.protobuf.GeneratedMessage.FieldAccessorTable + internal_static_muduo_Empty_fieldAccessorTable; + + public static com.google.protobuf.Descriptors.FileDescriptor + getDescriptor() { + return descriptor; + } + private static com.google.protobuf.Descriptors.FileDescriptor + descriptor; + static { + java.lang.String[] descriptorData = { + "\n\013query.proto\022\005muduo\"9\n\005Query\022\n\n\002id\030\001 \002(" + + "\003\022\022\n\nquestioner\030\002 \002(\t\022\020\n\010question\030\003 \003(\t\"" + + "L\n\006Answer\022\n\n\002id\030\001 \002(\003\022\022\n\nquestioner\030\002 \002(" + + "\t\022\020\n\010answerer\030\003 \002(\t\022\020\n\010solution\030\004 \003(\t\"\023\n" + + "\005Empty\022\n\n\002id\030\001 \001(\005B \n\021muduo.codec.testsB" + + "\013QueryProtos" + }; + com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = + new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() { + public com.google.protobuf.ExtensionRegistry assignDescriptors( + com.google.protobuf.Descriptors.FileDescriptor root) { + descriptor = root; + internal_static_muduo_Query_descriptor = + getDescriptor().getMessageTypes().get(0); + internal_static_muduo_Query_fieldAccessorTable = new + com.google.protobuf.GeneratedMessage.FieldAccessorTable( + internal_static_muduo_Query_descriptor, + new java.lang.String[] { "Id", "Questioner", "Question", }, + muduo.codec.tests.QueryProtos.Query.class, + muduo.codec.tests.QueryProtos.Query.Builder.class); + internal_static_muduo_Answer_descriptor = + getDescriptor().getMessageTypes().get(1); + internal_static_muduo_Answer_fieldAccessorTable = new + com.google.protobuf.GeneratedMessage.FieldAccessorTable( + internal_static_muduo_Answer_descriptor, + new java.lang.String[] { "Id", "Questioner", "Answerer", "Solution", }, + muduo.codec.tests.QueryProtos.Answer.class, + muduo.codec.tests.QueryProtos.Answer.Builder.class); + internal_static_muduo_Empty_descriptor = + getDescriptor().getMessageTypes().get(2); + internal_static_muduo_Empty_fieldAccessorTable = new + com.google.protobuf.GeneratedMessage.FieldAccessorTable( + internal_static_muduo_Empty_descriptor, + new java.lang.String[] { "Id", }, + muduo.codec.tests.QueryProtos.Empty.class, + muduo.codec.tests.QueryProtos.Empty.Builder.class); + return null; + } + }; + com.google.protobuf.Descriptors.FileDescriptor + .internalBuildGeneratedFileFrom(descriptorData, + new com.google.protobuf.Descriptors.FileDescriptor[] { + }, assigner); + } + + // @@protoc_insertion_point(outer_class_scope) +} diff --git a/protorpc/muduo/rpc/NewChannelCallback.java b/protorpc/muduo/rpc/NewChannelCallback.java new file mode 100644 index 0000000..6a6b12a --- /dev/null +++ b/protorpc/muduo/rpc/NewChannelCallback.java @@ -0,0 +1,6 @@ +package muduo.rpc; + +public interface NewChannelCallback { + + public abstract void run(RpcChannel channel); +} diff --git a/protorpc/muduo/rpc/RpcChannel.java b/protorpc/muduo/rpc/RpcChannel.java new file mode 100644 index 0000000..3f46aca --- /dev/null +++ b/protorpc/muduo/rpc/RpcChannel.java @@ -0,0 +1,150 @@ +package muduo.rpc; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicLong; + +import muduo.rpc.proto.RpcProto.ErrorCode; +import muduo.rpc.proto.RpcProto.MessageType; +import muduo.rpc.proto.RpcProto.RpcMessage; +import muduo.rpc.proto.RpcProto.RpcMessage.Builder; + +import org.jboss.netty.channel.Channel; +import org.jboss.netty.channel.ChannelHandlerContext; +import org.jboss.netty.channel.MessageEvent; + +import com.google.protobuf.ByteString; +import com.google.protobuf.Descriptors.MethodDescriptor; +import com.google.protobuf.Message; +import com.google.protobuf.RpcCallback; +import com.google.protobuf.RpcController; +import com.google.protobuf.Service; + +public class RpcChannel implements com.google.protobuf.RpcChannel { + + private class Outstanding { + + public Outstanding(Message responsePrototype, RpcCallback done) { + this.responsePrototype = responsePrototype; + this.done = done; + } + + public Message responsePrototype; + public RpcCallback done; + } + + private Channel channel; + private AtomicLong id = new AtomicLong(1); + private Map outstandings = new ConcurrentHashMap(); + private Map services; + + public RpcChannel(Channel channel) { + this.channel = channel; + } + + public void setServiceMap(Map services) { + this.services = services; + } + + public Channel getChannel() { + return channel; + } + + public void messageReceived(ChannelHandlerContext ctx, final MessageEvent e) { + RpcMessage message = (RpcMessage) e.getMessage(); + assert e.getChannel() == channel; + System.out.println(message); + if (message.getType() == MessageType.REQUEST) { + doRequest(message); + } else if (message.getType() == MessageType.RESPONSE) { + Outstanding o = outstandings.get(message.getId()); + if (o != null) { + Message resp = fromByteString(o.responsePrototype, message.getResponse()); + o.done.run(resp); + } + } + } + + private void doRequest(RpcMessage message) { + Service service = services.get(message.getService()); + Builder errorBuilder = RpcMessage.newBuilder().setType(MessageType.ERROR); + boolean succeed = false; + if (service != null) { + MethodDescriptor method = service.getDescriptorForType() + .findMethodByName(message.getMethod()); + if (method != null) { + Message request = fromByteString(service.getRequestPrototype(method), + message.getRequest()); + if (request != null) { + final long id = message.getId(); + RpcCallback done = new RpcCallback() { + @Override + public void run(Message response) { + done(response, id); + } + }; + succeed = doCall(request, service, method, done); + } else { + errorBuilder.setError(ErrorCode.INVALID_REQUEST); + } + } else { + errorBuilder.setError(ErrorCode.NO_METHOD); + } + } else { + errorBuilder.setError(ErrorCode.NO_SERVICE); + } + if (!succeed) { + RpcMessage resp = errorBuilder.build(); + channel.write(resp); + } + } + + private Message fromByteString(Message prototype, ByteString bytes) { + Message message = null; + try { + message = prototype.toBuilder().mergeFrom(bytes).build(); + } catch (Exception e) { + } + return message; + } + + private boolean doCall(Message request, Service service, MethodDescriptor method, + RpcCallback done) { + service.callMethod(method, null, request, done); + return true; + } + + protected void done(Message response, long id) { + if (response != null) { + RpcMessage resp = RpcMessage.newBuilder() + .setType(MessageType.RESPONSE) + .setId(id) + .setResponse(response.toByteString()) + .build(); + channel.write(resp); + } else { + RpcMessage resp = RpcMessage.newBuilder() + .setType(MessageType.ERROR) + .setId(id) + .setError(ErrorCode.INVALID_RESPONSE) + .build(); + channel.write(resp); + } + } + + @Override + public void callMethod(MethodDescriptor method, RpcController controller, Message request, + Message responsePrototype, RpcCallback done) { + long callId = id.getAndIncrement(); + RpcMessage message = RpcMessage.newBuilder() + .setType(MessageType.REQUEST) + .setId(callId) + .setService(method.getService().getFullName()) + .setMethod(method.getName()) + .setRequest(request.toByteString()) + .build(); + outstandings.put(callId, new Outstanding(responsePrototype, done)); + channel.write(message); + } + +} diff --git a/protorpc/muduo/rpc/RpcChannelPiplineFactory.java b/protorpc/muduo/rpc/RpcChannelPiplineFactory.java new file mode 100644 index 0000000..ad1f92e --- /dev/null +++ b/protorpc/muduo/rpc/RpcChannelPiplineFactory.java @@ -0,0 +1,33 @@ +package muduo.rpc; + +import org.jboss.netty.channel.ChannelPipeline; +import org.jboss.netty.channel.ChannelPipelineFactory; +import org.jboss.netty.channel.Channels; +import org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder; +import org.jboss.netty.handler.codec.frame.LengthFieldPrepender; + +public class RpcChannelPiplineFactory implements ChannelPipelineFactory { + + private RpcDecoder rpcDecoder = new RpcDecoder(); + private RpcEncoder rpcEncoder = new RpcEncoder(); + private LengthFieldPrepender frameEncoder = new LengthFieldPrepender(4); + private RpcPeer rpcPeer; + + public RpcChannelPiplineFactory(RpcPeer peer) { + this.rpcPeer = peer; + } + + @Override + public ChannelPipeline getPipeline() throws Exception { + ChannelPipeline p = Channels.pipeline(); + p.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(16 * 1024 * 1024, 0, 4, 0, 4)); + p.addLast("rpcDecoder", rpcDecoder); + + p.addLast("frameEncoder", frameEncoder); + p.addLast("rpcEncoder", rpcEncoder); + + p.addLast("handler", new RpcMessageHandler(rpcPeer)); + return p; + } + +} diff --git a/protorpc/muduo/rpc/RpcClient.java b/protorpc/muduo/rpc/RpcClient.java new file mode 100644 index 0000000..f72d7e6 --- /dev/null +++ b/protorpc/muduo/rpc/RpcClient.java @@ -0,0 +1,57 @@ +package muduo.rpc; + +import java.net.SocketAddress; +import java.util.concurrent.Executors; + +import org.jboss.netty.bootstrap.ClientBootstrap; +import org.jboss.netty.channel.Channel; +import org.jboss.netty.channel.ChannelFactory; +import org.jboss.netty.channel.ChannelFuture; +import org.jboss.netty.channel.ChannelFutureListener; +import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory; + +public class RpcClient extends RpcPeer { + + ClientBootstrap bootstrap; + private RpcChannel rpcChannel; + + public RpcClient() { + ChannelFactory channelFactory = new NioClientSocketChannelFactory( + Executors.newCachedThreadPool(), + Executors.newCachedThreadPool()); + + bootstrap = new ClientBootstrap(channelFactory); + bootstrap.setPipelineFactory(new RpcChannelPiplineFactory(this)); + } + + public RpcChannel blockingConnect(SocketAddress addr) { + Channel channel = bootstrap.connect(addr).awaitUninterruptibly().getChannel(); + rpcChannel = new RpcChannel(channel); + RpcMessageHandler handler = (RpcMessageHandler) channel.getPipeline().get("handler"); + handler.setChannel(rpcChannel); + return rpcChannel; + } + + public void startConnect(SocketAddress addr, NewChannelCallback newChannelCallback) { + ChannelFuture future = bootstrap.connect(addr); + future.addListener(new ChannelFutureListener() { + @Override + public void operationComplete(ChannelFuture future) throws Exception { + System.err.println("operationComplete"); + // channelConnected(future.getChannel()); + } + }); + this.newChannelCallback = newChannelCallback; + } + + @Override + public void channelConnected(Channel channel) { + rpcChannel = new RpcChannel(channel); + setupNewChannel(rpcChannel); + } + + public RpcChannel getChannel() { + return rpcChannel; + } + +} diff --git a/protorpc/muduo/rpc/RpcDecoder.java b/protorpc/muduo/rpc/RpcDecoder.java new file mode 100644 index 0000000..a9043f0 --- /dev/null +++ b/protorpc/muduo/rpc/RpcDecoder.java @@ -0,0 +1,45 @@ +package muduo.rpc; + +import java.nio.charset.Charset; +import java.util.zip.Adler32; + +import muduo.rpc.proto.RpcProto.RpcMessage; + +import org.jboss.netty.buffer.ChannelBuffer; +import org.jboss.netty.channel.Channel; +import org.jboss.netty.channel.ChannelHandlerContext; +import org.jboss.netty.handler.codec.oneone.OneToOneDecoder; +import org.jboss.netty.channel.ChannelHandler.Sharable; + +@Sharable +public class RpcDecoder extends OneToOneDecoder { + + @Override + public Object decode(ChannelHandlerContext ctx, Channel channel, Object obj) + throws Exception { + if (obj instanceof ChannelBuffer) { + ChannelBuffer buffer = (ChannelBuffer) obj; + if (buffer.readableBytes() > 8) { + String version = buffer.toString(buffer.readerIndex(), 4, Charset.defaultCharset()); + if (version.equals("RPC0")) { + Adler32 adler32 = new Adler32(); + adler32.update(buffer.array(), + buffer.arrayOffset() + buffer.readerIndex(), + buffer.readableBytes() - 4); + buffer.markReaderIndex(); + buffer.readerIndex(buffer.writerIndex() - 4); + int checksum = buffer.readInt(); + if (checksum == (int)adler32.getValue()) { + buffer.resetReaderIndex(); + RpcMessage message = RpcMessage.newBuilder().mergeFrom( + buffer.array(), + buffer.arrayOffset() + buffer.readerIndex() + 4, + buffer.readableBytes() - 8).build(); + return message; + } + } + } + } + return obj; + } +} diff --git a/protorpc/muduo/rpc/RpcEncoder.java b/protorpc/muduo/rpc/RpcEncoder.java new file mode 100644 index 0000000..2cdc996 --- /dev/null +++ b/protorpc/muduo/rpc/RpcEncoder.java @@ -0,0 +1,45 @@ +package muduo.rpc; + +import java.util.zip.Adler32; + +import muduo.rpc.proto.RpcProto.RpcMessage; + +import org.jboss.netty.buffer.BigEndianHeapChannelBuffer; +import org.jboss.netty.buffer.ChannelBuffer; +import org.jboss.netty.channel.Channel; +import org.jboss.netty.channel.ChannelHandler.Sharable; +import org.jboss.netty.channel.ChannelHandlerContext; +import org.jboss.netty.handler.codec.oneone.OneToOneEncoder; + +import com.google.protobuf.CodedOutputStream; + +@Sharable +public class RpcEncoder extends OneToOneEncoder { + + public RpcEncoder() { + super(); + } + + @Override + public Object encode(ChannelHandlerContext ctx, Channel channel, Object obj) + throws Exception { + if (!(obj instanceof RpcMessage)) { + return obj; + } + RpcMessage message = (RpcMessage) obj; + int size = message.getSerializedSize(); + ChannelBuffer buffer = new BigEndianHeapChannelBuffer(4 + size + 4); + buffer.writeBytes("RPC0".getBytes()); + int writerIndex = buffer.writerIndex(); + CodedOutputStream output = CodedOutputStream.newInstance( + buffer.array(), buffer.writerIndex(), buffer.writableBytes() - 4); + message.writeTo(output); + output.checkNoSpaceLeft(); + + buffer.writerIndex(writerIndex + size); + Adler32 checksum = new Adler32(); + checksum.update(buffer.array(), buffer.arrayOffset(), buffer.readableBytes()); + buffer.writeInt((int) checksum.getValue()); + return buffer; + } +} \ No newline at end of file diff --git a/protorpc/muduo/rpc/RpcMessageHandler.java b/protorpc/muduo/rpc/RpcMessageHandler.java new file mode 100644 index 0000000..dab3ebe --- /dev/null +++ b/protorpc/muduo/rpc/RpcMessageHandler.java @@ -0,0 +1,36 @@ +package muduo.rpc; + +import org.jboss.netty.channel.ChannelHandlerContext; +import org.jboss.netty.channel.ChannelStateEvent; +import org.jboss.netty.channel.MessageEvent; +import org.jboss.netty.channel.SimpleChannelUpstreamHandler; + +public class RpcMessageHandler extends SimpleChannelUpstreamHandler { + + private volatile RpcChannel channel; + private RpcPeer rpcPeer; + + public RpcMessageHandler(RpcPeer peer) { + this.rpcPeer = peer; + } + + public RpcChannel getChannel() { + return channel; + } + + public void setChannel(RpcChannel ch) { + channel = ch; + } + + @Override + public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception { + System.err.println("channelConnected"); + rpcPeer.channelConnected(e.getChannel()); + } + + @Override + public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { + assert e.getChannel() == channel.getChannel(); + channel.messageReceived(ctx, e); + } +} diff --git a/protorpc/muduo/rpc/RpcPeer.java b/protorpc/muduo/rpc/RpcPeer.java new file mode 100644 index 0000000..d4f765f --- /dev/null +++ b/protorpc/muduo/rpc/RpcPeer.java @@ -0,0 +1,35 @@ +package muduo.rpc; + +import java.util.Collections; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import org.jboss.netty.channel.Channel; + +import com.google.protobuf.Service; + +public abstract class RpcPeer { + + protected NewChannelCallback newChannelCallback; + protected Map services = new ConcurrentHashMap(); + + public void registerService(Service service) { + services.put(service.getDescriptorForType().getFullName(), service); + } + + public void setNewChannelCallback(NewChannelCallback newChannelCallback) { + this.newChannelCallback = newChannelCallback; + } + + protected void setupNewChannel(RpcChannel rpcChannel) { + Channel channel = rpcChannel.getChannel(); + RpcMessageHandler handler = (RpcMessageHandler) channel.getPipeline().get("handler"); + handler.setChannel(rpcChannel); + rpcChannel.setServiceMap(Collections.unmodifiableMap(services)); + if (newChannelCallback != null) { + newChannelCallback.run(rpcChannel); + } + } + + public abstract void channelConnected(Channel channel); +} diff --git a/protorpc/muduo/rpc/RpcServer.java b/protorpc/muduo/rpc/RpcServer.java new file mode 100644 index 0000000..332050c --- /dev/null +++ b/protorpc/muduo/rpc/RpcServer.java @@ -0,0 +1,32 @@ +package muduo.rpc; + +import java.net.InetSocketAddress; +import java.util.concurrent.Executors; + +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.Channel; +import org.jboss.netty.channel.ChannelFactory; +import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory; + +public class RpcServer extends RpcPeer { + + ServerBootstrap bootstrap; + + public RpcServer() { + ChannelFactory channelFactory = new NioServerSocketChannelFactory( + Executors.newCachedThreadPool(), + Executors.newCachedThreadPool()); + bootstrap = new ServerBootstrap(channelFactory); + bootstrap.setPipelineFactory(new RpcChannelPiplineFactory(this)); + } + + public void start(int port) { + bootstrap.bind(new InetSocketAddress(port)); + } + + @Override + public void channelConnected(Channel channel) { + RpcChannel rpcChannel = new RpcChannel(channel); + setupNewChannel(rpcChannel); + } +} diff --git a/protorpc/muduo/rpc/proto/RpcProto.java b/protorpc/muduo/rpc/proto/RpcProto.java new file mode 100644 index 0000000..1892be9 --- /dev/null +++ b/protorpc/muduo/rpc/proto/RpcProto.java @@ -0,0 +1,1000 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: rpc.proto + +package muduo.rpc.proto; + +public final class RpcProto { + private RpcProto() {} + public static void registerAllExtensions( + com.google.protobuf.ExtensionRegistry registry) { + } + public enum MessageType + implements com.google.protobuf.ProtocolMessageEnum { + REQUEST(0, 1), + RESPONSE(1, 2), + ERROR(2, 3), + ; + + public static final int REQUEST_VALUE = 1; + public static final int RESPONSE_VALUE = 2; + public static final int ERROR_VALUE = 3; + + + public final int getNumber() { return value; } + + public static MessageType valueOf(int value) { + switch (value) { + case 1: return REQUEST; + case 2: return RESPONSE; + case 3: return ERROR; + default: return null; + } + } + + public static com.google.protobuf.Internal.EnumLiteMap + internalGetValueMap() { + return internalValueMap; + } + private static com.google.protobuf.Internal.EnumLiteMap + internalValueMap = + new com.google.protobuf.Internal.EnumLiteMap() { + public MessageType findValueByNumber(int number) { + return MessageType.valueOf(number); + } + }; + + public final com.google.protobuf.Descriptors.EnumValueDescriptor + getValueDescriptor() { + return getDescriptor().getValues().get(index); + } + public final com.google.protobuf.Descriptors.EnumDescriptor + getDescriptorForType() { + return getDescriptor(); + } + public static final com.google.protobuf.Descriptors.EnumDescriptor + getDescriptor() { + return muduo.rpc.proto.RpcProto.getDescriptor().getEnumTypes().get(0); + } + + private static final MessageType[] VALUES = { + REQUEST, RESPONSE, ERROR, + }; + + public static MessageType valueOf( + com.google.protobuf.Descriptors.EnumValueDescriptor desc) { + if (desc.getType() != getDescriptor()) { + throw new java.lang.IllegalArgumentException( + "EnumValueDescriptor is not for this type."); + } + return VALUES[desc.getIndex()]; + } + + private final int index; + private final int value; + + private MessageType(int index, int value) { + this.index = index; + this.value = value; + } + + // @@protoc_insertion_point(enum_scope:MessageType) + } + + public enum ErrorCode + implements com.google.protobuf.ProtocolMessageEnum { + WRONG_PROTO(0, 1), + NO_SERVICE(1, 2), + NO_METHOD(2, 3), + INVALID_REQUEST(3, 4), + INVALID_RESPONSE(4, 5), + ; + + public static final int WRONG_PROTO_VALUE = 1; + public static final int NO_SERVICE_VALUE = 2; + public static final int NO_METHOD_VALUE = 3; + public static final int INVALID_REQUEST_VALUE = 4; + public static final int INVALID_RESPONSE_VALUE = 5; + + + public final int getNumber() { return value; } + + public static ErrorCode valueOf(int value) { + switch (value) { + case 1: return WRONG_PROTO; + case 2: return NO_SERVICE; + case 3: return NO_METHOD; + case 4: return INVALID_REQUEST; + case 5: return INVALID_RESPONSE; + default: return null; + } + } + + public static com.google.protobuf.Internal.EnumLiteMap + internalGetValueMap() { + return internalValueMap; + } + private static com.google.protobuf.Internal.EnumLiteMap + internalValueMap = + new com.google.protobuf.Internal.EnumLiteMap() { + public ErrorCode findValueByNumber(int number) { + return ErrorCode.valueOf(number); + } + }; + + public final com.google.protobuf.Descriptors.EnumValueDescriptor + getValueDescriptor() { + return getDescriptor().getValues().get(index); + } + public final com.google.protobuf.Descriptors.EnumDescriptor + getDescriptorForType() { + return getDescriptor(); + } + public static final com.google.protobuf.Descriptors.EnumDescriptor + getDescriptor() { + return muduo.rpc.proto.RpcProto.getDescriptor().getEnumTypes().get(1); + } + + private static final ErrorCode[] VALUES = { + WRONG_PROTO, NO_SERVICE, NO_METHOD, INVALID_REQUEST, INVALID_RESPONSE, + }; + + public static ErrorCode valueOf( + com.google.protobuf.Descriptors.EnumValueDescriptor desc) { + if (desc.getType() != getDescriptor()) { + throw new java.lang.IllegalArgumentException( + "EnumValueDescriptor is not for this type."); + } + return VALUES[desc.getIndex()]; + } + + private final int index; + private final int value; + + private ErrorCode(int index, int value) { + this.index = index; + this.value = value; + } + + // @@protoc_insertion_point(enum_scope:ErrorCode) + } + + public interface RpcMessageOrBuilder + extends com.google.protobuf.MessageOrBuilder { + + // required .MessageType type = 1; + boolean hasType(); + muduo.rpc.proto.RpcProto.MessageType getType(); + + // required fixed64 id = 2; + boolean hasId(); + long getId(); + + // optional string service = 3; + boolean hasService(); + String getService(); + + // optional string method = 4; + boolean hasMethod(); + String getMethod(); + + // optional bytes request = 5; + boolean hasRequest(); + com.google.protobuf.ByteString getRequest(); + + // optional bytes response = 6; + boolean hasResponse(); + com.google.protobuf.ByteString getResponse(); + + // optional .ErrorCode error = 7; + boolean hasError(); + muduo.rpc.proto.RpcProto.ErrorCode getError(); + } + public static final class RpcMessage extends + com.google.protobuf.GeneratedMessage + implements RpcMessageOrBuilder { + // Use RpcMessage.newBuilder() to construct. + private RpcMessage(Builder builder) { + super(builder); + } + private RpcMessage(boolean noInit) {} + + private static final RpcMessage defaultInstance; + public static RpcMessage getDefaultInstance() { + return defaultInstance; + } + + public RpcMessage getDefaultInstanceForType() { + return defaultInstance; + } + + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return muduo.rpc.proto.RpcProto.internal_static_RpcMessage_descriptor; + } + + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return muduo.rpc.proto.RpcProto.internal_static_RpcMessage_fieldAccessorTable; + } + + private int bitField0_; + // required .MessageType type = 1; + public static final int TYPE_FIELD_NUMBER = 1; + private muduo.rpc.proto.RpcProto.MessageType type_; + public boolean hasType() { + return ((bitField0_ & 0x00000001) == 0x00000001); + } + public muduo.rpc.proto.RpcProto.MessageType getType() { + return type_; + } + + // required fixed64 id = 2; + public static final int ID_FIELD_NUMBER = 2; + private long id_; + public boolean hasId() { + return ((bitField0_ & 0x00000002) == 0x00000002); + } + public long getId() { + return id_; + } + + // optional string service = 3; + public static final int SERVICE_FIELD_NUMBER = 3; + private Object service_; + public boolean hasService() { + return ((bitField0_ & 0x00000004) == 0x00000004); + } + public String getService() { + Object ref = service_; + if (ref instanceof String) { + return (String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + String s = bs.toStringUtf8(); + if (com.google.protobuf.Internal.isValidUtf8(bs)) { + service_ = s; + } + return s; + } + } + private com.google.protobuf.ByteString getServiceBytes() { + Object ref = service_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((String) ref); + service_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + // optional string method = 4; + public static final int METHOD_FIELD_NUMBER = 4; + private Object method_; + public boolean hasMethod() { + return ((bitField0_ & 0x00000008) == 0x00000008); + } + public String getMethod() { + Object ref = method_; + if (ref instanceof String) { + return (String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + String s = bs.toStringUtf8(); + if (com.google.protobuf.Internal.isValidUtf8(bs)) { + method_ = s; + } + return s; + } + } + private com.google.protobuf.ByteString getMethodBytes() { + Object ref = method_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((String) ref); + method_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + // optional bytes request = 5; + public static final int REQUEST_FIELD_NUMBER = 5; + private com.google.protobuf.ByteString request_; + public boolean hasRequest() { + return ((bitField0_ & 0x00000010) == 0x00000010); + } + public com.google.protobuf.ByteString getRequest() { + return request_; + } + + // optional bytes response = 6; + public static final int RESPONSE_FIELD_NUMBER = 6; + private com.google.protobuf.ByteString response_; + public boolean hasResponse() { + return ((bitField0_ & 0x00000020) == 0x00000020); + } + public com.google.protobuf.ByteString getResponse() { + return response_; + } + + // optional .ErrorCode error = 7; + public static final int ERROR_FIELD_NUMBER = 7; + private muduo.rpc.proto.RpcProto.ErrorCode error_; + public boolean hasError() { + return ((bitField0_ & 0x00000040) == 0x00000040); + } + public muduo.rpc.proto.RpcProto.ErrorCode getError() { + return error_; + } + + private void initFields() { + type_ = muduo.rpc.proto.RpcProto.MessageType.REQUEST; + id_ = 0L; + service_ = ""; + method_ = ""; + request_ = com.google.protobuf.ByteString.EMPTY; + response_ = com.google.protobuf.ByteString.EMPTY; + error_ = muduo.rpc.proto.RpcProto.ErrorCode.WRONG_PROTO; + } + private byte memoizedIsInitialized = -1; + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized != -1) return isInitialized == 1; + + if (!hasType()) { + memoizedIsInitialized = 0; + return false; + } + if (!hasId()) { + memoizedIsInitialized = 0; + return false; + } + memoizedIsInitialized = 1; + return true; + } + + public void writeTo(com.google.protobuf.CodedOutputStream output) + throws java.io.IOException { + getSerializedSize(); + if (((bitField0_ & 0x00000001) == 0x00000001)) { + output.writeEnum(1, type_.getNumber()); + } + if (((bitField0_ & 0x00000002) == 0x00000002)) { + output.writeFixed64(2, id_); + } + if (((bitField0_ & 0x00000004) == 0x00000004)) { + output.writeBytes(3, getServiceBytes()); + } + if (((bitField0_ & 0x00000008) == 0x00000008)) { + output.writeBytes(4, getMethodBytes()); + } + if (((bitField0_ & 0x00000010) == 0x00000010)) { + output.writeBytes(5, request_); + } + if (((bitField0_ & 0x00000020) == 0x00000020)) { + output.writeBytes(6, response_); + } + if (((bitField0_ & 0x00000040) == 0x00000040)) { + output.writeEnum(7, error_.getNumber()); + } + getUnknownFields().writeTo(output); + } + + private int memoizedSerializedSize = -1; + public int getSerializedSize() { + int size = memoizedSerializedSize; + if (size != -1) return size; + + size = 0; + if (((bitField0_ & 0x00000001) == 0x00000001)) { + size += com.google.protobuf.CodedOutputStream + .computeEnumSize(1, type_.getNumber()); + } + if (((bitField0_ & 0x00000002) == 0x00000002)) { + size += com.google.protobuf.CodedOutputStream + .computeFixed64Size(2, id_); + } + if (((bitField0_ & 0x00000004) == 0x00000004)) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(3, getServiceBytes()); + } + if (((bitField0_ & 0x00000008) == 0x00000008)) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(4, getMethodBytes()); + } + if (((bitField0_ & 0x00000010) == 0x00000010)) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(5, request_); + } + if (((bitField0_ & 0x00000020) == 0x00000020)) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(6, response_); + } + if (((bitField0_ & 0x00000040) == 0x00000040)) { + size += com.google.protobuf.CodedOutputStream + .computeEnumSize(7, error_.getNumber()); + } + size += getUnknownFields().getSerializedSize(); + memoizedSerializedSize = size; + return size; + } + + @java.lang.Override + protected Object writeReplace() throws java.io.ObjectStreamException { + return super.writeReplace(); + } + + public static muduo.rpc.proto.RpcProto.RpcMessage parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return newBuilder().mergeFrom(data).buildParsed(); + } + public static muduo.rpc.proto.RpcProto.RpcMessage parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return newBuilder().mergeFrom(data, extensionRegistry) + .buildParsed(); + } + public static muduo.rpc.proto.RpcProto.RpcMessage parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return newBuilder().mergeFrom(data).buildParsed(); + } + public static muduo.rpc.proto.RpcProto.RpcMessage parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return newBuilder().mergeFrom(data, extensionRegistry) + .buildParsed(); + } + public static muduo.rpc.proto.RpcProto.RpcMessage parseFrom(java.io.InputStream input) + throws java.io.IOException { + return newBuilder().mergeFrom(input).buildParsed(); + } + public static muduo.rpc.proto.RpcProto.RpcMessage parseFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return newBuilder().mergeFrom(input, extensionRegistry) + .buildParsed(); + } + public static muduo.rpc.proto.RpcProto.RpcMessage parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + Builder builder = newBuilder(); + if (builder.mergeDelimitedFrom(input)) { + return builder.buildParsed(); + } else { + return null; + } + } + public static muduo.rpc.proto.RpcProto.RpcMessage parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + Builder builder = newBuilder(); + if (builder.mergeDelimitedFrom(input, extensionRegistry)) { + return builder.buildParsed(); + } else { + return null; + } + } + public static muduo.rpc.proto.RpcProto.RpcMessage parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return newBuilder().mergeFrom(input).buildParsed(); + } + public static muduo.rpc.proto.RpcProto.RpcMessage parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return newBuilder().mergeFrom(input, extensionRegistry) + .buildParsed(); + } + + public static Builder newBuilder() { return Builder.create(); } + public Builder newBuilderForType() { return newBuilder(); } + public static Builder newBuilder(muduo.rpc.proto.RpcProto.RpcMessage prototype) { + return newBuilder().mergeFrom(prototype); + } + public Builder toBuilder() { return newBuilder(this); } + + @java.lang.Override + protected Builder newBuilderForType( + com.google.protobuf.GeneratedMessage.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + public static final class Builder extends + com.google.protobuf.GeneratedMessage.Builder + implements muduo.rpc.proto.RpcProto.RpcMessageOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return muduo.rpc.proto.RpcProto.internal_static_RpcMessage_descriptor; + } + + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return muduo.rpc.proto.RpcProto.internal_static_RpcMessage_fieldAccessorTable; + } + + // Construct using muduo.rpc.proto.RpcProto.RpcMessage.newBuilder() + private Builder() { + maybeForceBuilderInitialization(); + } + + private Builder(BuilderParent parent) { + super(parent); + maybeForceBuilderInitialization(); + } + private void maybeForceBuilderInitialization() { + if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { + } + } + private static Builder create() { + return new Builder(); + } + + public Builder clear() { + super.clear(); + type_ = muduo.rpc.proto.RpcProto.MessageType.REQUEST; + bitField0_ = (bitField0_ & ~0x00000001); + id_ = 0L; + bitField0_ = (bitField0_ & ~0x00000002); + service_ = ""; + bitField0_ = (bitField0_ & ~0x00000004); + method_ = ""; + bitField0_ = (bitField0_ & ~0x00000008); + request_ = com.google.protobuf.ByteString.EMPTY; + bitField0_ = (bitField0_ & ~0x00000010); + response_ = com.google.protobuf.ByteString.EMPTY; + bitField0_ = (bitField0_ & ~0x00000020); + error_ = muduo.rpc.proto.RpcProto.ErrorCode.WRONG_PROTO; + bitField0_ = (bitField0_ & ~0x00000040); + return this; + } + + public Builder clone() { + return create().mergeFrom(buildPartial()); + } + + public com.google.protobuf.Descriptors.Descriptor + getDescriptorForType() { + return muduo.rpc.proto.RpcProto.RpcMessage.getDescriptor(); + } + + public muduo.rpc.proto.RpcProto.RpcMessage getDefaultInstanceForType() { + return muduo.rpc.proto.RpcProto.RpcMessage.getDefaultInstance(); + } + + public muduo.rpc.proto.RpcProto.RpcMessage build() { + muduo.rpc.proto.RpcProto.RpcMessage result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + private muduo.rpc.proto.RpcProto.RpcMessage buildParsed() + throws com.google.protobuf.InvalidProtocolBufferException { + muduo.rpc.proto.RpcProto.RpcMessage result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException( + result).asInvalidProtocolBufferException(); + } + return result; + } + + public muduo.rpc.proto.RpcProto.RpcMessage buildPartial() { + muduo.rpc.proto.RpcProto.RpcMessage result = new muduo.rpc.proto.RpcProto.RpcMessage(this); + int from_bitField0_ = bitField0_; + int to_bitField0_ = 0; + if (((from_bitField0_ & 0x00000001) == 0x00000001)) { + to_bitField0_ |= 0x00000001; + } + result.type_ = type_; + if (((from_bitField0_ & 0x00000002) == 0x00000002)) { + to_bitField0_ |= 0x00000002; + } + result.id_ = id_; + if (((from_bitField0_ & 0x00000004) == 0x00000004)) { + to_bitField0_ |= 0x00000004; + } + result.service_ = service_; + if (((from_bitField0_ & 0x00000008) == 0x00000008)) { + to_bitField0_ |= 0x00000008; + } + result.method_ = method_; + if (((from_bitField0_ & 0x00000010) == 0x00000010)) { + to_bitField0_ |= 0x00000010; + } + result.request_ = request_; + if (((from_bitField0_ & 0x00000020) == 0x00000020)) { + to_bitField0_ |= 0x00000020; + } + result.response_ = response_; + if (((from_bitField0_ & 0x00000040) == 0x00000040)) { + to_bitField0_ |= 0x00000040; + } + result.error_ = error_; + result.bitField0_ = to_bitField0_; + onBuilt(); + return result; + } + + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof muduo.rpc.proto.RpcProto.RpcMessage) { + return mergeFrom((muduo.rpc.proto.RpcProto.RpcMessage)other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(muduo.rpc.proto.RpcProto.RpcMessage other) { + if (other == muduo.rpc.proto.RpcProto.RpcMessage.getDefaultInstance()) return this; + if (other.hasType()) { + setType(other.getType()); + } + if (other.hasId()) { + setId(other.getId()); + } + if (other.hasService()) { + setService(other.getService()); + } + if (other.hasMethod()) { + setMethod(other.getMethod()); + } + if (other.hasRequest()) { + setRequest(other.getRequest()); + } + if (other.hasResponse()) { + setResponse(other.getResponse()); + } + if (other.hasError()) { + setError(other.getError()); + } + this.mergeUnknownFields(other.getUnknownFields()); + return this; + } + + public final boolean isInitialized() { + if (!hasType()) { + + return false; + } + if (!hasId()) { + + return false; + } + return true; + } + + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + com.google.protobuf.UnknownFieldSet.Builder unknownFields = + com.google.protobuf.UnknownFieldSet.newBuilder( + this.getUnknownFields()); + while (true) { + int tag = input.readTag(); + switch (tag) { + case 0: + this.setUnknownFields(unknownFields.build()); + onChanged(); + return this; + default: { + if (!parseUnknownField(input, unknownFields, + extensionRegistry, tag)) { + this.setUnknownFields(unknownFields.build()); + onChanged(); + return this; + } + break; + } + case 8: { + int rawValue = input.readEnum(); + muduo.rpc.proto.RpcProto.MessageType value = muduo.rpc.proto.RpcProto.MessageType.valueOf(rawValue); + if (value == null) { + unknownFields.mergeVarintField(1, rawValue); + } else { + bitField0_ |= 0x00000001; + type_ = value; + } + break; + } + case 17: { + bitField0_ |= 0x00000002; + id_ = input.readFixed64(); + break; + } + case 26: { + bitField0_ |= 0x00000004; + service_ = input.readBytes(); + break; + } + case 34: { + bitField0_ |= 0x00000008; + method_ = input.readBytes(); + break; + } + case 42: { + bitField0_ |= 0x00000010; + request_ = input.readBytes(); + break; + } + case 50: { + bitField0_ |= 0x00000020; + response_ = input.readBytes(); + break; + } + case 56: { + int rawValue = input.readEnum(); + muduo.rpc.proto.RpcProto.ErrorCode value = muduo.rpc.proto.RpcProto.ErrorCode.valueOf(rawValue); + if (value == null) { + unknownFields.mergeVarintField(7, rawValue); + } else { + bitField0_ |= 0x00000040; + error_ = value; + } + break; + } + } + } + } + + private int bitField0_; + + // required .MessageType type = 1; + private muduo.rpc.proto.RpcProto.MessageType type_ = muduo.rpc.proto.RpcProto.MessageType.REQUEST; + public boolean hasType() { + return ((bitField0_ & 0x00000001) == 0x00000001); + } + public muduo.rpc.proto.RpcProto.MessageType getType() { + return type_; + } + public Builder setType(muduo.rpc.proto.RpcProto.MessageType value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000001; + type_ = value; + onChanged(); + return this; + } + public Builder clearType() { + bitField0_ = (bitField0_ & ~0x00000001); + type_ = muduo.rpc.proto.RpcProto.MessageType.REQUEST; + onChanged(); + return this; + } + + // required fixed64 id = 2; + private long id_ ; + public boolean hasId() { + return ((bitField0_ & 0x00000002) == 0x00000002); + } + public long getId() { + return id_; + } + public Builder setId(long value) { + bitField0_ |= 0x00000002; + id_ = value; + onChanged(); + return this; + } + public Builder clearId() { + bitField0_ = (bitField0_ & ~0x00000002); + id_ = 0L; + onChanged(); + return this; + } + + // optional string service = 3; + private Object service_ = ""; + public boolean hasService() { + return ((bitField0_ & 0x00000004) == 0x00000004); + } + public String getService() { + Object ref = service_; + if (!(ref instanceof String)) { + String s = ((com.google.protobuf.ByteString) ref).toStringUtf8(); + service_ = s; + return s; + } else { + return (String) ref; + } + } + public Builder setService(String value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000004; + service_ = value; + onChanged(); + return this; + } + public Builder clearService() { + bitField0_ = (bitField0_ & ~0x00000004); + service_ = getDefaultInstance().getService(); + onChanged(); + return this; + } + void setService(com.google.protobuf.ByteString value) { + bitField0_ |= 0x00000004; + service_ = value; + onChanged(); + } + + // optional string method = 4; + private Object method_ = ""; + public boolean hasMethod() { + return ((bitField0_ & 0x00000008) == 0x00000008); + } + public String getMethod() { + Object ref = method_; + if (!(ref instanceof String)) { + String s = ((com.google.protobuf.ByteString) ref).toStringUtf8(); + method_ = s; + return s; + } else { + return (String) ref; + } + } + public Builder setMethod(String value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000008; + method_ = value; + onChanged(); + return this; + } + public Builder clearMethod() { + bitField0_ = (bitField0_ & ~0x00000008); + method_ = getDefaultInstance().getMethod(); + onChanged(); + return this; + } + void setMethod(com.google.protobuf.ByteString value) { + bitField0_ |= 0x00000008; + method_ = value; + onChanged(); + } + + // optional bytes request = 5; + private com.google.protobuf.ByteString request_ = com.google.protobuf.ByteString.EMPTY; + public boolean hasRequest() { + return ((bitField0_ & 0x00000010) == 0x00000010); + } + public com.google.protobuf.ByteString getRequest() { + return request_; + } + public Builder setRequest(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000010; + request_ = value; + onChanged(); + return this; + } + public Builder clearRequest() { + bitField0_ = (bitField0_ & ~0x00000010); + request_ = getDefaultInstance().getRequest(); + onChanged(); + return this; + } + + // optional bytes response = 6; + private com.google.protobuf.ByteString response_ = com.google.protobuf.ByteString.EMPTY; + public boolean hasResponse() { + return ((bitField0_ & 0x00000020) == 0x00000020); + } + public com.google.protobuf.ByteString getResponse() { + return response_; + } + public Builder setResponse(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000020; + response_ = value; + onChanged(); + return this; + } + public Builder clearResponse() { + bitField0_ = (bitField0_ & ~0x00000020); + response_ = getDefaultInstance().getResponse(); + onChanged(); + return this; + } + + // optional .ErrorCode error = 7; + private muduo.rpc.proto.RpcProto.ErrorCode error_ = muduo.rpc.proto.RpcProto.ErrorCode.WRONG_PROTO; + public boolean hasError() { + return ((bitField0_ & 0x00000040) == 0x00000040); + } + public muduo.rpc.proto.RpcProto.ErrorCode getError() { + return error_; + } + public Builder setError(muduo.rpc.proto.RpcProto.ErrorCode value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000040; + error_ = value; + onChanged(); + return this; + } + public Builder clearError() { + bitField0_ = (bitField0_ & ~0x00000040); + error_ = muduo.rpc.proto.RpcProto.ErrorCode.WRONG_PROTO; + onChanged(); + return this; + } + + // @@protoc_insertion_point(builder_scope:RpcMessage) + } + + static { + defaultInstance = new RpcMessage(true); + defaultInstance.initFields(); + } + + // @@protoc_insertion_point(class_scope:RpcMessage) + } + + private static com.google.protobuf.Descriptors.Descriptor + internal_static_RpcMessage_descriptor; + private static + com.google.protobuf.GeneratedMessage.FieldAccessorTable + internal_static_RpcMessage_fieldAccessorTable; + + public static com.google.protobuf.Descriptors.FileDescriptor + getDescriptor() { + return descriptor; + } + private static com.google.protobuf.Descriptors.FileDescriptor + descriptor; + static { + java.lang.String[] descriptorData = { + "\n\trpc.proto\"\223\001\n\nRpcMessage\022\032\n\004type\030\001 \002(\016" + + "2\014.MessageType\022\n\n\002id\030\002 \002(\006\022\017\n\007service\030\003 " + + "\001(\t\022\016\n\006method\030\004 \001(\t\022\017\n\007request\030\005 \001(\014\022\020\n\010" + + "response\030\006 \001(\014\022\031\n\005error\030\007 \001(\0162\n.ErrorCod" + + "e*3\n\013MessageType\022\013\n\007REQUEST\020\001\022\014\n\010RESPONS" + + "E\020\002\022\t\n\005ERROR\020\003*f\n\tErrorCode\022\017\n\013WRONG_PRO" + + "TO\020\001\022\016\n\nNO_SERVICE\020\002\022\r\n\tNO_METHOD\020\003\022\023\n\017I" + + "NVALID_REQUEST\020\004\022\024\n\020INVALID_RESPONSE\020\005B\033" + + "\n\017muduo.rpc.protoB\010RpcProto" + }; + com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = + new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() { + public com.google.protobuf.ExtensionRegistry assignDescriptors( + com.google.protobuf.Descriptors.FileDescriptor root) { + descriptor = root; + internal_static_RpcMessage_descriptor = + getDescriptor().getMessageTypes().get(0); + internal_static_RpcMessage_fieldAccessorTable = new + com.google.protobuf.GeneratedMessage.FieldAccessorTable( + internal_static_RpcMessage_descriptor, + new java.lang.String[] { "Type", "Id", "Service", "Method", "Request", "Response", "Error", }, + muduo.rpc.proto.RpcProto.RpcMessage.class, + muduo.rpc.proto.RpcProto.RpcMessage.Builder.class); + return null; + } + }; + com.google.protobuf.Descriptors.FileDescriptor + .internalBuildGeneratedFileFrom(descriptorData, + new com.google.protobuf.Descriptors.FileDescriptor[] { + }, assigner); + } + + // @@protoc_insertion_point(outer_class_scope) +} diff --git a/protorpc/muduo/rpc/test/MockChannel.java b/protorpc/muduo/rpc/test/MockChannel.java new file mode 100644 index 0000000..158cb75 --- /dev/null +++ b/protorpc/muduo/rpc/test/MockChannel.java @@ -0,0 +1,136 @@ +package muduo.rpc.test; + +import java.net.SocketAddress; + +import org.jboss.netty.channel.Channel; +import org.jboss.netty.channel.ChannelConfig; +import org.jboss.netty.channel.ChannelFactory; +import org.jboss.netty.channel.ChannelFuture; +import org.jboss.netty.channel.ChannelPipeline; + +class MockChannel implements Channel { + + Object message; + + @Override + public int compareTo(Channel o) { + return 0; + } + + @Override + public Integer getId() { + return null; + } + + @Override + public ChannelFactory getFactory() { + return null; + } + + @Override + public Channel getParent() { + return null; + } + + @Override + public ChannelConfig getConfig() { + return null; + } + + @Override + public ChannelPipeline getPipeline() { + return null; + } + + @Override + public boolean isOpen() { + return false; + } + + @Override + public boolean isBound() { + return false; + } + + @Override + public boolean isConnected() { + return false; + } + + @Override + public SocketAddress getLocalAddress() { + return null; + } + + @Override + public SocketAddress getRemoteAddress() { + return null; + } + + @Override + public ChannelFuture write(Object message) { + this.message = message; + return null; + } + + @Override + public ChannelFuture write(Object message, SocketAddress remoteAddress) { + return null; + } + + @Override + public ChannelFuture bind(SocketAddress localAddress) { + return null; + } + + @Override + public ChannelFuture connect(SocketAddress remoteAddress) { + return null; + } + + @Override + public ChannelFuture disconnect() { + return null; + } + + @Override + public ChannelFuture unbind() { + return null; + } + + @Override + public ChannelFuture close() { + return null; + } + + @Override + public ChannelFuture getCloseFuture() { + return null; + } + + @Override + public int getInterestOps() { + return 0; + } + + @Override + public boolean isReadable() { + return false; + } + + @Override + public boolean isWritable() { + return false; + } + + @Override + public ChannelFuture setInterestOps(int interestOps) { + return null; + } + + @Override + public ChannelFuture setReadable(boolean readable) { + return null; + } + +} diff --git a/protorpc/muduo/rpc/test/RpcTest.java b/protorpc/muduo/rpc/test/RpcTest.java new file mode 100644 index 0000000..1babc91 --- /dev/null +++ b/protorpc/muduo/rpc/test/RpcTest.java @@ -0,0 +1,143 @@ +package muduo.rpc.test; + +import static org.junit.Assert.assertEquals; + +import java.util.HashMap; +import java.util.Map; + +import muduo.rpc.RpcChannel; +import muduo.rpc.RpcDecoder; +import muduo.rpc.RpcEncoder; +import muduo.rpc.proto.RpcProto.MessageType; +import muduo.rpc.proto.RpcProto.RpcMessage; + +import org.jboss.netty.buffer.BigEndianHeapChannelBuffer; +import org.jboss.netty.buffer.ChannelBuffer; +import org.jboss.netty.channel.UpstreamMessageEvent; +import org.junit.Test; + +import sudoku.Sudoku; +import sudoku.Sudoku.SudokuRequest; +import sudoku.Sudoku.SudokuResponse; +import sudoku.Sudoku.SudokuService; +import sudoku.Sudoku.SudokuService.Interface; + +import com.google.protobuf.RpcCallback; +import com.google.protobuf.RpcController; +import com.google.protobuf.Service; + +public class RpcTest { + + @Test + public void testEncoder() throws Exception { + RpcEncoder encoder = new RpcEncoder(); + RpcMessage message = RpcMessage.newBuilder().setType(MessageType.REQUEST).setId(1).build(); + encoder.encode(null, null, message); + } + + @Test + public void testDecoder() throws Exception { + RpcEncoder encoder = new RpcEncoder(); + RpcMessage message = RpcMessage.newBuilder().setType(MessageType.REQUEST).setId(1).build(); + ChannelBuffer buffer = (ChannelBuffer) encoder.encode(null, null, message); + + RpcDecoder decoder = new RpcDecoder(); + RpcMessage decodedMessage = (RpcMessage) decoder.decode(null, null, buffer); + assertEquals(1, decodedMessage.getId()); + } + + @Test + public void testDecoder2() throws Exception { + RpcEncoder encoder = new RpcEncoder(); + RpcMessage message = RpcMessage.newBuilder().setType(MessageType.REQUEST).setId(2).build(); + ChannelBuffer buffer = (ChannelBuffer) encoder.encode(null, null, message); + ChannelBuffer buf2 = new BigEndianHeapChannelBuffer(buffer.readableBytes() + 8); + buf2.writeInt(123); + buf2.writeBytes(buffer); + + buf2.readInt(); + RpcDecoder decoder = new RpcDecoder(); + RpcMessage decodedMessage = (RpcMessage) decoder.decode(null, null, buf2); + assertEquals(2, decodedMessage.getId()); + } + + SudokuResponse gotResponse; + + @Test + public void testClient() throws Exception { + MockChannel mockChannel = new MockChannel(); + RpcChannel channel = new RpcChannel(mockChannel); + SudokuService remoteService = Sudoku.SudokuService.newStub(channel); + SudokuRequest request = SudokuRequest.newBuilder().setCheckerboard("001010").build(); + remoteService.solve(null, request, new RpcCallback() { + @Override + public void run(SudokuResponse response) { + // System.out.println(parameter); + gotResponse = response; + } + }); + RpcMessage message = (RpcMessage) mockChannel.message; + assertEquals(1, message.getId()); + assertEquals(MessageType.REQUEST, message.getType()); + assertEquals(remoteService.getDescriptorForType().getFullName(), message.getService()); + assertEquals("Solve", message.getMethod()); + + SudokuResponse sudokuResponse = SudokuResponse.newBuilder() + .setSolved(true) + .setCheckerboard("123456") + .build(); + RpcMessage response = RpcMessage.newBuilder() + .setType(MessageType.RESPONSE) + .setId(1) + .setResponse(sudokuResponse.toByteString()) + .build(); + channel.messageReceived(null, new UpstreamMessageEvent(mockChannel, response, null)); + assertEquals(sudokuResponse, gotResponse); + } + + SudokuRequest gotRequest; + + @Test + public void testServer() throws Exception { + + MockChannel mockChannel = new MockChannel(); + Map services = new HashMap(); + final SudokuResponse sudokuResponse = SudokuResponse.newBuilder() + .setSolved(true) + .setCheckerboard("98765") + .build(); + Interface mockImpl = new Interface() { + + @Override + public void solve(RpcController controller, SudokuRequest request, + RpcCallback done) { + gotRequest = request; + + done.run(sudokuResponse); + } + }; + services.put(SudokuService.getDescriptor().getFullName(), + SudokuService.newReflectiveService(mockImpl)); + RpcChannel channel = new RpcChannel(mockChannel); + channel.setServiceMap(services); + + SudokuRequest sudokuRequest = SudokuRequest.newBuilder().setCheckerboard("001010").build(); + RpcMessage request = RpcMessage.newBuilder() + .setType(MessageType.REQUEST) + .setId(2) + .setService(SudokuService.getDescriptor().getFullName()) + .setMethod("Solve") + .setRequest(sudokuRequest.toByteString()) + .build(); + + channel.messageReceived(null, new UpstreamMessageEvent(mockChannel, request, null)); + assertEquals(sudokuRequest, gotRequest); + + RpcMessage response = RpcMessage.newBuilder() + .setType(MessageType.RESPONSE) + .setId(2) + .setResponse(sudokuResponse.toByteString()) + .build(); + assertEquals(response, mockChannel.message); + } +} diff --git a/protorpc/rpc.proto b/protorpc/rpc.proto new file mode 100644 index 0000000..16edb61 --- /dev/null +++ b/protorpc/rpc.proto @@ -0,0 +1,32 @@ +option java_package = "muduo.rpc.proto"; +option java_outer_classname = "RpcProto"; + +enum MessageType +{ + REQUEST = 1; + RESPONSE = 2; + ERROR = 3; +} + +enum ErrorCode +{ + WRONG_PROTO = 1; + NO_SERVICE = 2; + NO_METHOD = 3; + INVALID_REQUEST = 4; + INVALID_RESPONSE = 5; +} + +message RpcMessage +{ + required MessageType type = 1; + required fixed64 id = 2; + + optional string service = 3; + optional string method = 4; + optional bytes request = 5; + + optional bytes response = 6; + + optional ErrorCode error = 7; +} diff --git a/protorpc/sudoku/Client.java b/protorpc/sudoku/Client.java new file mode 100644 index 0000000..80890b9 --- /dev/null +++ b/protorpc/sudoku/Client.java @@ -0,0 +1,49 @@ +package sudoku; + +import java.net.InetSocketAddress; + +import muduo.rpc.NewChannelCallback; +import muduo.rpc.RpcChannel; +import muduo.rpc.RpcClient; +import sudoku.Sudoku.SudokuRequest; +import sudoku.Sudoku.SudokuResponse; +import sudoku.Sudoku.SudokuService; + +import com.google.protobuf.RpcCallback; + +public class Client { + + private static void blockingConnect(InetSocketAddress addr) { + RpcClient client = new RpcClient(); + RpcChannel channel = client.blockingConnect(addr); + sendRequest(channel); + } + + private static void asyncConnect(InetSocketAddress addr) { + RpcClient client = new RpcClient(); + client.registerService(Sudoku.SudokuService.newReflectiveService(new SudokuImpl())); + client.startConnect(addr, new NewChannelCallback() { + @Override + public void run(RpcChannel channel) { + sendRequest(channel); + } + }); + } + + private static void sendRequest(RpcChannel channel) { + SudokuService remoteService = Sudoku.SudokuService.newStub(channel); + SudokuRequest request = SudokuRequest.newBuilder().setCheckerboard("001010").build(); + remoteService.solve(null, request, new RpcCallback() { + @Override + public void run(SudokuResponse parameter) { + System.out.println(parameter); + } + }); + } + + public static void main(String[] args) throws Exception { + InetSocketAddress addr = new InetSocketAddress("localhost", 8888); + // asyncConnect(addr); + blockingConnect(addr); + } +} diff --git a/protorpc/sudoku/Server.java b/protorpc/sudoku/Server.java new file mode 100644 index 0000000..294ba20 --- /dev/null +++ b/protorpc/sudoku/Server.java @@ -0,0 +1,22 @@ +package sudoku; + +import muduo.rpc.NewChannelCallback; +import muduo.rpc.RpcChannel; +import muduo.rpc.RpcServer; + +public class Server { + + public static void main(String[] args) { + RpcServer server = new RpcServer(); + server.registerService(Sudoku.SudokuService.newReflectiveService(new SudokuImpl())); + server.setNewChannelCallback(new NewChannelCallback() { + + @Override + public void run(RpcChannel channel) { + // TODO call client + + } + }); + server.start(8888); + } +} diff --git a/protorpc/sudoku/Sudoku.java b/protorpc/sudoku/Sudoku.java new file mode 100644 index 0000000..321fc7e --- /dev/null +++ b/protorpc/sudoku/Sudoku.java @@ -0,0 +1,1104 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: sudoku.proto + +package sudoku; + +public final class Sudoku { + private Sudoku() {} + public static void registerAllExtensions( + com.google.protobuf.ExtensionRegistry registry) { + } + public interface SudokuRequestOrBuilder + extends com.google.protobuf.MessageOrBuilder { + + // required string checkerboard = 1; + boolean hasCheckerboard(); + String getCheckerboard(); + } + public static final class SudokuRequest extends + com.google.protobuf.GeneratedMessage + implements SudokuRequestOrBuilder { + // Use SudokuRequest.newBuilder() to construct. + private SudokuRequest(Builder builder) { + super(builder); + } + private SudokuRequest(boolean noInit) {} + + private static final SudokuRequest defaultInstance; + public static SudokuRequest getDefaultInstance() { + return defaultInstance; + } + + public SudokuRequest getDefaultInstanceForType() { + return defaultInstance; + } + + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return sudoku.Sudoku.internal_static_sudoku_SudokuRequest_descriptor; + } + + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return sudoku.Sudoku.internal_static_sudoku_SudokuRequest_fieldAccessorTable; + } + + private int bitField0_; + // required string checkerboard = 1; + public static final int CHECKERBOARD_FIELD_NUMBER = 1; + private java.lang.Object checkerboard_; + public boolean hasCheckerboard() { + return ((bitField0_ & 0x00000001) == 0x00000001); + } + public String getCheckerboard() { + java.lang.Object ref = checkerboard_; + if (ref instanceof String) { + return (String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + String s = bs.toStringUtf8(); + if (com.google.protobuf.Internal.isValidUtf8(bs)) { + checkerboard_ = s; + } + return s; + } + } + private com.google.protobuf.ByteString getCheckerboardBytes() { + java.lang.Object ref = checkerboard_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((String) ref); + checkerboard_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + private void initFields() { + checkerboard_ = ""; + } + private byte memoizedIsInitialized = -1; + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized != -1) return isInitialized == 1; + + if (!hasCheckerboard()) { + memoizedIsInitialized = 0; + return false; + } + memoizedIsInitialized = 1; + return true; + } + + public void writeTo(com.google.protobuf.CodedOutputStream output) + throws java.io.IOException { + getSerializedSize(); + if (((bitField0_ & 0x00000001) == 0x00000001)) { + output.writeBytes(1, getCheckerboardBytes()); + } + getUnknownFields().writeTo(output); + } + + private int memoizedSerializedSize = -1; + public int getSerializedSize() { + int size = memoizedSerializedSize; + if (size != -1) return size; + + size = 0; + if (((bitField0_ & 0x00000001) == 0x00000001)) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(1, getCheckerboardBytes()); + } + size += getUnknownFields().getSerializedSize(); + memoizedSerializedSize = size; + return size; + } + + private static final long serialVersionUID = 0L; + @java.lang.Override + protected java.lang.Object writeReplace() + throws java.io.ObjectStreamException { + return super.writeReplace(); + } + + public static sudoku.Sudoku.SudokuRequest parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return newBuilder().mergeFrom(data).buildParsed(); + } + public static sudoku.Sudoku.SudokuRequest parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return newBuilder().mergeFrom(data, extensionRegistry) + .buildParsed(); + } + public static sudoku.Sudoku.SudokuRequest parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return newBuilder().mergeFrom(data).buildParsed(); + } + public static sudoku.Sudoku.SudokuRequest parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return newBuilder().mergeFrom(data, extensionRegistry) + .buildParsed(); + } + public static sudoku.Sudoku.SudokuRequest parseFrom(java.io.InputStream input) + throws java.io.IOException { + return newBuilder().mergeFrom(input).buildParsed(); + } + public static sudoku.Sudoku.SudokuRequest parseFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return newBuilder().mergeFrom(input, extensionRegistry) + .buildParsed(); + } + public static sudoku.Sudoku.SudokuRequest parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + Builder builder = newBuilder(); + if (builder.mergeDelimitedFrom(input)) { + return builder.buildParsed(); + } else { + return null; + } + } + public static sudoku.Sudoku.SudokuRequest parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + Builder builder = newBuilder(); + if (builder.mergeDelimitedFrom(input, extensionRegistry)) { + return builder.buildParsed(); + } else { + return null; + } + } + public static sudoku.Sudoku.SudokuRequest parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return newBuilder().mergeFrom(input).buildParsed(); + } + public static sudoku.Sudoku.SudokuRequest parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return newBuilder().mergeFrom(input, extensionRegistry) + .buildParsed(); + } + + public static Builder newBuilder() { return Builder.create(); } + public Builder newBuilderForType() { return newBuilder(); } + public static Builder newBuilder(sudoku.Sudoku.SudokuRequest prototype) { + return newBuilder().mergeFrom(prototype); + } + public Builder toBuilder() { return newBuilder(this); } + + @java.lang.Override + protected Builder newBuilderForType( + com.google.protobuf.GeneratedMessage.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + public static final class Builder extends + com.google.protobuf.GeneratedMessage.Builder + implements sudoku.Sudoku.SudokuRequestOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return sudoku.Sudoku.internal_static_sudoku_SudokuRequest_descriptor; + } + + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return sudoku.Sudoku.internal_static_sudoku_SudokuRequest_fieldAccessorTable; + } + + // Construct using sudoku.Sudoku.SudokuRequest.newBuilder() + private Builder() { + maybeForceBuilderInitialization(); + } + + private Builder(BuilderParent parent) { + super(parent); + maybeForceBuilderInitialization(); + } + private void maybeForceBuilderInitialization() { + if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { + } + } + private static Builder create() { + return new Builder(); + } + + public Builder clear() { + super.clear(); + checkerboard_ = ""; + bitField0_ = (bitField0_ & ~0x00000001); + return this; + } + + public Builder clone() { + return create().mergeFrom(buildPartial()); + } + + public com.google.protobuf.Descriptors.Descriptor + getDescriptorForType() { + return sudoku.Sudoku.SudokuRequest.getDescriptor(); + } + + public sudoku.Sudoku.SudokuRequest getDefaultInstanceForType() { + return sudoku.Sudoku.SudokuRequest.getDefaultInstance(); + } + + public sudoku.Sudoku.SudokuRequest build() { + sudoku.Sudoku.SudokuRequest result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + private sudoku.Sudoku.SudokuRequest buildParsed() + throws com.google.protobuf.InvalidProtocolBufferException { + sudoku.Sudoku.SudokuRequest result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException( + result).asInvalidProtocolBufferException(); + } + return result; + } + + public sudoku.Sudoku.SudokuRequest buildPartial() { + sudoku.Sudoku.SudokuRequest result = new sudoku.Sudoku.SudokuRequest(this); + int from_bitField0_ = bitField0_; + int to_bitField0_ = 0; + if (((from_bitField0_ & 0x00000001) == 0x00000001)) { + to_bitField0_ |= 0x00000001; + } + result.checkerboard_ = checkerboard_; + result.bitField0_ = to_bitField0_; + onBuilt(); + return result; + } + + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof sudoku.Sudoku.SudokuRequest) { + return mergeFrom((sudoku.Sudoku.SudokuRequest)other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(sudoku.Sudoku.SudokuRequest other) { + if (other == sudoku.Sudoku.SudokuRequest.getDefaultInstance()) return this; + if (other.hasCheckerboard()) { + setCheckerboard(other.getCheckerboard()); + } + this.mergeUnknownFields(other.getUnknownFields()); + return this; + } + + public final boolean isInitialized() { + if (!hasCheckerboard()) { + + return false; + } + return true; + } + + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + com.google.protobuf.UnknownFieldSet.Builder unknownFields = + com.google.protobuf.UnknownFieldSet.newBuilder( + this.getUnknownFields()); + while (true) { + int tag = input.readTag(); + switch (tag) { + case 0: + this.setUnknownFields(unknownFields.build()); + onChanged(); + return this; + default: { + if (!parseUnknownField(input, unknownFields, + extensionRegistry, tag)) { + this.setUnknownFields(unknownFields.build()); + onChanged(); + return this; + } + break; + } + case 10: { + bitField0_ |= 0x00000001; + checkerboard_ = input.readBytes(); + break; + } + } + } + } + + private int bitField0_; + + // required string checkerboard = 1; + private java.lang.Object checkerboard_ = ""; + public boolean hasCheckerboard() { + return ((bitField0_ & 0x00000001) == 0x00000001); + } + public String getCheckerboard() { + java.lang.Object ref = checkerboard_; + if (!(ref instanceof String)) { + String s = ((com.google.protobuf.ByteString) ref).toStringUtf8(); + checkerboard_ = s; + return s; + } else { + return (String) ref; + } + } + public Builder setCheckerboard(String value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000001; + checkerboard_ = value; + onChanged(); + return this; + } + public Builder clearCheckerboard() { + bitField0_ = (bitField0_ & ~0x00000001); + checkerboard_ = getDefaultInstance().getCheckerboard(); + onChanged(); + return this; + } + void setCheckerboard(com.google.protobuf.ByteString value) { + bitField0_ |= 0x00000001; + checkerboard_ = value; + onChanged(); + } + + // @@protoc_insertion_point(builder_scope:sudoku.SudokuRequest) + } + + static { + defaultInstance = new SudokuRequest(true); + defaultInstance.initFields(); + } + + // @@protoc_insertion_point(class_scope:sudoku.SudokuRequest) + } + + public interface SudokuResponseOrBuilder + extends com.google.protobuf.MessageOrBuilder { + + // optional bool solved = 1 [default = false]; + boolean hasSolved(); + boolean getSolved(); + + // optional string checkerboard = 2; + boolean hasCheckerboard(); + String getCheckerboard(); + } + public static final class SudokuResponse extends + com.google.protobuf.GeneratedMessage + implements SudokuResponseOrBuilder { + // Use SudokuResponse.newBuilder() to construct. + private SudokuResponse(Builder builder) { + super(builder); + } + private SudokuResponse(boolean noInit) {} + + private static final SudokuResponse defaultInstance; + public static SudokuResponse getDefaultInstance() { + return defaultInstance; + } + + public SudokuResponse getDefaultInstanceForType() { + return defaultInstance; + } + + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return sudoku.Sudoku.internal_static_sudoku_SudokuResponse_descriptor; + } + + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return sudoku.Sudoku.internal_static_sudoku_SudokuResponse_fieldAccessorTable; + } + + private int bitField0_; + // optional bool solved = 1 [default = false]; + public static final int SOLVED_FIELD_NUMBER = 1; + private boolean solved_; + public boolean hasSolved() { + return ((bitField0_ & 0x00000001) == 0x00000001); + } + public boolean getSolved() { + return solved_; + } + + // optional string checkerboard = 2; + public static final int CHECKERBOARD_FIELD_NUMBER = 2; + private java.lang.Object checkerboard_; + public boolean hasCheckerboard() { + return ((bitField0_ & 0x00000002) == 0x00000002); + } + public String getCheckerboard() { + java.lang.Object ref = checkerboard_; + if (ref instanceof String) { + return (String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + String s = bs.toStringUtf8(); + if (com.google.protobuf.Internal.isValidUtf8(bs)) { + checkerboard_ = s; + } + return s; + } + } + private com.google.protobuf.ByteString getCheckerboardBytes() { + java.lang.Object ref = checkerboard_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8((String) ref); + checkerboard_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + private void initFields() { + solved_ = false; + checkerboard_ = ""; + } + private byte memoizedIsInitialized = -1; + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized != -1) return isInitialized == 1; + + memoizedIsInitialized = 1; + return true; + } + + public void writeTo(com.google.protobuf.CodedOutputStream output) + throws java.io.IOException { + getSerializedSize(); + if (((bitField0_ & 0x00000001) == 0x00000001)) { + output.writeBool(1, solved_); + } + if (((bitField0_ & 0x00000002) == 0x00000002)) { + output.writeBytes(2, getCheckerboardBytes()); + } + getUnknownFields().writeTo(output); + } + + private int memoizedSerializedSize = -1; + public int getSerializedSize() { + int size = memoizedSerializedSize; + if (size != -1) return size; + + size = 0; + if (((bitField0_ & 0x00000001) == 0x00000001)) { + size += com.google.protobuf.CodedOutputStream + .computeBoolSize(1, solved_); + } + if (((bitField0_ & 0x00000002) == 0x00000002)) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(2, getCheckerboardBytes()); + } + size += getUnknownFields().getSerializedSize(); + memoizedSerializedSize = size; + return size; + } + + private static final long serialVersionUID = 0L; + @java.lang.Override + protected java.lang.Object writeReplace() + throws java.io.ObjectStreamException { + return super.writeReplace(); + } + + public static sudoku.Sudoku.SudokuResponse parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return newBuilder().mergeFrom(data).buildParsed(); + } + public static sudoku.Sudoku.SudokuResponse parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return newBuilder().mergeFrom(data, extensionRegistry) + .buildParsed(); + } + public static sudoku.Sudoku.SudokuResponse parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return newBuilder().mergeFrom(data).buildParsed(); + } + public static sudoku.Sudoku.SudokuResponse parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return newBuilder().mergeFrom(data, extensionRegistry) + .buildParsed(); + } + public static sudoku.Sudoku.SudokuResponse parseFrom(java.io.InputStream input) + throws java.io.IOException { + return newBuilder().mergeFrom(input).buildParsed(); + } + public static sudoku.Sudoku.SudokuResponse parseFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return newBuilder().mergeFrom(input, extensionRegistry) + .buildParsed(); + } + public static sudoku.Sudoku.SudokuResponse parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + Builder builder = newBuilder(); + if (builder.mergeDelimitedFrom(input)) { + return builder.buildParsed(); + } else { + return null; + } + } + public static sudoku.Sudoku.SudokuResponse parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + Builder builder = newBuilder(); + if (builder.mergeDelimitedFrom(input, extensionRegistry)) { + return builder.buildParsed(); + } else { + return null; + } + } + public static sudoku.Sudoku.SudokuResponse parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return newBuilder().mergeFrom(input).buildParsed(); + } + public static sudoku.Sudoku.SudokuResponse parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return newBuilder().mergeFrom(input, extensionRegistry) + .buildParsed(); + } + + public static Builder newBuilder() { return Builder.create(); } + public Builder newBuilderForType() { return newBuilder(); } + public static Builder newBuilder(sudoku.Sudoku.SudokuResponse prototype) { + return newBuilder().mergeFrom(prototype); + } + public Builder toBuilder() { return newBuilder(this); } + + @java.lang.Override + protected Builder newBuilderForType( + com.google.protobuf.GeneratedMessage.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + public static final class Builder extends + com.google.protobuf.GeneratedMessage.Builder + implements sudoku.Sudoku.SudokuResponseOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return sudoku.Sudoku.internal_static_sudoku_SudokuResponse_descriptor; + } + + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return sudoku.Sudoku.internal_static_sudoku_SudokuResponse_fieldAccessorTable; + } + + // Construct using sudoku.Sudoku.SudokuResponse.newBuilder() + private Builder() { + maybeForceBuilderInitialization(); + } + + private Builder(BuilderParent parent) { + super(parent); + maybeForceBuilderInitialization(); + } + private void maybeForceBuilderInitialization() { + if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { + } + } + private static Builder create() { + return new Builder(); + } + + public Builder clear() { + super.clear(); + solved_ = false; + bitField0_ = (bitField0_ & ~0x00000001); + checkerboard_ = ""; + bitField0_ = (bitField0_ & ~0x00000002); + return this; + } + + public Builder clone() { + return create().mergeFrom(buildPartial()); + } + + public com.google.protobuf.Descriptors.Descriptor + getDescriptorForType() { + return sudoku.Sudoku.SudokuResponse.getDescriptor(); + } + + public sudoku.Sudoku.SudokuResponse getDefaultInstanceForType() { + return sudoku.Sudoku.SudokuResponse.getDefaultInstance(); + } + + public sudoku.Sudoku.SudokuResponse build() { + sudoku.Sudoku.SudokuResponse result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + private sudoku.Sudoku.SudokuResponse buildParsed() + throws com.google.protobuf.InvalidProtocolBufferException { + sudoku.Sudoku.SudokuResponse result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException( + result).asInvalidProtocolBufferException(); + } + return result; + } + + public sudoku.Sudoku.SudokuResponse buildPartial() { + sudoku.Sudoku.SudokuResponse result = new sudoku.Sudoku.SudokuResponse(this); + int from_bitField0_ = bitField0_; + int to_bitField0_ = 0; + if (((from_bitField0_ & 0x00000001) == 0x00000001)) { + to_bitField0_ |= 0x00000001; + } + result.solved_ = solved_; + if (((from_bitField0_ & 0x00000002) == 0x00000002)) { + to_bitField0_ |= 0x00000002; + } + result.checkerboard_ = checkerboard_; + result.bitField0_ = to_bitField0_; + onBuilt(); + return result; + } + + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof sudoku.Sudoku.SudokuResponse) { + return mergeFrom((sudoku.Sudoku.SudokuResponse)other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(sudoku.Sudoku.SudokuResponse other) { + if (other == sudoku.Sudoku.SudokuResponse.getDefaultInstance()) return this; + if (other.hasSolved()) { + setSolved(other.getSolved()); + } + if (other.hasCheckerboard()) { + setCheckerboard(other.getCheckerboard()); + } + this.mergeUnknownFields(other.getUnknownFields()); + return this; + } + + public final boolean isInitialized() { + return true; + } + + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + com.google.protobuf.UnknownFieldSet.Builder unknownFields = + com.google.protobuf.UnknownFieldSet.newBuilder( + this.getUnknownFields()); + while (true) { + int tag = input.readTag(); + switch (tag) { + case 0: + this.setUnknownFields(unknownFields.build()); + onChanged(); + return this; + default: { + if (!parseUnknownField(input, unknownFields, + extensionRegistry, tag)) { + this.setUnknownFields(unknownFields.build()); + onChanged(); + return this; + } + break; + } + case 8: { + bitField0_ |= 0x00000001; + solved_ = input.readBool(); + break; + } + case 18: { + bitField0_ |= 0x00000002; + checkerboard_ = input.readBytes(); + break; + } + } + } + } + + private int bitField0_; + + // optional bool solved = 1 [default = false]; + private boolean solved_ ; + public boolean hasSolved() { + return ((bitField0_ & 0x00000001) == 0x00000001); + } + public boolean getSolved() { + return solved_; + } + public Builder setSolved(boolean value) { + bitField0_ |= 0x00000001; + solved_ = value; + onChanged(); + return this; + } + public Builder clearSolved() { + bitField0_ = (bitField0_ & ~0x00000001); + solved_ = false; + onChanged(); + return this; + } + + // optional string checkerboard = 2; + private java.lang.Object checkerboard_ = ""; + public boolean hasCheckerboard() { + return ((bitField0_ & 0x00000002) == 0x00000002); + } + public String getCheckerboard() { + java.lang.Object ref = checkerboard_; + if (!(ref instanceof String)) { + String s = ((com.google.protobuf.ByteString) ref).toStringUtf8(); + checkerboard_ = s; + return s; + } else { + return (String) ref; + } + } + public Builder setCheckerboard(String value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000002; + checkerboard_ = value; + onChanged(); + return this; + } + public Builder clearCheckerboard() { + bitField0_ = (bitField0_ & ~0x00000002); + checkerboard_ = getDefaultInstance().getCheckerboard(); + onChanged(); + return this; + } + void setCheckerboard(com.google.protobuf.ByteString value) { + bitField0_ |= 0x00000002; + checkerboard_ = value; + onChanged(); + } + + // @@protoc_insertion_point(builder_scope:sudoku.SudokuResponse) + } + + static { + defaultInstance = new SudokuResponse(true); + defaultInstance.initFields(); + } + + // @@protoc_insertion_point(class_scope:sudoku.SudokuResponse) + } + + public static abstract class SudokuService + implements com.google.protobuf.Service { + protected SudokuService() {} + + public interface Interface { + public abstract void solve( + com.google.protobuf.RpcController controller, + sudoku.Sudoku.SudokuRequest request, + com.google.protobuf.RpcCallback done); + + } + + public static com.google.protobuf.Service newReflectiveService( + final Interface impl) { + return new SudokuService() { + @java.lang.Override + public void solve( + com.google.protobuf.RpcController controller, + sudoku.Sudoku.SudokuRequest request, + com.google.protobuf.RpcCallback done) { + impl.solve(controller, request, done); + } + + }; + } + + public static com.google.protobuf.BlockingService + newReflectiveBlockingService(final BlockingInterface impl) { + return new com.google.protobuf.BlockingService() { + public final com.google.protobuf.Descriptors.ServiceDescriptor + getDescriptorForType() { + return getDescriptor(); + } + + public final com.google.protobuf.Message callBlockingMethod( + com.google.protobuf.Descriptors.MethodDescriptor method, + com.google.protobuf.RpcController controller, + com.google.protobuf.Message request) + throws com.google.protobuf.ServiceException { + if (method.getService() != getDescriptor()) { + throw new java.lang.IllegalArgumentException( + "Service.callBlockingMethod() given method descriptor for " + + "wrong service type."); + } + switch(method.getIndex()) { + case 0: + return impl.solve(controller, (sudoku.Sudoku.SudokuRequest)request); + default: + throw new java.lang.AssertionError("Can't get here."); + } + } + + public final com.google.protobuf.Message + getRequestPrototype( + com.google.protobuf.Descriptors.MethodDescriptor method) { + if (method.getService() != getDescriptor()) { + throw new java.lang.IllegalArgumentException( + "Service.getRequestPrototype() given method " + + "descriptor for wrong service type."); + } + switch(method.getIndex()) { + case 0: + return sudoku.Sudoku.SudokuRequest.getDefaultInstance(); + default: + throw new java.lang.AssertionError("Can't get here."); + } + } + + public final com.google.protobuf.Message + getResponsePrototype( + com.google.protobuf.Descriptors.MethodDescriptor method) { + if (method.getService() != getDescriptor()) { + throw new java.lang.IllegalArgumentException( + "Service.getResponsePrototype() given method " + + "descriptor for wrong service type."); + } + switch(method.getIndex()) { + case 0: + return sudoku.Sudoku.SudokuResponse.getDefaultInstance(); + default: + throw new java.lang.AssertionError("Can't get here."); + } + } + + }; + } + + public abstract void solve( + com.google.protobuf.RpcController controller, + sudoku.Sudoku.SudokuRequest request, + com.google.protobuf.RpcCallback done); + + public static final + com.google.protobuf.Descriptors.ServiceDescriptor + getDescriptor() { + return sudoku.Sudoku.getDescriptor().getServices().get(0); + } + public final com.google.protobuf.Descriptors.ServiceDescriptor + getDescriptorForType() { + return getDescriptor(); + } + + public final void callMethod( + com.google.protobuf.Descriptors.MethodDescriptor method, + com.google.protobuf.RpcController controller, + com.google.protobuf.Message request, + com.google.protobuf.RpcCallback< + com.google.protobuf.Message> done) { + if (method.getService() != getDescriptor()) { + throw new java.lang.IllegalArgumentException( + "Service.callMethod() given method descriptor for wrong " + + "service type."); + } + switch(method.getIndex()) { + case 0: + this.solve(controller, (sudoku.Sudoku.SudokuRequest)request, + com.google.protobuf.RpcUtil.specializeCallback( + done)); + return; + default: + throw new java.lang.AssertionError("Can't get here."); + } + } + + public final com.google.protobuf.Message + getRequestPrototype( + com.google.protobuf.Descriptors.MethodDescriptor method) { + if (method.getService() != getDescriptor()) { + throw new java.lang.IllegalArgumentException( + "Service.getRequestPrototype() given method " + + "descriptor for wrong service type."); + } + switch(method.getIndex()) { + case 0: + return sudoku.Sudoku.SudokuRequest.getDefaultInstance(); + default: + throw new java.lang.AssertionError("Can't get here."); + } + } + + public final com.google.protobuf.Message + getResponsePrototype( + com.google.protobuf.Descriptors.MethodDescriptor method) { + if (method.getService() != getDescriptor()) { + throw new java.lang.IllegalArgumentException( + "Service.getResponsePrototype() given method " + + "descriptor for wrong service type."); + } + switch(method.getIndex()) { + case 0: + return sudoku.Sudoku.SudokuResponse.getDefaultInstance(); + default: + throw new java.lang.AssertionError("Can't get here."); + } + } + + public static Stub newStub( + com.google.protobuf.RpcChannel channel) { + return new Stub(channel); + } + + public static final class Stub extends sudoku.Sudoku.SudokuService implements Interface { + private Stub(com.google.protobuf.RpcChannel channel) { + this.channel = channel; + } + + private final com.google.protobuf.RpcChannel channel; + + public com.google.protobuf.RpcChannel getChannel() { + return channel; + } + + public void solve( + com.google.protobuf.RpcController controller, + sudoku.Sudoku.SudokuRequest request, + com.google.protobuf.RpcCallback done) { + channel.callMethod( + getDescriptor().getMethods().get(0), + controller, + request, + sudoku.Sudoku.SudokuResponse.getDefaultInstance(), + com.google.protobuf.RpcUtil.generalizeCallback( + done, + sudoku.Sudoku.SudokuResponse.class, + sudoku.Sudoku.SudokuResponse.getDefaultInstance())); + } + } + + public static BlockingInterface newBlockingStub( + com.google.protobuf.BlockingRpcChannel channel) { + return new BlockingStub(channel); + } + + public interface BlockingInterface { + public sudoku.Sudoku.SudokuResponse solve( + com.google.protobuf.RpcController controller, + sudoku.Sudoku.SudokuRequest request) + throws com.google.protobuf.ServiceException; + } + + private static final class BlockingStub implements BlockingInterface { + private BlockingStub(com.google.protobuf.BlockingRpcChannel channel) { + this.channel = channel; + } + + private final com.google.protobuf.BlockingRpcChannel channel; + + public sudoku.Sudoku.SudokuResponse solve( + com.google.protobuf.RpcController controller, + sudoku.Sudoku.SudokuRequest request) + throws com.google.protobuf.ServiceException { + return (sudoku.Sudoku.SudokuResponse) channel.callBlockingMethod( + getDescriptor().getMethods().get(0), + controller, + request, + sudoku.Sudoku.SudokuResponse.getDefaultInstance()); + } + + } + } + + private static com.google.protobuf.Descriptors.Descriptor + internal_static_sudoku_SudokuRequest_descriptor; + private static + com.google.protobuf.GeneratedMessage.FieldAccessorTable + internal_static_sudoku_SudokuRequest_fieldAccessorTable; + private static com.google.protobuf.Descriptors.Descriptor + internal_static_sudoku_SudokuResponse_descriptor; + private static + com.google.protobuf.GeneratedMessage.FieldAccessorTable + internal_static_sudoku_SudokuResponse_fieldAccessorTable; + + public static com.google.protobuf.Descriptors.FileDescriptor + getDescriptor() { + return descriptor; + } + private static com.google.protobuf.Descriptors.FileDescriptor + descriptor; + static { + java.lang.String[] descriptorData = { + "\n\014sudoku.proto\022\006sudoku\"%\n\rSudokuRequest\022" + + "\024\n\014checkerboard\030\001 \002(\t\"=\n\016SudokuResponse\022" + + "\025\n\006solved\030\001 \001(\010:\005false\022\024\n\014checkerboard\030\002" + + " \001(\t2G\n\rSudokuService\0226\n\005Solve\022\025.sudoku." + + "SudokuRequest\032\026.sudoku.SudokuResponseB\t\200" + + "\001\001\210\001\001\220\001\001" + }; + com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = + new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() { + public com.google.protobuf.ExtensionRegistry assignDescriptors( + com.google.protobuf.Descriptors.FileDescriptor root) { + descriptor = root; + internal_static_sudoku_SudokuRequest_descriptor = + getDescriptor().getMessageTypes().get(0); + internal_static_sudoku_SudokuRequest_fieldAccessorTable = new + com.google.protobuf.GeneratedMessage.FieldAccessorTable( + internal_static_sudoku_SudokuRequest_descriptor, + new java.lang.String[] { "Checkerboard", }, + sudoku.Sudoku.SudokuRequest.class, + sudoku.Sudoku.SudokuRequest.Builder.class); + internal_static_sudoku_SudokuResponse_descriptor = + getDescriptor().getMessageTypes().get(1); + internal_static_sudoku_SudokuResponse_fieldAccessorTable = new + com.google.protobuf.GeneratedMessage.FieldAccessorTable( + internal_static_sudoku_SudokuResponse_descriptor, + new java.lang.String[] { "Solved", "Checkerboard", }, + sudoku.Sudoku.SudokuResponse.class, + sudoku.Sudoku.SudokuResponse.Builder.class); + return null; + } + }; + com.google.protobuf.Descriptors.FileDescriptor + .internalBuildGeneratedFileFrom(descriptorData, + new com.google.protobuf.Descriptors.FileDescriptor[] { + }, assigner); + } + + // @@protoc_insertion_point(outer_class_scope) +} diff --git a/protorpc/sudoku/SudokuImpl.java b/protorpc/sudoku/SudokuImpl.java new file mode 100644 index 0000000..077f581 --- /dev/null +++ b/protorpc/sudoku/SudokuImpl.java @@ -0,0 +1,19 @@ +package sudoku; + +import sudoku.Sudoku.SudokuRequest; +import sudoku.Sudoku.SudokuResponse; +import sudoku.Sudoku.SudokuService.Interface; + +import com.google.protobuf.RpcCallback; +import com.google.protobuf.RpcController; + +public class SudokuImpl implements Interface { + + @Override + public void solve(RpcController controller, SudokuRequest request, + RpcCallback done) { + SudokuResponse resp = SudokuResponse.newBuilder() + .setSolved(true).setCheckerboard("12345").build(); + done.run(resp); + } +}