forked from json-iterator/java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEncoder.java
More file actions
115 lines (88 loc) · 3.28 KB
/
Encoder.java
File metadata and controls
115 lines (88 loc) · 3.28 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
package com.jsoniter.spi;
import com.jsoniter.output.JsonStream;
import java.io.IOException;
public interface Encoder {
void encode(Object obj, JsonStream stream) throws IOException;
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 Encoder {
@Override
public void encode(Object obj, JsonStream stream) throws IOException {
encodeShort((Short) obj, stream);
}
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 Encoder {
@Override
public void encode(Object obj, JsonStream stream) throws IOException {
encodeInt((Integer) obj, stream);
}
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 Encoder {
@Override
public void encode(Object obj, JsonStream stream) throws IOException {
encodeLong((Long) obj, stream);
}
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 Encoder {
@Override
public void encode(Object obj, JsonStream stream) throws IOException {
encodeFloat((Float) obj, stream);
}
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 Encoder {
@Override
public void encode(Object obj, JsonStream stream) throws IOException {
encodeDouble((Double) obj, stream);
}
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('"');
}
}
}