Skip to content

Commit a378a01

Browse files
CrazyHZMralf0131
authored andcommitted
Merge dubbo-serialization-avro into incubator-dubbo apache#3708 (apache#3717)
1 parent 72020df commit a378a01

File tree

15 files changed

+636
-30
lines changed

15 files changed

+636
-30
lines changed

dubbo-all/pom.xml

+8
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,13 @@
339339
<scope>compile</scope>
340340
<optional>true</optional>
341341
</dependency>
342+
<dependency>
343+
<groupId>org.apache.dubbo</groupId>
344+
<artifactId>dubbo-serialization-avro</artifactId>
345+
<version>${project.version}</version>
346+
<scope>compile</scope>
347+
<optional>true</optional>
348+
</dependency>
342349
<dependency>
343350
<groupId>org.apache.dubbo</groupId>
344351
<artifactId>dubbo-serialization-protostuff</artifactId>
@@ -531,6 +538,7 @@
531538
<include>org.apache.dubbo:dubbo-serialization-hessian2</include>
532539
<include>org.apache.dubbo:dubbo-serialization-fst</include>
533540
<include>org.apache.dubbo:dubbo-serialization-kryo</include>
541+
<include>org.apache.dubbo:dubbo-serialization-avro</include>
534542
<include>org.apache.dubbo:dubbo-serialization-jdk</include>
535543
<include>org.apache.dubbo:dubbo-serialization-protostuff</include>
536544
<include>org.apache.dubbo:dubbo-configcenter-api</include>

dubbo-bom/pom.xml

+5
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,11 @@
318318
<artifactId>dubbo-serialization-protostuff</artifactId>
319319
<version>${project.version}</version>
320320
</dependency>
321+
<dependency>
322+
<groupId>org.apache.dubbo</groupId>
323+
<artifactId>dubbo-serialization-avro</artifactId>
324+
<version>${project.version}</version>
325+
</dependency>
321326
<dependency>
322327
<groupId>org.apache.dubbo</groupId>
323328
<artifactId>dubbo-compatible</artifactId>

dubbo-dependencies-bom/pom.xml

+20-15
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
<?xml version="1.0" encoding="UTF-8"?>
21
<!--
3-
~ Licensed to the Apache Software Foundation (ASF) under one or more
4-
~ contributor license agreements. See the NOTICE file distributed with
5-
~ this work for additional information regarding copyright ownership.
6-
~ The ASF licenses this file to You under the Apache License, Version 2.0
7-
~ (the "License"); you may not use this file except in compliance with
8-
~ the License. You may obtain a copy of the License at
9-
~
10-
~ http://www.apache.org/licenses/LICENSE-2.0
11-
~
12-
~ Unless required by applicable law or agreed to in writing, software
13-
~ distributed under the License is distributed on an "AS IS" BASIS,
14-
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15-
~ See the License for the specific language governing permissions and
16-
~ limitations under the License.
2+
Licensed to the Apache Software Foundation (ASF) under one or more
3+
contributor license agreements. See the NOTICE file distributed with
4+
this work for additional information regarding copyright ownership.
5+
The ASF licenses this file to You under the Apache License, Version 2.0
6+
(the "License"); you may not use this file except in compliance with
7+
the License. You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
1716
-->
1817

1918
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
@@ -117,6 +116,7 @@
117116
<kryo_version>4.0.1</kryo_version>
118117
<kryo_serializers_version>0.42</kryo_serializers_version>
119118
<fst_version>2.48-jdk-6</fst_version>
119+
<avro_version>1.8.2</avro_version>
120120
<apollo_client_version>1.1.1</apollo_client_version>
121121
<snakeyaml_version>1.20</snakeyaml_version>
122122
<commons_lang3_version>3.8.1</commons_lang3_version>
@@ -309,6 +309,11 @@
309309
<artifactId>fst</artifactId>
310310
<version>${fst_version}</version>
311311
</dependency>
312+
<dependency>
313+
<groupId>org.apache.avro</groupId>
314+
<artifactId>avro</artifactId>
315+
<version>${avro_version}</version>
316+
</dependency>
312317
<dependency>
313318
<groupId>io.protostuff</groupId>
314319
<artifactId>protostuff-core</artifactId>

dubbo-dependencies/pom.xml

+14-15
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
<?xml version="1.0" encoding="UTF-8"?>
21
<!--
3-
~ Licensed to the Apache Software Foundation (ASF) under one or more
4-
~ contributor license agreements. See the NOTICE file distributed with
5-
~ this work for additional information regarding copyright ownership.
6-
~ The ASF licenses this file to You under the Apache License, Version 2.0
7-
~ (the "License"); you may not use this file except in compliance with
8-
~ the License. You may obtain a copy of the License at
9-
~
10-
~ http://www.apache.org/licenses/LICENSE-2.0
11-
~
12-
~ Unless required by applicable law or agreed to in writing, software
13-
~ distributed under the License is distributed on an "AS IS" BASIS,
14-
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15-
~ See the License for the specific language governing permissions and
16-
~ limitations under the License.
2+
Licensed to the Apache Software Foundation (ASF) under one or more
3+
contributor license agreements. See the NOTICE file distributed with
4+
this work for additional information regarding copyright ownership.
5+
The ASF licenses this file to You under the Apache License, Version 2.0
6+
(the "License"); you may not use this file except in compliance with
7+
the License. You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
1716
-->
1817

