forked from msgpack/msgpack-java
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPacker.java
More file actions
226 lines (199 loc) · 5.81 KB
/
Copy pathPacker.java
File metadata and controls
226 lines (199 loc) · 5.81 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
//
// MessagePack for Java
//
// Copyright (C) 2009-2011 FURUHASHI Sadayuki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package org.msgpack.packer;
import java.math.BigInteger;
import java.io.IOException;
import java.nio.ByteBuffer;
import org.msgpack.value.Value;
import org.msgpack.MessagePack;
import org.msgpack.MessagePackable;
public abstract class Packer {
protected MessagePack msgpack = new MessagePack(); // TODO initialize
public abstract void writeNil() throws IOException;
public abstract void writeBoolean(boolean v) throws IOException;
public abstract void writeByte(byte v) throws IOException;
public abstract void writeShort(short v) throws IOException;
public abstract void writeInt(int v) throws IOException;
public abstract void writeLong(long v) throws IOException;
public abstract void writeBigInteger(BigInteger v) throws IOException;
public abstract void writeFloat(float v) throws IOException;
public abstract void writeDouble(double v) throws IOException;
public void writeByteArray(byte[] b) throws IOException {
writeByteArray(b, 0, b.length);
}
public abstract void writeByteArray(byte[] b, int off, int len) throws IOException;
//public abstract void writeByteArray(ByteBuffer b) throws IOException;
public abstract void writeString(String s) throws IOException;
public abstract void writeArrayBegin(int size) throws IOException;
public abstract void writeArrayEnd(boolean check) throws IOException;
public void writeArrayEnd() throws IOException {
writeArrayEnd(true);
}
public abstract void writeMapBegin(int size) throws IOException;
public abstract void writeMapEnd(boolean check) throws IOException;
public void writeMapEnd() throws IOException {
writeMapEnd(true);
}
public Packer write(Object o) throws IOException {
msgpack.getTemplate(o.getClass()).write(this, o);
return this;
}
public Packer writeOptional(Object o) throws IOException {
if(o == null) {
writeNil();
return this;
}
return write(o);
}
public Packer write(Value v) throws IOException {
v.writeTo(this);
return this;
}
// public Packer write(Object o) throws IOException {
// msgpack.getTemplate(o.getClass()).write(this, o);
// return this;
// }
//
// public Packer write(Value v) throws IOException {
// v.writeTo(this);
// return this;
// }
//
// public Packer write(MessagePackable v) throws IOException {
// v.writeTo(this);
// return this;
// }
//
// public Packer write(boolean v) throws IOException {
// writeBoolean(v);
// return this;
// }
//
// public Packer write(byte v) throws IOException {
// writeByte(v);
// return this;
// }
//
// public Packer write(short v) throws IOException {
// writeShort(v);
// return this;
// }
//
// public Packer write(int v) throws IOException {
// writeInt(v);
// return this;
// }
//
// public Packer write(long v) throws IOException {
// writeLong(v);
// return this;
// }
//
// public Packer write(float v) throws IOException {
// writeFloat(v);
// return this;
// }
//
// public Packer write(double v) throws IOException {
// writeDouble(v);
// return this;
// }
//
// public Packer write(Boolean v) throws IOException {
// if(v == null) {
// writeNil();
// } else {
// writeBoolean(v);
// }
// return this;
// }
//
// public Packer write(Byte v) throws IOException {
// if(v == null) {
// writeNil();
// } else {
// writeByte(v);
// }
// return this;
// }
//
// public Packer write(Short v) throws IOException {
// if(v == null) {
// writeNil();
// } else {
// writeShort(v);
// }
// return this;
// }
//
// public Packer write(Integer v) throws IOException {
// if(v == null) {
// writeNil();
// } else {
// writeInt(v);
// }
// return this;
// }
//
// public Packer write(Long v) throws IOException {
// if(v == null) {
// writeNil();
// } else {
// writeLong(v);
// }
// return this;
// }
//
// public Packer write(Float v) throws IOException {
// if(v == null) {
// writeNil();
// } else {
// writeFloat(v);
// }
// return this;
// }
//
// public Packer write(Double v) throws IOException {
// if(v == null) {
// writeNil();
// } else {
// writeDouble(v);
// }
// return this;
// }
//
// public Packer write(String s) throws IOException {
// writeString(s);
// return this;
// }
//
// public Packer write(byte[] b) throws IOException {
// writeByteArray(b);
// return this;
// }
//
// public Packer write(byte[] b, int off, int len) throws IOException {
// writeByteArray(b, off, len);
// return this;
// }
//
// //public Packer write(ByteBuffer b) throws IOException {
// // writeByteBuffer(b);
// // return this;
// //}
}