From ba8b5cb06d2a955d91fd0614db2b477719207e02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?lg=E6=9E=97=E5=9B=BD?= Date: Sun, 5 May 2019 10:22:50 +0800 Subject: [PATCH 1/8] modify generic filter to support google pb service test. --- .../org/apache/dubbo/common/Constants.java | 2 + dubbo-dependencies-bom/pom.xml | 12 +++ dubbo-rpc/dubbo-rpc-api/pom.xml | 8 ++ .../dubbo/rpc/filter/GenericFilter.java | 15 +++- .../dubbo/rpc/support/ProtobufUtils.java | 73 +++++++++++++++++++ .../dubbo/rpc/support/ProtocolUtils.java | 7 +- 6 files changed, 115 insertions(+), 2 deletions(-) create mode 100644 dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/ProtobufUtils.java diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/Constants.java b/dubbo-common/src/main/java/org/apache/dubbo/common/Constants.java index 596d91c5928..d13471b87f9 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/Constants.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/Constants.java @@ -727,6 +727,8 @@ public class Constants { public static final String GENERIC_SERIALIZATION_BEAN = "bean"; + public static final String GENERIC_SERIALIZATION_PROTO = "proto"; + public static final String DUBBO_IP_TO_REGISTRY = "DUBBO_IP_TO_REGISTRY"; public static final String DUBBO_PORT_TO_REGISTRY = "DUBBO_PORT_TO_REGISTRY"; diff --git a/dubbo-dependencies-bom/pom.xml b/dubbo-dependencies-bom/pom.xml index 1ba31db4c43..f668f22f2a8 100644 --- a/dubbo-dependencies-bom/pom.xml +++ b/dubbo-dependencies-bom/pom.xml @@ -107,6 +107,8 @@ 3.1.15 0.8.0 4.0.38 + 3.6.0 + 3.6.0 3.1.0 9.4.11.v20180605 1.1.0.Final @@ -263,6 +265,16 @@ hessian-lite ${hessian_lite_version} + + com.google.protobuf + protobuf-java + ${protobuf-java} + + + com.google.protobuf + protobuf-java-util + ${protobuf.java.util} + javax.servlet javax.servlet-api diff --git a/dubbo-rpc/dubbo-rpc-api/pom.xml b/dubbo-rpc/dubbo-rpc-api/pom.xml index aae1c05b6ed..b47a4ae9324 100644 --- a/dubbo-rpc/dubbo-rpc-api/pom.xml +++ b/dubbo-rpc/dubbo-rpc-api/pom.xml @@ -44,5 +44,13 @@ dubbo-remoting-api ${project.parent.version} + + com.google.protobuf + protobuf-java + + + com.google.protobuf + protobuf-java-util + \ No newline at end of file diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/GenericFilter.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/GenericFilter.java index ae7b92c40f1..6a6ac822ed2 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/GenericFilter.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/GenericFilter.java @@ -38,6 +38,7 @@ import org.apache.dubbo.rpc.RpcResult; import org.apache.dubbo.rpc.service.GenericException; import org.apache.dubbo.rpc.service.GenericService; +import org.apache.dubbo.rpc.support.ProtobufUtils; import org.apache.dubbo.rpc.support.ProtocolUtils; import java.io.IOException; @@ -76,7 +77,7 @@ public Result invoke(Invoker invoker, Invocation inv) throws RpcException { } else if (ProtocolUtils.isJavaGenericSerialization(generic)) { for (int i = 0; i < args.length; i++) { if (byte[].class == args[i].getClass()) { - try(UnsafeByteArrayInputStream is = new UnsafeByteArrayInputStream((byte[]) args[i])) { + try (UnsafeByteArrayInputStream is = new UnsafeByteArrayInputStream((byte[]) args[i])) { args[i] = ExtensionLoader.getExtensionLoader(Serialization.class) .getExtension(Constants.GENERIC_SERIALIZATION_NATIVE_JAVA) .deserialize(null, is).readObject(); @@ -107,6 +108,16 @@ public Result invoke(Invoker invoker, Invocation inv) throws RpcException { args[i].getClass().getName()); } } + } else if (ProtocolUtils.isProtobufGenericSerialization(generic)) { + //as proto3 only accept one parameter + if (args.length == 1 && args[0] instanceof String) { + args[0] = ProtobufUtils.deserialize((String) args[0], method.getParameterTypes()[0]); + } else { + throw new RpcException( + new StringBuilder("Generic serialization [").append(Constants.GENERIC_SERIALIZATION_PROTO) + .append("] only support one").append(String.class.getName()).append(" argument ") + .append(" and your message size is ").append(args.length).append(" and type is").append(args[0].getClass().getName()).toString()); + } } Result result = invoker.invoke(new RpcInvocation(method, args, inv.getAttachments())); if (result.hasException() @@ -125,6 +136,8 @@ public Result invoke(Invoker invoker, Invocation inv) throws RpcException { } } else if (ProtocolUtils.isBeanGenericSerialization(generic)) { return new RpcResult(JavaBeanSerializeUtil.serialize(result.getValue(), JavaBeanAccessor.METHOD)); + } else if (ProtocolUtils.isProtobufGenericSerialization(generic)) { + return new RpcResult(ProtobufUtils.serialize(result.getValue())); } else { return new RpcResult(PojoUtils.generalize(result.getValue())); } diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/ProtobufUtils.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/ProtobufUtils.java new file mode 100644 index 00000000000..7e90bf671c6 --- /dev/null +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/ProtobufUtils.java @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.dubbo.rpc.support; + +import java.lang.reflect.Method; + +import com.google.protobuf.GeneratedMessageV3; +import com.google.protobuf.GeneratedMessageV3.Builder; +import com.google.protobuf.MessageOrBuilder; +import com.google.protobuf.util.JsonFormat; +import com.google.protobuf.util.JsonFormat.Parser; +import com.google.protobuf.util.JsonFormat.Printer; + +public class ProtobufUtils { + + public static boolean isSupported(Class clazz) { + if (clazz == null) { + return false; + } + + if (GeneratedMessageV3.class.isAssignableFrom(clazz)) { + return true; + } + return false; + } + + public static T deserialize(String json, Class requestClass) { + if (!isSupported(requestClass)) { + throw new UnsupportedOperationException(requestClass.getName() + "can not be deserialize"); + } + Builder builder; + try{ + builder = getMessageBuilder(requestClass); + Parser parser = JsonFormat.parser(); + parser.merge(json, builder); + }catch (Exception e){ + throw new RuntimeException("Failed to deserialize "+requestClass,e ); + } + + return (T) builder.build(); + } + + public static String serialize(Object value) { + String result; + try { + Printer printer = JsonFormat.printer(); + result = printer.print((MessageOrBuilder) value); + } catch (Exception e) { + result = e.getMessage(); + } + return result; + } + + private static Builder getMessageBuilder(Class requestType) throws Exception { + Method method = requestType.getMethod("newBuilder"); + + return (Builder) method.invoke(null, null); + } +} \ No newline at end of file diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/ProtocolUtils.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/ProtocolUtils.java index ce5da6b51be..f71dc67c06b 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/ProtocolUtils.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/ProtocolUtils.java @@ -51,7 +51,8 @@ public static boolean isGeneric(String generic) { && !"".equals(generic) && (Constants.GENERIC_SERIALIZATION_DEFAULT.equalsIgnoreCase(generic) /* Normal generalization cal */ || Constants.GENERIC_SERIALIZATION_NATIVE_JAVA.equalsIgnoreCase(generic) /* Streaming generalization call supporting jdk serialization */ - || Constants.GENERIC_SERIALIZATION_BEAN.equalsIgnoreCase(generic)); + || Constants.GENERIC_SERIALIZATION_BEAN.equalsIgnoreCase(generic) + || Constants.GENERIC_SERIALIZATION_PROTO.equalsIgnoreCase(generic)); } public static boolean isDefaultGenericSerialization(String generic) { @@ -67,4 +68,8 @@ public static boolean isJavaGenericSerialization(String generic) { public static boolean isBeanGenericSerialization(String generic) { return isGeneric(generic) && Constants.GENERIC_SERIALIZATION_BEAN.equals(generic); } + + public static boolean isProtobufGenericSerialization(String generic) { + return isGeneric(generic) && Constants.GENERIC_SERIALIZATION_PROTO.equals(generic); + } } From 1a49b8b4b50f370c9656a7cc77f1bbe14a93bd53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?lg=E6=9E=97=E5=9B=BD?= Date: Sun, 5 May 2019 16:59:06 +0800 Subject: [PATCH 2/8] save --- .../FastJsonObjectInput.java | 121 ++++++++++++++++++ .../FastJsonObjectOutput.java | 113 ++++++++++++++++ .../FastJsonSerialization.java | 57 +++++++++ .../dubbo-serialization-googlePb/pom.xml | 50 ++++++++ .../protobuf/GenericProtobufObjectInput.java | 118 +++++++++++++++++ .../protobuf/GenericProtobufObjectOutput.java | 104 +++++++++++++++ .../GenericProtobufSerialization.java | 53 ++++++++ .../serialize/protobuf/ProtobufUtils.java | 73 +++++++++++ ...pache.dubbo.common.serialize.Serialization | 1 + 9 files changed, 690 insertions(+) create mode 100644 dubbo-serialization/dubbo-serialization-fastjson/src/main/java/org.apache.dubbo.common.serialize.fastjson/FastJsonObjectInput.java create mode 100644 dubbo-serialization/dubbo-serialization-fastjson/src/main/java/org.apache.dubbo.common.serialize.fastjson/FastJsonObjectOutput.java create mode 100644 dubbo-serialization/dubbo-serialization-fastjson/src/main/java/org.apache.dubbo.common.serialize.fastjson/FastJsonSerialization.java create mode 100644 dubbo-serialization/dubbo-serialization-googlePb/pom.xml create mode 100644 dubbo-serialization/dubbo-serialization-googlePb/src/main/java/org/apache/dubbo/common/serialize/protobuf/GenericProtobufObjectInput.java create mode 100644 dubbo-serialization/dubbo-serialization-googlePb/src/main/java/org/apache/dubbo/common/serialize/protobuf/GenericProtobufObjectOutput.java create mode 100644 dubbo-serialization/dubbo-serialization-googlePb/src/main/java/org/apache/dubbo/common/serialize/protobuf/GenericProtobufSerialization.java create mode 100644 dubbo-serialization/dubbo-serialization-googlePb/src/main/java/org/apache/dubbo/common/serialize/protobuf/ProtobufUtils.java create mode 100644 dubbo-serialization/dubbo-serialization-googlePb/src/main/resources/internal/org.apache.dubbo.common.serialize.Serialization diff --git a/dubbo-serialization/dubbo-serialization-fastjson/src/main/java/org.apache.dubbo.common.serialize.fastjson/FastJsonObjectInput.java b/dubbo-serialization/dubbo-serialization-fastjson/src/main/java/org.apache.dubbo.common.serialize.fastjson/FastJsonObjectInput.java new file mode 100644 index 00000000000..ccf6a2b3d51 --- /dev/null +++ b/dubbo-serialization/dubbo-serialization-fastjson/src/main/java/org.apache.dubbo.common.serialize.fastjson/FastJsonObjectInput.java @@ -0,0 +1,121 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.dubbo.common.serialize.fastjson; + +import org.apache.dubbo.common.serialize.ObjectInput; + +import com.alibaba.fastjson.JSON; + +import java.io.BufferedReader; +import java.io.EOFException; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.lang.reflect.Type; + +/** + * FastJson object input implementation + */ +public class FastJsonObjectInput implements ObjectInput { + + private final BufferedReader reader; + + public FastJsonObjectInput(InputStream in) { + this(new InputStreamReader(in)); + } + + public FastJsonObjectInput(Reader reader) { + this.reader = new BufferedReader(reader); + } + + @Override + public boolean readBool() throws IOException { + return read(boolean.class); + } + + @Override + public byte readByte() throws IOException { + return read(byte.class); + } + + @Override + public short readShort() throws IOException { + return read(short.class); + } + + @Override + public int readInt() throws IOException { + return read(int.class); + } + + @Override + public long readLong() throws IOException { + return read(long.class); + } + + @Override + public float readFloat() throws IOException { + return read(float.class); + } + + @Override + public double readDouble() throws IOException { + return read(double.class); + } + + @Override + public String readUTF() throws IOException { + return read(String.class); + } + + @Override + public byte[] readBytes() throws IOException { + return readLine().getBytes(); + } + + @Override + public Object readObject() throws IOException, ClassNotFoundException { + String json = readLine(); + return JSON.parse(json); + } + + @Override + public T readObject(Class cls) throws IOException, ClassNotFoundException { + return read(cls); + } + + @Override + @SuppressWarnings("unchecked") + public T readObject(Class cls, Type type) throws IOException, ClassNotFoundException { + String json = readLine(); + return (T) JSON.parseObject(json, type); + } + + private String readLine() throws IOException, EOFException { + String line = reader.readLine(); + if (line == null || line.trim().length() == 0) { + throw new EOFException(); + } + return line; + } + + private T read(Class cls) throws IOException { + String json = readLine(); + return JSON.parseObject(json, cls); + } +} diff --git a/dubbo-serialization/dubbo-serialization-fastjson/src/main/java/org.apache.dubbo.common.serialize.fastjson/FastJsonObjectOutput.java b/dubbo-serialization/dubbo-serialization-fastjson/src/main/java/org.apache.dubbo.common.serialize.fastjson/FastJsonObjectOutput.java new file mode 100644 index 00000000000..3f9ec2083da --- /dev/null +++ b/dubbo-serialization/dubbo-serialization-fastjson/src/main/java/org.apache.dubbo.common.serialize.fastjson/FastJsonObjectOutput.java @@ -0,0 +1,113 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.dubbo.common.serialize.fastjson; + +import org.apache.dubbo.common.serialize.ObjectOutput; + +import com.alibaba.fastjson.serializer.JSONSerializer; +import com.alibaba.fastjson.serializer.SerializeWriter; +import com.alibaba.fastjson.serializer.SerializerFeature; + +import java.io.IOException; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.PrintWriter; +import java.io.Writer; + +/** + * FastJson object output implementation + */ +public class FastJsonObjectOutput implements ObjectOutput { + + private final PrintWriter writer; + + public FastJsonObjectOutput(OutputStream out) { + this(new OutputStreamWriter(out)); + } + + public FastJsonObjectOutput(Writer writer) { + this.writer = new PrintWriter(writer); + } + + @Override + public void writeBool(boolean v) throws IOException { + writeObject(v); + } + + @Override + public void writeByte(byte v) throws IOException { + writeObject(v); + } + + @Override + public void writeShort(short v) throws IOException { + writeObject(v); + } + + @Override + public void writeInt(int v) throws IOException { + writeObject(v); + } + + @Override + public void writeLong(long v) throws IOException { + writeObject(v); + } + + @Override + public void writeFloat(float v) throws IOException { + writeObject(v); + } + + @Override + public void writeDouble(double v) throws IOException { + writeObject(v); + } + + @Override + public void writeUTF(String v) throws IOException { + writeObject(v); + } + + @Override + public void writeBytes(byte[] b) throws IOException { + writer.println(new String(b)); + } + + @Override + public void writeBytes(byte[] b, int off, int len) throws IOException { + writer.println(new String(b, off, len)); + } + + @Override + public void writeObject(Object obj) throws IOException { + SerializeWriter out = new SerializeWriter(); + JSONSerializer serializer = new JSONSerializer(out); + serializer.config(SerializerFeature.WriteEnumUsingToString, true); + serializer.write(obj); + out.writeTo(writer); + out.close(); // for reuse SerializeWriter buf + writer.println(); + writer.flush(); + } + + @Override + public void flushBuffer() throws IOException { + writer.flush(); + } + +} diff --git a/dubbo-serialization/dubbo-serialization-fastjson/src/main/java/org.apache.dubbo.common.serialize.fastjson/FastJsonSerialization.java b/dubbo-serialization/dubbo-serialization-fastjson/src/main/java/org.apache.dubbo.common.serialize.fastjson/FastJsonSerialization.java new file mode 100644 index 00000000000..097587132c7 --- /dev/null +++ b/dubbo-serialization/dubbo-serialization-fastjson/src/main/java/org.apache.dubbo.common.serialize.fastjson/FastJsonSerialization.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.dubbo.common.serialize.fastjson; + +import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.serialize.ObjectInput; +import org.apache.dubbo.common.serialize.ObjectOutput; +import org.apache.dubbo.common.serialize.Serialization; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +/** + * FastJson serialization implementation + * + *
+ *     e.g. <dubbo:protocol serialization="fastjson" />
+ * 
+ */ +public class FastJsonSerialization implements Serialization { + + @Override + public byte getContentTypeId() { + return 6; + } + + @Override + public String getContentType() { + return "text/json"; + } + + @Override + public ObjectOutput serialize(URL url, OutputStream output) throws IOException { + return new FastJsonObjectOutput(output); + } + + @Override + public ObjectInput deserialize(URL url, InputStream input) throws IOException { + return new FastJsonObjectInput(input); + } + +} diff --git a/dubbo-serialization/dubbo-serialization-googlePb/pom.xml b/dubbo-serialization/dubbo-serialization-googlePb/pom.xml new file mode 100644 index 00000000000..8aaba821a0e --- /dev/null +++ b/dubbo-serialization/dubbo-serialization-googlePb/pom.xml @@ -0,0 +1,50 @@ + + + + 4.0.0 + + org.apache.dubbo + dubbo-serialization + ${revision} + + + dubbo-serialization-googlePb + jar + ${project.artifactId} + The Generic-protobuf serialization module of dubbo project + + false + + + + org.apache.dubbo + dubbo-serialization-api + ${project.parent.version} + + + com.google.protobuf + protobuf-java + + + com.google.protobuf + protobuf-java-util + + + \ No newline at end of file diff --git a/dubbo-serialization/dubbo-serialization-googlePb/src/main/java/org/apache/dubbo/common/serialize/protobuf/GenericProtobufObjectInput.java b/dubbo-serialization/dubbo-serialization-googlePb/src/main/java/org/apache/dubbo/common/serialize/protobuf/GenericProtobufObjectInput.java new file mode 100644 index 00000000000..20313cf04f6 --- /dev/null +++ b/dubbo-serialization/dubbo-serialization-googlePb/src/main/java/org/apache/dubbo/common/serialize/protobuf/GenericProtobufObjectInput.java @@ -0,0 +1,118 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.dubbo.common.serialize.protobuf; + +import org.apache.dubbo.common.serialize.ObjectInput; + +import java.io.BufferedReader; +import java.io.EOFException; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.lang.reflect.Type; + +/** + * GenericGooglePb object input implementation + */ +public class GenericProtobufObjectInput implements ObjectInput { + + private final BufferedReader reader; + + public GenericProtobufObjectInput(InputStream in) { + this(new InputStreamReader(in)); + } + + public GenericProtobufObjectInput(Reader reader) { + this.reader = new BufferedReader(reader); + } + + @Override + public boolean readBool() throws IOException { + return read(boolean.class); + } + + @Override + public byte readByte() throws IOException { + return read(byte.class); + } + + @Override + public short readShort() throws IOException { + return read(short.class); + } + + @Override + public int readInt() throws IOException { + return read(int.class); + } + + @Override + public long readLong() throws IOException { + return read(long.class); + } + + @Override + public float readFloat() throws IOException { + return read(float.class); + } + + @Override + public double readDouble() throws IOException { + return read(double.class); + } + + @Override + public String readUTF() throws IOException { + return read(String.class); + } + + @Override + public byte[] readBytes() throws IOException { + return readLine().getBytes(); + } + + @Override + public Object readObject() { + throw new UnsupportedOperationException("this method require class type"); + } + + @Override + public T readObject(Class cls) throws IOException, ClassNotFoundException { + return read(cls); + } + + @Override + @SuppressWarnings("unchecked") + public T readObject(Class cls, Type type) throws IOException, ClassNotFoundException { + String json = readLine(); + return ProtobufUtils.deserialize(json,cls); + } + + private String readLine() throws IOException, EOFException { + String line = reader.readLine(); + if (line == null || line.trim().length() == 0) { + throw new EOFException(); + } + return line; + } + + private T read(Class cls) throws IOException { + String json = readLine(); + return ProtobufUtils.deserialize(json,cls); + } +} diff --git a/dubbo-serialization/dubbo-serialization-googlePb/src/main/java/org/apache/dubbo/common/serialize/protobuf/GenericProtobufObjectOutput.java b/dubbo-serialization/dubbo-serialization-googlePb/src/main/java/org/apache/dubbo/common/serialize/protobuf/GenericProtobufObjectOutput.java new file mode 100644 index 00000000000..d622e3aac03 --- /dev/null +++ b/dubbo-serialization/dubbo-serialization-googlePb/src/main/java/org/apache/dubbo/common/serialize/protobuf/GenericProtobufObjectOutput.java @@ -0,0 +1,104 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.dubbo.common.serialize.protobuf; + +import org.apache.dubbo.common.serialize.ObjectOutput; + +import java.io.IOException; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.PrintWriter; +import java.io.Writer; + +/** + * GenericGooglePb object output implementation + */ +public class GenericProtobufObjectOutput implements ObjectOutput { + + private final PrintWriter writer; + + public GenericProtobufObjectOutput(OutputStream out) { + this(new OutputStreamWriter(out)); + } + + public GenericProtobufObjectOutput(Writer writer) { + this.writer = new PrintWriter(writer); + } + + @Override + public void writeBool(boolean v) throws IOException { + writeObject(v); + } + + @Override + public void writeByte(byte v) throws IOException { + writeObject(v); + } + + @Override + public void writeShort(short v) throws IOException { + writeObject(v); + } + + @Override + public void writeInt(int v) throws IOException { + writeObject(v); + } + + @Override + public void writeLong(long v) throws IOException { + writeObject(v); + } + + @Override + public void writeFloat(float v) throws IOException { + writeObject(v); + } + + @Override + public void writeDouble(double v) throws IOException { + writeObject(v); + } + + @Override + public void writeUTF(String v) throws IOException { + writeObject(v); + } + + @Override + public void writeBytes(byte[] b) throws IOException { + writer.println(new String(b)); + } + + @Override + public void writeBytes(byte[] b, int off, int len) throws IOException { + writer.println(new String(b, off, len)); + } + + @Override + public void writeObject(Object obj) throws IOException { + writer.write(ProtobufUtils.serialize(obj)); + writer.println(); + writer.flush(); + } + + @Override + public void flushBuffer() throws IOException { + writer.flush(); + } + +} diff --git a/dubbo-serialization/dubbo-serialization-googlePb/src/main/java/org/apache/dubbo/common/serialize/protobuf/GenericProtobufSerialization.java b/dubbo-serialization/dubbo-serialization-googlePb/src/main/java/org/apache/dubbo/common/serialize/protobuf/GenericProtobufSerialization.java new file mode 100644 index 00000000000..fe0c0fe182b --- /dev/null +++ b/dubbo-serialization/dubbo-serialization-googlePb/src/main/java/org/apache/dubbo/common/serialize/protobuf/GenericProtobufSerialization.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.dubbo.common.serialize.protobuf; + +import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.serialize.ObjectInput; +import org.apache.dubbo.common.serialize.ObjectOutput; +import org.apache.dubbo.common.serialize.Serialization; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +/** + * GooglePb serialization implementation + * + */ +public class GenericProtobufSerialization implements Serialization { + + @Override + public byte getContentTypeId() { + return 6; + } + + @Override + public String getContentType() { + return "text/proto-json"; + } + + @Override + public ObjectOutput serialize(URL url, OutputStream output) throws IOException { + return new GenericProtobufObjectOutput(output); + } + + @Override + public ObjectInput deserialize(URL url, InputStream input) throws IOException { + return new GenericProtobufObjectInput(input); + } +} diff --git a/dubbo-serialization/dubbo-serialization-googlePb/src/main/java/org/apache/dubbo/common/serialize/protobuf/ProtobufUtils.java b/dubbo-serialization/dubbo-serialization-googlePb/src/main/java/org/apache/dubbo/common/serialize/protobuf/ProtobufUtils.java new file mode 100644 index 00000000000..641ab45eab4 --- /dev/null +++ b/dubbo-serialization/dubbo-serialization-googlePb/src/main/java/org/apache/dubbo/common/serialize/protobuf/ProtobufUtils.java @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.dubbo.common.serialize.protobuf; + +import java.lang.reflect.Method; + +import com.google.protobuf.GeneratedMessageV3; +import com.google.protobuf.GeneratedMessageV3.Builder; +import com.google.protobuf.MessageOrBuilder; +import com.google.protobuf.util.JsonFormat; +import com.google.protobuf.util.JsonFormat.Parser; +import com.google.protobuf.util.JsonFormat.Printer; + +public class ProtobufUtils { + + public static boolean isSupported(Class clazz) { + if (clazz == null) { + return false; + } + + if (GeneratedMessageV3.class.isAssignableFrom(clazz)) { + return true; + } + return false; + } + + public static T deserialize(String json, Class requestClass) { + if (!isSupported(requestClass)) { + throw new UnsupportedOperationException(requestClass.getName() + "can not be deserialize"); + } + Builder builder; + try{ + builder = getMessageBuilder(requestClass); + Parser parser = JsonFormat.parser(); + parser.merge(json, builder); + }catch (Exception e){ + throw new RuntimeException("Failed to deserialize "+requestClass,e ); + } + + return (T) builder.build(); + } + + public static String serialize(Object value) { + String result; + try { + Printer printer = JsonFormat.printer(); + result = printer.print((MessageOrBuilder) value); + } catch (Exception e) { + result = e.getMessage(); + } + return result; + } + + private static Builder getMessageBuilder(Class requestType) throws Exception { + Method method = requestType.getMethod("newBuilder"); + + return (Builder) method.invoke(null, null); + } +} \ No newline at end of file diff --git a/dubbo-serialization/dubbo-serialization-googlePb/src/main/resources/internal/org.apache.dubbo.common.serialize.Serialization b/dubbo-serialization/dubbo-serialization-googlePb/src/main/resources/internal/org.apache.dubbo.common.serialize.Serialization new file mode 100644 index 00000000000..c254237f6f2 --- /dev/null +++ b/dubbo-serialization/dubbo-serialization-googlePb/src/main/resources/internal/org.apache.dubbo.common.serialize.Serialization @@ -0,0 +1 @@ +genericProtobuf=org.apache.dubbo.common.serialize.protobuf.GenericProtobufSerialization \ No newline at end of file From 191425289cd89aa53afbc91fcfc8c62d0da73866 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?lg=E6=9E=97=E5=9B=BD?= Date: Sun, 5 May 2019 16:59:23 +0800 Subject: [PATCH 3/8] save code --- .../org/apache/dubbo/common/Constants.java | 2 +- dubbo-rpc/dubbo-rpc-api/pom.xml | 8 -- .../dubbo/rpc/filter/GenericFilter.java | 21 ++- .../dubbo/rpc/support/ProtobufUtils.java | 73 ----------- .../dubbo/rpc/support/ProtocolUtils.java | 4 +- .../fastjson/FastJsonObjectInput.java | 121 ------------------ .../fastjson/FastJsonObjectOutput.java | 113 ---------------- .../fastjson/FastJsonSerialization.java | 57 --------- dubbo-serialization/pom.xml | 1 + 9 files changed, 21 insertions(+), 379 deletions(-) delete mode 100644 dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/ProtobufUtils.java delete mode 100644 dubbo-serialization/dubbo-serialization-fastjson/src/main/java/org/apache/dubbo/common/serialize/fastjson/FastJsonObjectInput.java delete mode 100644 dubbo-serialization/dubbo-serialization-fastjson/src/main/java/org/apache/dubbo/common/serialize/fastjson/FastJsonObjectOutput.java delete mode 100644 dubbo-serialization/dubbo-serialization-fastjson/src/main/java/org/apache/dubbo/common/serialize/fastjson/FastJsonSerialization.java diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/Constants.java b/dubbo-common/src/main/java/org/apache/dubbo/common/Constants.java index d13471b87f9..f001c0c88dc 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/Constants.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/Constants.java @@ -727,7 +727,7 @@ public class Constants { public static final String GENERIC_SERIALIZATION_BEAN = "bean"; - public static final String GENERIC_SERIALIZATION_PROTO = "proto"; + public static final String GENERIC_SERIALIZATION_PROTOBUF = "genericProtobuf"; public static final String DUBBO_IP_TO_REGISTRY = "DUBBO_IP_TO_REGISTRY"; diff --git a/dubbo-rpc/dubbo-rpc-api/pom.xml b/dubbo-rpc/dubbo-rpc-api/pom.xml index b47a4ae9324..aae1c05b6ed 100644 --- a/dubbo-rpc/dubbo-rpc-api/pom.xml +++ b/dubbo-rpc/dubbo-rpc-api/pom.xml @@ -44,13 +44,5 @@ dubbo-remoting-api ${project.parent.version} - - com.google.protobuf - protobuf-java - - - com.google.protobuf - protobuf-java-util - \ No newline at end of file diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/GenericFilter.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/GenericFilter.java index 6a6ac822ed2..f4f9fe4ab76 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/GenericFilter.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/GenericFilter.java @@ -38,7 +38,6 @@ import org.apache.dubbo.rpc.RpcResult; import org.apache.dubbo.rpc.service.GenericException; import org.apache.dubbo.rpc.service.GenericService; -import org.apache.dubbo.rpc.support.ProtobufUtils; import org.apache.dubbo.rpc.support.ProtocolUtils; import java.io.IOException; @@ -111,10 +110,16 @@ public Result invoke(Invoker invoker, Invocation inv) throws RpcException { } else if (ProtocolUtils.isProtobufGenericSerialization(generic)) { //as proto3 only accept one parameter if (args.length == 1 && args[0] instanceof String) { - args[0] = ProtobufUtils.deserialize((String) args[0], method.getParameterTypes()[0]); + try (UnsafeByteArrayInputStream is = new UnsafeByteArrayInputStream( ((String)args[0]).getBytes())) { + args[0] = ExtensionLoader.getExtensionLoader(Serialization.class) + .getExtension(Constants.GENERIC_SERIALIZATION_PROTOBUF) + .deserialize(null, is).readObject(method.getParameterTypes()[0]); + } catch (Exception e) { + throw new RpcException("Deserialize argument failed.", e); + } } else { throw new RpcException( - new StringBuilder("Generic serialization [").append(Constants.GENERIC_SERIALIZATION_PROTO) + new StringBuilder("Generic serialization [").append(Constants.GENERIC_SERIALIZATION_PROTOBUF) .append("] only support one").append(String.class.getName()).append(" argument ") .append(" and your message size is ").append(args.length).append(" and type is").append(args[0].getClass().getName()).toString()); } @@ -137,7 +142,15 @@ public Result invoke(Invoker invoker, Invocation inv) throws RpcException { } else if (ProtocolUtils.isBeanGenericSerialization(generic)) { return new RpcResult(JavaBeanSerializeUtil.serialize(result.getValue(), JavaBeanAccessor.METHOD)); } else if (ProtocolUtils.isProtobufGenericSerialization(generic)) { - return new RpcResult(ProtobufUtils.serialize(result.getValue())); + try{ + UnsafeByteArrayOutputStream os = new UnsafeByteArrayOutputStream(512); + ExtensionLoader.getExtensionLoader(Serialization.class) + .getExtension(Constants.GENERIC_SERIALIZATION_PROTOBUF) + .serialize(null, os).writeObject(result.getValue()); + return new RpcResult(os.toByteArray()); + }catch (IOException e){ + throw new RpcException("Serialize result failed.", e); + } } else { return new RpcResult(PojoUtils.generalize(result.getValue())); } diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/ProtobufUtils.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/ProtobufUtils.java deleted file mode 100644 index 7e90bf671c6..00000000000 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/ProtobufUtils.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.dubbo.rpc.support; - -import java.lang.reflect.Method; - -import com.google.protobuf.GeneratedMessageV3; -import com.google.protobuf.GeneratedMessageV3.Builder; -import com.google.protobuf.MessageOrBuilder; -import com.google.protobuf.util.JsonFormat; -import com.google.protobuf.util.JsonFormat.Parser; -import com.google.protobuf.util.JsonFormat.Printer; - -public class ProtobufUtils { - - public static boolean isSupported(Class clazz) { - if (clazz == null) { - return false; - } - - if (GeneratedMessageV3.class.isAssignableFrom(clazz)) { - return true; - } - return false; - } - - public static T deserialize(String json, Class requestClass) { - if (!isSupported(requestClass)) { - throw new UnsupportedOperationException(requestClass.getName() + "can not be deserialize"); - } - Builder builder; - try{ - builder = getMessageBuilder(requestClass); - Parser parser = JsonFormat.parser(); - parser.merge(json, builder); - }catch (Exception e){ - throw new RuntimeException("Failed to deserialize "+requestClass,e ); - } - - return (T) builder.build(); - } - - public static String serialize(Object value) { - String result; - try { - Printer printer = JsonFormat.printer(); - result = printer.print((MessageOrBuilder) value); - } catch (Exception e) { - result = e.getMessage(); - } - return result; - } - - private static Builder getMessageBuilder(Class requestType) throws Exception { - Method method = requestType.getMethod("newBuilder"); - - return (Builder) method.invoke(null, null); - } -} \ No newline at end of file diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/ProtocolUtils.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/ProtocolUtils.java index f71dc67c06b..a64717c26c4 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/ProtocolUtils.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/support/ProtocolUtils.java @@ -52,7 +52,7 @@ public static boolean isGeneric(String generic) { && (Constants.GENERIC_SERIALIZATION_DEFAULT.equalsIgnoreCase(generic) /* Normal generalization cal */ || Constants.GENERIC_SERIALIZATION_NATIVE_JAVA.equalsIgnoreCase(generic) /* Streaming generalization call supporting jdk serialization */ || Constants.GENERIC_SERIALIZATION_BEAN.equalsIgnoreCase(generic) - || Constants.GENERIC_SERIALIZATION_PROTO.equalsIgnoreCase(generic)); + || Constants.GENERIC_SERIALIZATION_PROTOBUF.equalsIgnoreCase(generic)); } public static boolean isDefaultGenericSerialization(String generic) { @@ -70,6 +70,6 @@ public static boolean isBeanGenericSerialization(String generic) { } public static boolean isProtobufGenericSerialization(String generic) { - return isGeneric(generic) && Constants.GENERIC_SERIALIZATION_PROTO.equals(generic); + return isGeneric(generic) && Constants.GENERIC_SERIALIZATION_PROTOBUF.equals(generic); } } diff --git a/dubbo-serialization/dubbo-serialization-fastjson/src/main/java/org/apache/dubbo/common/serialize/fastjson/FastJsonObjectInput.java b/dubbo-serialization/dubbo-serialization-fastjson/src/main/java/org/apache/dubbo/common/serialize/fastjson/FastJsonObjectInput.java deleted file mode 100644 index ccf6a2b3d51..00000000000 --- a/dubbo-serialization/dubbo-serialization-fastjson/src/main/java/org/apache/dubbo/common/serialize/fastjson/FastJsonObjectInput.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.dubbo.common.serialize.fastjson; - -import org.apache.dubbo.common.serialize.ObjectInput; - -import com.alibaba.fastjson.JSON; - -import java.io.BufferedReader; -import java.io.EOFException; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; -import java.lang.reflect.Type; - -/** - * FastJson object input implementation - */ -public class FastJsonObjectInput implements ObjectInput { - - private final BufferedReader reader; - - public FastJsonObjectInput(InputStream in) { - this(new InputStreamReader(in)); - } - - public FastJsonObjectInput(Reader reader) { - this.reader = new BufferedReader(reader); - } - - @Override - public boolean readBool() throws IOException { - return read(boolean.class); - } - - @Override - public byte readByte() throws IOException { - return read(byte.class); - } - - @Override - public short readShort() throws IOException { - return read(short.class); - } - - @Override - public int readInt() throws IOException { - return read(int.class); - } - - @Override - public long readLong() throws IOException { - return read(long.class); - } - - @Override - public float readFloat() throws IOException { - return read(float.class); - } - - @Override - public double readDouble() throws IOException { - return read(double.class); - } - - @Override - public String readUTF() throws IOException { - return read(String.class); - } - - @Override - public byte[] readBytes() throws IOException { - return readLine().getBytes(); - } - - @Override - public Object readObject() throws IOException, ClassNotFoundException { - String json = readLine(); - return JSON.parse(json); - } - - @Override - public T readObject(Class cls) throws IOException, ClassNotFoundException { - return read(cls); - } - - @Override - @SuppressWarnings("unchecked") - public T readObject(Class cls, Type type) throws IOException, ClassNotFoundException { - String json = readLine(); - return (T) JSON.parseObject(json, type); - } - - private String readLine() throws IOException, EOFException { - String line = reader.readLine(); - if (line == null || line.trim().length() == 0) { - throw new EOFException(); - } - return line; - } - - private T read(Class cls) throws IOException { - String json = readLine(); - return JSON.parseObject(json, cls); - } -} diff --git a/dubbo-serialization/dubbo-serialization-fastjson/src/main/java/org/apache/dubbo/common/serialize/fastjson/FastJsonObjectOutput.java b/dubbo-serialization/dubbo-serialization-fastjson/src/main/java/org/apache/dubbo/common/serialize/fastjson/FastJsonObjectOutput.java deleted file mode 100644 index 3f9ec2083da..00000000000 --- a/dubbo-serialization/dubbo-serialization-fastjson/src/main/java/org/apache/dubbo/common/serialize/fastjson/FastJsonObjectOutput.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.dubbo.common.serialize.fastjson; - -import org.apache.dubbo.common.serialize.ObjectOutput; - -import com.alibaba.fastjson.serializer.JSONSerializer; -import com.alibaba.fastjson.serializer.SerializeWriter; -import com.alibaba.fastjson.serializer.SerializerFeature; - -import java.io.IOException; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.io.PrintWriter; -import java.io.Writer; - -/** - * FastJson object output implementation - */ -public class FastJsonObjectOutput implements ObjectOutput { - - private final PrintWriter writer; - - public FastJsonObjectOutput(OutputStream out) { - this(new OutputStreamWriter(out)); - } - - public FastJsonObjectOutput(Writer writer) { - this.writer = new PrintWriter(writer); - } - - @Override - public void writeBool(boolean v) throws IOException { - writeObject(v); - } - - @Override - public void writeByte(byte v) throws IOException { - writeObject(v); - } - - @Override - public void writeShort(short v) throws IOException { - writeObject(v); - } - - @Override - public void writeInt(int v) throws IOException { - writeObject(v); - } - - @Override - public void writeLong(long v) throws IOException { - writeObject(v); - } - - @Override - public void writeFloat(float v) throws IOException { - writeObject(v); - } - - @Override - public void writeDouble(double v) throws IOException { - writeObject(v); - } - - @Override - public void writeUTF(String v) throws IOException { - writeObject(v); - } - - @Override - public void writeBytes(byte[] b) throws IOException { - writer.println(new String(b)); - } - - @Override - public void writeBytes(byte[] b, int off, int len) throws IOException { - writer.println(new String(b, off, len)); - } - - @Override - public void writeObject(Object obj) throws IOException { - SerializeWriter out = new SerializeWriter(); - JSONSerializer serializer = new JSONSerializer(out); - serializer.config(SerializerFeature.WriteEnumUsingToString, true); - serializer.write(obj); - out.writeTo(writer); - out.close(); // for reuse SerializeWriter buf - writer.println(); - writer.flush(); - } - - @Override - public void flushBuffer() throws IOException { - writer.flush(); - } - -} diff --git a/dubbo-serialization/dubbo-serialization-fastjson/src/main/java/org/apache/dubbo/common/serialize/fastjson/FastJsonSerialization.java b/dubbo-serialization/dubbo-serialization-fastjson/src/main/java/org/apache/dubbo/common/serialize/fastjson/FastJsonSerialization.java deleted file mode 100644 index 097587132c7..00000000000 --- a/dubbo-serialization/dubbo-serialization-fastjson/src/main/java/org/apache/dubbo/common/serialize/fastjson/FastJsonSerialization.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.dubbo.common.serialize.fastjson; - -import org.apache.dubbo.common.URL; -import org.apache.dubbo.common.serialize.ObjectInput; -import org.apache.dubbo.common.serialize.ObjectOutput; -import org.apache.dubbo.common.serialize.Serialization; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -/** - * FastJson serialization implementation - * - *
- *     e.g. <dubbo:protocol serialization="fastjson" />
- * 
- */ -public class FastJsonSerialization implements Serialization { - - @Override - public byte getContentTypeId() { - return 6; - } - - @Override - public String getContentType() { - return "text/json"; - } - - @Override - public ObjectOutput serialize(URL url, OutputStream output) throws IOException { - return new FastJsonObjectOutput(output); - } - - @Override - public ObjectInput deserialize(URL url, InputStream input) throws IOException { - return new FastJsonObjectInput(input); - } - -} diff --git a/dubbo-serialization/pom.xml b/dubbo-serialization/pom.xml index 97b986d1b85..abaa155daa0 100644 --- a/dubbo-serialization/pom.xml +++ b/dubbo-serialization/pom.xml @@ -39,5 +39,6 @@ dubbo-serialization-avro dubbo-serialization-test dubbo-serialization-gson + dubbo-serialization-googlePb From c1f51b34cd8cd5c42abb349570434ee34d5086e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?lg=E6=9E=97=E5=9B=BD?= Date: Sun, 5 May 2019 18:39:21 +0800 Subject: [PATCH 4/8] =?UTF-8?q?save=20genericFilter=20=E6=94=B9=E5=86=99?= =?UTF-8?q?=E5=AE=8C=E6=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/org/apache/dubbo/rpc/filter/GenericFilter.java | 2 +- .../common/serialize/protobuf/GenericProtobufSerialization.java | 2 +- .../internal/org.apache.dubbo.common.serialize.Serialization | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename dubbo-serialization/dubbo-serialization-googlePb/src/main/resources/{ => META-INF/dubbo}/internal/org.apache.dubbo.common.serialize.Serialization (100%) diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/GenericFilter.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/GenericFilter.java index f4f9fe4ab76..4bc74a72042 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/GenericFilter.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/GenericFilter.java @@ -147,7 +147,7 @@ public Result invoke(Invoker invoker, Invocation inv) throws RpcException { ExtensionLoader.getExtensionLoader(Serialization.class) .getExtension(Constants.GENERIC_SERIALIZATION_PROTOBUF) .serialize(null, os).writeObject(result.getValue()); - return new RpcResult(os.toByteArray()); + return new RpcResult(os.toString()); }catch (IOException e){ throw new RpcException("Serialize result failed.", e); } diff --git a/dubbo-serialization/dubbo-serialization-googlePb/src/main/java/org/apache/dubbo/common/serialize/protobuf/GenericProtobufSerialization.java b/dubbo-serialization/dubbo-serialization-googlePb/src/main/java/org/apache/dubbo/common/serialize/protobuf/GenericProtobufSerialization.java index fe0c0fe182b..b8bbd64d043 100644 --- a/dubbo-serialization/dubbo-serialization-googlePb/src/main/java/org/apache/dubbo/common/serialize/protobuf/GenericProtobufSerialization.java +++ b/dubbo-serialization/dubbo-serialization-googlePb/src/main/java/org/apache/dubbo/common/serialize/protobuf/GenericProtobufSerialization.java @@ -33,7 +33,7 @@ public class GenericProtobufSerialization implements Serialization { @Override public byte getContentTypeId() { - return 6; + return 11; } @Override diff --git a/dubbo-serialization/dubbo-serialization-googlePb/src/main/resources/internal/org.apache.dubbo.common.serialize.Serialization b/dubbo-serialization/dubbo-serialization-googlePb/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.serialize.Serialization similarity index 100% rename from dubbo-serialization/dubbo-serialization-googlePb/src/main/resources/internal/org.apache.dubbo.common.serialize.Serialization rename to dubbo-serialization/dubbo-serialization-googlePb/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.serialize.Serialization From 6c858c86de2b66c1ec59884c6713ee37ad51811b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?lg=E6=9E=97=E5=9B=BD?= Date: Mon, 6 May 2019 19:43:26 +0800 Subject: [PATCH 5/8] save --- dubbo-all/pom.xml | 8 + dubbo-bom/pom.xml | 5 + .../org/apache/dubbo/common/Constants.java | 2 +- dubbo-distribution/pom.xml | 5 + .../dubbo/rpc/filter/GenericFilter.java | 16 +- .../fastjson}/FastJsonObjectInput.java | 0 .../fastjson}/FastJsonObjectOutput.java | 0 .../fastjson}/FastJsonSerialization.java | 0 .../dubbo-serialization-googlePb/pom.xml | 10 +- .../GenericProtobufObjectInput.java | 31 +- .../GenericProtobufObjectOutput.java | 27 +- .../GenericProtobufSerialization.java | 16 +- .../protobuf/{ => support}/ProtobufUtils.java | 38 +- ...pache.dubbo.common.serialize.Serialization | 2 +- .../dubbo-serialization-test/pom.xml | 5 + .../GenericProtobufObjectOutputTest.java | 85 + .../GenericProtobufSerializationTest.java | 26 + .../protobuf/support/model/GooglePB.java | 3431 +++++++++++++++++ .../test/resources/protobuf/GooglePB.proto | 35 + 19 files changed, 3664 insertions(+), 78 deletions(-) rename dubbo-serialization/dubbo-serialization-fastjson/src/main/java/{org.apache.dubbo.common.serialize.fastjson => org/apache/dubbo/common/serialize/fastjson}/FastJsonObjectInput.java (100%) rename dubbo-serialization/dubbo-serialization-fastjson/src/main/java/{org.apache.dubbo.common.serialize.fastjson => org/apache/dubbo/common/serialize/fastjson}/FastJsonObjectOutput.java (100%) rename dubbo-serialization/dubbo-serialization-fastjson/src/main/java/{org.apache.dubbo.common.serialize.fastjson => org/apache/dubbo/common/serialize/fastjson}/FastJsonSerialization.java (100%) rename dubbo-serialization/dubbo-serialization-googlePb/src/main/java/org/apache/dubbo/common/serialize/protobuf/{ => support}/GenericProtobufObjectInput.java (78%) rename dubbo-serialization/dubbo-serialization-googlePb/src/main/java/org/apache/dubbo/common/serialize/protobuf/{ => support}/GenericProtobufObjectOutput.java (76%) rename dubbo-serialization/dubbo-serialization-googlePb/src/main/java/org/apache/dubbo/common/serialize/protobuf/{ => support}/GenericProtobufSerialization.java (82%) rename dubbo-serialization/dubbo-serialization-googlePb/src/main/java/org/apache/dubbo/common/serialize/protobuf/{ => support}/ProtobufUtils.java (66%) create mode 100644 dubbo-serialization/dubbo-serialization-test/src/test/java/org/apache/dubbo/common/serialize/protobuf/support/GenericProtobufObjectOutputTest.java create mode 100644 dubbo-serialization/dubbo-serialization-test/src/test/java/org/apache/dubbo/common/serialize/protobuf/support/GenericProtobufSerializationTest.java create mode 100644 dubbo-serialization/dubbo-serialization-test/src/test/java/org/apache/dubbo/common/serialize/protobuf/support/model/GooglePB.java create mode 100644 dubbo-serialization/dubbo-serialization-test/src/test/resources/protobuf/GooglePB.proto diff --git a/dubbo-all/pom.xml b/dubbo-all/pom.xml index cceac62cc82..670f2252469 100644 --- a/dubbo-all/pom.xml +++ b/dubbo-all/pom.xml @@ -373,6 +373,13 @@ compile true + + org.apache.dubbo + dubbo-serialization-googlePb + ${project.version} + compile + true + org.apache.dubbo dubbo-configcenter-api @@ -571,6 +578,7 @@ org.apache.dubbo:dubbo-serialization-jdk org.apache.dubbo:dubbo-serialization-protostuff org.apache.dubbo:dubbo-serialization-gson + org.apache.dubbo:dubbo-serialization-googlePb org.apache.dubbo:dubbo-configcenter-api org.apache.dubbo:dubbo-configcenter-definition org.apache.dubbo:dubbo-configcenter-apollo diff --git a/dubbo-bom/pom.xml b/dubbo-bom/pom.xml index 2a6ef723e0d..b072d633abe 100644 --- a/dubbo-bom/pom.xml +++ b/dubbo-bom/pom.xml @@ -332,6 +332,11 @@ dubbo-serialization-gson ${project.version} + + org.apache.dubbo + dubbo-serialization-googlePb + ${project.version} + org.apache.dubbo dubbo-compatible diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/Constants.java b/dubbo-common/src/main/java/org/apache/dubbo/common/Constants.java index b4bc4881920..c1d164197a6 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/Constants.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/Constants.java @@ -727,7 +727,7 @@ public class Constants { public static final String GENERIC_SERIALIZATION_BEAN = "bean"; - public static final String GENERIC_SERIALIZATION_PROTOBUF = "genericProtobuf"; + public static final String GENERIC_SERIALIZATION_PROTOBUF = "gernericprotobuf"; public static final String DUBBO_IP_TO_REGISTRY = "DUBBO_IP_TO_REGISTRY"; diff --git a/dubbo-distribution/pom.xml b/dubbo-distribution/pom.xml index f830aa4379c..5e307cbf271 100644 --- a/dubbo-distribution/pom.xml +++ b/dubbo-distribution/pom.xml @@ -325,6 +325,11 @@ dubbo-serialization-gson ${project.version} + + org.apache.dubbo + dubbo-serialization-googlePb + ${project.version} + org.apache.dubbo dubbo diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/GenericFilter.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/GenericFilter.java index 4bc74a72042..1e6e0a84b3c 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/GenericFilter.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/GenericFilter.java @@ -108,11 +108,11 @@ public Result invoke(Invoker invoker, Invocation inv) throws RpcException { } } } else if (ProtocolUtils.isProtobufGenericSerialization(generic)) { - //as proto3 only accept one parameter + // as proto3 only accept one protobuf parameter if (args.length == 1 && args[0] instanceof String) { - try (UnsafeByteArrayInputStream is = new UnsafeByteArrayInputStream( ((String)args[0]).getBytes())) { + try (UnsafeByteArrayInputStream is = new UnsafeByteArrayInputStream(((String) args[0]).getBytes())) { args[0] = ExtensionLoader.getExtensionLoader(Serialization.class) - .getExtension(Constants.GENERIC_SERIALIZATION_PROTOBUF) + .getExtension("" + Constants.GENERIC_SERIALIZATION_PROTOBUF) .deserialize(null, is).readObject(method.getParameterTypes()[0]); } catch (Exception e) { throw new RpcException("Deserialize argument failed.", e); @@ -137,19 +137,21 @@ public Result invoke(Invoker invoker, Invocation inv) throws RpcException { .serialize(null, os).writeObject(result.getValue()); return new RpcResult(os.toByteArray()); } catch (IOException e) { - throw new RpcException("Serialize result failed.", e); + throw new RpcException(new StringBuilder("Generic serialization [").append(Constants.GENERIC_SERIALIZATION_NATIVE_JAVA) + .append("] serialize result failed.").toString(), e); } } else if (ProtocolUtils.isBeanGenericSerialization(generic)) { return new RpcResult(JavaBeanSerializeUtil.serialize(result.getValue(), JavaBeanAccessor.METHOD)); } else if (ProtocolUtils.isProtobufGenericSerialization(generic)) { - try{ + try { UnsafeByteArrayOutputStream os = new UnsafeByteArrayOutputStream(512); ExtensionLoader.getExtensionLoader(Serialization.class) .getExtension(Constants.GENERIC_SERIALIZATION_PROTOBUF) .serialize(null, os).writeObject(result.getValue()); return new RpcResult(os.toString()); - }catch (IOException e){ - throw new RpcException("Serialize result failed.", e); + } catch (IOException e) { + throw new RpcException(new StringBuilder("Generic serialization [").append(Constants.GENERIC_SERIALIZATION_PROTOBUF) + .append("] serialize result failed.").toString(), e); } } else { return new RpcResult(PojoUtils.generalize(result.getValue())); diff --git a/dubbo-serialization/dubbo-serialization-fastjson/src/main/java/org.apache.dubbo.common.serialize.fastjson/FastJsonObjectInput.java b/dubbo-serialization/dubbo-serialization-fastjson/src/main/java/org/apache/dubbo/common/serialize/fastjson/FastJsonObjectInput.java similarity index 100% rename from dubbo-serialization/dubbo-serialization-fastjson/src/main/java/org.apache.dubbo.common.serialize.fastjson/FastJsonObjectInput.java rename to dubbo-serialization/dubbo-serialization-fastjson/src/main/java/org/apache/dubbo/common/serialize/fastjson/FastJsonObjectInput.java diff --git a/dubbo-serialization/dubbo-serialization-fastjson/src/main/java/org.apache.dubbo.common.serialize.fastjson/FastJsonObjectOutput.java b/dubbo-serialization/dubbo-serialization-fastjson/src/main/java/org/apache/dubbo/common/serialize/fastjson/FastJsonObjectOutput.java similarity index 100% rename from dubbo-serialization/dubbo-serialization-fastjson/src/main/java/org.apache.dubbo.common.serialize.fastjson/FastJsonObjectOutput.java rename to dubbo-serialization/dubbo-serialization-fastjson/src/main/java/org/apache/dubbo/common/serialize/fastjson/FastJsonObjectOutput.java diff --git a/dubbo-serialization/dubbo-serialization-fastjson/src/main/java/org.apache.dubbo.common.serialize.fastjson/FastJsonSerialization.java b/dubbo-serialization/dubbo-serialization-fastjson/src/main/java/org/apache/dubbo/common/serialize/fastjson/FastJsonSerialization.java similarity index 100% rename from dubbo-serialization/dubbo-serialization-fastjson/src/main/java/org.apache.dubbo.common.serialize.fastjson/FastJsonSerialization.java rename to dubbo-serialization/dubbo-serialization-fastjson/src/main/java/org/apache/dubbo/common/serialize/fastjson/FastJsonSerialization.java diff --git a/dubbo-serialization/dubbo-serialization-googlePb/pom.xml b/dubbo-serialization/dubbo-serialization-googlePb/pom.xml index 8aaba821a0e..424149e1dcc 100644 --- a/dubbo-serialization/dubbo-serialization-googlePb/pom.xml +++ b/dubbo-serialization/dubbo-serialization-googlePb/pom.xml @@ -14,21 +14,17 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> - - + 4.0.0 - org.apache.dubbo dubbo-serialization + org.apache.dubbo ${revision} - dubbo-serialization-googlePb jar ${project.artifactId} - The Generic-protobuf serialization module of dubbo project + The protobuf serialization module of dubbo project false diff --git a/dubbo-serialization/dubbo-serialization-googlePb/src/main/java/org/apache/dubbo/common/serialize/protobuf/GenericProtobufObjectInput.java b/dubbo-serialization/dubbo-serialization-googlePb/src/main/java/org/apache/dubbo/common/serialize/protobuf/support/GenericProtobufObjectInput.java similarity index 78% rename from dubbo-serialization/dubbo-serialization-googlePb/src/main/java/org/apache/dubbo/common/serialize/protobuf/GenericProtobufObjectInput.java rename to dubbo-serialization/dubbo-serialization-googlePb/src/main/java/org/apache/dubbo/common/serialize/protobuf/support/GenericProtobufObjectInput.java index 20313cf04f6..a1c565037df 100644 --- a/dubbo-serialization/dubbo-serialization-googlePb/src/main/java/org/apache/dubbo/common/serialize/protobuf/GenericProtobufObjectInput.java +++ b/dubbo-serialization/dubbo-serialization-googlePb/src/main/java/org/apache/dubbo/common/serialize/protobuf/support/GenericProtobufObjectInput.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.common.serialize.protobuf; +package org.apache.dubbo.common.serialize.protobuf.support; import org.apache.dubbo.common.serialize.ObjectInput; @@ -23,22 +23,16 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; -import java.io.Reader; import java.lang.reflect.Type; /** - * GenericGooglePb object input implementation + * GenericGoogleProtobuf object input implementation */ public class GenericProtobufObjectInput implements ObjectInput { - private final BufferedReader reader; public GenericProtobufObjectInput(InputStream in) { - this(new InputStreamReader(in)); - } - - public GenericProtobufObjectInput(Reader reader) { - this.reader = new BufferedReader(reader); + this.reader = new BufferedReader(new InputStreamReader(in)); } @Override @@ -87,23 +81,22 @@ public byte[] readBytes() throws IOException { } @Override - public Object readObject() { - throw new UnsupportedOperationException("this method require class type"); + public Object readObject() throws IOException { + return read(String.class); } @Override - public T readObject(Class cls) throws IOException, ClassNotFoundException { + public T readObject(Class cls) throws IOException { return read(cls); } @Override @SuppressWarnings("unchecked") - public T readObject(Class cls, Type type) throws IOException, ClassNotFoundException { - String json = readLine(); - return ProtobufUtils.deserialize(json,cls); + public T readObject(Class cls, Type type) throws IOException { + return readObject(cls); } - private String readLine() throws IOException, EOFException { + private String readLine() throws IOException { String line = reader.readLine(); if (line == null || line.trim().length() == 0) { throw new EOFException(); @@ -112,7 +105,11 @@ private String readLine() throws IOException, EOFException { } private T read(Class cls) throws IOException { + if (!ProtobufUtils.isSupported(cls)) { + throw new IllegalArgumentException("This serialization only support google protobuf entity, the class is :" + cls.getName()); + } + String json = readLine(); - return ProtobufUtils.deserialize(json,cls); + return ProtobufUtils.deserialize(json, cls); } } diff --git a/dubbo-serialization/dubbo-serialization-googlePb/src/main/java/org/apache/dubbo/common/serialize/protobuf/GenericProtobufObjectOutput.java b/dubbo-serialization/dubbo-serialization-googlePb/src/main/java/org/apache/dubbo/common/serialize/protobuf/support/GenericProtobufObjectOutput.java similarity index 76% rename from dubbo-serialization/dubbo-serialization-googlePb/src/main/java/org/apache/dubbo/common/serialize/protobuf/GenericProtobufObjectOutput.java rename to dubbo-serialization/dubbo-serialization-googlePb/src/main/java/org/apache/dubbo/common/serialize/protobuf/support/GenericProtobufObjectOutput.java index d622e3aac03..93b488edc73 100644 --- a/dubbo-serialization/dubbo-serialization-googlePb/src/main/java/org/apache/dubbo/common/serialize/protobuf/GenericProtobufObjectOutput.java +++ b/dubbo-serialization/dubbo-serialization-googlePb/src/main/java/org/apache/dubbo/common/serialize/protobuf/support/GenericProtobufObjectOutput.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.common.serialize.protobuf; +package org.apache.dubbo.common.serialize.protobuf.support; import org.apache.dubbo.common.serialize.ObjectOutput; @@ -22,21 +22,16 @@ import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.PrintWriter; -import java.io.Writer; /** - * GenericGooglePb object output implementation + * GenericGoogleProtobuf object output implementation */ public class GenericProtobufObjectOutput implements ObjectOutput { private final PrintWriter writer; public GenericProtobufObjectOutput(OutputStream out) { - this(new OutputStreamWriter(out)); - } - - public GenericProtobufObjectOutput(Writer writer) { - this.writer = new PrintWriter(writer); + this.writer = new PrintWriter(new OutputStreamWriter(out)); } @Override @@ -80,25 +75,33 @@ public void writeUTF(String v) throws IOException { } @Override - public void writeBytes(byte[] b) throws IOException { + public void writeBytes(byte[] b) { writer.println(new String(b)); } @Override - public void writeBytes(byte[] b, int off, int len) throws IOException { + public void writeBytes(byte[] b, int off, int len) { writer.println(new String(b, off, len)); } @Override public void writeObject(Object obj) throws IOException { + if (obj == null) { + throw new IllegalArgumentException("This serialization only support google protobuf object, the object is : null"); + } + + if (!ProtobufUtils.isSupported(obj.getClass())) { + throw new IllegalArgumentException("This serialization only support google protobuf object, the object class is: " + obj.getClass().getName()); + } + writer.write(ProtobufUtils.serialize(obj)); writer.println(); writer.flush(); } @Override - public void flushBuffer() throws IOException { + public void flushBuffer() { writer.flush(); } -} +} \ No newline at end of file diff --git a/dubbo-serialization/dubbo-serialization-googlePb/src/main/java/org/apache/dubbo/common/serialize/protobuf/GenericProtobufSerialization.java b/dubbo-serialization/dubbo-serialization-googlePb/src/main/java/org/apache/dubbo/common/serialize/protobuf/support/GenericProtobufSerialization.java similarity index 82% rename from dubbo-serialization/dubbo-serialization-googlePb/src/main/java/org/apache/dubbo/common/serialize/protobuf/GenericProtobufSerialization.java rename to dubbo-serialization/dubbo-serialization-googlePb/src/main/java/org/apache/dubbo/common/serialize/protobuf/support/GenericProtobufSerialization.java index b8bbd64d043..8b9395c95b7 100644 --- a/dubbo-serialization/dubbo-serialization-googlePb/src/main/java/org/apache/dubbo/common/serialize/protobuf/GenericProtobufSerialization.java +++ b/dubbo-serialization/dubbo-serialization-googlePb/src/main/java/org/apache/dubbo/common/serialize/protobuf/support/GenericProtobufSerialization.java @@ -14,40 +14,40 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.common.serialize.protobuf; +package org.apache.dubbo.common.serialize.protobuf.support; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.serialize.ObjectInput; import org.apache.dubbo.common.serialize.ObjectOutput; import org.apache.dubbo.common.serialize.Serialization; -import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; /** - * GooglePb serialization implementation + * This serizalization is use for google protobuf generic reference. + * The entity be transported between client and server by json string. * */ public class GenericProtobufSerialization implements Serialization { @Override public byte getContentTypeId() { - return 11; + return 21; } @Override public String getContentType() { - return "text/proto-json"; + return "text/json"; } @Override - public ObjectOutput serialize(URL url, OutputStream output) throws IOException { + public ObjectOutput serialize(URL url, OutputStream output) { return new GenericProtobufObjectOutput(output); } @Override - public ObjectInput deserialize(URL url, InputStream input) throws IOException { + public ObjectInput deserialize(URL url, InputStream input) { return new GenericProtobufObjectInput(input); } -} +} \ No newline at end of file diff --git a/dubbo-serialization/dubbo-serialization-googlePb/src/main/java/org/apache/dubbo/common/serialize/protobuf/ProtobufUtils.java b/dubbo-serialization/dubbo-serialization-googlePb/src/main/java/org/apache/dubbo/common/serialize/protobuf/support/ProtobufUtils.java similarity index 66% rename from dubbo-serialization/dubbo-serialization-googlePb/src/main/java/org/apache/dubbo/common/serialize/protobuf/ProtobufUtils.java rename to dubbo-serialization/dubbo-serialization-googlePb/src/main/java/org/apache/dubbo/common/serialize/protobuf/support/ProtobufUtils.java index 641ab45eab4..7a2eda8814c 100644 --- a/dubbo-serialization/dubbo-serialization-googlePb/src/main/java/org/apache/dubbo/common/serialize/protobuf/ProtobufUtils.java +++ b/dubbo-serialization/dubbo-serialization-googlePb/src/main/java/org/apache/dubbo/common/serialize/protobuf/support/ProtobufUtils.java @@ -14,20 +14,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.common.serialize.protobuf; - -import java.lang.reflect.Method; +package org.apache.dubbo.common.serialize.protobuf.support; import com.google.protobuf.GeneratedMessageV3; import com.google.protobuf.GeneratedMessageV3.Builder; +import com.google.protobuf.InvalidProtocolBufferException; import com.google.protobuf.MessageOrBuilder; import com.google.protobuf.util.JsonFormat; -import com.google.protobuf.util.JsonFormat.Parser; import com.google.protobuf.util.JsonFormat.Printer; +import java.lang.reflect.Method; + public class ProtobufUtils { - public static boolean isSupported(Class clazz) { + static boolean isSupported(Class clazz) { if (clazz == null) { return false; } @@ -38,36 +38,24 @@ public static boolean isSupported(Class clazz) { return false; } - public static T deserialize(String json, Class requestClass) { - if (!isSupported(requestClass)) { - throw new UnsupportedOperationException(requestClass.getName() + "can not be deserialize"); - } + static T deserialize(String json, Class requestClass) throws InvalidProtocolBufferException { Builder builder; - try{ + try { builder = getMessageBuilder(requestClass); - Parser parser = JsonFormat.parser(); - parser.merge(json, builder); - }catch (Exception e){ - throw new RuntimeException("Failed to deserialize "+requestClass,e ); + } catch (Exception e) { + throw new IllegalArgumentException("Get google protobuf message builder from " + requestClass.getName() + "failed", e); } - + JsonFormat.parser().merge(json, builder); return (T) builder.build(); } - public static String serialize(Object value) { - String result; - try { - Printer printer = JsonFormat.printer(); - result = printer.print((MessageOrBuilder) value); - } catch (Exception e) { - result = e.getMessage(); - } - return result; + static String serialize(Object value) throws InvalidProtocolBufferException { + Printer printer = JsonFormat.printer().omittingInsignificantWhitespace(); + return printer.print((MessageOrBuilder) value); } private static Builder getMessageBuilder(Class requestType) throws Exception { Method method = requestType.getMethod("newBuilder"); - return (Builder) method.invoke(null, null); } } \ No newline at end of file diff --git a/dubbo-serialization/dubbo-serialization-googlePb/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.serialize.Serialization b/dubbo-serialization/dubbo-serialization-googlePb/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.serialize.Serialization index c254237f6f2..ac9006c3bde 100644 --- a/dubbo-serialization/dubbo-serialization-googlePb/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.serialize.Serialization +++ b/dubbo-serialization/dubbo-serialization-googlePb/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.serialize.Serialization @@ -1 +1 @@ -genericProtobuf=org.apache.dubbo.common.serialize.protobuf.GenericProtobufSerialization \ No newline at end of file +gernericprotobuf=org.apache.dubbo.common.serialize.protobuf.support.GenericProtobufSerialization \ No newline at end of file diff --git a/dubbo-serialization/dubbo-serialization-test/pom.xml b/dubbo-serialization/dubbo-serialization-test/pom.xml index 868b45bc82b..5ecca33adef 100644 --- a/dubbo-serialization/dubbo-serialization-test/pom.xml +++ b/dubbo-serialization/dubbo-serialization-test/pom.xml @@ -77,5 +77,10 @@ dubbo-serialization-avro ${project.parent.version} + + org.apache.dubbo + dubbo-serialization-googlePb + ${project.parent.version} + diff --git a/dubbo-serialization/dubbo-serialization-test/src/test/java/org/apache/dubbo/common/serialize/protobuf/support/GenericProtobufObjectOutputTest.java b/dubbo-serialization/dubbo-serialization-test/src/test/java/org/apache/dubbo/common/serialize/protobuf/support/GenericProtobufObjectOutputTest.java new file mode 100644 index 00000000000..986616bdc9f --- /dev/null +++ b/dubbo-serialization/dubbo-serialization-test/src/test/java/org/apache/dubbo/common/serialize/protobuf/support/GenericProtobufObjectOutputTest.java @@ -0,0 +1,85 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.dubbo.common.serialize.protobuf.support; + +import org.apache.dubbo.common.serialize.protobuf.support.model.GooglePB; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Random; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; + + +public class GenericProtobufObjectOutputTest { + private ByteArrayOutputStream byteArrayOutputStream; + private GenericProtobufObjectOutput genericProtobufObjectOutput; + private GenericProtobufObjectInput genericProtobufObjectInput; + private ByteArrayInputStream byteArrayInputStream; + + @BeforeEach + public void setUp() { + this.byteArrayOutputStream = new ByteArrayOutputStream(); + this.genericProtobufObjectOutput = new GenericProtobufObjectOutput(byteArrayOutputStream); + } + + @Test + public void testWriteObjectNull() throws IOException { + assertThrows(IllegalArgumentException.class, () -> { + this.genericProtobufObjectOutput.writeObject(null); + }); + } + + @Test + public void testWriteGooglePbObject() throws IOException { + Random random = new Random(); + final int bound = 100000; + List phoneNumberList = new ArrayList<>(); + for (int i = 0; i < 5; i++) { + phoneNumberList.add(GooglePB.PhoneNumber.newBuilder().setNumber(random.nextInt(bound) + "").setType(GooglePB.PhoneType.forNumber(random.nextInt(GooglePB.PhoneType.values().length - 1))).build()); + } + + Map phoneNumberMap = new HashMap<>(); + for (int i = 0; i < 5; i++) { + phoneNumberMap.put("phoneNumber" + i, GooglePB.PhoneNumber.newBuilder().setNumber(random.nextInt(bound) + "").setType(GooglePB.PhoneType.forNumber(random.nextInt(GooglePB.PhoneType.values().length - 1))).build()); + } + GooglePB.PBRequestType request = GooglePB.PBRequestType.newBuilder() + .setAge(15).setCash(10).setMoney(15.0).setNum(100L) + .addAllPhone(phoneNumberList).putAllDoubleMap(phoneNumberMap).build(); + + this.genericProtobufObjectOutput.writeObject(request); + this.flushToInput(); + assertThat(genericProtobufObjectInput.readObject(GooglePB.PBRequestType.class), is(request)); + } + + private void flushToInput() { + this.genericProtobufObjectOutput.flushBuffer(); + this.byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray()); + this.genericProtobufObjectInput = new GenericProtobufObjectInput(byteArrayInputStream); + } +} + diff --git a/dubbo-serialization/dubbo-serialization-test/src/test/java/org/apache/dubbo/common/serialize/protobuf/support/GenericProtobufSerializationTest.java b/dubbo-serialization/dubbo-serialization-test/src/test/java/org/apache/dubbo/common/serialize/protobuf/support/GenericProtobufSerializationTest.java new file mode 100644 index 00000000000..6a7748edd6f --- /dev/null +++ b/dubbo-serialization/dubbo-serialization-test/src/test/java/org/apache/dubbo/common/serialize/protobuf/support/GenericProtobufSerializationTest.java @@ -0,0 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.dubbo.common.serialize.protobuf.support; + +import org.apache.dubbo.common.serialize.base.AbstractSerializationTest; +import org.apache.dubbo.common.serialize.protostuff.ProtostuffSerialization; + +public class GenericProtobufSerializationTest extends AbstractSerializationTest { + { + serialization = new ProtostuffSerialization(); + } +} diff --git a/dubbo-serialization/dubbo-serialization-test/src/test/java/org/apache/dubbo/common/serialize/protobuf/support/model/GooglePB.java b/dubbo-serialization/dubbo-serialization-test/src/test/java/org/apache/dubbo/common/serialize/protobuf/support/model/GooglePB.java new file mode 100644 index 00000000000..257b37f91be --- /dev/null +++ b/dubbo-serialization/dubbo-serialization-test/src/test/java/org/apache/dubbo/common/serialize/protobuf/support/model/GooglePB.java @@ -0,0 +1,3431 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: GooglePB.proto + +package org.apache.dubbo.common.serialize.protobuf.support.model; + +public final class GooglePB { + private GooglePB() {} + public static void registerAllExtensions( + com.google.protobuf.ExtensionRegistryLite registry) { + } + + public static void registerAllExtensions( + com.google.protobuf.ExtensionRegistry registry) { + registerAllExtensions( + (com.google.protobuf.ExtensionRegistryLite) registry); + } + /** + * Protobuf enum {@code org.apache.dubbo.common.serialize.protobuf.model.PhoneType} + */ + public enum PhoneType + implements com.google.protobuf.ProtocolMessageEnum { + /** + * MOBILE = 0; + */ + MOBILE(0), + /** + * HOME = 1; + */ + HOME(1), + /** + * WORK = 2; + */ + WORK(2), + ; + + /** + * MOBILE = 0; + */ + public static final int MOBILE_VALUE = 0; + /** + * HOME = 1; + */ + public static final int HOME_VALUE = 1; + /** + * WORK = 2; + */ + public static final int WORK_VALUE = 2; + + + public final int getNumber() { + return value; + } + + /** + * @deprecated Use {@link #forNumber(int)} instead. + */ + @Deprecated + public static PhoneType valueOf(int value) { + return forNumber(value); + } + + public static PhoneType forNumber(int value) { + switch (value) { + case 0: return MOBILE; + case 1: return HOME; + case 2: return WORK; + default: return null; + } + } + + public static com.google.protobuf.Internal.EnumLiteMap + internalGetValueMap() { + return internalValueMap; + } + private static final com.google.protobuf.Internal.EnumLiteMap< + PhoneType> internalValueMap = + new com.google.protobuf.Internal.EnumLiteMap() { + public PhoneType findValueByNumber(int number) { + return PhoneType.forNumber(number); + } + }; + + public final com.google.protobuf.Descriptors.EnumValueDescriptor + getValueDescriptor() { + return getDescriptor().getValues().get(ordinal()); + } + public final com.google.protobuf.Descriptors.EnumDescriptor + getDescriptorForType() { + return getDescriptor(); + } + public static final com.google.protobuf.Descriptors.EnumDescriptor + getDescriptor() { + return GooglePB.getDescriptor().getEnumTypes().get(0); + } + + private static final PhoneType[] VALUES = values(); + + public static PhoneType valueOf( + com.google.protobuf.Descriptors.EnumValueDescriptor desc) { + if (desc.getType() != getDescriptor()) { + throw new IllegalArgumentException( + "EnumValueDescriptor is not for this type."); + } + return VALUES[desc.getIndex()]; + } + + private final int value; + + private PhoneType(int value) { + this.value = value; + } + + // @@protoc_insertion_point(enum_scope:org.apache.dubbo.common.serialize.protobuf.model.PhoneType) + } + + public interface PBRequestTypeOrBuilder extends + // @@protoc_insertion_point(interface_extends:org.apache.dubbo.common.serialize.protobuf.model.PBRequestType) + com.google.protobuf.MessageOrBuilder { + + /** + * optional double money = 1; + */ + boolean hasMoney(); + /** + * optional double money = 1; + */ + double getMoney(); + + /** + * optional float cash = 2; + */ + boolean hasCash(); + /** + * optional float cash = 2; + */ + float getCash(); + + /** + * optional int32 age = 3; + */ + boolean hasAge(); + /** + * optional int32 age = 3; + */ + int getAge(); + + /** + * optional int64 num = 4; + */ + boolean hasNum(); + /** + * optional int64 num = 4; + */ + long getNum(); + + /** + * optional bool sex = 5; + */ + boolean hasSex(); + /** + * optional bool sex = 5; + */ + boolean getSex(); + + /** + * optional string name = 6; + */ + boolean hasName(); + /** + * optional string name = 6; + */ + String getName(); + /** + * optional string name = 6; + */ + com.google.protobuf.ByteString + getNameBytes(); + + /** + * optional bytes msg = 7; + */ + boolean hasMsg(); + /** + * optional bytes msg = 7; + */ + com.google.protobuf.ByteString getMsg(); + + /** + * repeated .org.apache.dubbo.common.serialize.protobuf.model.PhoneNumber phone = 8; + */ + java.util.List + getPhoneList(); + /** + * repeated .org.apache.dubbo.common.serialize.protobuf.model.PhoneNumber phone = 8; + */ + GooglePB.PhoneNumber getPhone(int index); + /** + * repeated .org.apache.dubbo.common.serialize.protobuf.model.PhoneNumber phone = 8; + */ + int getPhoneCount(); + /** + * repeated .org.apache.dubbo.common.serialize.protobuf.model.PhoneNumber phone = 8; + */ + java.util.List + getPhoneOrBuilderList(); + /** + * repeated .org.apache.dubbo.common.serialize.protobuf.model.PhoneNumber phone = 8; + */ + GooglePB.PhoneNumberOrBuilder getPhoneOrBuilder( + int index); + + /** + * map<string, .org.apache.dubbo.common.serialize.protobuf.model.PhoneNumber> doubleMap = 9; + */ + int getDoubleMapCount(); + /** + * map<string, .org.apache.dubbo.common.serialize.protobuf.model.PhoneNumber> doubleMap = 9; + */ + boolean containsDoubleMap( + String key); + /** + * Use {@link #getDoubleMapMap()} instead. + */ + @Deprecated + java.util.Map + getDoubleMap(); + /** + * map<string, .org.apache.dubbo.common.serialize.protobuf.model.PhoneNumber> doubleMap = 9; + */ + java.util.Map + getDoubleMapMap(); + /** + * map<string, .org.apache.dubbo.common.serialize.protobuf.model.PhoneNumber> doubleMap = 9; + */ + + GooglePB.PhoneNumber getDoubleMapOrDefault( + String key, + GooglePB.PhoneNumber defaultValue); + /** + * map<string, .org.apache.dubbo.common.serialize.protobuf.model.PhoneNumber> doubleMap = 9; + */ + + GooglePB.PhoneNumber getDoubleMapOrThrow( + String key); + } + /** + * Protobuf type {@code org.apache.dubbo.common.serialize.protobuf.model.PBRequestType} + */ + public static final class PBRequestType extends + com.google.protobuf.GeneratedMessageV3 implements + // @@protoc_insertion_point(message_implements:org.apache.dubbo.common.serialize.protobuf.model.PBRequestType) + PBRequestTypeOrBuilder { + private static final long serialVersionUID = 0L; + // Use PBRequestType.newBuilder() to construct. + private PBRequestType(com.google.protobuf.GeneratedMessageV3.Builder builder) { + super(builder); + } + private PBRequestType() { + money_ = 0D; + cash_ = 0F; + age_ = 0; + num_ = 0L; + sex_ = false; + name_ = ""; + msg_ = com.google.protobuf.ByteString.EMPTY; + phone_ = java.util.Collections.emptyList(); + } + + @Override + public final com.google.protobuf.UnknownFieldSet + getUnknownFields() { + return this.unknownFields; + } + private PBRequestType( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + this(); + int mutable_bitField0_ = 0; + com.google.protobuf.UnknownFieldSet.Builder unknownFields = + com.google.protobuf.UnknownFieldSet.newBuilder(); + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + default: { + if (!parseUnknownField( + input, unknownFields, extensionRegistry, tag)) { + done = true; + } + break; + } + case 9: { + bitField0_ |= 0x00000001; + money_ = input.readDouble(); + break; + } + case 21: { + bitField0_ |= 0x00000002; + cash_ = input.readFloat(); + break; + } + case 24: { + bitField0_ |= 0x00000004; + age_ = input.readInt32(); + break; + } + case 32: { + bitField0_ |= 0x00000008; + num_ = input.readInt64(); + break; + } + case 40: { + bitField0_ |= 0x00000010; + sex_ = input.readBool(); + break; + } + case 50: { + com.google.protobuf.ByteString bs = input.readBytes(); + bitField0_ |= 0x00000020; + name_ = bs; + break; + } + case 58: { + bitField0_ |= 0x00000040; + msg_ = input.readBytes(); + break; + } + case 66: { + if (!((mutable_bitField0_ & 0x00000080) == 0x00000080)) { + phone_ = new java.util.ArrayList(); + mutable_bitField0_ |= 0x00000080; + } + phone_.add( + input.readMessage(GooglePB.PhoneNumber.PARSER, extensionRegistry)); + break; + } + case 74: { + if (!((mutable_bitField0_ & 0x00000100) == 0x00000100)) { + doubleMap_ = com.google.protobuf.MapField.newMapField( + DoubleMapDefaultEntryHolder.defaultEntry); + mutable_bitField0_ |= 0x00000100; + } + com.google.protobuf.MapEntry + doubleMap__ = input.readMessage( + DoubleMapDefaultEntryHolder.defaultEntry.getParserForType(), extensionRegistry); + doubleMap_.getMutableMap().put( + doubleMap__.getKey(), doubleMap__.getValue()); + break; + } + } + } + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(this); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException( + e).setUnfinishedMessage(this); + } finally { + if (((mutable_bitField0_ & 0x00000080) == 0x00000080)) { + phone_ = java.util.Collections.unmodifiableList(phone_); + } + this.unknownFields = unknownFields.build(); + makeExtensionsImmutable(); + } + } + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return GooglePB.internal_static_org_apache_dubbo_common_serialize_protobuf_model_PBRequestType_descriptor; + } + + @SuppressWarnings({"rawtypes"}) + protected com.google.protobuf.MapField internalGetMapField( + int number) { + switch (number) { + case 9: + return internalGetDoubleMap(); + default: + throw new RuntimeException( + "Invalid map field number: " + number); + } + } + protected FieldAccessorTable + internalGetFieldAccessorTable() { + return GooglePB.internal_static_org_apache_dubbo_common_serialize_protobuf_model_PBRequestType_fieldAccessorTable + .ensureFieldAccessorsInitialized( + GooglePB.PBRequestType.class, GooglePB.PBRequestType.Builder.class); + } + + private int bitField0_; + public static final int MONEY_FIELD_NUMBER = 1; + private double money_; + /** + * optional double money = 1; + */ + public boolean hasMoney() { + return ((bitField0_ & 0x00000001) == 0x00000001); + } + /** + * optional double money = 1; + */ + public double getMoney() { + return money_; + } + + public static final int CASH_FIELD_NUMBER = 2; + private float cash_; + /** + * optional float cash = 2; + */ + public boolean hasCash() { + return ((bitField0_ & 0x00000002) == 0x00000002); + } + /** + * optional float cash = 2; + */ + public float getCash() { + return cash_; + } + + public static final int AGE_FIELD_NUMBER = 3; + private int age_; + /** + * optional int32 age = 3; + */ + public boolean hasAge() { + return ((bitField0_ & 0x00000004) == 0x00000004); + } + /** + * optional int32 age = 3; + */ + public int getAge() { + return age_; + } + + public static final int NUM_FIELD_NUMBER = 4; + private long num_; + /** + * optional int64 num = 4; + */ + public boolean hasNum() { + return ((bitField0_ & 0x00000008) == 0x00000008); + } + /** + * optional int64 num = 4; + */ + public long getNum() { + return num_; + } + + public static final int SEX_FIELD_NUMBER = 5; + private boolean sex_; + /** + * optional bool sex = 5; + */ + public boolean hasSex() { + return ((bitField0_ & 0x00000010) == 0x00000010); + } + /** + * optional bool sex = 5; + */ + public boolean getSex() { + return sex_; + } + + public static final int NAME_FIELD_NUMBER = 6; + private volatile Object name_; + /** + * optional string name = 6; + */ + public boolean hasName() { + return ((bitField0_ & 0x00000020) == 0x00000020); + } + /** + * optional string name = 6; + */ + public String getName() { + Object ref = name_; + if (ref instanceof String) { + return (String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + String s = bs.toStringUtf8(); + if (bs.isValidUtf8()) { + name_ = s; + } + return s; + } + } + /** + * optional string name = 6; + */ + public com.google.protobuf.ByteString + getNameBytes() { + Object ref = name_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (String) ref); + name_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int MSG_FIELD_NUMBER = 7; + private com.google.protobuf.ByteString msg_; + /** + * optional bytes msg = 7; + */ + public boolean hasMsg() { + return ((bitField0_ & 0x00000040) == 0x00000040); + } + /** + * optional bytes msg = 7; + */ + public com.google.protobuf.ByteString getMsg() { + return msg_; + } + + public static final int PHONE_FIELD_NUMBER = 8; + private java.util.List phone_; + /** + * repeated .org.apache.dubbo.common.serialize.protobuf.model.PhoneNumber phone = 8; + */ + public java.util.List getPhoneList() { + return phone_; + } + /** + * repeated .org.apache.dubbo.common.serialize.protobuf.model.PhoneNumber phone = 8; + */ + public java.util.List + getPhoneOrBuilderList() { + return phone_; + } + /** + * repeated .org.apache.dubbo.common.serialize.protobuf.model.PhoneNumber phone = 8; + */ + public int getPhoneCount() { + return phone_.size(); + } + /** + * repeated .org.apache.dubbo.common.serialize.protobuf.model.PhoneNumber phone = 8; + */ + public GooglePB.PhoneNumber getPhone(int index) { + return phone_.get(index); + } + /** + * repeated .org.apache.dubbo.common.serialize.protobuf.model.PhoneNumber phone = 8; + */ + public GooglePB.PhoneNumberOrBuilder getPhoneOrBuilder( + int index) { + return phone_.get(index); + } + + public static final int DOUBLEMAP_FIELD_NUMBER = 9; + private static final class DoubleMapDefaultEntryHolder { + static final com.google.protobuf.MapEntry< + String, PhoneNumber> defaultEntry = + com.google.protobuf.MapEntry + .newDefaultInstance( + GooglePB.internal_static_org_apache_dubbo_common_serialize_protobuf_model_PBRequestType_DoubleMapEntry_descriptor, + com.google.protobuf.WireFormat.FieldType.STRING, + "", + com.google.protobuf.WireFormat.FieldType.MESSAGE, + GooglePB.PhoneNumber.getDefaultInstance()); + } + private com.google.protobuf.MapField< + String, PhoneNumber> doubleMap_; + private com.google.protobuf.MapField + internalGetDoubleMap() { + if (doubleMap_ == null) { + return com.google.protobuf.MapField.emptyMapField( + DoubleMapDefaultEntryHolder.defaultEntry); + } + return doubleMap_; + } + + public int getDoubleMapCount() { + return internalGetDoubleMap().getMap().size(); + } + /** + * map<string, .org.apache.dubbo.common.serialize.protobuf.model.PhoneNumber> doubleMap = 9; + */ + + public boolean containsDoubleMap( + String key) { + if (key == null) { throw new NullPointerException(); } + return internalGetDoubleMap().getMap().containsKey(key); + } + /** + * Use {@link #getDoubleMapMap()} instead. + */ + @Deprecated + public java.util.Map getDoubleMap() { + return getDoubleMapMap(); + } + /** + * map<string, .org.apache.dubbo.common.serialize.protobuf.model.PhoneNumber> doubleMap = 9; + */ + + public java.util.Map getDoubleMapMap() { + return internalGetDoubleMap().getMap(); + } + /** + * map<string, .org.apache.dubbo.common.serialize.protobuf.model.PhoneNumber> doubleMap = 9; + */ + + public GooglePB.PhoneNumber getDoubleMapOrDefault( + String key, + GooglePB.PhoneNumber defaultValue) { + if (key == null) { throw new NullPointerException(); } + java.util.Map map = + internalGetDoubleMap().getMap(); + return map.containsKey(key) ? map.get(key) : defaultValue; + } + /** + * map<string, .org.apache.dubbo.common.serialize.protobuf.model.PhoneNumber> doubleMap = 9; + */ + + public GooglePB.PhoneNumber getDoubleMapOrThrow( + String key) { + if (key == null) { throw new NullPointerException(); } + java.util.Map map = + internalGetDoubleMap().getMap(); + if (!map.containsKey(key)) { + throw new IllegalArgumentException(); + } + return map.get(key); + } + + private byte memoizedIsInitialized = -1; + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + for (int i = 0; i < getPhoneCount(); i++) { + if (!getPhone(i).isInitialized()) { + memoizedIsInitialized = 0; + return false; + } + } + for (GooglePB.PhoneNumber item : getDoubleMapMap().values()) { + if (!item.isInitialized()) { + memoizedIsInitialized = 0; + return false; + } + } + memoizedIsInitialized = 1; + return true; + } + + public void writeTo(com.google.protobuf.CodedOutputStream output) + throws java.io.IOException { + if (((bitField0_ & 0x00000001) == 0x00000001)) { + output.writeDouble(1, money_); + } + if (((bitField0_ & 0x00000002) == 0x00000002)) { + output.writeFloat(2, cash_); + } + if (((bitField0_ & 0x00000004) == 0x00000004)) { + output.writeInt32(3, age_); + } + if (((bitField0_ & 0x00000008) == 0x00000008)) { + output.writeInt64(4, num_); + } + if (((bitField0_ & 0x00000010) == 0x00000010)) { + output.writeBool(5, sex_); + } + if (((bitField0_ & 0x00000020) == 0x00000020)) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 6, name_); + } + if (((bitField0_ & 0x00000040) == 0x00000040)) { + output.writeBytes(7, msg_); + } + for (int i = 0; i < phone_.size(); i++) { + output.writeMessage(8, phone_.get(i)); + } + com.google.protobuf.GeneratedMessageV3 + .serializeStringMapTo( + output, + internalGetDoubleMap(), + DoubleMapDefaultEntryHolder.defaultEntry, + 9); + unknownFields.writeTo(output); + } + + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + if (((bitField0_ & 0x00000001) == 0x00000001)) { + size += com.google.protobuf.CodedOutputStream + .computeDoubleSize(1, money_); + } + if (((bitField0_ & 0x00000002) == 0x00000002)) { + size += com.google.protobuf.CodedOutputStream + .computeFloatSize(2, cash_); + } + if (((bitField0_ & 0x00000004) == 0x00000004)) { + size += com.google.protobuf.CodedOutputStream + .computeInt32Size(3, age_); + } + if (((bitField0_ & 0x00000008) == 0x00000008)) { + size += com.google.protobuf.CodedOutputStream + .computeInt64Size(4, num_); + } + if (((bitField0_ & 0x00000010) == 0x00000010)) { + size += com.google.protobuf.CodedOutputStream + .computeBoolSize(5, sex_); + } + if (((bitField0_ & 0x00000020) == 0x00000020)) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(6, name_); + } + if (((bitField0_ & 0x00000040) == 0x00000040)) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(7, msg_); + } + for (int i = 0; i < phone_.size(); i++) { + size += com.google.protobuf.CodedOutputStream + .computeMessageSize(8, phone_.get(i)); + } + for (java.util.Map.Entry entry + : internalGetDoubleMap().getMap().entrySet()) { + com.google.protobuf.MapEntry + doubleMap__ = DoubleMapDefaultEntryHolder.defaultEntry.newBuilderForType() + .setKey(entry.getKey()) + .setValue(entry.getValue()) + .build(); + size += com.google.protobuf.CodedOutputStream + .computeMessageSize(9, doubleMap__); + } + size += unknownFields.getSerializedSize(); + memoizedSize = size; + return size; + } + + @Override + public boolean equals(final Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof GooglePB.PBRequestType)) { + return super.equals(obj); + } + GooglePB.PBRequestType other = (GooglePB.PBRequestType) obj; + + boolean result = true; + result = result && (hasMoney() == other.hasMoney()); + if (hasMoney()) { + result = result && ( + Double.doubleToLongBits(getMoney()) + == Double.doubleToLongBits( + other.getMoney())); + } + result = result && (hasCash() == other.hasCash()); + if (hasCash()) { + result = result && ( + Float.floatToIntBits(getCash()) + == Float.floatToIntBits( + other.getCash())); + } + result = result && (hasAge() == other.hasAge()); + if (hasAge()) { + result = result && (getAge() + == other.getAge()); + } + result = result && (hasNum() == other.hasNum()); + if (hasNum()) { + result = result && (getNum() + == other.getNum()); + } + result = result && (hasSex() == other.hasSex()); + if (hasSex()) { + result = result && (getSex() + == other.getSex()); + } + result = result && (hasName() == other.hasName()); + if (hasName()) { + result = result && getName() + .equals(other.getName()); + } + result = result && (hasMsg() == other.hasMsg()); + if (hasMsg()) { + result = result && getMsg() + .equals(other.getMsg()); + } + result = result && getPhoneList() + .equals(other.getPhoneList()); + result = result && internalGetDoubleMap().equals( + other.internalGetDoubleMap()); + result = result && unknownFields.equals(other.unknownFields); + return result; + } + + @Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + if (hasMoney()) { + hash = (37 * hash) + MONEY_FIELD_NUMBER; + hash = (53 * hash) + com.google.protobuf.Internal.hashLong( + Double.doubleToLongBits(getMoney())); + } + if (hasCash()) { + hash = (37 * hash) + CASH_FIELD_NUMBER; + hash = (53 * hash) + Float.floatToIntBits( + getCash()); + } + if (hasAge()) { + hash = (37 * hash) + AGE_FIELD_NUMBER; + hash = (53 * hash) + getAge(); + } + if (hasNum()) { + hash = (37 * hash) + NUM_FIELD_NUMBER; + hash = (53 * hash) + com.google.protobuf.Internal.hashLong( + getNum()); + } + if (hasSex()) { + hash = (37 * hash) + SEX_FIELD_NUMBER; + hash = (53 * hash) + com.google.protobuf.Internal.hashBoolean( + getSex()); + } + if (hasName()) { + hash = (37 * hash) + NAME_FIELD_NUMBER; + hash = (53 * hash) + getName().hashCode(); + } + if (hasMsg()) { + hash = (37 * hash) + MSG_FIELD_NUMBER; + hash = (53 * hash) + getMsg().hashCode(); + } + if (getPhoneCount() > 0) { + hash = (37 * hash) + PHONE_FIELD_NUMBER; + hash = (53 * hash) + getPhoneList().hashCode(); + } + if (!internalGetDoubleMap().getMap().isEmpty()) { + hash = (37 * hash) + DOUBLEMAP_FIELD_NUMBER; + hash = (53 * hash) + internalGetDoubleMap().hashCode(); + } + hash = (29 * hash) + unknownFields.hashCode(); + memoizedHashCode = hash; + return hash; + } + + public static GooglePB.PBRequestType parseFrom( + java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static GooglePB.PBRequestType parseFrom( + java.nio.ByteBuffer data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static GooglePB.PBRequestType parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static GooglePB.PBRequestType parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static GooglePB.PBRequestType parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static GooglePB.PBRequestType parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static GooglePB.PBRequestType parseFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input); + } + public static GooglePB.PBRequestType parseFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input, extensionRegistry); + } + public static GooglePB.PBRequestType parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseDelimitedWithIOException(PARSER, input); + } + public static GooglePB.PBRequestType parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseDelimitedWithIOException(PARSER, input, extensionRegistry); + } + public static GooglePB.PBRequestType parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input); + } + public static GooglePB.PBRequestType parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input, extensionRegistry); + } + + public Builder newBuilderForType() { return newBuilder(); } + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + public static Builder newBuilder(GooglePB.PBRequestType prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + public Builder toBuilder() { + return this == DEFAULT_INSTANCE + ? new Builder() : new Builder().mergeFrom(this); + } + + @Override + protected Builder newBuilderForType( + BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * Protobuf type {@code org.apache.dubbo.common.serialize.protobuf.model.PBRequestType} + */ + public static final class Builder extends + com.google.protobuf.GeneratedMessageV3.Builder implements + // @@protoc_insertion_point(builder_implements:org.apache.dubbo.common.serialize.protobuf.model.PBRequestType) + GooglePB.PBRequestTypeOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return GooglePB.internal_static_org_apache_dubbo_common_serialize_protobuf_model_PBRequestType_descriptor; + } + + @SuppressWarnings({"rawtypes"}) + protected com.google.protobuf.MapField internalGetMapField( + int number) { + switch (number) { + case 9: + return internalGetDoubleMap(); + default: + throw new RuntimeException( + "Invalid map field number: " + number); + } + } + @SuppressWarnings({"rawtypes"}) + protected com.google.protobuf.MapField internalGetMutableMapField( + int number) { + switch (number) { + case 9: + return internalGetMutableDoubleMap(); + default: + throw new RuntimeException( + "Invalid map field number: " + number); + } + } + protected FieldAccessorTable + internalGetFieldAccessorTable() { + return GooglePB.internal_static_org_apache_dubbo_common_serialize_protobuf_model_PBRequestType_fieldAccessorTable + .ensureFieldAccessorsInitialized( + GooglePB.PBRequestType.class, GooglePB.PBRequestType.Builder.class); + } + + // Construct using org.apache.dubbo.common.serialize.protobuf.model.GooglePB.PBRequestType.newBuilder() + private Builder() { + maybeForceBuilderInitialization(); + } + + private Builder( + BuilderParent parent) { + super(parent); + maybeForceBuilderInitialization(); + } + private void maybeForceBuilderInitialization() { + if (com.google.protobuf.GeneratedMessageV3 + .alwaysUseFieldBuilders) { + getPhoneFieldBuilder(); + } + } + public Builder clear() { + super.clear(); + money_ = 0D; + bitField0_ = (bitField0_ & ~0x00000001); + cash_ = 0F; + bitField0_ = (bitField0_ & ~0x00000002); + age_ = 0; + bitField0_ = (bitField0_ & ~0x00000004); + num_ = 0L; + bitField0_ = (bitField0_ & ~0x00000008); + sex_ = false; + bitField0_ = (bitField0_ & ~0x00000010); + name_ = ""; + bitField0_ = (bitField0_ & ~0x00000020); + msg_ = com.google.protobuf.ByteString.EMPTY; + bitField0_ = (bitField0_ & ~0x00000040); + if (phoneBuilder_ == null) { + phone_ = java.util.Collections.emptyList(); + bitField0_ = (bitField0_ & ~0x00000080); + } else { + phoneBuilder_.clear(); + } + internalGetMutableDoubleMap().clear(); + return this; + } + + public com.google.protobuf.Descriptors.Descriptor + getDescriptorForType() { + return GooglePB.internal_static_org_apache_dubbo_common_serialize_protobuf_model_PBRequestType_descriptor; + } + + public GooglePB.PBRequestType getDefaultInstanceForType() { + return GooglePB.PBRequestType.getDefaultInstance(); + } + + public GooglePB.PBRequestType build() { + GooglePB.PBRequestType result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + public GooglePB.PBRequestType buildPartial() { + GooglePB.PBRequestType result = new GooglePB.PBRequestType(this); + int from_bitField0_ = bitField0_; + int to_bitField0_ = 0; + if (((from_bitField0_ & 0x00000001) == 0x00000001)) { + to_bitField0_ |= 0x00000001; + } + result.money_ = money_; + if (((from_bitField0_ & 0x00000002) == 0x00000002)) { + to_bitField0_ |= 0x00000002; + } + result.cash_ = cash_; + if (((from_bitField0_ & 0x00000004) == 0x00000004)) { + to_bitField0_ |= 0x00000004; + } + result.age_ = age_; + if (((from_bitField0_ & 0x00000008) == 0x00000008)) { + to_bitField0_ |= 0x00000008; + } + result.num_ = num_; + if (((from_bitField0_ & 0x00000010) == 0x00000010)) { + to_bitField0_ |= 0x00000010; + } + result.sex_ = sex_; + if (((from_bitField0_ & 0x00000020) == 0x00000020)) { + to_bitField0_ |= 0x00000020; + } + result.name_ = name_; + if (((from_bitField0_ & 0x00000040) == 0x00000040)) { + to_bitField0_ |= 0x00000040; + } + result.msg_ = msg_; + if (phoneBuilder_ == null) { + if (((bitField0_ & 0x00000080) == 0x00000080)) { + phone_ = java.util.Collections.unmodifiableList(phone_); + bitField0_ = (bitField0_ & ~0x00000080); + } + result.phone_ = phone_; + } else { + result.phone_ = phoneBuilder_.build(); + } + result.doubleMap_ = internalGetDoubleMap(); + result.doubleMap_.makeImmutable(); + result.bitField0_ = to_bitField0_; + onBuilt(); + return result; + } + + public Builder clone() { + return (Builder) super.clone(); + } + public Builder setField( + com.google.protobuf.Descriptors.FieldDescriptor field, + Object value) { + return (Builder) super.setField(field, value); + } + public Builder clearField( + com.google.protobuf.Descriptors.FieldDescriptor field) { + return (Builder) super.clearField(field); + } + public Builder clearOneof( + com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return (Builder) super.clearOneof(oneof); + } + public Builder setRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, + int index, Object value) { + return (Builder) super.setRepeatedField(field, index, value); + } + public Builder addRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, + Object value) { + return (Builder) super.addRepeatedField(field, value); + } + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof GooglePB.PBRequestType) { + return mergeFrom((GooglePB.PBRequestType)other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(GooglePB.PBRequestType other) { + if (other == GooglePB.PBRequestType.getDefaultInstance()) return this; + if (other.hasMoney()) { + setMoney(other.getMoney()); + } + if (other.hasCash()) { + setCash(other.getCash()); + } + if (other.hasAge()) { + setAge(other.getAge()); + } + if (other.hasNum()) { + setNum(other.getNum()); + } + if (other.hasSex()) { + setSex(other.getSex()); + } + if (other.hasName()) { + bitField0_ |= 0x00000020; + name_ = other.name_; + onChanged(); + } + if (other.hasMsg()) { + setMsg(other.getMsg()); + } + if (phoneBuilder_ == null) { + if (!other.phone_.isEmpty()) { + if (phone_.isEmpty()) { + phone_ = other.phone_; + bitField0_ = (bitField0_ & ~0x00000080); + } else { + ensurePhoneIsMutable(); + phone_.addAll(other.phone_); + } + onChanged(); + } + } else { + if (!other.phone_.isEmpty()) { + if (phoneBuilder_.isEmpty()) { + phoneBuilder_.dispose(); + phoneBuilder_ = null; + phone_ = other.phone_; + bitField0_ = (bitField0_ & ~0x00000080); + phoneBuilder_ = + com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders ? + getPhoneFieldBuilder() : null; + } else { + phoneBuilder_.addAllMessages(other.phone_); + } + } + } + internalGetMutableDoubleMap().mergeFrom( + other.internalGetDoubleMap()); + this.mergeUnknownFields(other.unknownFields); + onChanged(); + return this; + } + + public final boolean isInitialized() { + for (int i = 0; i < getPhoneCount(); i++) { + if (!getPhone(i).isInitialized()) { + return false; + } + } + for (GooglePB.PhoneNumber item : getDoubleMapMap().values()) { + if (!item.isInitialized()) { + return false; + } + } + return true; + } + + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + GooglePB.PBRequestType parsedMessage = null; + try { + parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + parsedMessage = (GooglePB.PBRequestType) e.getUnfinishedMessage(); + throw e.unwrapIOException(); + } finally { + if (parsedMessage != null) { + mergeFrom(parsedMessage); + } + } + return this; + } + private int bitField0_; + + private double money_ ; + /** + * optional double money = 1; + */ + public boolean hasMoney() { + return ((bitField0_ & 0x00000001) == 0x00000001); + } + /** + * optional double money = 1; + */ + public double getMoney() { + return money_; + } + /** + * optional double money = 1; + */ + public Builder setMoney(double value) { + bitField0_ |= 0x00000001; + money_ = value; + onChanged(); + return this; + } + /** + * optional double money = 1; + */ + public Builder clearMoney() { + bitField0_ = (bitField0_ & ~0x00000001); + money_ = 0D; + onChanged(); + return this; + } + + private float cash_ ; + /** + * optional float cash = 2; + */ + public boolean hasCash() { + return ((bitField0_ & 0x00000002) == 0x00000002); + } + /** + * optional float cash = 2; + */ + public float getCash() { + return cash_; + } + /** + * optional float cash = 2; + */ + public Builder setCash(float value) { + bitField0_ |= 0x00000002; + cash_ = value; + onChanged(); + return this; + } + /** + * optional float cash = 2; + */ + public Builder clearCash() { + bitField0_ = (bitField0_ & ~0x00000002); + cash_ = 0F; + onChanged(); + return this; + } + + private int age_ ; + /** + * optional int32 age = 3; + */ + public boolean hasAge() { + return ((bitField0_ & 0x00000004) == 0x00000004); + } + /** + * optional int32 age = 3; + */ + public int getAge() { + return age_; + } + /** + * optional int32 age = 3; + */ + public Builder setAge(int value) { + bitField0_ |= 0x00000004; + age_ = value; + onChanged(); + return this; + } + /** + * optional int32 age = 3; + */ + public Builder clearAge() { + bitField0_ = (bitField0_ & ~0x00000004); + age_ = 0; + onChanged(); + return this; + } + + private long num_ ; + /** + * optional int64 num = 4; + */ + public boolean hasNum() { + return ((bitField0_ & 0x00000008) == 0x00000008); + } + /** + * optional int64 num = 4; + */ + public long getNum() { + return num_; + } + /** + * optional int64 num = 4; + */ + public Builder setNum(long value) { + bitField0_ |= 0x00000008; + num_ = value; + onChanged(); + return this; + } + /** + * optional int64 num = 4; + */ + public Builder clearNum() { + bitField0_ = (bitField0_ & ~0x00000008); + num_ = 0L; + onChanged(); + return this; + } + + private boolean sex_ ; + /** + * optional bool sex = 5; + */ + public boolean hasSex() { + return ((bitField0_ & 0x00000010) == 0x00000010); + } + /** + * optional bool sex = 5; + */ + public boolean getSex() { + return sex_; + } + /** + * optional bool sex = 5; + */ + public Builder setSex(boolean value) { + bitField0_ |= 0x00000010; + sex_ = value; + onChanged(); + return this; + } + /** + * optional bool sex = 5; + */ + public Builder clearSex() { + bitField0_ = (bitField0_ & ~0x00000010); + sex_ = false; + onChanged(); + return this; + } + + private Object name_ = ""; + /** + * optional string name = 6; + */ + public boolean hasName() { + return ((bitField0_ & 0x00000020) == 0x00000020); + } + /** + * optional string name = 6; + */ + public String getName() { + Object ref = name_; + if (!(ref instanceof String)) { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + String s = bs.toStringUtf8(); + if (bs.isValidUtf8()) { + name_ = s; + } + return s; + } else { + return (String) ref; + } + } + /** + * optional string name = 6; + */ + public com.google.protobuf.ByteString + getNameBytes() { + Object ref = name_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (String) ref); + name_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * optional string name = 6; + */ + public Builder setName( + String value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000020; + name_ = value; + onChanged(); + return this; + } + /** + * optional string name = 6; + */ + public Builder clearName() { + bitField0_ = (bitField0_ & ~0x00000020); + name_ = getDefaultInstance().getName(); + onChanged(); + return this; + } + /** + * optional string name = 6; + */ + public Builder setNameBytes( + com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000020; + name_ = value; + onChanged(); + return this; + } + + private com.google.protobuf.ByteString msg_ = com.google.protobuf.ByteString.EMPTY; + /** + * optional bytes msg = 7; + */ + public boolean hasMsg() { + return ((bitField0_ & 0x00000040) == 0x00000040); + } + /** + * optional bytes msg = 7; + */ + public com.google.protobuf.ByteString getMsg() { + return msg_; + } + /** + * optional bytes msg = 7; + */ + public Builder setMsg(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000040; + msg_ = value; + onChanged(); + return this; + } + /** + * optional bytes msg = 7; + */ + public Builder clearMsg() { + bitField0_ = (bitField0_ & ~0x00000040); + msg_ = getDefaultInstance().getMsg(); + onChanged(); + return this; + } + + private java.util.List phone_ = + java.util.Collections.emptyList(); + private void ensurePhoneIsMutable() { + if (!((bitField0_ & 0x00000080) == 0x00000080)) { + phone_ = new java.util.ArrayList(phone_); + bitField0_ |= 0x00000080; + } + } + + private com.google.protobuf.RepeatedFieldBuilderV3< + PhoneNumber, PhoneNumber.Builder, PhoneNumberOrBuilder> phoneBuilder_; + + /** + * repeated .org.apache.dubbo.common.serialize.protobuf.model.PhoneNumber phone = 8; + */ + public java.util.List getPhoneList() { + if (phoneBuilder_ == null) { + return java.util.Collections.unmodifiableList(phone_); + } else { + return phoneBuilder_.getMessageList(); + } + } + /** + * repeated .org.apache.dubbo.common.serialize.protobuf.model.PhoneNumber phone = 8; + */ + public int getPhoneCount() { + if (phoneBuilder_ == null) { + return phone_.size(); + } else { + return phoneBuilder_.getCount(); + } + } + /** + * repeated .org.apache.dubbo.common.serialize.protobuf.model.PhoneNumber phone = 8; + */ + public GooglePB.PhoneNumber getPhone(int index) { + if (phoneBuilder_ == null) { + return phone_.get(index); + } else { + return phoneBuilder_.getMessage(index); + } + } + /** + * repeated .org.apache.dubbo.common.serialize.protobuf.model.PhoneNumber phone = 8; + */ + public Builder setPhone( + int index, GooglePB.PhoneNumber value) { + if (phoneBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + ensurePhoneIsMutable(); + phone_.set(index, value); + onChanged(); + } else { + phoneBuilder_.setMessage(index, value); + } + return this; + } + /** + * repeated .org.apache.dubbo.common.serialize.protobuf.model.PhoneNumber phone = 8; + */ + public Builder setPhone( + int index, GooglePB.PhoneNumber.Builder builderForValue) { + if (phoneBuilder_ == null) { + ensurePhoneIsMutable(); + phone_.set(index, builderForValue.build()); + onChanged(); + } else { + phoneBuilder_.setMessage(index, builderForValue.build()); + } + return this; + } + /** + * repeated .org.apache.dubbo.common.serialize.protobuf.model.PhoneNumber phone = 8; + */ + public Builder addPhone(GooglePB.PhoneNumber value) { + if (phoneBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + ensurePhoneIsMutable(); + phone_.add(value); + onChanged(); + } else { + phoneBuilder_.addMessage(value); + } + return this; + } + /** + * repeated .org.apache.dubbo.common.serialize.protobuf.model.PhoneNumber phone = 8; + */ + public Builder addPhone( + int index, GooglePB.PhoneNumber value) { + if (phoneBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + ensurePhoneIsMutable(); + phone_.add(index, value); + onChanged(); + } else { + phoneBuilder_.addMessage(index, value); + } + return this; + } + /** + * repeated .org.apache.dubbo.common.serialize.protobuf.model.PhoneNumber phone = 8; + */ + public Builder addPhone( + GooglePB.PhoneNumber.Builder builderForValue) { + if (phoneBuilder_ == null) { + ensurePhoneIsMutable(); + phone_.add(builderForValue.build()); + onChanged(); + } else { + phoneBuilder_.addMessage(builderForValue.build()); + } + return this; + } + /** + * repeated .org.apache.dubbo.common.serialize.protobuf.model.PhoneNumber phone = 8; + */ + public Builder addPhone( + int index, GooglePB.PhoneNumber.Builder builderForValue) { + if (phoneBuilder_ == null) { + ensurePhoneIsMutable(); + phone_.add(index, builderForValue.build()); + onChanged(); + } else { + phoneBuilder_.addMessage(index, builderForValue.build()); + } + return this; + } + /** + * repeated .org.apache.dubbo.common.serialize.protobuf.model.PhoneNumber phone = 8; + */ + public Builder addAllPhone( + Iterable values) { + if (phoneBuilder_ == null) { + ensurePhoneIsMutable(); + com.google.protobuf.AbstractMessageLite.Builder.addAll( + values, phone_); + onChanged(); + } else { + phoneBuilder_.addAllMessages(values); + } + return this; + } + /** + * repeated .org.apache.dubbo.common.serialize.protobuf.model.PhoneNumber phone = 8; + */ + public Builder clearPhone() { + if (phoneBuilder_ == null) { + phone_ = java.util.Collections.emptyList(); + bitField0_ = (bitField0_ & ~0x00000080); + onChanged(); + } else { + phoneBuilder_.clear(); + } + return this; + } + /** + * repeated .org.apache.dubbo.common.serialize.protobuf.model.PhoneNumber phone = 8; + */ + public Builder removePhone(int index) { + if (phoneBuilder_ == null) { + ensurePhoneIsMutable(); + phone_.remove(index); + onChanged(); + } else { + phoneBuilder_.remove(index); + } + return this; + } + /** + * repeated .org.apache.dubbo.common.serialize.protobuf.model.PhoneNumber phone = 8; + */ + public GooglePB.PhoneNumber.Builder getPhoneBuilder( + int index) { + return getPhoneFieldBuilder().getBuilder(index); + } + /** + * repeated .org.apache.dubbo.common.serialize.protobuf.model.PhoneNumber phone = 8; + */ + public GooglePB.PhoneNumberOrBuilder getPhoneOrBuilder( + int index) { + if (phoneBuilder_ == null) { + return phone_.get(index); } else { + return phoneBuilder_.getMessageOrBuilder(index); + } + } + /** + * repeated .org.apache.dubbo.common.serialize.protobuf.model.PhoneNumber phone = 8; + */ + public java.util.List + getPhoneOrBuilderList() { + if (phoneBuilder_ != null) { + return phoneBuilder_.getMessageOrBuilderList(); + } else { + return java.util.Collections.unmodifiableList(phone_); + } + } + /** + * repeated .org.apache.dubbo.common.serialize.protobuf.model.PhoneNumber phone = 8; + */ + public GooglePB.PhoneNumber.Builder addPhoneBuilder() { + return getPhoneFieldBuilder().addBuilder( + GooglePB.PhoneNumber.getDefaultInstance()); + } + /** + * repeated .org.apache.dubbo.common.serialize.protobuf.model.PhoneNumber phone = 8; + */ + public GooglePB.PhoneNumber.Builder addPhoneBuilder( + int index) { + return getPhoneFieldBuilder().addBuilder( + index, GooglePB.PhoneNumber.getDefaultInstance()); + } + /** + * repeated .org.apache.dubbo.common.serialize.protobuf.model.PhoneNumber phone = 8; + */ + public java.util.List + getPhoneBuilderList() { + return getPhoneFieldBuilder().getBuilderList(); + } + private com.google.protobuf.RepeatedFieldBuilderV3< + PhoneNumber, PhoneNumber.Builder, PhoneNumberOrBuilder> + getPhoneFieldBuilder() { + if (phoneBuilder_ == null) { + phoneBuilder_ = new com.google.protobuf.RepeatedFieldBuilderV3< + PhoneNumber, PhoneNumber.Builder, PhoneNumberOrBuilder>( + phone_, + ((bitField0_ & 0x00000080) == 0x00000080), + getParentForChildren(), + isClean()); + phone_ = null; + } + return phoneBuilder_; + } + + private com.google.protobuf.MapField< + String, PhoneNumber> doubleMap_; + private com.google.protobuf.MapField + internalGetDoubleMap() { + if (doubleMap_ == null) { + return com.google.protobuf.MapField.emptyMapField( + DoubleMapDefaultEntryHolder.defaultEntry); + } + return doubleMap_; + } + private com.google.protobuf.MapField + internalGetMutableDoubleMap() { + onChanged();; + if (doubleMap_ == null) { + doubleMap_ = com.google.protobuf.MapField.newMapField( + DoubleMapDefaultEntryHolder.defaultEntry); + } + if (!doubleMap_.isMutable()) { + doubleMap_ = doubleMap_.copy(); + } + return doubleMap_; + } + + public int getDoubleMapCount() { + return internalGetDoubleMap().getMap().size(); + } + /** + * map<string, .org.apache.dubbo.common.serialize.protobuf.model.PhoneNumber> doubleMap = 9; + */ + + public boolean containsDoubleMap( + String key) { + if (key == null) { throw new NullPointerException(); } + return internalGetDoubleMap().getMap().containsKey(key); + } + /** + * Use {@link #getDoubleMapMap()} instead. + */ + @Deprecated + public java.util.Map getDoubleMap() { + return getDoubleMapMap(); + } + /** + * map<string, .org.apache.dubbo.common.serialize.protobuf.model.PhoneNumber> doubleMap = 9; + */ + + public java.util.Map getDoubleMapMap() { + return internalGetDoubleMap().getMap(); + } + /** + * map<string, .org.apache.dubbo.common.serialize.protobuf.model.PhoneNumber> doubleMap = 9; + */ + + public GooglePB.PhoneNumber getDoubleMapOrDefault( + String key, + GooglePB.PhoneNumber defaultValue) { + if (key == null) { throw new NullPointerException(); } + java.util.Map map = + internalGetDoubleMap().getMap(); + return map.containsKey(key) ? map.get(key) : defaultValue; + } + /** + * map<string, .org.apache.dubbo.common.serialize.protobuf.model.PhoneNumber> doubleMap = 9; + */ + + public GooglePB.PhoneNumber getDoubleMapOrThrow( + String key) { + if (key == null) { throw new NullPointerException(); } + java.util.Map map = + internalGetDoubleMap().getMap(); + if (!map.containsKey(key)) { + throw new IllegalArgumentException(); + } + return map.get(key); + } + + public Builder clearDoubleMap() { + internalGetMutableDoubleMap().getMutableMap() + .clear(); + return this; + } + /** + * map<string, .org.apache.dubbo.common.serialize.protobuf.model.PhoneNumber> doubleMap = 9; + */ + + public Builder removeDoubleMap( + String key) { + if (key == null) { throw new NullPointerException(); } + internalGetMutableDoubleMap().getMutableMap() + .remove(key); + return this; + } + /** + * Use alternate mutation accessors instead. + */ + @Deprecated + public java.util.Map + getMutableDoubleMap() { + return internalGetMutableDoubleMap().getMutableMap(); + } + /** + * map<string, .org.apache.dubbo.common.serialize.protobuf.model.PhoneNumber> doubleMap = 9; + */ + public Builder putDoubleMap( + String key, + GooglePB.PhoneNumber value) { + if (key == null) { throw new NullPointerException(); } + if (value == null) { throw new NullPointerException(); } + internalGetMutableDoubleMap().getMutableMap() + .put(key, value); + return this; + } + /** + * map<string, .org.apache.dubbo.common.serialize.protobuf.model.PhoneNumber> doubleMap = 9; + */ + + public Builder putAllDoubleMap( + java.util.Map values) { + internalGetMutableDoubleMap().getMutableMap() + .putAll(values); + return this; + } + public final Builder setUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.setUnknownFields(unknownFields); + } + + public final Builder mergeUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.mergeUnknownFields(unknownFields); + } + + + // @@protoc_insertion_point(builder_scope:org.apache.dubbo.common.serialize.protobuf.model.PBRequestType) + } + + // @@protoc_insertion_point(class_scope:org.apache.dubbo.common.serialize.protobuf.model.PBRequestType) + private static final GooglePB.PBRequestType DEFAULT_INSTANCE; + static { + DEFAULT_INSTANCE = new GooglePB.PBRequestType(); + } + + public static GooglePB.PBRequestType getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + @Deprecated public static final com.google.protobuf.Parser + PARSER = new com.google.protobuf.AbstractParser() { + public PBRequestType parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return new PBRequestType(input, extensionRegistry); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + public GooglePB.PBRequestType getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } + + } + + public interface PBResponseTypeOrBuilder extends + // @@protoc_insertion_point(interface_extends:org.apache.dubbo.common.serialize.protobuf.model.PBResponseType) + com.google.protobuf.MessageOrBuilder { + + /** + * optional string msg = 1; + */ + boolean hasMsg(); + /** + * optional string msg = 1; + */ + String getMsg(); + /** + * optional string msg = 1; + */ + com.google.protobuf.ByteString + getMsgBytes(); + + /** + * optional .org.apache.dubbo.common.serialize.protobuf.model.PBRequestType CDubboPBRequestType = 3; + */ + boolean hasCDubboPBRequestType(); + /** + * optional .org.apache.dubbo.common.serialize.protobuf.model.PBRequestType CDubboPBRequestType = 3; + */ + GooglePB.PBRequestType getCDubboPBRequestType(); + /** + * optional .org.apache.dubbo.common.serialize.protobuf.model.PBRequestType CDubboPBRequestType = 3; + */ + GooglePB.PBRequestTypeOrBuilder getCDubboPBRequestTypeOrBuilder(); + } + /** + * Protobuf type {@code org.apache.dubbo.common.serialize.protobuf.model.PBResponseType} + */ + public static final class PBResponseType extends + com.google.protobuf.GeneratedMessageV3 implements + // @@protoc_insertion_point(message_implements:org.apache.dubbo.common.serialize.protobuf.model.PBResponseType) + PBResponseTypeOrBuilder { + private static final long serialVersionUID = 0L; + // Use PBResponseType.newBuilder() to construct. + private PBResponseType(com.google.protobuf.GeneratedMessageV3.Builder builder) { + super(builder); + } + private PBResponseType() { + msg_ = ""; + } + + @Override + public final com.google.protobuf.UnknownFieldSet + getUnknownFields() { + return this.unknownFields; + } + private PBResponseType( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + this(); + int mutable_bitField0_ = 0; + com.google.protobuf.UnknownFieldSet.Builder unknownFields = + com.google.protobuf.UnknownFieldSet.newBuilder(); + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + default: { + if (!parseUnknownField( + input, unknownFields, extensionRegistry, tag)) { + done = true; + } + break; + } + case 10: { + com.google.protobuf.ByteString bs = input.readBytes(); + bitField0_ |= 0x00000001; + msg_ = bs; + break; + } + case 26: { + GooglePB.PBRequestType.Builder subBuilder = null; + if (((bitField0_ & 0x00000002) == 0x00000002)) { + subBuilder = cDubboPBRequestType_.toBuilder(); + } + cDubboPBRequestType_ = input.readMessage(GooglePB.PBRequestType.PARSER, extensionRegistry); + if (subBuilder != null) { + subBuilder.mergeFrom(cDubboPBRequestType_); + cDubboPBRequestType_ = subBuilder.buildPartial(); + } + bitField0_ |= 0x00000002; + break; + } + } + } + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(this); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException( + e).setUnfinishedMessage(this); + } finally { + this.unknownFields = unknownFields.build(); + makeExtensionsImmutable(); + } + } + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return GooglePB.internal_static_org_apache_dubbo_common_serialize_protobuf_model_PBResponseType_descriptor; + } + + protected FieldAccessorTable + internalGetFieldAccessorTable() { + return GooglePB.internal_static_org_apache_dubbo_common_serialize_protobuf_model_PBResponseType_fieldAccessorTable + .ensureFieldAccessorsInitialized( + GooglePB.PBResponseType.class, GooglePB.PBResponseType.Builder.class); + } + + private int bitField0_; + public static final int MSG_FIELD_NUMBER = 1; + private volatile Object msg_; + /** + * optional string msg = 1; + */ + public boolean hasMsg() { + return ((bitField0_ & 0x00000001) == 0x00000001); + } + /** + * optional string msg = 1; + */ + public String getMsg() { + Object ref = msg_; + if (ref instanceof String) { + return (String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + String s = bs.toStringUtf8(); + if (bs.isValidUtf8()) { + msg_ = s; + } + return s; + } + } + /** + * optional string msg = 1; + */ + public com.google.protobuf.ByteString + getMsgBytes() { + Object ref = msg_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (String) ref); + msg_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int CDUBBOPBREQUESTTYPE_FIELD_NUMBER = 3; + private GooglePB.PBRequestType cDubboPBRequestType_; + /** + * optional .org.apache.dubbo.common.serialize.protobuf.model.PBRequestType CDubboPBRequestType = 3; + */ + public boolean hasCDubboPBRequestType() { + return ((bitField0_ & 0x00000002) == 0x00000002); + } + /** + * optional .org.apache.dubbo.common.serialize.protobuf.model.PBRequestType CDubboPBRequestType = 3; + */ + public GooglePB.PBRequestType getCDubboPBRequestType() { + return cDubboPBRequestType_ == null ? GooglePB.PBRequestType.getDefaultInstance() : cDubboPBRequestType_; + } + /** + * optional .org.apache.dubbo.common.serialize.protobuf.model.PBRequestType CDubboPBRequestType = 3; + */ + public GooglePB.PBRequestTypeOrBuilder getCDubboPBRequestTypeOrBuilder() { + return cDubboPBRequestType_ == null ? GooglePB.PBRequestType.getDefaultInstance() : cDubboPBRequestType_; + } + + private byte memoizedIsInitialized = -1; + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + if (hasCDubboPBRequestType()) { + if (!getCDubboPBRequestType().isInitialized()) { + memoizedIsInitialized = 0; + return false; + } + } + memoizedIsInitialized = 1; + return true; + } + + public void writeTo(com.google.protobuf.CodedOutputStream output) + throws java.io.IOException { + if (((bitField0_ & 0x00000001) == 0x00000001)) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 1, msg_); + } + if (((bitField0_ & 0x00000002) == 0x00000002)) { + output.writeMessage(3, getCDubboPBRequestType()); + } + unknownFields.writeTo(output); + } + + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + if (((bitField0_ & 0x00000001) == 0x00000001)) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, msg_); + } + if (((bitField0_ & 0x00000002) == 0x00000002)) { + size += com.google.protobuf.CodedOutputStream + .computeMessageSize(3, getCDubboPBRequestType()); + } + size += unknownFields.getSerializedSize(); + memoizedSize = size; + return size; + } + + @Override + public boolean equals(final Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof GooglePB.PBResponseType)) { + return super.equals(obj); + } + GooglePB.PBResponseType other = (GooglePB.PBResponseType) obj; + + boolean result = true; + result = result && (hasMsg() == other.hasMsg()); + if (hasMsg()) { + result = result && getMsg() + .equals(other.getMsg()); + } + result = result && (hasCDubboPBRequestType() == other.hasCDubboPBRequestType()); + if (hasCDubboPBRequestType()) { + result = result && getCDubboPBRequestType() + .equals(other.getCDubboPBRequestType()); + } + result = result && unknownFields.equals(other.unknownFields); + return result; + } + + @Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + if (hasMsg()) { + hash = (37 * hash) + MSG_FIELD_NUMBER; + hash = (53 * hash) + getMsg().hashCode(); + } + if (hasCDubboPBRequestType()) { + hash = (37 * hash) + CDUBBOPBREQUESTTYPE_FIELD_NUMBER; + hash = (53 * hash) + getCDubboPBRequestType().hashCode(); + } + hash = (29 * hash) + unknownFields.hashCode(); + memoizedHashCode = hash; + return hash; + } + + public static GooglePB.PBResponseType parseFrom( + java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static GooglePB.PBResponseType parseFrom( + java.nio.ByteBuffer data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static GooglePB.PBResponseType parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static GooglePB.PBResponseType parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static GooglePB.PBResponseType parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static GooglePB.PBResponseType parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static GooglePB.PBResponseType parseFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input); + } + public static GooglePB.PBResponseType parseFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input, extensionRegistry); + } + public static GooglePB.PBResponseType parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseDelimitedWithIOException(PARSER, input); + } + public static GooglePB.PBResponseType parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseDelimitedWithIOException(PARSER, input, extensionRegistry); + } + public static GooglePB.PBResponseType parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input); + } + public static GooglePB.PBResponseType parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input, extensionRegistry); + } + + public Builder newBuilderForType() { return newBuilder(); } + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + public static Builder newBuilder(GooglePB.PBResponseType prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + public Builder toBuilder() { + return this == DEFAULT_INSTANCE + ? new Builder() : new Builder().mergeFrom(this); + } + + @Override + protected Builder newBuilderForType( + BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * Protobuf type {@code org.apache.dubbo.common.serialize.protobuf.model.PBResponseType} + */ + public static final class Builder extends + com.google.protobuf.GeneratedMessageV3.Builder implements + // @@protoc_insertion_point(builder_implements:org.apache.dubbo.common.serialize.protobuf.model.PBResponseType) + GooglePB.PBResponseTypeOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return GooglePB.internal_static_org_apache_dubbo_common_serialize_protobuf_model_PBResponseType_descriptor; + } + + protected FieldAccessorTable + internalGetFieldAccessorTable() { + return GooglePB.internal_static_org_apache_dubbo_common_serialize_protobuf_model_PBResponseType_fieldAccessorTable + .ensureFieldAccessorsInitialized( + GooglePB.PBResponseType.class, GooglePB.PBResponseType.Builder.class); + } + + // Construct using org.apache.dubbo.common.serialize.protobuf.model.GooglePB.PBResponseType.newBuilder() + private Builder() { + maybeForceBuilderInitialization(); + } + + private Builder( + BuilderParent parent) { + super(parent); + maybeForceBuilderInitialization(); + } + private void maybeForceBuilderInitialization() { + if (com.google.protobuf.GeneratedMessageV3 + .alwaysUseFieldBuilders) { + getCDubboPBRequestTypeFieldBuilder(); + } + } + public Builder clear() { + super.clear(); + msg_ = ""; + bitField0_ = (bitField0_ & ~0x00000001); + if (cDubboPBRequestTypeBuilder_ == null) { + cDubboPBRequestType_ = null; + } else { + cDubboPBRequestTypeBuilder_.clear(); + } + bitField0_ = (bitField0_ & ~0x00000002); + return this; + } + + public com.google.protobuf.Descriptors.Descriptor + getDescriptorForType() { + return GooglePB.internal_static_org_apache_dubbo_common_serialize_protobuf_model_PBResponseType_descriptor; + } + + public GooglePB.PBResponseType getDefaultInstanceForType() { + return GooglePB.PBResponseType.getDefaultInstance(); + } + + public GooglePB.PBResponseType build() { + GooglePB.PBResponseType result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + public GooglePB.PBResponseType buildPartial() { + GooglePB.PBResponseType result = new GooglePB.PBResponseType(this); + int from_bitField0_ = bitField0_; + int to_bitField0_ = 0; + if (((from_bitField0_ & 0x00000001) == 0x00000001)) { + to_bitField0_ |= 0x00000001; + } + result.msg_ = msg_; + if (((from_bitField0_ & 0x00000002) == 0x00000002)) { + to_bitField0_ |= 0x00000002; + } + if (cDubboPBRequestTypeBuilder_ == null) { + result.cDubboPBRequestType_ = cDubboPBRequestType_; + } else { + result.cDubboPBRequestType_ = cDubboPBRequestTypeBuilder_.build(); + } + result.bitField0_ = to_bitField0_; + onBuilt(); + return result; + } + + public Builder clone() { + return (Builder) super.clone(); + } + public Builder setField( + com.google.protobuf.Descriptors.FieldDescriptor field, + Object value) { + return (Builder) super.setField(field, value); + } + public Builder clearField( + com.google.protobuf.Descriptors.FieldDescriptor field) { + return (Builder) super.clearField(field); + } + public Builder clearOneof( + com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return (Builder) super.clearOneof(oneof); + } + public Builder setRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, + int index, Object value) { + return (Builder) super.setRepeatedField(field, index, value); + } + public Builder addRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, + Object value) { + return (Builder) super.addRepeatedField(field, value); + } + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof GooglePB.PBResponseType) { + return mergeFrom((GooglePB.PBResponseType)other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(GooglePB.PBResponseType other) { + if (other == GooglePB.PBResponseType.getDefaultInstance()) return this; + if (other.hasMsg()) { + bitField0_ |= 0x00000001; + msg_ = other.msg_; + onChanged(); + } + if (other.hasCDubboPBRequestType()) { + mergeCDubboPBRequestType(other.getCDubboPBRequestType()); + } + this.mergeUnknownFields(other.unknownFields); + onChanged(); + return this; + } + + public final boolean isInitialized() { + if (hasCDubboPBRequestType()) { + if (!getCDubboPBRequestType().isInitialized()) { + return false; + } + } + return true; + } + + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + GooglePB.PBResponseType parsedMessage = null; + try { + parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + parsedMessage = (GooglePB.PBResponseType) e.getUnfinishedMessage(); + throw e.unwrapIOException(); + } finally { + if (parsedMessage != null) { + mergeFrom(parsedMessage); + } + } + return this; + } + private int bitField0_; + + private Object msg_ = ""; + /** + * optional string msg = 1; + */ + public boolean hasMsg() { + return ((bitField0_ & 0x00000001) == 0x00000001); + } + /** + * optional string msg = 1; + */ + public String getMsg() { + Object ref = msg_; + if (!(ref instanceof String)) { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + String s = bs.toStringUtf8(); + if (bs.isValidUtf8()) { + msg_ = s; + } + return s; + } else { + return (String) ref; + } + } + /** + * optional string msg = 1; + */ + public com.google.protobuf.ByteString + getMsgBytes() { + Object ref = msg_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (String) ref); + msg_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * optional string msg = 1; + */ + public Builder setMsg( + String value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000001; + msg_ = value; + onChanged(); + return this; + } + /** + * optional string msg = 1; + */ + public Builder clearMsg() { + bitField0_ = (bitField0_ & ~0x00000001); + msg_ = getDefaultInstance().getMsg(); + onChanged(); + return this; + } + /** + * optional string msg = 1; + */ + public Builder setMsgBytes( + com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000001; + msg_ = value; + onChanged(); + return this; + } + + private GooglePB.PBRequestType cDubboPBRequestType_ = null; + private com.google.protobuf.SingleFieldBuilderV3< + PBRequestType, PBRequestType.Builder, PBRequestTypeOrBuilder> cDubboPBRequestTypeBuilder_; + /** + * optional .org.apache.dubbo.common.serialize.protobuf.model.PBRequestType CDubboPBRequestType = 3; + */ + public boolean hasCDubboPBRequestType() { + return ((bitField0_ & 0x00000002) == 0x00000002); + } + /** + * optional .org.apache.dubbo.common.serialize.protobuf.model.PBRequestType CDubboPBRequestType = 3; + */ + public GooglePB.PBRequestType getCDubboPBRequestType() { + if (cDubboPBRequestTypeBuilder_ == null) { + return cDubboPBRequestType_ == null ? GooglePB.PBRequestType.getDefaultInstance() : cDubboPBRequestType_; + } else { + return cDubboPBRequestTypeBuilder_.getMessage(); + } + } + /** + * optional .org.apache.dubbo.common.serialize.protobuf.model.PBRequestType CDubboPBRequestType = 3; + */ + public Builder setCDubboPBRequestType(GooglePB.PBRequestType value) { + if (cDubboPBRequestTypeBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + cDubboPBRequestType_ = value; + onChanged(); + } else { + cDubboPBRequestTypeBuilder_.setMessage(value); + } + bitField0_ |= 0x00000002; + return this; + } + /** + * optional .org.apache.dubbo.common.serialize.protobuf.model.PBRequestType CDubboPBRequestType = 3; + */ + public Builder setCDubboPBRequestType( + GooglePB.PBRequestType.Builder builderForValue) { + if (cDubboPBRequestTypeBuilder_ == null) { + cDubboPBRequestType_ = builderForValue.build(); + onChanged(); + } else { + cDubboPBRequestTypeBuilder_.setMessage(builderForValue.build()); + } + bitField0_ |= 0x00000002; + return this; + } + /** + * optional .org.apache.dubbo.common.serialize.protobuf.model.PBRequestType CDubboPBRequestType = 3; + */ + public Builder mergeCDubboPBRequestType(GooglePB.PBRequestType value) { + if (cDubboPBRequestTypeBuilder_ == null) { + if (((bitField0_ & 0x00000002) == 0x00000002) && + cDubboPBRequestType_ != null && + cDubboPBRequestType_ != GooglePB.PBRequestType.getDefaultInstance()) { + cDubboPBRequestType_ = + GooglePB.PBRequestType.newBuilder(cDubboPBRequestType_).mergeFrom(value).buildPartial(); + } else { + cDubboPBRequestType_ = value; + } + onChanged(); + } else { + cDubboPBRequestTypeBuilder_.mergeFrom(value); + } + bitField0_ |= 0x00000002; + return this; + } + /** + * optional .org.apache.dubbo.common.serialize.protobuf.model.PBRequestType CDubboPBRequestType = 3; + */ + public Builder clearCDubboPBRequestType() { + if (cDubboPBRequestTypeBuilder_ == null) { + cDubboPBRequestType_ = null; + onChanged(); + } else { + cDubboPBRequestTypeBuilder_.clear(); + } + bitField0_ = (bitField0_ & ~0x00000002); + return this; + } + /** + * optional .org.apache.dubbo.common.serialize.protobuf.model.PBRequestType CDubboPBRequestType = 3; + */ + public GooglePB.PBRequestType.Builder getCDubboPBRequestTypeBuilder() { + bitField0_ |= 0x00000002; + onChanged(); + return getCDubboPBRequestTypeFieldBuilder().getBuilder(); + } + /** + * optional .org.apache.dubbo.common.serialize.protobuf.model.PBRequestType CDubboPBRequestType = 3; + */ + public GooglePB.PBRequestTypeOrBuilder getCDubboPBRequestTypeOrBuilder() { + if (cDubboPBRequestTypeBuilder_ != null) { + return cDubboPBRequestTypeBuilder_.getMessageOrBuilder(); + } else { + return cDubboPBRequestType_ == null ? + GooglePB.PBRequestType.getDefaultInstance() : cDubboPBRequestType_; + } + } + /** + * optional .org.apache.dubbo.common.serialize.protobuf.model.PBRequestType CDubboPBRequestType = 3; + */ + private com.google.protobuf.SingleFieldBuilderV3< + PBRequestType, PBRequestType.Builder, PBRequestTypeOrBuilder> + getCDubboPBRequestTypeFieldBuilder() { + if (cDubboPBRequestTypeBuilder_ == null) { + cDubboPBRequestTypeBuilder_ = new com.google.protobuf.SingleFieldBuilderV3< + PBRequestType, PBRequestType.Builder, PBRequestTypeOrBuilder>( + getCDubboPBRequestType(), + getParentForChildren(), + isClean()); + cDubboPBRequestType_ = null; + } + return cDubboPBRequestTypeBuilder_; + } + public final Builder setUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.setUnknownFields(unknownFields); + } + + public final Builder mergeUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.mergeUnknownFields(unknownFields); + } + + + // @@protoc_insertion_point(builder_scope:org.apache.dubbo.common.serialize.protobuf.model.PBResponseType) + } + + // @@protoc_insertion_point(class_scope:org.apache.dubbo.common.serialize.protobuf.model.PBResponseType) + private static final GooglePB.PBResponseType DEFAULT_INSTANCE; + static { + DEFAULT_INSTANCE = new GooglePB.PBResponseType(); + } + + public static GooglePB.PBResponseType getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + @Deprecated public static final com.google.protobuf.Parser + PARSER = new com.google.protobuf.AbstractParser() { + public PBResponseType parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return new PBResponseType(input, extensionRegistry); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + public GooglePB.PBResponseType getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } + + } + + public interface PhoneNumberOrBuilder extends + // @@protoc_insertion_point(interface_extends:org.apache.dubbo.common.serialize.protobuf.model.PhoneNumber) + com.google.protobuf.MessageOrBuilder { + + /** + * required string number = 1; + */ + boolean hasNumber(); + /** + * required string number = 1; + */ + String getNumber(); + /** + * required string number = 1; + */ + com.google.protobuf.ByteString + getNumberBytes(); + + /** + * optional .org.apache.dubbo.common.serialize.protobuf.model.PhoneType type = 2 [default = HOME]; + */ + boolean hasType(); + /** + * optional .org.apache.dubbo.common.serialize.protobuf.model.PhoneType type = 2 [default = HOME]; + */ + GooglePB.PhoneType getType(); + } + /** + * Protobuf type {@code org.apache.dubbo.common.serialize.protobuf.model.PhoneNumber} + */ + public static final class PhoneNumber extends + com.google.protobuf.GeneratedMessageV3 implements + // @@protoc_insertion_point(message_implements:org.apache.dubbo.common.serialize.protobuf.model.PhoneNumber) + PhoneNumberOrBuilder { + private static final long serialVersionUID = 0L; + // Use PhoneNumber.newBuilder() to construct. + private PhoneNumber(com.google.protobuf.GeneratedMessageV3.Builder builder) { + super(builder); + } + private PhoneNumber() { + number_ = ""; + type_ = 1; + } + + @Override + public final com.google.protobuf.UnknownFieldSet + getUnknownFields() { + return this.unknownFields; + } + private PhoneNumber( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + this(); + int mutable_bitField0_ = 0; + com.google.protobuf.UnknownFieldSet.Builder unknownFields = + com.google.protobuf.UnknownFieldSet.newBuilder(); + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + default: { + if (!parseUnknownField( + input, unknownFields, extensionRegistry, tag)) { + done = true; + } + break; + } + case 10: { + com.google.protobuf.ByteString bs = input.readBytes(); + bitField0_ |= 0x00000001; + number_ = bs; + break; + } + case 16: { + int rawValue = input.readEnum(); + GooglePB.PhoneType value = GooglePB.PhoneType.valueOf(rawValue); + if (value == null) { + unknownFields.mergeVarintField(2, rawValue); + } else { + bitField0_ |= 0x00000002; + type_ = rawValue; + } + break; + } + } + } + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(this); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException( + e).setUnfinishedMessage(this); + } finally { + this.unknownFields = unknownFields.build(); + makeExtensionsImmutable(); + } + } + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return GooglePB.internal_static_org_apache_dubbo_common_serialize_protobuf_model_PhoneNumber_descriptor; + } + + protected FieldAccessorTable + internalGetFieldAccessorTable() { + return GooglePB.internal_static_org_apache_dubbo_common_serialize_protobuf_model_PhoneNumber_fieldAccessorTable + .ensureFieldAccessorsInitialized( + GooglePB.PhoneNumber.class, GooglePB.PhoneNumber.Builder.class); + } + + private int bitField0_; + public static final int NUMBER_FIELD_NUMBER = 1; + private volatile Object number_; + /** + * required string number = 1; + */ + public boolean hasNumber() { + return ((bitField0_ & 0x00000001) == 0x00000001); + } + /** + * required string number = 1; + */ + public String getNumber() { + Object ref = number_; + if (ref instanceof String) { + return (String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + String s = bs.toStringUtf8(); + if (bs.isValidUtf8()) { + number_ = s; + } + return s; + } + } + /** + * required string number = 1; + */ + public com.google.protobuf.ByteString + getNumberBytes() { + Object ref = number_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (String) ref); + number_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int TYPE_FIELD_NUMBER = 2; + private int type_; + /** + * optional .org.apache.dubbo.common.serialize.protobuf.model.PhoneType type = 2 [default = HOME]; + */ + public boolean hasType() { + return ((bitField0_ & 0x00000002) == 0x00000002); + } + /** + * optional .org.apache.dubbo.common.serialize.protobuf.model.PhoneType type = 2 [default = HOME]; + */ + public GooglePB.PhoneType getType() { + GooglePB.PhoneType result = GooglePB.PhoneType.valueOf(type_); + return result == null ? GooglePB.PhoneType.HOME : result; + } + + private byte memoizedIsInitialized = -1; + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + if (!hasNumber()) { + memoizedIsInitialized = 0; + return false; + } + memoizedIsInitialized = 1; + return true; + } + + public void writeTo(com.google.protobuf.CodedOutputStream output) + throws java.io.IOException { + if (((bitField0_ & 0x00000001) == 0x00000001)) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 1, number_); + } + if (((bitField0_ & 0x00000002) == 0x00000002)) { + output.writeEnum(2, type_); + } + unknownFields.writeTo(output); + } + + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + if (((bitField0_ & 0x00000001) == 0x00000001)) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, number_); + } + if (((bitField0_ & 0x00000002) == 0x00000002)) { + size += com.google.protobuf.CodedOutputStream + .computeEnumSize(2, type_); + } + size += unknownFields.getSerializedSize(); + memoizedSize = size; + return size; + } + + @Override + public boolean equals(final Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof GooglePB.PhoneNumber)) { + return super.equals(obj); + } + GooglePB.PhoneNumber other = (GooglePB.PhoneNumber) obj; + + boolean result = true; + result = result && (hasNumber() == other.hasNumber()); + if (hasNumber()) { + result = result && getNumber() + .equals(other.getNumber()); + } + result = result && (hasType() == other.hasType()); + if (hasType()) { + result = result && type_ == other.type_; + } + result = result && unknownFields.equals(other.unknownFields); + return result; + } + + @Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + if (hasNumber()) { + hash = (37 * hash) + NUMBER_FIELD_NUMBER; + hash = (53 * hash) + getNumber().hashCode(); + } + if (hasType()) { + hash = (37 * hash) + TYPE_FIELD_NUMBER; + hash = (53 * hash) + type_; + } + hash = (29 * hash) + unknownFields.hashCode(); + memoizedHashCode = hash; + return hash; + } + + public static GooglePB.PhoneNumber parseFrom( + java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static GooglePB.PhoneNumber parseFrom( + java.nio.ByteBuffer data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static GooglePB.PhoneNumber parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static GooglePB.PhoneNumber parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static GooglePB.PhoneNumber parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static GooglePB.PhoneNumber parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static GooglePB.PhoneNumber parseFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input); + } + public static GooglePB.PhoneNumber parseFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input, extensionRegistry); + } + public static GooglePB.PhoneNumber parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseDelimitedWithIOException(PARSER, input); + } + public static GooglePB.PhoneNumber parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseDelimitedWithIOException(PARSER, input, extensionRegistry); + } + public static GooglePB.PhoneNumber parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input); + } + public static GooglePB.PhoneNumber parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input, extensionRegistry); + } + + public Builder newBuilderForType() { return newBuilder(); } + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + public static Builder newBuilder(GooglePB.PhoneNumber prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + public Builder toBuilder() { + return this == DEFAULT_INSTANCE + ? new Builder() : new Builder().mergeFrom(this); + } + + @Override + protected Builder newBuilderForType( + BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * Protobuf type {@code org.apache.dubbo.common.serialize.protobuf.model.PhoneNumber} + */ + public static final class Builder extends + com.google.protobuf.GeneratedMessageV3.Builder implements + // @@protoc_insertion_point(builder_implements:org.apache.dubbo.common.serialize.protobuf.model.PhoneNumber) + GooglePB.PhoneNumberOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return GooglePB.internal_static_org_apache_dubbo_common_serialize_protobuf_model_PhoneNumber_descriptor; + } + + protected FieldAccessorTable + internalGetFieldAccessorTable() { + return GooglePB.internal_static_org_apache_dubbo_common_serialize_protobuf_model_PhoneNumber_fieldAccessorTable + .ensureFieldAccessorsInitialized( + GooglePB.PhoneNumber.class, GooglePB.PhoneNumber.Builder.class); + } + + // Construct using org.apache.dubbo.common.serialize.protobuf.model.GooglePB.PhoneNumber.newBuilder() + private Builder() { + maybeForceBuilderInitialization(); + } + + private Builder( + BuilderParent parent) { + super(parent); + maybeForceBuilderInitialization(); + } + private void maybeForceBuilderInitialization() { + if (com.google.protobuf.GeneratedMessageV3 + .alwaysUseFieldBuilders) { + } + } + public Builder clear() { + super.clear(); + number_ = ""; + bitField0_ = (bitField0_ & ~0x00000001); + type_ = 1; + bitField0_ = (bitField0_ & ~0x00000002); + return this; + } + + public com.google.protobuf.Descriptors.Descriptor + getDescriptorForType() { + return GooglePB.internal_static_org_apache_dubbo_common_serialize_protobuf_model_PhoneNumber_descriptor; + } + + public GooglePB.PhoneNumber getDefaultInstanceForType() { + return GooglePB.PhoneNumber.getDefaultInstance(); + } + + public GooglePB.PhoneNumber build() { + GooglePB.PhoneNumber result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + public GooglePB.PhoneNumber buildPartial() { + GooglePB.PhoneNumber result = new GooglePB.PhoneNumber(this); + int from_bitField0_ = bitField0_; + int to_bitField0_ = 0; + if (((from_bitField0_ & 0x00000001) == 0x00000001)) { + to_bitField0_ |= 0x00000001; + } + result.number_ = number_; + if (((from_bitField0_ & 0x00000002) == 0x00000002)) { + to_bitField0_ |= 0x00000002; + } + result.type_ = type_; + result.bitField0_ = to_bitField0_; + onBuilt(); + return result; + } + + public Builder clone() { + return (Builder) super.clone(); + } + public Builder setField( + com.google.protobuf.Descriptors.FieldDescriptor field, + Object value) { + return (Builder) super.setField(field, value); + } + public Builder clearField( + com.google.protobuf.Descriptors.FieldDescriptor field) { + return (Builder) super.clearField(field); + } + public Builder clearOneof( + com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return (Builder) super.clearOneof(oneof); + } + public Builder setRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, + int index, Object value) { + return (Builder) super.setRepeatedField(field, index, value); + } + public Builder addRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, + Object value) { + return (Builder) super.addRepeatedField(field, value); + } + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof GooglePB.PhoneNumber) { + return mergeFrom((GooglePB.PhoneNumber)other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(GooglePB.PhoneNumber other) { + if (other == GooglePB.PhoneNumber.getDefaultInstance()) return this; + if (other.hasNumber()) { + bitField0_ |= 0x00000001; + number_ = other.number_; + onChanged(); + } + if (other.hasType()) { + setType(other.getType()); + } + this.mergeUnknownFields(other.unknownFields); + onChanged(); + return this; + } + + public final boolean isInitialized() { + if (!hasNumber()) { + return false; + } + return true; + } + + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + GooglePB.PhoneNumber parsedMessage = null; + try { + parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + parsedMessage = (GooglePB.PhoneNumber) e.getUnfinishedMessage(); + throw e.unwrapIOException(); + } finally { + if (parsedMessage != null) { + mergeFrom(parsedMessage); + } + } + return this; + } + private int bitField0_; + + private Object number_ = ""; + /** + * required string number = 1; + */ + public boolean hasNumber() { + return ((bitField0_ & 0x00000001) == 0x00000001); + } + /** + * required string number = 1; + */ + public String getNumber() { + Object ref = number_; + if (!(ref instanceof String)) { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + String s = bs.toStringUtf8(); + if (bs.isValidUtf8()) { + number_ = s; + } + return s; + } else { + return (String) ref; + } + } + /** + * required string number = 1; + */ + public com.google.protobuf.ByteString + getNumberBytes() { + Object ref = number_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (String) ref); + number_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * required string number = 1; + */ + public Builder setNumber( + String value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000001; + number_ = value; + onChanged(); + return this; + } + /** + * required string number = 1; + */ + public Builder clearNumber() { + bitField0_ = (bitField0_ & ~0x00000001); + number_ = getDefaultInstance().getNumber(); + onChanged(); + return this; + } + /** + * required string number = 1; + */ + public Builder setNumberBytes( + com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000001; + number_ = value; + onChanged(); + return this; + } + + private int type_ = 1; + /** + * optional .org.apache.dubbo.common.serialize.protobuf.model.PhoneType type = 2 [default = HOME]; + */ + public boolean hasType() { + return ((bitField0_ & 0x00000002) == 0x00000002); + } + /** + * optional .org.apache.dubbo.common.serialize.protobuf.model.PhoneType type = 2 [default = HOME]; + */ + public GooglePB.PhoneType getType() { + GooglePB.PhoneType result = GooglePB.PhoneType.valueOf(type_); + return result == null ? GooglePB.PhoneType.HOME : result; + } + /** + * optional .org.apache.dubbo.common.serialize.protobuf.model.PhoneType type = 2 [default = HOME]; + */ + public Builder setType(GooglePB.PhoneType value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000002; + type_ = value.getNumber(); + onChanged(); + return this; + } + /** + * optional .org.apache.dubbo.common.serialize.protobuf.model.PhoneType type = 2 [default = HOME]; + */ + public Builder clearType() { + bitField0_ = (bitField0_ & ~0x00000002); + type_ = 1; + onChanged(); + return this; + } + public final Builder setUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.setUnknownFields(unknownFields); + } + + public final Builder mergeUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.mergeUnknownFields(unknownFields); + } + + + // @@protoc_insertion_point(builder_scope:org.apache.dubbo.common.serialize.protobuf.model.PhoneNumber) + } + + // @@protoc_insertion_point(class_scope:org.apache.dubbo.common.serialize.protobuf.model.PhoneNumber) + private static final GooglePB.PhoneNumber DEFAULT_INSTANCE; + static { + DEFAULT_INSTANCE = new GooglePB.PhoneNumber(); + } + + public static GooglePB.PhoneNumber getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + @Deprecated public static final com.google.protobuf.Parser + PARSER = new com.google.protobuf.AbstractParser() { + public PhoneNumber parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return new PhoneNumber(input, extensionRegistry); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + public GooglePB.PhoneNumber getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } + + } + + private static final com.google.protobuf.Descriptors.Descriptor + internal_static_org_apache_dubbo_common_serialize_protobuf_model_PBRequestType_descriptor; + private static final + com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internal_static_org_apache_dubbo_common_serialize_protobuf_model_PBRequestType_fieldAccessorTable; + private static final com.google.protobuf.Descriptors.Descriptor + internal_static_org_apache_dubbo_common_serialize_protobuf_model_PBRequestType_DoubleMapEntry_descriptor; + private static final + com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internal_static_org_apache_dubbo_common_serialize_protobuf_model_PBRequestType_DoubleMapEntry_fieldAccessorTable; + private static final com.google.protobuf.Descriptors.Descriptor + internal_static_org_apache_dubbo_common_serialize_protobuf_model_PBResponseType_descriptor; + private static final + com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internal_static_org_apache_dubbo_common_serialize_protobuf_model_PBResponseType_fieldAccessorTable; + private static final com.google.protobuf.Descriptors.Descriptor + internal_static_org_apache_dubbo_common_serialize_protobuf_model_PhoneNumber_descriptor; + private static final + com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internal_static_org_apache_dubbo_common_serialize_protobuf_model_PhoneNumber_fieldAccessorTable; + + public static com.google.protobuf.Descriptors.FileDescriptor + getDescriptor() { + return descriptor; + } + private static com.google.protobuf.Descriptors.FileDescriptor + descriptor; + static { + String[] descriptorData = { + "\n\016GooglePB.proto\0220org.apache.dubbo.commo" + + "n.serialize.protobuf.model\"\220\003\n\rPBRequest" + + "Type\022\r\n\005money\030\001 \001(\001\022\014\n\004cash\030\002 \001(\002\022\013\n\003age" + + "\030\003 \001(\005\022\013\n\003num\030\004 \001(\003\022\013\n\003sex\030\005 \001(\010\022\014\n\004name" + + "\030\006 \001(\t\022\013\n\003msg\030\007 \001(\014\022L\n\005phone\030\010 \003(\0132=.org" + + ".apache.dubbo.common.serialize.protobuf." + + "model.PhoneNumber\022a\n\tdoubleMap\030\t \003(\0132N.o" + + "rg.apache.dubbo.common.serialize.protobu" + + "f.model.PBRequestType.DoubleMapEntry\032o\n\016" + + "DoubleMapEntry\022\013\n\003key\030\001 \001(\t\022L\n\005value\030\002 \001", + "(\0132=.org.apache.dubbo.common.serialize.p" + + "rotobuf.model.PhoneNumber:\0028\001\"{\n\016PBRespo" + + "nseType\022\013\n\003msg\030\001 \001(\t\022\\\n\023CDubboPBRequestT" + + "ype\030\003 \001(\0132?.org.apache.dubbo.common.seri" + + "alize.protobuf.model.PBRequestType\"n\n\013Ph" + + "oneNumber\022\016\n\006number\030\001 \002(\t\022O\n\004type\030\002 \001(\0162" + + ";.org.apache.dubbo.common.serialize.prot" + + "obuf.model.PhoneType:\004HOME*+\n\tPhoneType\022" + + "\n\n\006MOBILE\020\000\022\010\n\004HOME\020\001\022\010\n\004WORK\020\0022\241\001\n\017CDub" + + "boPBService\022\215\001\n\010sayHello\022?.org.apache.du", + "bbo.common.serialize.protobuf.model.PBRe" + + "questType\032@.org.apache.dubbo.common.seri" + + "alize.protobuf.model.PBResponseType" + }; + 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; + return null; + } + }; + com.google.protobuf.Descriptors.FileDescriptor + .internalBuildGeneratedFileFrom(descriptorData, + new com.google.protobuf.Descriptors.FileDescriptor[] { + }, assigner); + internal_static_org_apache_dubbo_common_serialize_protobuf_model_PBRequestType_descriptor = + getDescriptor().getMessageTypes().get(0); + internal_static_org_apache_dubbo_common_serialize_protobuf_model_PBRequestType_fieldAccessorTable = new + com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_org_apache_dubbo_common_serialize_protobuf_model_PBRequestType_descriptor, + new String[] { "Money", "Cash", "Age", "Num", "Sex", "Name", "Msg", "Phone", "DoubleMap", }); + internal_static_org_apache_dubbo_common_serialize_protobuf_model_PBRequestType_DoubleMapEntry_descriptor = + internal_static_org_apache_dubbo_common_serialize_protobuf_model_PBRequestType_descriptor.getNestedTypes().get(0); + internal_static_org_apache_dubbo_common_serialize_protobuf_model_PBRequestType_DoubleMapEntry_fieldAccessorTable = new + com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_org_apache_dubbo_common_serialize_protobuf_model_PBRequestType_DoubleMapEntry_descriptor, + new String[] { "Key", "Value", }); + internal_static_org_apache_dubbo_common_serialize_protobuf_model_PBResponseType_descriptor = + getDescriptor().getMessageTypes().get(1); + internal_static_org_apache_dubbo_common_serialize_protobuf_model_PBResponseType_fieldAccessorTable = new + com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_org_apache_dubbo_common_serialize_protobuf_model_PBResponseType_descriptor, + new String[] { "Msg", "CDubboPBRequestType", }); + internal_static_org_apache_dubbo_common_serialize_protobuf_model_PhoneNumber_descriptor = + getDescriptor().getMessageTypes().get(2); + internal_static_org_apache_dubbo_common_serialize_protobuf_model_PhoneNumber_fieldAccessorTable = new + com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_org_apache_dubbo_common_serialize_protobuf_model_PhoneNumber_descriptor, + new String[] { "Number", "Type", }); + } + + // @@protoc_insertion_point(outer_class_scope) +} diff --git a/dubbo-serialization/dubbo-serialization-test/src/test/resources/protobuf/GooglePB.proto b/dubbo-serialization/dubbo-serialization-test/src/test/resources/protobuf/GooglePB.proto new file mode 100644 index 00000000000..6b3f38a4913 --- /dev/null +++ b/dubbo-serialization/dubbo-serialization-test/src/test/resources/protobuf/GooglePB.proto @@ -0,0 +1,35 @@ +syntax = "proto2"; + +package org.apache.dubbo.common.serialize.protobuf.model; + +message PBRequestType { + optional double money = 1; + optional float cash = 2; + optional int32 age = 3; + optional int64 num = 4; + optional bool sex = 5; + optional string name = 6; + optional bytes msg = 7; + repeated org.apache.dubbo.common.serialize.protobuf.model.PhoneNumber phone = 8; + map doubleMap = 9; +} + +message PBResponseType { + optional string msg = 1; + optional org.apache.dubbo.common.serialize.protobuf.model.PBRequestType CDubboPBRequestType = 3; +} + +message PhoneNumber { + required string number = 1; + optional org.apache.dubbo.common.serialize.protobuf.model.PhoneType type = 2 [default = HOME]; +} + +enum PhoneType { + MOBILE = 0; + HOME = 1; + WORK = 2; +} + +service CDubboPBService { + rpc sayHello (org.apache.dubbo.common.serialize.protobuf.model.PBRequestType) returns (org.apache.dubbo.common.serialize.protobuf.model.PBResponseType); +} \ No newline at end of file From 51fe0448ce3a75120d72fa1c1d609fcddd90dee6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?lg=E6=9E=97=E5=9B=BD?= Date: Tue, 7 May 2019 20:52:27 +0800 Subject: [PATCH 6/8] add Licensed --- .../support/GenericProtobufObjectOutputTest.java | 2 +- .../src/test/resources/protobuf/GooglePB.proto | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/dubbo-serialization/dubbo-serialization-test/src/test/java/org/apache/dubbo/common/serialize/protobuf/support/GenericProtobufObjectOutputTest.java b/dubbo-serialization/dubbo-serialization-test/src/test/java/org/apache/dubbo/common/serialize/protobuf/support/GenericProtobufObjectOutputTest.java index 986616bdc9f..e420aec82ab 100644 --- a/dubbo-serialization/dubbo-serialization-test/src/test/java/org/apache/dubbo/common/serialize/protobuf/support/GenericProtobufObjectOutputTest.java +++ b/dubbo-serialization/dubbo-serialization-test/src/test/java/org/apache/dubbo/common/serialize/protobuf/support/GenericProtobufObjectOutputTest.java @@ -68,7 +68,7 @@ public void testWriteGooglePbObject() throws IOException { phoneNumberMap.put("phoneNumber" + i, GooglePB.PhoneNumber.newBuilder().setNumber(random.nextInt(bound) + "").setType(GooglePB.PhoneType.forNumber(random.nextInt(GooglePB.PhoneType.values().length - 1))).build()); } GooglePB.PBRequestType request = GooglePB.PBRequestType.newBuilder() - .setAge(15).setCash(10).setMoney(15.0).setNum(100L) + .setAge(15).setCash(10).setMoney(16.0).setNum(100L) .addAllPhone(phoneNumberList).putAllDoubleMap(phoneNumberMap).build(); this.genericProtobufObjectOutput.writeObject(request); diff --git a/dubbo-serialization/dubbo-serialization-test/src/test/resources/protobuf/GooglePB.proto b/dubbo-serialization/dubbo-serialization-test/src/test/resources/protobuf/GooglePB.proto index 6b3f38a4913..bda3e37b5a0 100644 --- a/dubbo-serialization/dubbo-serialization-test/src/test/resources/protobuf/GooglePB.proto +++ b/dubbo-serialization/dubbo-serialization-test/src/test/resources/protobuf/GooglePB.proto @@ -1,3 +1,19 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ syntax = "proto2"; package org.apache.dubbo.common.serialize.protobuf.model; From 557026f2655afe865cd0a740ea76163101756655 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?lg=E6=9E=97=E5=9B=BD?= Date: Wed, 8 May 2019 11:57:26 +0800 Subject: [PATCH 7/8] fix some problem after code review --- dubbo-all/pom.xml | 2 +- dubbo-bom/pom.xml | 2 +- .../org/apache/dubbo/common/Constants.java | 2 +- dubbo-dependencies-bom/pom.xml | 7 +++--- dubbo-distribution/pom.xml | 5 ---- .../dubbo/rpc/filter/GenericFilter.java | 23 ++++++++++++------- .../dubbo-serialization-googlePb/pom.xml | 2 +- ...pache.dubbo.common.serialize.Serialization | 2 +- .../dubbo-serialization-test/pom.xml | 2 +- dubbo-serialization/pom.xml | 2 +- 10 files changed, 25 insertions(+), 24 deletions(-) diff --git a/dubbo-all/pom.xml b/dubbo-all/pom.xml index b361e42c966..c353874f88d 100644 --- a/dubbo-all/pom.xml +++ b/dubbo-all/pom.xml @@ -389,7 +389,7 @@ org.apache.dubbo - dubbo-serialization-googlePb + dubbo-serialization-protobuf-json ${project.version} compile true diff --git a/dubbo-bom/pom.xml b/dubbo-bom/pom.xml index 6740ada0586..a7e44dcf6dc 100644 --- a/dubbo-bom/pom.xml +++ b/dubbo-bom/pom.xml @@ -344,7 +344,7 @@ org.apache.dubbo - dubbo-serialization-googlePb + dubbo-serialization-protobuf-json ${project.version} diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/Constants.java b/dubbo-common/src/main/java/org/apache/dubbo/common/Constants.java index c1d164197a6..cc52e77d6f7 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/Constants.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/Constants.java @@ -727,7 +727,7 @@ public class Constants { public static final String GENERIC_SERIALIZATION_BEAN = "bean"; - public static final String GENERIC_SERIALIZATION_PROTOBUF = "gernericprotobuf"; + public static final String GENERIC_SERIALIZATION_PROTOBUF = "protobuf-json"; public static final String DUBBO_IP_TO_REGISTRY = "DUBBO_IP_TO_REGISTRY"; diff --git a/dubbo-dependencies-bom/pom.xml b/dubbo-dependencies-bom/pom.xml index 71adfdc7eae..6fc9a88ebc0 100644 --- a/dubbo-dependencies-bom/pom.xml +++ b/dubbo-dependencies-bom/pom.xml @@ -108,8 +108,7 @@ 3.1.15 0.12.0 4.0.38 - 3.6.0 - 3.6.0 + 3.6.0 3.1.0 9.4.11.v20180605 1.1.0.Final @@ -276,12 +275,12 @@ com.google.protobuf protobuf-java - ${protobuf-java} + ${protobuf-java_version} com.google.protobuf protobuf-java-util - ${protobuf.java.util} + ${protobuf-java_version} javax.servlet diff --git a/dubbo-distribution/pom.xml b/dubbo-distribution/pom.xml index 26ac044a797..07fdf356d4f 100644 --- a/dubbo-distribution/pom.xml +++ b/dubbo-distribution/pom.xml @@ -335,11 +335,6 @@ dubbo-serialization-gson ${project.version} - - org.apache.dubbo - dubbo-serialization-googlePb - ${project.version} - org.apache.dubbo dubbo diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/GenericFilter.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/GenericFilter.java index 1e6e0a84b3c..fdbfdef275e 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/GenericFilter.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/GenericFilter.java @@ -110,7 +110,8 @@ public Result invoke(Invoker invoker, Invocation inv) throws RpcException { } else if (ProtocolUtils.isProtobufGenericSerialization(generic)) { // as proto3 only accept one protobuf parameter if (args.length == 1 && args[0] instanceof String) { - try (UnsafeByteArrayInputStream is = new UnsafeByteArrayInputStream(((String) args[0]).getBytes())) { + try (UnsafeByteArrayInputStream is = + new UnsafeByteArrayInputStream(((String) args[0]).getBytes())) { args[0] = ExtensionLoader.getExtensionLoader(Serialization.class) .getExtension("" + Constants.GENERIC_SERIALIZATION_PROTOBUF) .deserialize(null, is).readObject(method.getParameterTypes()[0]); @@ -119,9 +120,12 @@ public Result invoke(Invoker invoker, Invocation inv) throws RpcException { } } else { throw new RpcException( - new StringBuilder("Generic serialization [").append(Constants.GENERIC_SERIALIZATION_PROTOBUF) - .append("] only support one").append(String.class.getName()).append(" argument ") - .append(" and your message size is ").append(args.length).append(" and type is").append(args[0].getClass().getName()).toString()); + "Generic serialization [" + + Constants.GENERIC_SERIALIZATION_PROTOBUF + + "] only support one" + String.class.getName() + + " argument and your message size is " + + args.length + " and type is" + + args[0].getClass().getName()); } } Result result = invoker.invoke(new RpcInvocation(method, args, inv.getAttachments())); @@ -137,8 +141,10 @@ public Result invoke(Invoker invoker, Invocation inv) throws RpcException { .serialize(null, os).writeObject(result.getValue()); return new RpcResult(os.toByteArray()); } catch (IOException e) { - throw new RpcException(new StringBuilder("Generic serialization [").append(Constants.GENERIC_SERIALIZATION_NATIVE_JAVA) - .append("] serialize result failed.").toString(), e); + throw new RpcException( + "Generic serialization [" + + Constants.GENERIC_SERIALIZATION_NATIVE_JAVA + + "] serialize result failed.", e); } } else if (ProtocolUtils.isBeanGenericSerialization(generic)) { return new RpcResult(JavaBeanSerializeUtil.serialize(result.getValue(), JavaBeanAccessor.METHOD)); @@ -150,8 +156,9 @@ public Result invoke(Invoker invoker, Invocation inv) throws RpcException { .serialize(null, os).writeObject(result.getValue()); return new RpcResult(os.toString()); } catch (IOException e) { - throw new RpcException(new StringBuilder("Generic serialization [").append(Constants.GENERIC_SERIALIZATION_PROTOBUF) - .append("] serialize result failed.").toString(), e); + throw new RpcException("Generic serialization [" + + Constants.GENERIC_SERIALIZATION_PROTOBUF + + "] serialize result failed.", e); } } else { return new RpcResult(PojoUtils.generalize(result.getValue())); diff --git a/dubbo-serialization/dubbo-serialization-googlePb/pom.xml b/dubbo-serialization/dubbo-serialization-googlePb/pom.xml index 424149e1dcc..6580e8705a1 100644 --- a/dubbo-serialization/dubbo-serialization-googlePb/pom.xml +++ b/dubbo-serialization/dubbo-serialization-googlePb/pom.xml @@ -21,7 +21,7 @@ limitations under the License. org.apache.dubbo ${revision} - dubbo-serialization-googlePb + dubbo-serialization-protobuf-json jar ${project.artifactId} The protobuf serialization module of dubbo project diff --git a/dubbo-serialization/dubbo-serialization-googlePb/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.serialize.Serialization b/dubbo-serialization/dubbo-serialization-googlePb/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.serialize.Serialization index ac9006c3bde..56d6b68bf05 100644 --- a/dubbo-serialization/dubbo-serialization-googlePb/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.serialize.Serialization +++ b/dubbo-serialization/dubbo-serialization-googlePb/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.serialize.Serialization @@ -1 +1 @@ -gernericprotobuf=org.apache.dubbo.common.serialize.protobuf.support.GenericProtobufSerialization \ No newline at end of file +protobuf-json=org.apache.dubbo.common.serialize.protobuf.support.GenericProtobufSerialization \ No newline at end of file diff --git a/dubbo-serialization/dubbo-serialization-test/pom.xml b/dubbo-serialization/dubbo-serialization-test/pom.xml index 5ecca33adef..60d0c5ff0f1 100644 --- a/dubbo-serialization/dubbo-serialization-test/pom.xml +++ b/dubbo-serialization/dubbo-serialization-test/pom.xml @@ -79,7 +79,7 @@ org.apache.dubbo - dubbo-serialization-googlePb + dubbo-serialization-protobuf-json ${project.parent.version} diff --git a/dubbo-serialization/pom.xml b/dubbo-serialization/pom.xml index 34b03ef366a..448aa078628 100644 --- a/dubbo-serialization/pom.xml +++ b/dubbo-serialization/pom.xml @@ -39,7 +39,7 @@ dubbo-serialization-avro dubbo-serialization-test dubbo-serialization-gson - dubbo-serialization-googlePb + dubbo-serialization-protobuf-json dubbo-serialization-native-hession From 2052633b6cfd14c84f9e753fd21e4f65cf06494c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?lg=E6=9E=97=E5=9B=BD?= Date: Wed, 8 May 2019 14:56:54 +0800 Subject: [PATCH 8/8] change directory name after change module name --- .../pom.xml | 0 .../serialize/protobuf/support/GenericProtobufObjectInput.java | 0 .../serialize/protobuf/support/GenericProtobufObjectOutput.java | 0 .../serialize/protobuf/support/GenericProtobufSerialization.java | 0 .../dubbo/common/serialize/protobuf/support/ProtobufUtils.java | 0 .../internal/org.apache.dubbo.common.serialize.Serialization | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename dubbo-serialization/{dubbo-serialization-googlePb => dubbo-serialization-protobuf-json}/pom.xml (100%) rename dubbo-serialization/{dubbo-serialization-googlePb => dubbo-serialization-protobuf-json}/src/main/java/org/apache/dubbo/common/serialize/protobuf/support/GenericProtobufObjectInput.java (100%) rename dubbo-serialization/{dubbo-serialization-googlePb => dubbo-serialization-protobuf-json}/src/main/java/org/apache/dubbo/common/serialize/protobuf/support/GenericProtobufObjectOutput.java (100%) rename dubbo-serialization/{dubbo-serialization-googlePb => dubbo-serialization-protobuf-json}/src/main/java/org/apache/dubbo/common/serialize/protobuf/support/GenericProtobufSerialization.java (100%) rename dubbo-serialization/{dubbo-serialization-googlePb => dubbo-serialization-protobuf-json}/src/main/java/org/apache/dubbo/common/serialize/protobuf/support/ProtobufUtils.java (100%) rename dubbo-serialization/{dubbo-serialization-googlePb => dubbo-serialization-protobuf-json}/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.serialize.Serialization (100%) diff --git a/dubbo-serialization/dubbo-serialization-googlePb/pom.xml b/dubbo-serialization/dubbo-serialization-protobuf-json/pom.xml similarity index 100% rename from dubbo-serialization/dubbo-serialization-googlePb/pom.xml rename to dubbo-serialization/dubbo-serialization-protobuf-json/pom.xml diff --git a/dubbo-serialization/dubbo-serialization-googlePb/src/main/java/org/apache/dubbo/common/serialize/protobuf/support/GenericProtobufObjectInput.java b/dubbo-serialization/dubbo-serialization-protobuf-json/src/main/java/org/apache/dubbo/common/serialize/protobuf/support/GenericProtobufObjectInput.java similarity index 100% rename from dubbo-serialization/dubbo-serialization-googlePb/src/main/java/org/apache/dubbo/common/serialize/protobuf/support/GenericProtobufObjectInput.java rename to dubbo-serialization/dubbo-serialization-protobuf-json/src/main/java/org/apache/dubbo/common/serialize/protobuf/support/GenericProtobufObjectInput.java diff --git a/dubbo-serialization/dubbo-serialization-googlePb/src/main/java/org/apache/dubbo/common/serialize/protobuf/support/GenericProtobufObjectOutput.java b/dubbo-serialization/dubbo-serialization-protobuf-json/src/main/java/org/apache/dubbo/common/serialize/protobuf/support/GenericProtobufObjectOutput.java similarity index 100% rename from dubbo-serialization/dubbo-serialization-googlePb/src/main/java/org/apache/dubbo/common/serialize/protobuf/support/GenericProtobufObjectOutput.java rename to dubbo-serialization/dubbo-serialization-protobuf-json/src/main/java/org/apache/dubbo/common/serialize/protobuf/support/GenericProtobufObjectOutput.java diff --git a/dubbo-serialization/dubbo-serialization-googlePb/src/main/java/org/apache/dubbo/common/serialize/protobuf/support/GenericProtobufSerialization.java b/dubbo-serialization/dubbo-serialization-protobuf-json/src/main/java/org/apache/dubbo/common/serialize/protobuf/support/GenericProtobufSerialization.java similarity index 100% rename from dubbo-serialization/dubbo-serialization-googlePb/src/main/java/org/apache/dubbo/common/serialize/protobuf/support/GenericProtobufSerialization.java rename to dubbo-serialization/dubbo-serialization-protobuf-json/src/main/java/org/apache/dubbo/common/serialize/protobuf/support/GenericProtobufSerialization.java diff --git a/dubbo-serialization/dubbo-serialization-googlePb/src/main/java/org/apache/dubbo/common/serialize/protobuf/support/ProtobufUtils.java b/dubbo-serialization/dubbo-serialization-protobuf-json/src/main/java/org/apache/dubbo/common/serialize/protobuf/support/ProtobufUtils.java similarity index 100% rename from dubbo-serialization/dubbo-serialization-googlePb/src/main/java/org/apache/dubbo/common/serialize/protobuf/support/ProtobufUtils.java rename to dubbo-serialization/dubbo-serialization-protobuf-json/src/main/java/org/apache/dubbo/common/serialize/protobuf/support/ProtobufUtils.java diff --git a/dubbo-serialization/dubbo-serialization-googlePb/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.serialize.Serialization b/dubbo-serialization/dubbo-serialization-protobuf-json/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.serialize.Serialization similarity index 100% rename from dubbo-serialization/dubbo-serialization-googlePb/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.serialize.Serialization rename to dubbo-serialization/dubbo-serialization-protobuf-json/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.serialize.Serialization