├── .gitignore
├── README.md
├── pom.xml
└── src
├── main
└── java
│ └── com
│ └── jd
│ └── dd
│ └── glowworm
│ ├── PB.java
│ ├── PBException.java
│ ├── asm
│ ├── ASMException.java
│ ├── ByteVector.java
│ ├── ClassWriter.java
│ ├── FieldVisitor.java
│ ├── FieldWriter.java
│ ├── Item.java
│ ├── Label.java
│ ├── MethodVisitor.java
│ ├── MethodWriter.java
│ ├── Opcodes.java
│ └── Type.java
│ ├── deserializer
│ ├── ObjectDeserializer.java
│ ├── PBDeserializer.java
│ ├── asm
│ │ ├── ASMDeserializerFactory.java
│ │ └── ASMJavaBeanDeserializer.java
│ ├── multi
│ │ ├── ArrayDeserializer.java
│ │ ├── ListDeserializer.java
│ │ ├── MapDeserializer.java
│ │ ├── MultiDeserialier.java
│ │ └── SetDeserializer.java
│ ├── normal
│ │ ├── AtomicBooleanDeserializer.java
│ │ ├── AtomicIntegerDeserializer.java
│ │ ├── AtomicLongDeserializer.java
│ │ ├── BigDecimalDeserializer.java
│ │ ├── BigIntegerDeserializer.java
│ │ ├── ClassDeserializer.java
│ │ ├── DateDeserializer.java
│ │ ├── EnumDeserializer.java
│ │ ├── ExceptionDeserializer.java
│ │ ├── InetAddressDeserializer.java
│ │ ├── JavaObjectDeserializer.java
│ │ ├── StackTraceElementDeserializer.java
│ │ ├── StringDeserializer.java
│ │ ├── TimeDeserializer.java
│ │ └── TimestampDeserializer.java
│ ├── primary
│ │ ├── BooleanArrayDeserializer.java
│ │ ├── BooleanDeserializer.java
│ │ ├── ByteArrayDeserializer.java
│ │ ├── ByteDeserializer.java
│ │ ├── CharArrayDeserializer.java
│ │ ├── CharacterDeserializer.java
│ │ ├── DoubleArrayDeserializer.java
│ │ ├── DoubleDeserializer.java
│ │ ├── FloatArrayDeserializer.java
│ │ ├── FloatDeserializer.java
│ │ ├── IntArrayDeserializer.java
│ │ ├── IntegerDeserializer.java
│ │ ├── LongArrayDeserializer.java
│ │ ├── LongDeserializer.java
│ │ ├── ShortArrayDeserializer.java
│ │ └── ShortDeserializer.java
│ └── reflect
│ │ ├── DefaultFieldDeserializer.java
│ │ ├── FieldDeserializer.java
│ │ └── JavaBeanDeserializer.java
│ ├── serializer
│ ├── ObjectSerializer.java
│ ├── PBSerializer.java
│ ├── asm
│ │ └── ASMSerializerFactory.java
│ ├── multi
│ │ ├── ArraySerializer.java
│ │ ├── ListSerializer.java
│ │ ├── MapSerializer.java
│ │ ├── MultiSerializer.java
│ │ └── SetSerializer.java
│ ├── normal
│ │ ├── AtomicBooleanSerializer.java
│ │ ├── AtomicIntegerSerializer.java
│ │ ├── AtomicLongSerializer.java
│ │ ├── BigDecimalSerializer.java
│ │ ├── BigIntegerSerializer.java
│ │ ├── ClassSerializer.java
│ │ ├── DateSerializer.java
│ │ ├── EnumSerializer.java
│ │ ├── ExceptionSerializer.java
│ │ ├── InetAddressSerializer.java
│ │ ├── StringSerializer.java
│ │ ├── TimeSerializer.java
│ │ └── TimestampSerializer.java
│ ├── primary
│ │ ├── BooleanArraySerializer.java
│ │ ├── BooleanSerializer.java
│ │ ├── ByteArraySerializer.java
│ │ ├── ByteSerializer.java
│ │ ├── CharArraySerializer.java
│ │ ├── CharacterSerializer.java
│ │ ├── DoubleArraySerializer.java
│ │ ├── DoubleSerializer.java
│ │ ├── FloatArraySerializer.java
│ │ ├── FloatSerializer.java
│ │ ├── IntArraySerializer.java
│ │ ├── IntegerSerializer.java
│ │ ├── LongArraySerializer.java
│ │ ├── LongSerializer.java
│ │ ├── ShortArraySerializer.java
│ │ └── ShortSerializer.java
│ └── reflect
│ │ ├── FieldSerializer.java
│ │ ├── JavaBeanSerializer.java
│ │ └── ObjectFieldSerializer.java
│ └── util
│ ├── ASMClassLoader.java
│ ├── ASMUtils.java
│ ├── AntiCollisionHashMap.java
│ ├── Base64.java
│ ├── Buffer.java
│ ├── BufferInputStream.java
│ ├── BufferOutputStream.java
│ ├── CodedInputStream.java
│ ├── CodedOutputStream.java
│ ├── CustByteBuffer.java
│ ├── DeserializeBeanInfo.java
│ ├── ExistInputStream.java
│ ├── ExistOutputStream.java
│ ├── FieldInfo.java
│ ├── IdentityHashMap.java
│ ├── InputStreamBuffer.java
│ ├── InvalidProtocolBufferException.java
│ ├── OutputStreamBuffer.java
│ ├── Parameters.java
│ ├── SerializeContext.java
│ ├── Transient.java
│ ├── TypeInputStream.java
│ ├── TypeOutputStream.java
│ ├── TypeUtils.java
│ └── WireFormat.java
└── test
└── java
├── com
└── jd
│ └── bdp
│ └── seomonitor
│ └── model
│ └── page
│ └── SeoWord.java
├── testcase
├── TestBase.java
├── function
│ ├── AsmTest.java
│ ├── MultiTest.java
│ ├── NormalTest.java
│ └── ReflectTest.java
└── rule
│ ├── AsmTest.java
│ ├── BitTest.java
│ ├── MultiTest.java
│ ├── NormalTest.java
│ └── ReflectTest.java
└── userJavabean
├── AtomicPerson1.java
├── Broker.java
├── CommonResponse.java
├── Course.java
├── Difficulty.java
├── Food.java
├── Glowworm_Serializer_1.java
├── Group.java
├── InnerBean.java
├── InnerBean3.java
├── LoopPerson1.java
├── LoopPerson10.java
├── LoopPerson11.java
├── LoopPerson2.java
├── LoopPerson3.java
├── LoopPerson4.java
├── LoopPerson5.java
├── LoopPerson6.java
├── LoopPerson7.java
├── LoopPerson8.java
├── LoopPerson9.java
├── MapBean.java
├── MemoryRecord.java
├── NoDefaultConstructorBean.java
├── Person1.java
├── Person10.java
├── Person11.java
├── Person2.java
├── Person4.java
├── Person5.java
├── Person6.java
├── Person7.java
├── Person8.java
├── PersonCollection3.java
├── PersonCollection4.java
├── PersonForDate.java
├── Rule.java
├── RuleItem.java
├── School.java
├── Student.java
├── Student1.java
├── Student2.java
├── Supply1.java
├── Supply2.java
├── Supply3.java
├── TpMagic.java
├── TpMagic2.java
├── TransientBean1.java
├── TransientBean2.java
├── TransientBean3.java
├── TransientBean4.java
├── TransientBean5.java
├── User.java
├── User1.java
├── User10.java
├── User11.java
├── User12.java
├── User13.java
├── User14.java
├── User15.java
├── User16.java
├── User17.java
├── User18.java
├── User2.java
├── User3.java
├── User4.java
├── User5.java
├── User7.java
├── User8.java
├── User9.java
└── UserGeneric.java
/.gitignore:
--------------------------------------------------------------------------------
1 | target
2 | .idea
3 | *.iml
4 | .svn
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | glowworm高性能轻便的序列化组件
2 | ========
3 | http://bigbully.github.com/glowworm/
4 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/PBException.java:
--------------------------------------------------------------------------------
1 |
2 | package com.jd.dd.glowworm;
3 |
4 |
5 | public class PBException extends RuntimeException {
6 |
7 | private static final long serialVersionUID = 1L;
8 |
9 | public PBException() {
10 | super();
11 | }
12 |
13 | public PBException(String message) {
14 | super(message);
15 | }
16 |
17 | public PBException(String message, Throwable cause) {
18 | super(message, cause);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/asm/ASMException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.asm;
17 |
18 |
19 | public class ASMException extends RuntimeException {
20 |
21 | private static final long serialVersionUID = 1L;
22 |
23 | public ASMException(String message) {
24 | super(message);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/asm/FieldVisitor.java:
--------------------------------------------------------------------------------
1 | /***
2 | * ASM: a very small and fast Java bytecode manipulation framework
3 | * Copyright (c) 2000-2007 INRIA, France Telecom
4 | * All rights reserved.
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted provided that the following conditions
8 | * are met:
9 | * 1. Redistributions of source code must retain the above copyright
10 | * notice, this list of conditions and the following disclaimer.
11 | * 2. Redistributions in binary form must reproduce the above copyright
12 | * notice, this list of conditions and the following disclaimer in the
13 | * documentation and/or other materials provided with the distribution.
14 | * 3. Neither the name of the copyright holders nor the names of its
15 | * contributors may be used to endorse or promote products derived from
16 | * this software without specific prior written permission.
17 | *
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28 | * THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 | package com.jd.dd.glowworm.asm;
31 |
32 | /**
33 | * A visitor to visit a Java field. The methods of this interface must be called in the following order: (
34 | * visitAnnotation | visitAttribute )* visitEnd.
35 | *
36 | * @author Eric Bruneton
37 | */
38 | public interface FieldVisitor {
39 |
40 | /**
41 | * Visits the end of the field. This method, which is the last one to be called, is used to inform the visitor that
42 | * all the annotations and attributes of the field have been visited.
43 | */
44 | void visitEnd();
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/deserializer/ObjectDeserializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.deserializer;
17 |
18 | import java.lang.reflect.Type;
19 |
20 | public interface ObjectDeserializer {
21 |
22 | T deserialize(PBDeserializer deserializer, Type type, boolean needConfirmExist, Object... extraParams);
23 | }
24 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/deserializer/asm/ASMJavaBeanDeserializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.deserializer.asm;
17 |
18 | import com.jd.dd.glowworm.deserializer.ObjectDeserializer;
19 | import com.jd.dd.glowworm.deserializer.PBDeserializer;
20 | import com.jd.dd.glowworm.deserializer.reflect.FieldDeserializer;
21 | import com.jd.dd.glowworm.deserializer.reflect.JavaBeanDeserializer;
22 | import com.jd.dd.glowworm.util.FieldInfo;
23 |
24 | import java.lang.reflect.Type;
25 | import java.util.Map;
26 |
27 | public abstract class ASMJavaBeanDeserializer implements ObjectDeserializer {
28 |
29 | protected InnerJavaBeanDeserializer serializer;
30 |
31 | public ASMJavaBeanDeserializer(PBDeserializer mapping, Class> clazz) {
32 | serializer = new InnerJavaBeanDeserializer(mapping, clazz);
33 |
34 | serializer.getFieldDeserializerMap();
35 | }
36 |
37 | public abstract Object createInstance(PBDeserializer parser, Type type);
38 |
39 | public InnerJavaBeanDeserializer getInnterSerializer() {
40 | return serializer;
41 | }
42 |
43 | public T deserialize(PBDeserializer deserializer, Type type, boolean needConfirmExist, Object... extraParams) {
44 | return (T) serializer.deserialize(deserializer, type, false);
45 | }
46 |
47 | public Object createInstance(PBDeserializer parser) {
48 | return serializer.createInstance(parser, serializer.getClazz());
49 | }
50 |
51 | public FieldDeserializer createFieldDeserializer(PBDeserializer mapping, Class> clazz, FieldInfo fieldInfo) {
52 | return mapping.createFieldDeserializer(mapping, clazz, fieldInfo);
53 | }
54 |
55 | public FieldDeserializer getFieldDeserializer(String name) {
56 | return serializer.getFieldDeserializerMap().get(name);
57 | }
58 |
59 | public Type getFieldType(String name) {
60 | return serializer.getFieldDeserializerMap().get(name).getFieldType();
61 | }
62 |
63 | public boolean parseField(PBDeserializer parser, String key, Object object, Type objectType, Map fieldValues) {
64 | Map feildDeserializerMap = serializer.getFieldDeserializerMap();
65 | FieldDeserializer fieldDeserializer = feildDeserializerMap.get(key);
66 |
67 | if (fieldDeserializer == null) {
68 | for (Map.Entry entry : feildDeserializerMap.entrySet()) {
69 | if (entry.getKey().equalsIgnoreCase(key)) {
70 | fieldDeserializer = entry.getValue();
71 | break;
72 | }
73 | }
74 | }
75 |
76 | fieldDeserializer.parseField(parser, object, objectType, fieldValues);
77 | return true;
78 | }
79 |
80 | public final class InnerJavaBeanDeserializer extends JavaBeanDeserializer {
81 |
82 | private InnerJavaBeanDeserializer(PBDeserializer mapping, Class> clazz) {
83 | super(mapping, clazz);
84 | }
85 |
86 | public boolean parseField(PBDeserializer parser, String key, Object object, Type objectType, Map fieldValues) {
87 | return ASMJavaBeanDeserializer.this.parseField(parser, key, object, objectType, fieldValues);
88 | }
89 |
90 | public FieldDeserializer createFieldDeserializer(PBDeserializer mapping, Class> clazz, FieldInfo fieldInfo) {
91 | return ASMJavaBeanDeserializer.this.createFieldDeserializer(mapping, clazz, fieldInfo);
92 | }
93 | }
94 |
95 | }
96 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/deserializer/multi/ArrayDeserializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.deserializer.multi;
17 |
18 | import com.jd.dd.glowworm.deserializer.ObjectDeserializer;
19 | import com.jd.dd.glowworm.deserializer.PBDeserializer;
20 |
21 | import java.lang.reflect.Array;
22 | import java.lang.reflect.Type;
23 |
24 | public class ArrayDeserializer extends MultiDeserialier implements ObjectDeserializer {
25 |
26 | public final static ArrayDeserializer instance = new ArrayDeserializer();
27 |
28 | @Override
29 | public T deserialize(PBDeserializer deserializer, Type type, boolean needConfirmExist, Object... extraParams) {
30 | if (needConfirmExist) {
31 | try {
32 | if (deserializer.isObjectExist()) {
33 | Class componentType;
34 | if (!needConfirmExist) {
35 | componentType = (Class) extraParams[0];
36 | } else {
37 | componentType = ((Class) type).getComponentType();
38 | }
39 | return (T) getArray(deserializer, componentType);
40 | } else {
41 | return (T) deserializer.getReference();
42 | }
43 | } catch (Exception ex) {
44 | ex.printStackTrace();
45 | }
46 | } else {
47 | Class componentType;
48 | if (needConfirmExist) {
49 | componentType = (Class) extraParams[0];
50 | } else {
51 | componentType = ((Class) type).getComponentType();
52 | }
53 | return (T) getArray(deserializer, componentType);
54 | }
55 | return null;
56 | }
57 |
58 |
59 | private Object getArray(PBDeserializer parser, Class componentType) {
60 | int size = 0;
61 | try {
62 | size = parser.scanNaturalInt();
63 | } catch (Exception e) {
64 | e.printStackTrace();
65 | }
66 | Object array = Array.newInstance(componentType, size);
67 | parser.addToObjectIndexMap(array, this);
68 |
69 | if (componentType == Object.class) {
70 | getObjectElement(parser, array, size);
71 | } else {
72 | getElementWithGerenic(parser, array, componentType, size);
73 | }
74 | return array;
75 | }
76 |
77 | @Override
78 | public void setEachElement(Object multi, int i, Object item) {
79 | ((Object[]) multi)[i] = item;
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/deserializer/normal/AtomicBooleanDeserializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.deserializer.normal;
17 |
18 | import com.jd.dd.glowworm.deserializer.ObjectDeserializer;
19 | import com.jd.dd.glowworm.deserializer.PBDeserializer;
20 |
21 | import java.lang.reflect.Type;
22 | import java.util.concurrent.atomic.AtomicBoolean;
23 |
24 | public class AtomicBooleanDeserializer implements ObjectDeserializer {
25 |
26 | public final static AtomicBooleanDeserializer instance = new AtomicBooleanDeserializer();
27 |
28 | @Override
29 | public T deserialize(PBDeserializer deserializer, Type type, boolean needConfirmExist, Object... extraParams) {
30 | AtomicBoolean value = null;
31 | try {
32 | if (needConfirmExist && deserializer.isObjectExist() || !needConfirmExist) {
33 | value = deserializer.scanAtomicBool();
34 | }
35 | } catch (Exception ex) {
36 | ex.printStackTrace();
37 | }
38 | return (T) value;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/deserializer/normal/AtomicIntegerDeserializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.deserializer.normal;
17 |
18 | import com.jd.dd.glowworm.deserializer.ObjectDeserializer;
19 | import com.jd.dd.glowworm.deserializer.PBDeserializer;
20 |
21 | import java.lang.reflect.Type;
22 | import java.util.concurrent.atomic.AtomicInteger;
23 |
24 | public class AtomicIntegerDeserializer implements ObjectDeserializer {
25 |
26 | public final static AtomicIntegerDeserializer instance = new AtomicIntegerDeserializer();
27 |
28 | @Override
29 | public T deserialize(PBDeserializer deserializer, Type type, boolean needConfirmExist, Object... extraParams) {
30 | AtomicInteger value = null;
31 | try {
32 | if (needConfirmExist && deserializer.isObjectExist() || !needConfirmExist) {
33 | value = deserializer.scanAtomicInt();
34 | }
35 | } catch (Exception ex) {
36 | ex.printStackTrace();
37 | }
38 | return (T) value;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/deserializer/normal/AtomicLongDeserializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.deserializer.normal;
17 |
18 | import com.jd.dd.glowworm.deserializer.ObjectDeserializer;
19 | import com.jd.dd.glowworm.deserializer.PBDeserializer;
20 |
21 | import java.lang.reflect.Type;
22 | import java.util.concurrent.atomic.AtomicLong;
23 |
24 | public class AtomicLongDeserializer implements ObjectDeserializer {
25 |
26 | public final static AtomicLongDeserializer instance = new AtomicLongDeserializer();
27 |
28 | @Override
29 | public T deserialize(PBDeserializer deserializer, Type type, boolean needConfirmExist, Object... extraParams) {
30 | AtomicLong value = null;
31 | try {
32 | if (needConfirmExist && deserializer.isObjectExist() || !needConfirmExist) {
33 | value = deserializer.scanAtomicLong();
34 | }
35 | } catch (Exception ex) {
36 | ex.printStackTrace();
37 | }
38 | return (T) value;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/deserializer/normal/BigDecimalDeserializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.deserializer.normal;
17 |
18 | import com.jd.dd.glowworm.deserializer.ObjectDeserializer;
19 | import com.jd.dd.glowworm.deserializer.PBDeserializer;
20 |
21 | import java.lang.reflect.Type;
22 |
23 | public class BigDecimalDeserializer implements ObjectDeserializer {
24 |
25 | public final static BigDecimalDeserializer instance = new BigDecimalDeserializer();
26 |
27 | @Override
28 | public T deserialize(PBDeserializer deserializer, Type type, boolean needConfirmExist, Object... extraParams) {
29 | Object value = null;
30 | try {
31 | if (needConfirmExist && deserializer.isObjectExist() || !needConfirmExist) {
32 | value = deserializer.scanBigDecimal();
33 | }
34 | } catch (Exception ex) {
35 | ex.printStackTrace();
36 | }
37 | return (T) value;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/deserializer/normal/BigIntegerDeserializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.deserializer.normal;
17 |
18 | import com.jd.dd.glowworm.deserializer.ObjectDeserializer;
19 | import com.jd.dd.glowworm.deserializer.PBDeserializer;
20 |
21 | import java.lang.reflect.Type;
22 |
23 | public class BigIntegerDeserializer implements ObjectDeserializer {
24 |
25 | public final static BigIntegerDeserializer instance = new BigIntegerDeserializer();
26 |
27 | @Override
28 | public T deserialize(PBDeserializer deserializer, Type type, boolean needConfirmExist, Object... extraParams) {
29 | Object value = null;
30 | try {
31 | if (needConfirmExist && deserializer.isObjectExist() || !needConfirmExist) {
32 | value = deserializer.scanBigInteger();
33 | }
34 | } catch (Exception ex) {
35 | ex.printStackTrace();
36 | }
37 | return (T) value;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/deserializer/normal/ClassDeserializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.deserializer.normal;
17 |
18 | import com.jd.dd.glowworm.deserializer.ObjectDeserializer;
19 | import com.jd.dd.glowworm.deserializer.PBDeserializer;
20 |
21 | import java.lang.reflect.Type;
22 |
23 | public class ClassDeserializer implements ObjectDeserializer {
24 |
25 | public static final ClassDeserializer instance = new ClassDeserializer();
26 |
27 | @Override
28 | public T deserialize(PBDeserializer deserializer, Type type, boolean needConfirmExist, Object... extraParams) {
29 | Class value = null;
30 | try {
31 | if (needConfirmExist && deserializer.isObjectExist() || !needConfirmExist) {
32 | String className = deserializer.scanString();
33 | value = Class.forName(className);
34 | }
35 | } catch (Exception e) {
36 | e.printStackTrace();
37 | }
38 | return (T) value;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/deserializer/normal/DateDeserializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.deserializer.normal;
17 |
18 | import com.jd.dd.glowworm.deserializer.ObjectDeserializer;
19 | import com.jd.dd.glowworm.deserializer.PBDeserializer;
20 |
21 | import java.lang.reflect.Type;
22 | import java.util.Date;
23 |
24 | public class DateDeserializer implements ObjectDeserializer {
25 | public final static DateDeserializer instance = new DateDeserializer();
26 |
27 | @Override
28 | public T deserialize(PBDeserializer deserializer, Type type, boolean needConfirmExist, Object... extraParams) {
29 | Date value = null;
30 | try {
31 | if (needConfirmExist && deserializer.isObjectExist() || !needConfirmExist) {
32 | value = deserializer.scanDate();
33 | }
34 | } catch (Exception ex) {
35 | ex.printStackTrace();
36 | }
37 | return (T) value;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/deserializer/normal/EnumDeserializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.deserializer.normal;
17 |
18 | import com.jd.dd.glowworm.deserializer.ObjectDeserializer;
19 | import com.jd.dd.glowworm.deserializer.PBDeserializer;
20 |
21 | import java.lang.reflect.Type;
22 |
23 | public class EnumDeserializer implements ObjectDeserializer {
24 |
25 | private final Class> enumClass;
26 |
27 | public EnumDeserializer(Class> enumClass) {
28 | this.enumClass = enumClass;
29 | }
30 |
31 | @Override
32 | public T deserialize(PBDeserializer deserializer, Type type, boolean needConfirmExist, Object... extraParams) {
33 | Enum value = null;
34 | try {
35 | if (needConfirmExist && deserializer.isObjectExist() || !needConfirmExist) {
36 | value = deserializer.scanEnum(enumClass);
37 | }
38 | } catch (Exception ex) {
39 | ex.printStackTrace();
40 | }
41 | return (T) value;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/deserializer/normal/InetAddressDeserializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.deserializer.normal;
17 |
18 | import com.jd.dd.glowworm.deserializer.ObjectDeserializer;
19 | import com.jd.dd.glowworm.deserializer.PBDeserializer;
20 |
21 | import java.lang.reflect.Type;
22 | import java.net.InetAddress;
23 |
24 | public class InetAddressDeserializer implements ObjectDeserializer {
25 |
26 | public final static InetAddressDeserializer instance = new InetAddressDeserializer();
27 |
28 | @Override
29 | public T deserialize(PBDeserializer deserializer, Type type, boolean needConfirmExist, Object... extraParams) {
30 | InetAddress value = null;
31 | try {
32 | if (needConfirmExist && deserializer.isObjectExist() || !needConfirmExist) {
33 | value = deserializer.scanInetAddress();
34 | }
35 | } catch (Exception ex) {
36 | ex.printStackTrace();
37 | }
38 | return (T) value;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/deserializer/normal/JavaObjectDeserializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.deserializer.normal;
17 |
18 | import com.jd.dd.glowworm.deserializer.ObjectDeserializer;
19 | import com.jd.dd.glowworm.deserializer.PBDeserializer;
20 |
21 | import java.lang.reflect.Type;
22 |
23 |
24 | public class JavaObjectDeserializer implements ObjectDeserializer {
25 |
26 | public static final JavaObjectDeserializer instance = new JavaObjectDeserializer();
27 |
28 | //这个反序列化器进行所有用Object声明的属性的反序列化
29 | @Override
30 | public T deserialize(PBDeserializer deserializer, Type type, boolean needConfirmExist, Object... extraParams) {
31 | int typeCode = deserializer.scanType();
32 | return (T) deserializer.parsePureObject(typeCode);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/deserializer/normal/StackTraceElementDeserializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.deserializer.normal;
17 |
18 | import com.jd.dd.glowworm.deserializer.ObjectDeserializer;
19 | import com.jd.dd.glowworm.deserializer.PBDeserializer;
20 | import com.jd.dd.glowworm.deserializer.primary.IntegerDeserializer;
21 |
22 | import java.lang.reflect.Type;
23 |
24 | public class StackTraceElementDeserializer implements ObjectDeserializer {
25 |
26 | public static final StackTraceElementDeserializer instance = new StackTraceElementDeserializer();
27 |
28 | @Override
29 | public T deserialize(PBDeserializer deserializer, Type type, boolean needConfirmExist, Object... extraParams) {
30 | Object obj;
31 | if (needConfirmExist) {//作为对象的属性
32 | if (deserializer.isObjectExist()) {
33 | obj = getStackTraceElement(deserializer);
34 | } else {
35 | obj = deserializer.getReference();
36 | }
37 | } else {
38 | obj = getStackTraceElement(deserializer);
39 | }
40 | return (T) obj;
41 | }
42 |
43 | private Object getStackTraceElement(PBDeserializer deserializer) {
44 | String className = StringDeserializer.instance.deserialize(deserializer, null, true);
45 | if (className != null && !className.equals("")) {
46 | String fileName = StringDeserializer.instance.deserialize(deserializer, String.class, true);
47 | Integer lineNumber = IntegerDeserializer.instance.deserialize(deserializer, Integer.class, true);
48 | String methodName = StringDeserializer.instance.deserialize(deserializer, String.class, true);
49 | return new StackTraceElement(className, methodName, fileName, lineNumber);
50 | } else {
51 | return null;
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/deserializer/normal/StringDeserializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.deserializer.normal;
17 |
18 | import com.jd.dd.glowworm.deserializer.ObjectDeserializer;
19 | import com.jd.dd.glowworm.deserializer.PBDeserializer;
20 |
21 | import java.lang.reflect.Type;
22 |
23 | public class StringDeserializer implements ObjectDeserializer {
24 |
25 | public final static StringDeserializer instance = new StringDeserializer();
26 |
27 | @Override
28 | public T deserialize(PBDeserializer deserializer, Type type, boolean needConfirmExist, Object... extraParams) {
29 | String value = null;
30 | try {
31 | value = deserializer.scanStringWithCharset();
32 | } catch (Exception ex) {
33 | ex.printStackTrace();
34 | }
35 | return (T) value;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/deserializer/normal/TimeDeserializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.deserializer.normal;
17 |
18 | import com.jd.dd.glowworm.deserializer.ObjectDeserializer;
19 | import com.jd.dd.glowworm.deserializer.PBDeserializer;
20 |
21 | import java.lang.reflect.Type;
22 | import java.sql.Time;
23 |
24 | public class TimeDeserializer implements ObjectDeserializer {
25 | public final static TimeDeserializer instance = new TimeDeserializer();
26 |
27 | @Override
28 | public T deserialize(PBDeserializer deserializer, Type type, boolean needConfirmExist, Object... extraParams) {
29 | Time value = null;
30 | try {
31 | if (needConfirmExist && deserializer.isObjectExist() || !needConfirmExist) {
32 | value = deserializer.scanTime();
33 | }
34 | } catch (Exception ex) {
35 | ex.printStackTrace();
36 | }
37 | return (T) value;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/deserializer/normal/TimestampDeserializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.deserializer.normal;
17 |
18 | import com.jd.dd.glowworm.deserializer.ObjectDeserializer;
19 | import com.jd.dd.glowworm.deserializer.PBDeserializer;
20 |
21 | import java.lang.reflect.Type;
22 | import java.sql.Timestamp;
23 |
24 | public class TimestampDeserializer implements ObjectDeserializer {
25 | public final static TimestampDeserializer instance = new TimestampDeserializer();
26 |
27 | @Override
28 | public T deserialize(PBDeserializer deserializer, Type type, boolean needConfirmExist, Object... extraParams) {
29 | Timestamp value = null;
30 | try {
31 | if (needConfirmExist && deserializer.isObjectExist() || !needConfirmExist) {
32 | value = deserializer.scanTimeStamp();
33 | }
34 | } catch (Exception ex) {
35 | ex.printStackTrace();
36 | }
37 | return (T) value;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/deserializer/primary/BooleanArrayDeserializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.deserializer.primary;
17 |
18 | import com.jd.dd.glowworm.deserializer.ObjectDeserializer;
19 | import com.jd.dd.glowworm.deserializer.PBDeserializer;
20 |
21 | import java.lang.reflect.Type;
22 |
23 | public class BooleanArrayDeserializer implements ObjectDeserializer {
24 |
25 | public final static BooleanArrayDeserializer instance = new BooleanArrayDeserializer();
26 |
27 | @Override
28 | public T deserialize(PBDeserializer deserializer, Type type, boolean needConfirmExist, Object... extraParams) {
29 | boolean[] booleans = null;
30 | if (needConfirmExist && deserializer.isObjectExist() || !needConfirmExist) {
31 | try {
32 | booleans = deserializer.scanBooleanArray();
33 | } catch (Exception e) {
34 | e.printStackTrace();
35 | }
36 | }
37 | return (T) booleans;
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/deserializer/primary/BooleanDeserializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.deserializer.primary;
17 |
18 | import com.jd.dd.glowworm.deserializer.ObjectDeserializer;
19 | import com.jd.dd.glowworm.deserializer.PBDeserializer;
20 |
21 | import java.lang.reflect.Type;
22 |
23 | public class BooleanDeserializer implements ObjectDeserializer {
24 | public final static BooleanDeserializer instance = new BooleanDeserializer();
25 |
26 | @Override
27 | public T deserialize(PBDeserializer deserializer, Type type, boolean needConfirmExist, Object... extraParams) {
28 | Boolean value = null;
29 | try {
30 | if (needConfirmExist && deserializer.isObjectExist() || !needConfirmExist) {
31 | value = deserializer.scanBool();
32 | }
33 | } catch (Exception ex) {
34 | ex.printStackTrace();
35 | }
36 | return (T) value;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/deserializer/primary/ByteArrayDeserializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.deserializer.primary;
17 |
18 | import com.jd.dd.glowworm.deserializer.ObjectDeserializer;
19 | import com.jd.dd.glowworm.deserializer.PBDeserializer;
20 |
21 | import java.lang.reflect.Type;
22 |
23 | public class ByteArrayDeserializer implements ObjectDeserializer {
24 |
25 | public final static ByteArrayDeserializer instance = new ByteArrayDeserializer();
26 |
27 | @Override
28 | public T deserialize(PBDeserializer deserializer, Type type, boolean needConfirmExist, Object... extraParams) {
29 | byte[] ret = null;
30 | try {
31 | if (needConfirmExist && deserializer.isObjectExist() || !needConfirmExist) {
32 | ret = deserializer.scanByteArray();
33 | }
34 | } catch (Exception e) {
35 | e.printStackTrace();
36 | }
37 | return (T) ret;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/deserializer/primary/ByteDeserializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.deserializer.primary;
17 |
18 | import com.jd.dd.glowworm.deserializer.ObjectDeserializer;
19 | import com.jd.dd.glowworm.deserializer.PBDeserializer;
20 |
21 | import java.lang.reflect.Type;
22 |
23 | public class ByteDeserializer implements ObjectDeserializer {
24 | public final static ByteDeserializer instance = new ByteDeserializer();
25 |
26 | @Override
27 | public T deserialize(PBDeserializer deserializer, Type type, boolean needConfirmExist, Object... extraParams) {
28 | Byte value = null;
29 | try {
30 | if (needConfirmExist && deserializer.isObjectExist() || !needConfirmExist) {
31 | value = deserializer.scanByte();
32 | }
33 | } catch (Exception ex) {
34 | ex.printStackTrace();
35 | }
36 | return (T) value;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/deserializer/primary/CharArrayDeserializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.deserializer.primary;
17 |
18 | import com.jd.dd.glowworm.deserializer.ObjectDeserializer;
19 | import com.jd.dd.glowworm.deserializer.PBDeserializer;
20 |
21 | import java.lang.reflect.Type;
22 |
23 | public class CharArrayDeserializer implements ObjectDeserializer {
24 |
25 | public final static CharArrayDeserializer instance = new CharArrayDeserializer();
26 |
27 | @Override
28 | public T deserialize(PBDeserializer deserializer, Type type, boolean needConfirmExist, Object... extraParams) {
29 | String value = null;
30 | try {
31 | if (needConfirmExist && deserializer.isObjectExist() || !needConfirmExist) {
32 | value = deserializer.scanStringWithCharset();
33 | }
34 | } catch (Exception e) {
35 | e.printStackTrace();
36 | }
37 | return (T) value.toCharArray();
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/deserializer/primary/CharacterDeserializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.deserializer.primary;
17 |
18 | import com.jd.dd.glowworm.deserializer.ObjectDeserializer;
19 | import com.jd.dd.glowworm.deserializer.PBDeserializer;
20 | import com.jd.dd.glowworm.util.TypeUtils;
21 |
22 | import java.lang.reflect.Type;
23 |
24 | public class CharacterDeserializer implements ObjectDeserializer {
25 | public final static CharacterDeserializer instance = new CharacterDeserializer();
26 |
27 | @Override
28 | public T deserialize(PBDeserializer deserializer, Type type, boolean needConfirmExist, Object... extraParams) {
29 | Object value = null;
30 | try {
31 | if (needConfirmExist && deserializer.isObjectExist() || !needConfirmExist) {
32 | value = deserializer.scanStringWithCharset();
33 | }
34 | } catch (Exception ex) {
35 | ex.printStackTrace();
36 | }
37 | return (T) TypeUtils.castToChar(value);
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/deserializer/primary/DoubleArrayDeserializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.deserializer.primary;
17 |
18 | import com.jd.dd.glowworm.deserializer.ObjectDeserializer;
19 | import com.jd.dd.glowworm.deserializer.PBDeserializer;
20 |
21 | import java.lang.reflect.Type;
22 |
23 | public class DoubleArrayDeserializer implements ObjectDeserializer {
24 |
25 | public final static DoubleArrayDeserializer instance = new DoubleArrayDeserializer();
26 |
27 | @Override
28 | public T deserialize(PBDeserializer deserializer, Type type, boolean needConfirmExist, Object... extraParams) {
29 | double[] doubles = null;
30 | try {
31 | if (needConfirmExist && deserializer.isObjectExist() || !needConfirmExist) {
32 | doubles = deserializer.scanDoubleArray();
33 | }
34 | } catch (Exception e) {
35 | e.printStackTrace();
36 | }
37 | return (T) doubles;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/deserializer/primary/DoubleDeserializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.deserializer.primary;
17 |
18 | import com.jd.dd.glowworm.deserializer.ObjectDeserializer;
19 | import com.jd.dd.glowworm.deserializer.PBDeserializer;
20 |
21 | import java.lang.reflect.Type;
22 |
23 | public class DoubleDeserializer implements ObjectDeserializer {
24 |
25 | public final static DoubleDeserializer instance = new DoubleDeserializer();
26 |
27 | @Override
28 | public T deserialize(PBDeserializer deserializer, Type type, boolean needConfirmExist, Object... extraParams) {
29 | Double value = null;
30 | try {
31 | if (needConfirmExist && deserializer.isObjectExist() || !needConfirmExist) {
32 | value = deserializer.scanDouble();
33 | }
34 | } catch (Exception ex) {
35 | ex.printStackTrace();
36 | }
37 | return (T) value;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/deserializer/primary/FloatArrayDeserializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.deserializer.primary;
17 |
18 | import com.jd.dd.glowworm.deserializer.ObjectDeserializer;
19 | import com.jd.dd.glowworm.deserializer.PBDeserializer;
20 |
21 | import java.lang.reflect.Type;
22 |
23 | public class FloatArrayDeserializer implements ObjectDeserializer {
24 |
25 | public final static FloatArrayDeserializer instance = new FloatArrayDeserializer();
26 |
27 | @Override
28 | public T deserialize(PBDeserializer deserializer, Type type, boolean needConfirmExist, Object... extraParams) {
29 | float[] floats = null;
30 | try {
31 | if (needConfirmExist && deserializer.isObjectExist() || !needConfirmExist) {
32 | floats = deserializer.scanFloatArray();
33 | }
34 | } catch (Exception e) {
35 | e.printStackTrace();
36 | }
37 | return (T) floats;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/deserializer/primary/FloatDeserializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.deserializer.primary;
17 |
18 | import com.jd.dd.glowworm.deserializer.ObjectDeserializer;
19 | import com.jd.dd.glowworm.deserializer.PBDeserializer;
20 |
21 | import java.lang.reflect.Type;
22 |
23 | public class FloatDeserializer implements ObjectDeserializer {
24 |
25 | public final static FloatDeserializer instance = new FloatDeserializer();
26 |
27 | @Override
28 | public T deserialize(PBDeserializer deserializer, Type type, boolean needConfirmExist, Object... extraParams) {
29 | Float value = null;
30 | try {
31 | if (needConfirmExist && deserializer.isObjectExist() || !needConfirmExist) {
32 | value = deserializer.scanFloat();
33 | }
34 | } catch (Exception ex) {
35 | ex.printStackTrace();
36 | }
37 | return (T) value;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/deserializer/primary/IntArrayDeserializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.deserializer.primary;
17 |
18 | import com.jd.dd.glowworm.deserializer.ObjectDeserializer;
19 | import com.jd.dd.glowworm.deserializer.PBDeserializer;
20 |
21 | import java.lang.reflect.Type;
22 |
23 | public class IntArrayDeserializer implements ObjectDeserializer {
24 |
25 | public final static IntArrayDeserializer instance = new IntArrayDeserializer();
26 |
27 | @Override
28 | public T deserialize(PBDeserializer deserializer, Type type, boolean needConfirmExist, Object... extraParams) {
29 | int[] ints = null;
30 | try {
31 | if (needConfirmExist && deserializer.isObjectExist() || !needConfirmExist) {
32 | ints = deserializer.scanIntArray();
33 | }
34 | } catch (Exception e) {
35 | e.printStackTrace();
36 | }
37 | return (T) ints;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/deserializer/primary/IntegerDeserializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.deserializer.primary;
17 |
18 | import com.jd.dd.glowworm.deserializer.ObjectDeserializer;
19 | import com.jd.dd.glowworm.deserializer.PBDeserializer;
20 |
21 | import java.lang.reflect.Type;
22 |
23 | public class IntegerDeserializer implements ObjectDeserializer {
24 | public final static IntegerDeserializer instance = new IntegerDeserializer();
25 |
26 | @Override
27 | public T deserialize(PBDeserializer deserializer, Type type, boolean needConfirmExist, Object... extraParams) {
28 | Integer value = null;
29 | try {
30 | if (needConfirmExist && deserializer.isObjectExist() || !needConfirmExist) {
31 | value = deserializer.scanInt();
32 | }
33 | } catch (Exception ex) {
34 | ex.printStackTrace();
35 | }
36 | return (T) value;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/deserializer/primary/LongArrayDeserializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.deserializer.primary;
17 |
18 | import com.jd.dd.glowworm.deserializer.ObjectDeserializer;
19 | import com.jd.dd.glowworm.deserializer.PBDeserializer;
20 |
21 | import java.lang.reflect.Type;
22 |
23 | public class LongArrayDeserializer implements ObjectDeserializer {
24 |
25 | public final static LongArrayDeserializer instance = new LongArrayDeserializer();
26 |
27 | @Override
28 | public T deserialize(PBDeserializer deserializer, Type type, boolean needConfirmExist, Object... extraParams) {
29 | long[] longs = null;
30 | try {
31 | if (needConfirmExist && deserializer.isObjectExist() || !needConfirmExist) {
32 | longs = deserializer.scanLongArray();
33 | }
34 | } catch (Exception e) {
35 | e.printStackTrace();
36 | }
37 | return (T) longs;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/deserializer/primary/LongDeserializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.deserializer.primary;
17 |
18 | import com.jd.dd.glowworm.deserializer.ObjectDeserializer;
19 | import com.jd.dd.glowworm.deserializer.PBDeserializer;
20 |
21 | import java.lang.reflect.Type;
22 |
23 | public class LongDeserializer implements ObjectDeserializer {
24 |
25 | public final static LongDeserializer instance = new LongDeserializer();
26 |
27 | @Override
28 | public T deserialize(PBDeserializer deserializer, Type type, boolean needConfirmExist, Object... extraParams) {
29 | Long value = null;
30 | try {
31 | if (needConfirmExist && deserializer.isObjectExist() || !needConfirmExist) {
32 | value = deserializer.scanLong();
33 | }
34 | } catch (Exception ex) {
35 | ex.printStackTrace();
36 | }
37 | return (T) value;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/deserializer/primary/ShortArrayDeserializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.deserializer.primary;
17 |
18 | import com.jd.dd.glowworm.deserializer.ObjectDeserializer;
19 | import com.jd.dd.glowworm.deserializer.PBDeserializer;
20 |
21 | import java.lang.reflect.Type;
22 |
23 | public class ShortArrayDeserializer implements ObjectDeserializer {
24 |
25 | public final static ShortArrayDeserializer instance = new ShortArrayDeserializer();
26 |
27 | @Override
28 | public T deserialize(PBDeserializer deserializer, Type type, boolean needConfirmExist, Object... extraParams) {
29 | short[] shorts = null;
30 | try {
31 | if (needConfirmExist && deserializer.isObjectExist() || !needConfirmExist) {
32 | int size = deserializer.scanNaturalInt();
33 | shorts = new short[size];
34 | for (int i = 0; i < size; i++) {
35 | shorts[i] = deserializer.scanShort();
36 | }
37 | }
38 | } catch (Exception e) {
39 | e.printStackTrace();
40 | }
41 | return (T) shorts;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/deserializer/primary/ShortDeserializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.deserializer.primary;
17 |
18 | import com.jd.dd.glowworm.deserializer.ObjectDeserializer;
19 | import com.jd.dd.glowworm.deserializer.PBDeserializer;
20 |
21 | import java.lang.reflect.Type;
22 |
23 | public class ShortDeserializer implements ObjectDeserializer {
24 | public final static ShortDeserializer instance = new ShortDeserializer();
25 |
26 | @Override
27 | public T deserialize(PBDeserializer deserializer, Type type, boolean needConfirmExist, Object... extraParams) {
28 | Short value = null;
29 | try {
30 | if (needConfirmExist && deserializer.isObjectExist() || !needConfirmExist) {
31 | value = deserializer.scanShort();
32 | }
33 | } catch (Exception ex) {
34 | ex.printStackTrace();
35 | }
36 | return (T) value;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/deserializer/reflect/FieldDeserializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.deserializer.reflect;
17 |
18 | import com.jd.dd.glowworm.PBException;
19 | import com.jd.dd.glowworm.deserializer.PBDeserializer;
20 | import com.jd.dd.glowworm.util.FieldInfo;
21 |
22 | import java.lang.reflect.Method;
23 | import java.lang.reflect.Type;
24 | import java.util.Collection;
25 | import java.util.Map;
26 |
27 | public abstract class FieldDeserializer implements Comparable {
28 |
29 | protected final FieldInfo fieldInfo;
30 |
31 | protected final Class> clazz;
32 |
33 | public FieldDeserializer(Class> clazz, FieldInfo fieldInfo) {
34 | this.clazz = clazz;
35 | this.fieldInfo = fieldInfo;
36 | }
37 |
38 | public Method getMethod() {
39 | return fieldInfo.getMethod();
40 | }
41 |
42 | public Class> getFieldClass() {
43 | return fieldInfo.getFieldClass();
44 | }
45 |
46 | public Type getFieldType() {
47 | return fieldInfo.getFieldType();
48 | }
49 |
50 | public abstract void parseField(PBDeserializer parser, Object object, Type objectType,
51 | Map fieldValues);
52 |
53 | public void setValue(Object object, boolean value) {
54 | setValue(object, Boolean.valueOf(value));
55 | }
56 |
57 | public void setValue(Object object, int value) {
58 | setValue(object, Integer.valueOf(value));
59 | }
60 |
61 | public void setValue(Object object, long value) {
62 | setValue(object, Long.valueOf(value));
63 | }
64 |
65 | public void setValue(Object object, String value) {
66 | setValue(object, (Object) value);
67 | }
68 |
69 | @SuppressWarnings({"rawtypes", "unchecked"})
70 | public void setValue(Object object, Object value) {
71 | Method method = fieldInfo.getMethod();
72 | if (method != null) {
73 | try {
74 | if (fieldInfo.isGetOnly()) {
75 | Collection collection = (Collection) method.invoke(object);
76 | collection.addAll((Collection) value);
77 | } else {
78 | method.invoke(object, value);
79 | }
80 | } catch (Exception e) {
81 | throw new PBException("set property error, " + fieldInfo.getName(), e);
82 | }
83 | } else if (fieldInfo.getField() != null) {
84 | try {
85 | fieldInfo.getField().set(object, value);
86 | } catch (Exception e) {
87 | throw new PBException("set property error, " + fieldInfo.getName(), e);
88 | }
89 | }
90 | }
91 |
92 | public int compareTo(Object o) {
93 | return this.getFieldInfo().compareTo(((FieldDeserializer) o).getFieldInfo());
94 | }
95 |
96 | public FieldInfo getFieldInfo() {
97 | return fieldInfo;
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/serializer/ObjectSerializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.serializer;
17 |
18 | import java.io.IOException;
19 |
20 | public interface ObjectSerializer {
21 |
22 | void write(PBSerializer serializer, Object object, boolean needWriteType, Object... extraParams) throws IOException;
23 | }
24 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/serializer/multi/ArraySerializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.serializer.multi;
17 |
18 | import com.jd.dd.glowworm.asm.Type;
19 | import com.jd.dd.glowworm.serializer.ObjectSerializer;
20 | import com.jd.dd.glowworm.serializer.PBSerializer;
21 |
22 | import java.io.IOException;
23 |
24 | public class ArraySerializer extends MultiSerializer implements ObjectSerializer {
25 |
26 | public final static ArraySerializer instance = new ArraySerializer();
27 |
28 | @Override
29 | public Object getEachElement(Object array, int i) {
30 | return ((Object[]) array)[i];
31 | }
32 |
33 | @Override
34 | public void write(PBSerializer serializer, Object object, boolean needWriteType, Object... extraParams) throws IOException {
35 | if (needWriteType) {
36 | serializer.writeType(Type.ARRAY);
37 | }
38 | Class elementClazz;
39 | if (!needWriteType) {//如果是在写javabean的属性,则会传extraParams
40 | elementClazz = (Class) extraParams[0];
41 | } else {//如果在序列化集合,则不传extraParams
42 | elementClazz = object.getClass().getComponentType();
43 | }
44 | Object[] array = (Object[]) object;
45 | int size = array.length;
46 | serializer.writeNaturalInt(size);
47 | if (elementClazz == Object.class) {//如果是Object[]
48 | writeObjectElement(serializer, array, size);
49 | } else {//如果是特定类型的数组
50 | writeElementWithGerenic(serializer, array, elementClazz, size);
51 | }
52 | }
53 |
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/serializer/multi/ListSerializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.serializer.multi;
17 |
18 |
19 | import com.jd.dd.glowworm.asm.Type;
20 | import com.jd.dd.glowworm.serializer.ObjectSerializer;
21 | import com.jd.dd.glowworm.serializer.PBSerializer;
22 |
23 | import java.io.IOException;
24 | import java.util.ArrayList;
25 | import java.util.LinkedList;
26 | import java.util.List;
27 |
28 | public class ListSerializer extends MultiSerializer implements ObjectSerializer {
29 |
30 | public final static ListSerializer instance = new ListSerializer();
31 |
32 | @Override
33 | public Object getEachElement(Object multi, int i) {
34 | return ((List) multi).get(i);
35 | }
36 |
37 | @Override
38 | public void write(PBSerializer serializer, Object object, boolean needWriteType, Object... extraParams) throws IOException {
39 | int size = ((List) object).size();
40 | serializer.writeNaturalInt(size);
41 | if (!needWriteType) {
42 | if (isInterface(extraParams)) {
43 | writeActualType(serializer, object);
44 | }
45 | Class componentClazz = (Class) extraParams[0];
46 | if (componentClazz == Object.class) {//选择性写入类名(Object)
47 | writeObjectElement(serializer, object, size);
48 | } else {//都不写(Generic)
49 | writeElementWithGerenic(serializer, object, componentClazz, size);
50 | }
51 | } else {
52 | writeActualType(serializer, object);
53 | writeObjectElement(serializer, object, size);
54 | }
55 | }
56 |
57 | private void writeActualType(PBSerializer serializer, Object object) {
58 | Class clazz = object.getClass();
59 | if (ArrayList.class.isAssignableFrom(clazz)) {
60 | serializer.writeType(Type.LIST_ARRAYLIST);
61 | } else if (LinkedList.class.isAssignableFrom(clazz)) {
62 | serializer.writeType(Type.LIST_LINKEDLIST);
63 | } else if (clazz.getName().equals("java.util.Arrays$ArrayList")) {
64 | serializer.writeType(Type.LIST_ARRAYS_ARRAYLIST);
65 | } else {
66 | serializer.writeType(Type.Unknown);
67 | }
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/serializer/normal/AtomicBooleanSerializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.serializer.normal;
17 |
18 | import com.jd.dd.glowworm.serializer.ObjectSerializer;
19 | import com.jd.dd.glowworm.serializer.PBSerializer;
20 |
21 | import java.io.IOException;
22 | import java.util.concurrent.atomic.AtomicBoolean;
23 |
24 | public class AtomicBooleanSerializer implements ObjectSerializer {
25 |
26 | public final static AtomicBooleanSerializer instance = new AtomicBooleanSerializer();
27 |
28 | @Override
29 | public void write(PBSerializer serializer, Object object, boolean needWriteType, Object... extraParams) throws IOException {
30 | AtomicBoolean value = (AtomicBoolean) object;
31 | if (needWriteType) {
32 | serializer.writeType(com.jd.dd.glowworm.asm.Type.ATOMIC_BOOL);
33 | }
34 | serializer.writeBool(value.get());
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/serializer/normal/AtomicIntegerSerializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.serializer.normal;
17 |
18 | import com.jd.dd.glowworm.serializer.ObjectSerializer;
19 | import com.jd.dd.glowworm.serializer.PBSerializer;
20 |
21 | import java.io.IOException;
22 | import java.util.concurrent.atomic.AtomicInteger;
23 |
24 | public class AtomicIntegerSerializer implements ObjectSerializer {
25 |
26 | public final static AtomicIntegerSerializer instance = new AtomicIntegerSerializer();
27 |
28 | @Override
29 | public void write(PBSerializer serializer, Object object, boolean needWriteType, Object... extraParams) throws IOException {
30 | AtomicInteger value = (AtomicInteger) object;
31 | if (needWriteType) {
32 | serializer.writeType(com.jd.dd.glowworm.asm.Type.ATOMIC_INT);
33 | }
34 | serializer.writeInt(value.get());
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/serializer/normal/AtomicLongSerializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.serializer.normal;
17 |
18 | import com.jd.dd.glowworm.serializer.ObjectSerializer;
19 | import com.jd.dd.glowworm.serializer.PBSerializer;
20 |
21 | import java.io.IOException;
22 | import java.util.concurrent.atomic.AtomicLong;
23 |
24 | public class AtomicLongSerializer implements ObjectSerializer {
25 |
26 | public final static AtomicLongSerializer instance = new AtomicLongSerializer();
27 |
28 | @Override
29 | public void write(PBSerializer serializer, Object object, boolean needWriteType, Object... extraParams) throws IOException {
30 | AtomicLong value = (AtomicLong) object;
31 | if (needWriteType) {
32 | serializer.writeType(com.jd.dd.glowworm.asm.Type.ATOMIC_LONG);
33 | }
34 | serializer.writeLong(value.get());
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/serializer/normal/BigDecimalSerializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.serializer.normal;
17 |
18 | import com.jd.dd.glowworm.serializer.ObjectSerializer;
19 | import com.jd.dd.glowworm.serializer.PBSerializer;
20 |
21 | import java.io.IOException;
22 | import java.math.BigDecimal;
23 |
24 | public class BigDecimalSerializer implements ObjectSerializer {
25 |
26 | public final static BigDecimalSerializer instance = new BigDecimalSerializer();
27 |
28 | @Override
29 | public void write(PBSerializer serializer, Object object, boolean needWriteType, Object... extraParams) throws IOException {
30 | BigDecimal val = (BigDecimal) object;
31 | if (needWriteType) {
32 | serializer.writeType(com.jd.dd.glowworm.asm.Type.BIGDECIMAL);
33 | }
34 | serializer.writeString(val.toString());
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/serializer/normal/BigIntegerSerializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.serializer.normal;
17 |
18 | import com.jd.dd.glowworm.serializer.ObjectSerializer;
19 | import com.jd.dd.glowworm.serializer.PBSerializer;
20 |
21 | import java.io.IOException;
22 | import java.math.BigInteger;
23 |
24 | public class BigIntegerSerializer implements ObjectSerializer {
25 |
26 | public final static BigIntegerSerializer instance = new BigIntegerSerializer();
27 |
28 | @Override
29 | public void write(PBSerializer serializer, Object object, boolean needWriteType, Object... extraParams) throws IOException {
30 | BigInteger val = (BigInteger) object;
31 | if (needWriteType) {
32 | serializer.writeType(com.jd.dd.glowworm.asm.Type.BIGINTEGER);
33 | }
34 | serializer.writeString(val.toString());
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/serializer/normal/ClassSerializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.serializer.normal;
17 |
18 | import com.jd.dd.glowworm.serializer.ObjectSerializer;
19 | import com.jd.dd.glowworm.serializer.PBSerializer;
20 |
21 | import java.io.IOException;
22 |
23 | public class ClassSerializer implements ObjectSerializer {
24 |
25 | public final static ClassSerializer instance = new ClassSerializer();
26 |
27 | @Override
28 | public void write(PBSerializer serializer, Object object, boolean needWriteType, Object... extraParams) throws IOException {
29 | if (needWriteType) {
30 | serializer.writeType(com.jd.dd.glowworm.asm.Type.CLASS);
31 | }
32 | Class clazz = (Class) object;
33 | serializer.writeString(clazz.getName());
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/serializer/normal/DateSerializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.serializer.normal;
17 |
18 | import com.jd.dd.glowworm.serializer.ObjectSerializer;
19 | import com.jd.dd.glowworm.serializer.PBSerializer;
20 |
21 | import java.io.IOException;
22 | import java.util.Date;
23 |
24 | public class DateSerializer implements ObjectSerializer {
25 |
26 | public final static DateSerializer instance = new DateSerializer();
27 |
28 | @Override
29 | public void write(PBSerializer serializer, Object object, boolean needWriteType, Object... extraParams) throws IOException {
30 | Date value = (Date) object;
31 | if (needWriteType) {
32 | serializer.writeType(com.jd.dd.glowworm.asm.Type.DATE);
33 | }
34 | serializer.writeLong(value.getTime());
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/serializer/normal/EnumSerializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.serializer.normal;
17 |
18 | import com.jd.dd.glowworm.serializer.ObjectSerializer;
19 | import com.jd.dd.glowworm.serializer.PBSerializer;
20 |
21 | import java.io.IOException;
22 |
23 |
24 | public class EnumSerializer implements ObjectSerializer {
25 |
26 | public final static EnumSerializer instance = new EnumSerializer();
27 |
28 | @Override
29 | public void write(PBSerializer serializer, Object object, boolean needWriteType, Object... extraParams) throws IOException {
30 | Enum> e = (Enum>) object;
31 | if (needWriteType) {
32 | serializer.writeType(com.jd.dd.glowworm.asm.Type.ENUM);
33 | serializer.writeString(object.getClass().getName());
34 | }
35 | serializer.writeString(e.name());
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/serializer/normal/ExceptionSerializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.serializer.normal;
17 |
18 | import com.jd.dd.glowworm.asm.Type;
19 | import com.jd.dd.glowworm.serializer.PBSerializer;
20 | import com.jd.dd.glowworm.serializer.reflect.JavaBeanSerializer;
21 |
22 | import java.io.IOException;
23 |
24 | public class ExceptionSerializer extends JavaBeanSerializer {
25 |
26 | public ExceptionSerializer(Class> clazz) {
27 | super(clazz);
28 | }
29 |
30 | @Override
31 | public void write(PBSerializer serializer, Object object, boolean needWriteType, Object... extraParams) throws IOException {
32 | if (needWriteType) {
33 | serializer.writeType(Type.EXCEPTION);
34 | }
35 | super.write(serializer, object, false, extraParams);
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/serializer/normal/InetAddressSerializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.serializer.normal;
17 |
18 | import com.jd.dd.glowworm.serializer.ObjectSerializer;
19 | import com.jd.dd.glowworm.serializer.PBSerializer;
20 |
21 | import java.io.IOException;
22 | import java.net.InetAddress;
23 |
24 | public class InetAddressSerializer implements ObjectSerializer {
25 |
26 | public static InetAddressSerializer instance = new InetAddressSerializer();
27 |
28 | @Override
29 | public void write(PBSerializer serializer, Object object, boolean needWriteType, Object... extraParams) throws IOException {
30 | if (needWriteType) {
31 | serializer.writeType(com.jd.dd.glowworm.asm.Type.INETADDRESS);
32 | }
33 | serializer.writeString(((InetAddress) object).getHostAddress());
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/serializer/normal/StringSerializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.serializer.normal;
17 |
18 | import com.jd.dd.glowworm.serializer.ObjectSerializer;
19 | import com.jd.dd.glowworm.serializer.PBSerializer;
20 |
21 | import java.io.IOException;
22 |
23 | public class StringSerializer implements ObjectSerializer {
24 |
25 | public static StringSerializer instance = new StringSerializer();
26 |
27 | @Override
28 | public void write(PBSerializer serializer, Object object, boolean needWriteType, Object... extraParams) throws IOException {
29 | if (needWriteType) {
30 | serializer.writeType(com.jd.dd.glowworm.asm.Type.STRING);
31 | }
32 | serializer.writeStringWithCharset(object.toString());
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/serializer/normal/TimeSerializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.serializer.normal;
17 |
18 | import com.jd.dd.glowworm.serializer.ObjectSerializer;
19 | import com.jd.dd.glowworm.serializer.PBSerializer;
20 |
21 | import java.io.IOException;
22 | import java.sql.Time;
23 |
24 | public class TimeSerializer implements ObjectSerializer {
25 |
26 | public final static TimeSerializer instance = new TimeSerializer();
27 |
28 | @Override
29 | public void write(PBSerializer serializer, Object object, boolean needWriteType, Object... extraParams) throws IOException {
30 | Time value = (Time) object;
31 | if (needWriteType) {
32 | serializer.writeType(com.jd.dd.glowworm.asm.Type.TIME);
33 | }
34 | serializer.writeLong(value.getTime());
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/serializer/normal/TimestampSerializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.serializer.normal;
17 |
18 | import com.jd.dd.glowworm.serializer.ObjectSerializer;
19 | import com.jd.dd.glowworm.serializer.PBSerializer;
20 |
21 | import java.io.IOException;
22 | import java.sql.Timestamp;
23 |
24 | public class TimestampSerializer implements ObjectSerializer {
25 |
26 | public final static TimestampSerializer instance = new TimestampSerializer();
27 |
28 | @Override
29 | public void write(PBSerializer serializer, Object object, boolean needWriteType, Object... extraParams) throws IOException {
30 | Timestamp value = (Timestamp) object;
31 | if (needWriteType) {
32 | serializer.writeType(com.jd.dd.glowworm.asm.Type.TIMESTAMP);
33 | }
34 | serializer.writeLong(value.getTime());
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/serializer/primary/BooleanArraySerializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.serializer.primary;
17 |
18 | import com.jd.dd.glowworm.serializer.ObjectSerializer;
19 | import com.jd.dd.glowworm.serializer.PBSerializer;
20 |
21 | import java.io.IOException;
22 |
23 | public class BooleanArraySerializer implements ObjectSerializer {
24 |
25 | public static BooleanArraySerializer instance = new BooleanArraySerializer();
26 |
27 | public void write(PBSerializer serializer, Object object, boolean needWriteType, Object... extraParams) throws IOException {
28 | if (needWriteType) {
29 | serializer.writeType(com.jd.dd.glowworm.asm.Type.ARRAY_BOOLEAN);
30 | }
31 | boolean[] array = (boolean[]) object;
32 | serializer.writeBooleanArray(array);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/serializer/primary/BooleanSerializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.serializer.primary;
17 |
18 | import com.jd.dd.glowworm.serializer.ObjectSerializer;
19 | import com.jd.dd.glowworm.serializer.PBSerializer;
20 |
21 | import java.io.IOException;
22 |
23 | public class BooleanSerializer implements ObjectSerializer {
24 |
25 | public final static BooleanSerializer instance = new BooleanSerializer();
26 |
27 | @Override
28 | public void write(PBSerializer serializer, Object object, boolean needWriteType, Object... extraParams) throws IOException {
29 | Boolean value = (Boolean) object;
30 | if (needWriteType) {
31 | serializer.writeType(com.jd.dd.glowworm.asm.Type.BOOLEAN);
32 | }
33 | serializer.writeBool(value);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/serializer/primary/ByteArraySerializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.serializer.primary;
17 |
18 | import com.jd.dd.glowworm.serializer.ObjectSerializer;
19 | import com.jd.dd.glowworm.serializer.PBSerializer;
20 |
21 | import java.io.IOException;
22 |
23 | public class ByteArraySerializer implements ObjectSerializer {
24 |
25 | public static ByteArraySerializer instance = new ByteArraySerializer();
26 |
27 | public void write(PBSerializer serializer, Object object, boolean needWriteType, Object... extraParams) throws IOException {
28 | if (needWriteType) {
29 | serializer.writeType(com.jd.dd.glowworm.asm.Type.ARRAY_BYTE);
30 | }
31 | byte[] array = (byte[]) object;
32 | serializer.writeByteArray(array);
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/serializer/primary/ByteSerializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.serializer.primary;
17 |
18 | import com.jd.dd.glowworm.serializer.ObjectSerializer;
19 | import com.jd.dd.glowworm.serializer.PBSerializer;
20 |
21 | import java.io.IOException;
22 |
23 |
24 | public class ByteSerializer implements ObjectSerializer {
25 |
26 | public static ByteSerializer instance = new ByteSerializer();
27 |
28 | @Override
29 | public void write(PBSerializer serializer, Object object, boolean needWriteType, Object... extraParams) throws IOException {
30 | Byte value = (Byte) object;
31 | if (needWriteType) {
32 | serializer.writeType(com.jd.dd.glowworm.asm.Type.BYTE);
33 | }
34 | serializer.writeByte(value);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/serializer/primary/CharArraySerializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.serializer.primary;
17 |
18 | import com.jd.dd.glowworm.serializer.ObjectSerializer;
19 | import com.jd.dd.glowworm.serializer.PBSerializer;
20 |
21 | import java.io.IOException;
22 |
23 |
24 | public class CharArraySerializer implements ObjectSerializer {
25 |
26 | public static CharArraySerializer instance = new CharArraySerializer();
27 |
28 | public void write(PBSerializer serializer, Object object, boolean needWriteType, Object... extraParams) throws IOException {
29 | if (needWriteType) {
30 | serializer.writeType(com.jd.dd.glowworm.asm.Type.ARRAY_CHAR);
31 | }
32 | char[] chars = (char[]) object;
33 | serializer.writeStringWithCharset(new String(chars));
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/serializer/primary/CharacterSerializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.serializer.primary;
17 |
18 | import com.jd.dd.glowworm.serializer.ObjectSerializer;
19 | import com.jd.dd.glowworm.serializer.PBSerializer;
20 |
21 | import java.io.IOException;
22 |
23 | public class CharacterSerializer implements ObjectSerializer {
24 |
25 | public final static CharacterSerializer instance = new CharacterSerializer();
26 |
27 | @Override
28 | public void write(PBSerializer serializer, Object object, boolean needWriteType, Object... extraParams) throws IOException {
29 | Character value = (Character) object;
30 | if (needWriteType) {
31 | serializer.writeType(com.jd.dd.glowworm.asm.Type.CHAR);
32 | }
33 | serializer.writeStringWithCharset(value.toString());
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/serializer/primary/DoubleArraySerializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.serializer.primary;
17 |
18 | import com.jd.dd.glowworm.serializer.ObjectSerializer;
19 | import com.jd.dd.glowworm.serializer.PBSerializer;
20 |
21 | import java.io.IOException;
22 |
23 | public class DoubleArraySerializer implements ObjectSerializer {
24 |
25 | public static final DoubleArraySerializer instance = new DoubleArraySerializer();
26 |
27 | public void write(PBSerializer serializer, Object object, boolean needWriteType, Object... extraParams) throws IOException {
28 | if (needWriteType) {
29 | serializer.writeType(com.jd.dd.glowworm.asm.Type.ARRAY_DOUBLE);
30 | }
31 | double[] array = (double[]) object;
32 | serializer.writeDoubleArray(array);
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/serializer/primary/DoubleSerializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.serializer.primary;
17 |
18 | import com.jd.dd.glowworm.serializer.ObjectSerializer;
19 | import com.jd.dd.glowworm.serializer.PBSerializer;
20 |
21 | import java.io.IOException;
22 |
23 | public class DoubleSerializer implements ObjectSerializer {
24 |
25 | public final static DoubleSerializer instance = new DoubleSerializer();
26 |
27 | @Override
28 | public void write(PBSerializer serializer, Object object, boolean needWriteType, Object... extraParams) throws IOException {
29 | double doubleValue = ((Double) object).doubleValue();
30 | if (needWriteType) {
31 | serializer.writeType(com.jd.dd.glowworm.asm.Type.DOUBLE);
32 | }
33 | serializer.writeDouble(doubleValue);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/serializer/primary/FloatArraySerializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.serializer.primary;
17 |
18 | import com.jd.dd.glowworm.serializer.ObjectSerializer;
19 | import com.jd.dd.glowworm.serializer.PBSerializer;
20 |
21 | import java.io.IOException;
22 |
23 | public class FloatArraySerializer implements ObjectSerializer {
24 |
25 | public static final FloatArraySerializer instance = new FloatArraySerializer();
26 |
27 | public void write(PBSerializer serializer, Object object, boolean needWriteType, Object... extraParams) throws IOException {
28 | if (needWriteType) {
29 | serializer.writeType(com.jd.dd.glowworm.asm.Type.ARRAY_FLOAT);
30 | }
31 | float[] array = (float[]) object;
32 |
33 | serializer.writeFloatArray(array);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/serializer/primary/FloatSerializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.serializer.primary;
17 |
18 | import com.jd.dd.glowworm.serializer.ObjectSerializer;
19 | import com.jd.dd.glowworm.serializer.PBSerializer;
20 |
21 | import java.io.IOException;
22 |
23 | public class FloatSerializer implements ObjectSerializer {
24 |
25 | public static FloatSerializer instance = new FloatSerializer();
26 |
27 | @Override
28 | public void write(PBSerializer serializer, Object object, boolean needWriteType, Object... extraParams) throws IOException {
29 | float floatValue = ((Float) object).floatValue();
30 | if (needWriteType) {
31 | serializer.writeType(com.jd.dd.glowworm.asm.Type.FLOAT);
32 | }
33 | serializer.writeFloat(floatValue);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/serializer/primary/IntArraySerializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.serializer.primary;
17 |
18 | import com.jd.dd.glowworm.serializer.ObjectSerializer;
19 | import com.jd.dd.glowworm.serializer.PBSerializer;
20 |
21 | import java.io.IOException;
22 |
23 | public class IntArraySerializer implements ObjectSerializer {
24 |
25 | public static IntArraySerializer instance = new IntArraySerializer();
26 |
27 | public void write(PBSerializer serializer, Object object, boolean needWriteType, Object... extraParams) throws IOException {
28 | if (needWriteType) {
29 | serializer.writeType(com.jd.dd.glowworm.asm.Type.ARRAY_INT);
30 | }
31 | int[] array = (int[]) object;
32 |
33 | serializer.writeIntArray(array);
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/serializer/primary/IntegerSerializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.serializer.primary;
17 |
18 | import com.jd.dd.glowworm.serializer.ObjectSerializer;
19 | import com.jd.dd.glowworm.serializer.PBSerializer;
20 |
21 | import java.io.IOException;
22 |
23 | public class IntegerSerializer implements ObjectSerializer {
24 |
25 | public static IntegerSerializer instance = new IntegerSerializer();
26 |
27 | @Override
28 | public void write(PBSerializer serializer, Object object, boolean needWriteType, Object... extraParams) throws IOException {
29 | Number value = (Number) object;
30 | if (needWriteType) {
31 | serializer.writeType(com.jd.dd.glowworm.asm.Type.INT);
32 | }
33 | serializer.writeInt(value.intValue());
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/serializer/primary/LongArraySerializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.serializer.primary;
17 |
18 | import com.jd.dd.glowworm.serializer.ObjectSerializer;
19 | import com.jd.dd.glowworm.serializer.PBSerializer;
20 |
21 | import java.io.IOException;
22 |
23 | public class LongArraySerializer implements ObjectSerializer {
24 |
25 | public static LongArraySerializer instance = new LongArraySerializer();
26 |
27 | public void write(PBSerializer serializer, Object object, boolean needWriteType, Object... extraParams) throws IOException {
28 | if (needWriteType) {
29 | serializer.writeType(com.jd.dd.glowworm.asm.Type.ARRAY_LONG);
30 | }
31 | long[] array = (long[]) object;
32 |
33 | serializer.writeLongArray(array);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/serializer/primary/LongSerializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.serializer.primary;
17 |
18 | import com.jd.dd.glowworm.serializer.ObjectSerializer;
19 | import com.jd.dd.glowworm.serializer.PBSerializer;
20 |
21 | import java.io.IOException;
22 |
23 | public class LongSerializer implements ObjectSerializer {
24 |
25 | public final static LongSerializer instance = new LongSerializer();
26 |
27 | @Override
28 | public void write(PBSerializer serializer, Object object, boolean needWriteType, Object... extraParams) throws IOException {
29 | long longValue = ((Long) object).longValue();
30 | if (needWriteType) {
31 | serializer.writeType(com.jd.dd.glowworm.asm.Type.LONG);
32 | }
33 | serializer.writeLong(longValue);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/serializer/primary/ShortArraySerializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.serializer.primary;
17 |
18 | import com.jd.dd.glowworm.serializer.ObjectSerializer;
19 | import com.jd.dd.glowworm.serializer.PBSerializer;
20 |
21 | import java.io.IOException;
22 |
23 | public class ShortArraySerializer implements ObjectSerializer {
24 |
25 | public static ShortArraySerializer instance = new ShortArraySerializer();
26 |
27 | public void write(PBSerializer serializer, Object object, boolean needWriteType, Object... extraParams) throws IOException {
28 | if (needWriteType) {
29 | serializer.writeType(com.jd.dd.glowworm.asm.Type.ARRAY_SHORT);
30 | }
31 | short[] array = (short[]) object;
32 | serializer.writeShortArray(array);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/serializer/primary/ShortSerializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.serializer.primary;
17 |
18 | import com.jd.dd.glowworm.serializer.ObjectSerializer;
19 | import com.jd.dd.glowworm.serializer.PBSerializer;
20 |
21 | import java.io.IOException;
22 |
23 | public class ShortSerializer implements ObjectSerializer {
24 |
25 | public static ShortSerializer instance = new ShortSerializer();
26 |
27 | @Override
28 | public void write(PBSerializer serializer, Object object, boolean needWriteType, Object... extraParams) throws IOException {
29 | Number value = (Number) object;
30 | if (needWriteType) {
31 | serializer.writeType(com.jd.dd.glowworm.asm.Type.SHORT);
32 | }
33 | serializer.writeShort(value.shortValue());
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/serializer/reflect/FieldSerializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.serializer.reflect;
17 |
18 | import com.jd.dd.glowworm.serializer.PBSerializer;
19 | import com.jd.dd.glowworm.util.FieldInfo;
20 |
21 | import java.lang.reflect.Field;
22 | import java.lang.reflect.Method;
23 |
24 | public abstract class FieldSerializer implements Comparable {
25 |
26 | protected final FieldInfo fieldInfo;
27 | private boolean writeNull = false;
28 |
29 | public FieldSerializer(FieldInfo fieldInfo) {
30 | super();
31 | this.fieldInfo = fieldInfo;
32 | fieldInfo.setAccessible(true);
33 | }
34 |
35 | public boolean isWriteNull() {
36 | return writeNull;
37 | }
38 |
39 | public Field getField() {
40 | return fieldInfo.getField();
41 | }
42 |
43 | public String getName() {
44 | return fieldInfo.getName();
45 | }
46 |
47 | public Method getMethod() {
48 | return fieldInfo.getMethod();
49 | }
50 |
51 | public int compareTo(FieldSerializer o) {
52 | return this.getName().compareTo(o.getName());
53 | }
54 |
55 | public Object getPropertyValue(Object object) throws Exception {
56 | return fieldInfo.get(object);
57 | }
58 |
59 | public abstract void writeProperty(PBSerializer serializer, Object propertyValue, int fieldInfoIndexParm) throws Exception;
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/serializer/reflect/JavaBeanSerializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 360buy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.jd.dd.glowworm.serializer.reflect;
17 |
18 | import com.jd.dd.glowworm.PBException;
19 | import com.jd.dd.glowworm.serializer.ObjectSerializer;
20 | import com.jd.dd.glowworm.serializer.PBSerializer;
21 | import com.jd.dd.glowworm.util.FieldInfo;
22 | import com.jd.dd.glowworm.util.TypeUtils;
23 |
24 | import java.io.IOException;
25 | import java.lang.reflect.Field;
26 | import java.lang.reflect.Modifier;
27 | import java.util.ArrayList;
28 | import java.util.List;
29 | import java.util.Map;
30 |
31 | public class JavaBeanSerializer implements ObjectSerializer {
32 |
33 | private final FieldSerializer[] sortedGetters;
34 |
35 | public JavaBeanSerializer(Class> clazz) {
36 | this(clazz, (Map) null);
37 | }
38 |
39 | @Override
40 | public void write(PBSerializer serializer, Object object, boolean needWriteType, Object... extraParams) throws IOException {
41 | final FieldSerializer[] getters = this.sortedGetters;
42 |
43 | try {
44 | if (needWriteType) {
45 | serializer.writeType(com.jd.dd.glowworm.asm.Type.OBJECT);
46 | serializer.writeString(object.getClass().getName());
47 | }
48 |
49 | for (int i = 0; i < getters.length; ++i) {
50 | FieldSerializer fieldSerializer = getters[i];
51 | Field field = fieldSerializer.getField();
52 | if (field != null) {
53 | if (Modifier.isTransient(field.getModifiers())) {
54 | continue;
55 | }
56 | }
57 |
58 | Object propertyValue = fieldSerializer.getPropertyValue(object);
59 | fieldSerializer.writeProperty(serializer, propertyValue, i);
60 | }
61 | } catch (Exception e) {
62 | throw new PBException("write javaBean error", e);
63 | }
64 | }
65 |
66 | public JavaBeanSerializer(Class> clazz, Map aliasMap) {
67 | {
68 | List getterList = new ArrayList();
69 | List fieldInfoList = TypeUtils.computeGetters(clazz, aliasMap, true);
70 |
71 | for (FieldInfo fieldInfo : fieldInfoList) {
72 | getterList.add(createFieldSerializer(fieldInfo));
73 | }
74 |
75 | sortedGetters = getterList.toArray(new FieldSerializer[getterList.size()]);
76 | }
77 | }
78 |
79 | public FieldSerializer createFieldSerializer(FieldInfo fieldInfo) {
80 | return new ObjectFieldSerializer(fieldInfo);
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/src/main/java/com/jd/dd/glowworm/util/ASMClassLoader.java:
--------------------------------------------------------------------------------
1 | package com.jd.dd.glowworm.util;
2 |
3 | import com.jd.dd.glowworm.PBException;
4 |
5 | import java.security.PrivilegedAction;
6 |
7 |
8 | public class ASMClassLoader extends ClassLoader {
9 |
10 | private static java.security.ProtectionDomain DOMAIN;
11 |
12 | static {
13 | DOMAIN = (java.security.ProtectionDomain) java.security.AccessController.doPrivileged(new PrivilegedAction