diff --git a/dubbo-serialization/dubbo-serialization-protobuf/src/main/resources/META-INF.dubbo.internal/org.apache.dubbo.common.serialize.Serialization b/dubbo-serialization/dubbo-serialization-protobuf/src/main/resources/META-INF.dubbo.internal/org.apache.dubbo.common.serialize.Serialization
deleted file mode 100644
index c276c91610e..00000000000
--- a/dubbo-serialization/dubbo-serialization-protobuf/src/main/resources/META-INF.dubbo.internal/org.apache.dubbo.common.serialize.Serialization
+++ /dev/null
@@ -1 +0,0 @@
-protobuf=org.apache.dubbo.common.serialize.protobuf.ProtobufSerialization
\ No newline at end of file
diff --git a/dubbo-serialization/dubbo-serialization-protobuf/pom.xml b/dubbo-serialization/dubbo-serialization-protostuff/pom.xml
similarity index 75%
rename from dubbo-serialization/dubbo-serialization-protobuf/pom.xml
rename to dubbo-serialization/dubbo-serialization-protostuff/pom.xml
index d1843b0e9b3..80b3769fc58 100644
--- a/dubbo-serialization/dubbo-serialization-protobuf/pom.xml
+++ b/dubbo-serialization/dubbo-serialization-protostuff/pom.xml
@@ -25,13 +25,14 @@ limitations under the License.
2.7.0-SNAPSHOT
- dubbo-serialization-protobuf
+ dubbo-serialization-protostuff
jar
${project.artifactId}
- The protobuf serialization module of dubbo project
+ The protostuff serialization module of dubbo project
- 1.5.9
+ 1.5.9
+ 2.6
@@ -43,18 +44,18 @@ limitations under the License.
io.protostuff
protostuff-core
- ${protobuf.version}
+ ${protostuff.version}
io.protostuff
protostuff-runtime
- ${protobuf.version}
-
-
- org.objenesis
- objenesis
- 2.6
+ ${protostuff.version}
+
+
+
+
+
-
\ No newline at end of file
+
diff --git a/dubbo-serialization/dubbo-serialization-protobuf/src/main/java/org/apache/dubbo/common/serialize/protobuf/ProtobufObjectInput.java b/dubbo-serialization/dubbo-serialization-protostuff/src/main/java/org/apache/dubbo/common/serialize/protostuff/ProtostuffObjectInput.java
similarity index 76%
rename from dubbo-serialization/dubbo-serialization-protobuf/src/main/java/org/apache/dubbo/common/serialize/protobuf/ProtobufObjectInput.java
rename to dubbo-serialization/dubbo-serialization-protostuff/src/main/java/org/apache/dubbo/common/serialize/protostuff/ProtostuffObjectInput.java
index 64773e9cff7..f98cbd8914d 100644
--- a/dubbo-serialization/dubbo-serialization-protobuf/src/main/java/org/apache/dubbo/common/serialize/protobuf/ProtobufObjectInput.java
+++ b/dubbo-serialization/dubbo-serialization-protostuff/src/main/java/org/apache/dubbo/common/serialize/protostuff/ProtostuffObjectInput.java
@@ -15,24 +15,24 @@
* limitations under the License.
*/
-package org.apache.dubbo.common.serialize.protobuf;
+package org.apache.dubbo.common.serialize.protostuff;
import io.protostuff.ProtobufIOUtil;
import io.protostuff.Schema;
import io.protostuff.runtime.RuntimeSchema;
import org.apache.dubbo.common.serialize.ObjectInput;
-import org.apache.dubbo.common.serialize.protobuf.utils.WrapperUtils;
+import org.apache.dubbo.common.serialize.protostuff.utils.WrapperUtils;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Type;
-public class ProtobufObjectInput implements ObjectInput {
+public class ProtostuffObjectInput implements ObjectInput {
private DataInputStream dis;
- public ProtobufObjectInput(InputStream inputStream) {
+ public ProtostuffObjectInput(InputStream inputStream) {
dis = new DataInputStream(inputStream);
}
@@ -70,34 +70,10 @@ public Object readObject() throws IOException, ClassNotFoundException {
return result;
}
+ @SuppressWarnings("unchecked")
@Override
public T readObject(Class clazz) throws IOException, ClassNotFoundException {
- int classNameLength = dis.readInt();
- int bytesLength = dis.readInt();
-
- if (classNameLength < 0 || bytesLength < 0) {
- throw new IOException();
- }
-
- byte[] classNameBytes = new byte[classNameLength];
- dis.read(classNameBytes, 0, classNameLength);
-
- byte[] bytes = new byte[bytesLength];
- dis.read(bytes, 0, bytesLength);
-
- T result;
- if (WrapperUtils.needWrapper(clazz)) {
- Schema schema = RuntimeSchema.getSchema(Wrapper.class);
- Wrapper wrapper = schema.newMessage();
- ProtobufIOUtil.mergeFrom(bytes, wrapper, schema);
- result = (T) wrapper.getData();
- } else {
- Schema schema = RuntimeSchema.getSchema(clazz);
- result = schema.newMessage();
- ProtobufIOUtil.mergeFrom(bytes, result, schema);
- }
-
- return result;
+ return (T) readObject();
}
@Override
diff --git a/dubbo-serialization/dubbo-serialization-protobuf/src/main/java/org/apache/dubbo/common/serialize/protobuf/ProtobufObjectOutput.java b/dubbo-serialization/dubbo-serialization-protostuff/src/main/java/org/apache/dubbo/common/serialize/protostuff/ProtostuffObjectOutput.java
similarity index 71%
rename from dubbo-serialization/dubbo-serialization-protobuf/src/main/java/org/apache/dubbo/common/serialize/protobuf/ProtobufObjectOutput.java
rename to dubbo-serialization/dubbo-serialization-protostuff/src/main/java/org/apache/dubbo/common/serialize/protostuff/ProtostuffObjectOutput.java
index 8672a661973..fa34f5e70f1 100644
--- a/dubbo-serialization/dubbo-serialization-protobuf/src/main/java/org/apache/dubbo/common/serialize/protobuf/ProtobufObjectOutput.java
+++ b/dubbo-serialization/dubbo-serialization-protostuff/src/main/java/org/apache/dubbo/common/serialize/protostuff/ProtostuffObjectOutput.java
@@ -15,41 +15,48 @@
* limitations under the License.
*/
-package org.apache.dubbo.common.serialize.protobuf;
+package org.apache.dubbo.common.serialize.protostuff;
-import io.protostuff.*;
+import io.protostuff.LinkedBuffer;
+import io.protostuff.ProtobufIOUtil;
+import io.protostuff.Schema;
import io.protostuff.runtime.RuntimeSchema;
import org.apache.dubbo.common.serialize.ObjectOutput;
-import org.apache.dubbo.common.serialize.protobuf.utils.WrapperUtils;
+import org.apache.dubbo.common.serialize.protostuff.utils.WrapperUtils;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.OutputStream;
-public class ProtobufObjectOutput implements ObjectOutput {
+public class ProtostuffObjectOutput implements ObjectOutput {
+ private LinkedBuffer buffer = LinkedBuffer.allocate();
private DataOutputStream dos;
- public ProtobufObjectOutput(OutputStream outputStream) {
+ public ProtostuffObjectOutput(OutputStream outputStream) {
dos = new DataOutputStream(outputStream);
}
+ @SuppressWarnings("unchecked")
@Override
public void writeObject(Object obj) throws IOException {
- LinkedBuffer buffer = LinkedBuffer.allocate();
byte[] bytes;
byte[] classNameBytes;
- if (WrapperUtils.needWrapper(obj)) {
- Schema schema = RuntimeSchema.getSchema(Wrapper.class);
- Wrapper wrapper = new Wrapper(obj);
- bytes = ProtobufIOUtil.toByteArray(wrapper, schema, buffer);
- classNameBytes = Wrapper.class.getName().getBytes();
- } else {
- Schema schema = RuntimeSchema.getSchema(obj.getClass());
- bytes = ProtobufIOUtil.toByteArray(obj, schema, buffer);
- classNameBytes = obj.getClass().getName().getBytes();
+ try {
+ if (WrapperUtils.needWrapper(obj)) {
+ Schema schema = RuntimeSchema.getSchema(Wrapper.class);
+ Wrapper wrapper = new Wrapper(obj);
+ bytes = ProtobufIOUtil.toByteArray(wrapper, schema, buffer);
+ classNameBytes = Wrapper.class.getName().getBytes();
+ } else {
+ Schema schema = RuntimeSchema.getSchema(obj.getClass());
+ bytes = ProtobufIOUtil.toByteArray(obj, schema, buffer);
+ classNameBytes = obj.getClass().getName().getBytes();
+ }
+ } finally {
+ buffer.clear();
}
dos.writeInt(classNameBytes.length);
diff --git a/dubbo-serialization/dubbo-serialization-protobuf/src/main/java/org/apache/dubbo/common/serialize/protobuf/ProtobufSerialization.java b/dubbo-serialization/dubbo-serialization-protostuff/src/main/java/org/apache/dubbo/common/serialize/protostuff/ProtostuffSerialization.java
similarity index 84%
rename from dubbo-serialization/dubbo-serialization-protobuf/src/main/java/org/apache/dubbo/common/serialize/protobuf/ProtobufSerialization.java
rename to dubbo-serialization/dubbo-serialization-protostuff/src/main/java/org/apache/dubbo/common/serialize/protostuff/ProtostuffSerialization.java
index e87d25d6f73..aaf5bddc36d 100644
--- a/dubbo-serialization/dubbo-serialization-protobuf/src/main/java/org/apache/dubbo/common/serialize/protobuf/ProtobufSerialization.java
+++ b/dubbo-serialization/dubbo-serialization-protostuff/src/main/java/org/apache/dubbo/common/serialize/protostuff/ProtostuffSerialization.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.dubbo.common.serialize.protobuf;
+package org.apache.dubbo.common.serialize.protostuff;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.serialize.ObjectInput;
@@ -26,7 +26,7 @@
import java.io.InputStream;
import java.io.OutputStream;
-public class ProtobufSerialization implements Serialization {
+public class ProtostuffSerialization implements Serialization {
@Override
public byte getContentTypeId() {
return 10;
@@ -34,16 +34,16 @@ public byte getContentTypeId() {
@Override
public String getContentType() {
- return "x-application/protobuf";
+ return "x-application/protostuff";
}
@Override
public ObjectOutput serialize(URL url, OutputStream output) throws IOException {
- return new ProtobufObjectOutput(output);
+ return new ProtostuffObjectOutput(output);
}
@Override
public ObjectInput deserialize(URL url, InputStream input) throws IOException {
- return new ProtobufObjectInput(input);
+ return new ProtostuffObjectInput(input);
}
}
diff --git a/dubbo-serialization/dubbo-serialization-protobuf/src/main/java/org/apache/dubbo/common/serialize/protobuf/Wrapper.java b/dubbo-serialization/dubbo-serialization-protostuff/src/main/java/org/apache/dubbo/common/serialize/protostuff/Wrapper.java
similarity index 95%
rename from dubbo-serialization/dubbo-serialization-protobuf/src/main/java/org/apache/dubbo/common/serialize/protobuf/Wrapper.java
rename to dubbo-serialization/dubbo-serialization-protostuff/src/main/java/org/apache/dubbo/common/serialize/protostuff/Wrapper.java
index 498c6c99e48..9b56b43fad9 100644
--- a/dubbo-serialization/dubbo-serialization-protobuf/src/main/java/org/apache/dubbo/common/serialize/protobuf/Wrapper.java
+++ b/dubbo-serialization/dubbo-serialization-protostuff/src/main/java/org/apache/dubbo/common/serialize/protostuff/Wrapper.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.dubbo.common.serialize.protobuf;
+package org.apache.dubbo.common.serialize.protostuff;
/**
* Protostuff can only serialize/deserialize POJOs, for those it can't deal with, use this Wrapper.
diff --git a/dubbo-serialization/dubbo-serialization-protostuff/src/main/java/org/apache/dubbo/common/serialize/protostuff/delegate/TimeDelegate.java b/dubbo-serialization/dubbo-serialization-protostuff/src/main/java/org/apache/dubbo/common/serialize/protostuff/delegate/TimeDelegate.java
new file mode 100644
index 00000000000..8cc33c7d0be
--- /dev/null
+++ b/dubbo-serialization/dubbo-serialization-protostuff/src/main/java/org/apache/dubbo/common/serialize/protostuff/delegate/TimeDelegate.java
@@ -0,0 +1,54 @@
+/*
+ * 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.protostuff.delegate;
+
+import io.protostuff.Input;
+import io.protostuff.Output;
+import io.protostuff.Pipe;
+import io.protostuff.WireFormat;
+import io.protostuff.runtime.Delegate;
+
+import java.io.IOException;
+import java.sql.Time;
+
+public class TimeDelegate implements Delegate