1918
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

dubbo-distribution/pom.xml

+5
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,11 @@
245245
<artifactId>dubbo-serialization-protostuff</artifactId>
246246
<version>${project.version}</version>
247247
</dependency>
248+
<dependency>
249+
<groupId>org.apache.dubbo</groupId>
250+
<artifactId>dubbo-serialization-avro</artifactId>
251+
<version>${project.version}</version>
252+
</dependency>
248253
<dependency>
249254
<groupId>org.apache.dubbo</groupId>
250255
<artifactId>dubbo</artifactId>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<!--
2+
Licensed to the Apache Software Foundation (ASF) under one or more
3+
contributor license agreements. See the NOTICE file distributed with
4+
this work for additional information regarding copyright ownership.
5+
The ASF licenses this file to You under the Apache License, Version 2.0
6+
(the "License"); you may not use this file except in compliance with
7+
the License. You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
18+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
19+
<modelVersion>4.0.0</modelVersion>
20+
<parent>
21+
<groupId>org.apache.dubbo</groupId>
22+
<artifactId>dubbo-serialization</artifactId>
23+
<version>2.7.2-SNAPSHOT</version>
24+
</parent>
25+
<artifactId>dubbo-serialization-avro</artifactId>
26+
<packaging>jar</packaging>
27+
<name>${project.artifactId}</name>
28+
<description>The avro serialization module of dubbo project</description>
29+
<properties>
30+
<skip_maven_deploy>false</skip_maven_deploy>
31+
</properties>
32+
33+
<dependencies>
34+
<dependency>
35+
<groupId>org.apache.dubbo</groupId>
36+
<artifactId>dubbo-serialization-api</artifactId>
37+
<version>${project.parent.version}</version>
38+
</dependency>
39+
<dependency>
40+
<groupId>org.apache.avro</groupId>
41+
<artifactId>avro</artifactId>
42+
</dependency>
43+
</dependencies>
44+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.dubbo.common.serialize.avro;
18+
19+
import org.apache.avro.io.BinaryDecoder;
20+
import org.apache.avro.io.DecoderFactory;
21+
import org.apache.avro.reflect.ReflectDatumReader;
22+
import org.apache.avro.util.Utf8;
23+
import org.apache.dubbo.common.serialize.ObjectInput;
24+
25+
import java.io.IOException;
26+
import java.io.InputStream;
27+
import java.lang.reflect.Type;
28+
import java.util.HashMap;
29+
import java.util.Map;
30+
31+
public class AvroObjectInput implements ObjectInput {
32+
private static DecoderFactory decoderFactory = DecoderFactory.get();
33+
private BinaryDecoder decoder;
34+
35+
public AvroObjectInput(InputStream in) {
36+
decoder = decoderFactory.binaryDecoder(in, null);
37+
}
38+
39+
@Override
40+
public boolean readBool() throws IOException {
41+
return decoder.readBoolean();
42+
}
43+
44+
@Override
45+
public byte readByte() throws IOException {
46+
byte[] bytes = new byte[1];
47+
decoder.readFixed(bytes);
48+
return bytes[0];
49+
}
50+
51+
@Override
52+
public short readShort() throws IOException {
53+
return (short) decoder.readInt();
54+
}
55+
56+
@Override
57+
public int readInt() throws IOException {
58+
return decoder.readInt();
59+
}
60+
61+
@Override
62+
public long readLong() throws IOException {
63+
return decoder.readLong();
64+
}
65+
66+
@Override
67+
public float readFloat() throws IOException {
68+
return decoder.readFloat();
69+
}
70+
71+
@Override
72+
public double readDouble() throws IOException {
73+
return decoder.readDouble();
74+
}
75+
76+
@Override
77+
public String readUTF() throws IOException {
78+
Utf8 result = new Utf8();
79+
result = decoder.readString(result);
80+
return result.toString();
81+
}
82+
83+
@Override
84+
public byte[] readBytes() throws IOException {
85+
String resultStr = decoder.readString();
86+
return resultStr.getBytes("utf8");
87+
}
88+
89+
/**
90+
* will lost all attribute
91+
*/
92+
@Override
93+
public Object readObject() throws IOException, ClassNotFoundException {
94+
ReflectDatumReader<Object> reader = new ReflectDatumReader<>(Object.class);
95+
return reader.read(null, decoder);
96+
}
97+
98+
@Override
99+
@SuppressWarnings(value = {"unchecked"})
100+
public <T> T readObject(Class<T> cls) throws IOException, ClassNotFoundException {
101+
//Map interface class change to HashMap implement
102+
if (cls == Map.class) {
103+
cls = (Class<T>) HashMap.class;
104+
}
105+
106+
ReflectDatumReader<T> reader = new ReflectDatumReader<>(cls);
107+
return reader.read(null, decoder);
108+
}
109+
110+
@Override
111+
public <T> T readObject(Class<T> cls, Type type) throws IOException, ClassNotFoundException {
112+
ReflectDatumReader<T> reader = new ReflectDatumReader<>(cls);
113+
return reader.read(null, decoder);
114+
}
115+
116+
}

0 commit comments

Comments
 (0)