-
Notifications
You must be signed in to change notification settings - Fork 531
Expand file tree
/
Copy pathEncoder.java
More file actions
152 lines (117 loc) · 4.15 KB
/
Encoder.java
File metadata and controls
152 lines (117 loc) · 4.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
package com.jsoniter.spi;
import com.jsoniter.any.Any;
import com.jsoniter.output.JsonStream;
import java.io.IOException;
public interface Encoder {
void encode(Object obj, JsonStream stream) throws IOException;
interface ReflectionEncoder extends Encoder {
Any wrap(Object obj);
}
abstract class BooleanEncoder implements Encoder {
@Override
public void encode(Object obj, JsonStream stream) throws IOException {
encodeBoolean((Boolean) obj, stream);
}
public abstract void encodeBoolean(boolean obj, JsonStream stream) throws IOException;
}
abstract class ShortEncoder implements ReflectionEncoder {
@Override
public void encode(Object obj, JsonStream stream) throws IOException {
encodeShort((Short) obj, stream);
}
@Override
public Any wrap(Object obj) {
Short val = (Short) obj;
return Any.wrap((int) val);
}
public abstract void encodeShort(short obj, JsonStream stream) throws IOException;
}
class StringShortEncoder extends ShortEncoder {
@Override
public void encodeShort(short obj, JsonStream stream) throws IOException {
stream.write('"');
stream.writeVal(obj);
stream.write('"');
}
}
abstract class IntEncoder implements ReflectionEncoder {
@Override
public void encode(Object obj, JsonStream stream) throws IOException {
encodeInt((Integer) obj, stream);
}
@Override
public Any wrap(Object obj) {
Integer val = (Integer) obj;
return Any.wrap((int)val);
}
public abstract void encodeInt(int obj, JsonStream stream) throws IOException;
}
class StringIntEncoder extends IntEncoder {
@Override
public void encodeInt(int obj, JsonStream stream) throws IOException {
stream.write('"');
stream.writeVal(obj);
stream.write('"');
}
}
abstract class LongEncoder implements ReflectionEncoder {
@Override
public void encode(Object obj, JsonStream stream) throws IOException {
encodeLong((Long) obj, stream);
}
@Override
public Any wrap(Object obj) {
Long val = (Long) obj;
return Any.wrap((long)val);
}
public abstract void encodeLong(long obj, JsonStream stream) throws IOException;
}
class StringLongEncoder extends LongEncoder {
@Override
public void encodeLong(long obj, JsonStream stream) throws IOException {
stream.write('"');
stream.writeVal(obj);
stream.write('"');
}
}
abstract class FloatEncoder implements ReflectionEncoder {
@Override
public void encode(Object obj, JsonStream stream) throws IOException {
encodeFloat((Float) obj, stream);
}
@Override
public Any wrap(Object obj) {
Float val = (Float) obj;
return Any.wrap((float)val);
}
public abstract void encodeFloat(float obj, JsonStream stream) throws IOException;
}
class StringFloatEncoder extends FloatEncoder {
@Override
public void encodeFloat(float obj, JsonStream stream) throws IOException {
stream.write('"');
stream.writeVal(obj);
stream.write('"');
}
}
abstract class DoubleEncoder implements ReflectionEncoder {
@Override
public void encode(Object obj, JsonStream stream) throws IOException {
encodeDouble((Double) obj, stream);
}
@Override
public Any wrap(Object obj) {
Double val = (Double) obj;
return Any.wrap((double)val);
}
public abstract void encodeDouble(double obj, JsonStream stream) throws IOException;
}
class StringDoubleEncoder extends DoubleEncoder {
@Override
public void encodeDouble(double obj, JsonStream stream) throws IOException {
stream.write('"');
stream.writeVal(obj);
stream.write('"');
}
}
}