You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by li...@apache.org on 2019/07/23 09:07:18 UTC

[dubbo] branch master updated: use standard protobuf json format to write byte[] (#4638)

This is an automated email from the ASF dual-hosted git repository.

liujun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo.git


The following commit(s) were added to refs/heads/master by this push:
     new 24e851e  use standard protobuf json format to write byte[] (#4638)
24e851e is described below

commit 24e851ec85bbcc5d3ccb9abbca857e97310cb487
Author: ken.lj <ke...@gmail.com>
AuthorDate: Tue Jul 23 17:06:54 2019 +0800

    use standard protobuf json format to write byte[] (#4638)
---
 .../serialize/protobuf/support/GenericProtobufObjectInput.java |  7 ++++---
 .../protobuf/support/GenericProtobufObjectOutput.java          | 10 ++++++----
 2 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/dubbo-serialization/dubbo-serialization-protobuf-json/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
index 92b1fe3..0641c4d 100644
--- a/dubbo-serialization/dubbo-serialization-protobuf-json/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
@@ -16,14 +16,15 @@
  */
 package org.apache.dubbo.common.serialize.protobuf.support;
 
-import com.google.common.base.Charsets;
+import org.apache.dubbo.common.serialize.ObjectInput;
+
 import com.google.protobuf.BoolValue;
+import com.google.protobuf.BytesValue;
 import com.google.protobuf.DoubleValue;
 import com.google.protobuf.FloatValue;
 import com.google.protobuf.Int32Value;
 import com.google.protobuf.Int64Value;
 import com.google.protobuf.StringValue;
-import org.apache.dubbo.common.serialize.ObjectInput;
 
 import java.io.BufferedReader;
 import java.io.EOFException;
@@ -85,7 +86,7 @@ public class GenericProtobufObjectInput implements ObjectInput {
 
     @Override
     public byte[] readBytes() throws IOException {
-        return readUTF().getBytes(Charsets.ISO_8859_1);
+        return read(BytesValue.class).getValue().toByteArray();
     }
 
     @Override
diff --git a/dubbo-serialization/dubbo-serialization-protobuf-json/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
index de9f545..7384fdd 100644
--- a/dubbo-serialization/dubbo-serialization-protobuf-json/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
@@ -16,14 +16,16 @@
  */
 package org.apache.dubbo.common.serialize.protobuf.support;
 
-import com.google.common.base.Charsets;
+import org.apache.dubbo.common.serialize.ObjectOutput;
+
 import com.google.protobuf.BoolValue;
+import com.google.protobuf.ByteString;
+import com.google.protobuf.BytesValue;
 import com.google.protobuf.DoubleValue;
 import com.google.protobuf.FloatValue;
 import com.google.protobuf.Int32Value;
 import com.google.protobuf.Int64Value;
 import com.google.protobuf.StringValue;
-import org.apache.dubbo.common.serialize.ObjectOutput;
 
 import java.io.IOException;
 import java.io.OutputStream;
@@ -85,12 +87,12 @@ public class GenericProtobufObjectOutput implements ObjectOutput {
 
     @Override
     public void writeBytes(byte[] b) throws IOException {
-        writeUTF(new String(b, Charsets.ISO_8859_1));
+        writeObject(BytesValue.newBuilder().setValue(ByteString.copyFrom(b)).build());
     }
 
     @Override
     public void writeBytes(byte[] b, int off, int len) throws IOException {
-        writeUTF(new String(b, off, len, Charsets.ISO_8859_1));
+        writeObject(BytesValue.newBuilder().setValue(ByteString.copyFrom(b, off, len)).build());
     }