|
21 | 21 | import java.io.IOException; |
22 | 22 | import java.nio.ByteBuffer; |
23 | 23 | import org.msgpack.value.Value; |
| 24 | +import org.msgpack.MessagePack; |
24 | 25 | import org.msgpack.MessagePackable; |
25 | 26 |
|
26 | 27 | public abstract class Packer { |
| 28 | + protected MessagePack msgpack; // TODO initialize |
| 29 | + |
27 | 30 | public abstract void writeNil() throws IOException; |
28 | 31 |
|
29 | 32 | public abstract void writeBoolean(boolean v) throws IOException; |
@@ -68,120 +71,148 @@ public void writeMapEnd() throws IOException { |
68 | 71 | writeMapEnd(true); |
69 | 72 | } |
70 | 73 |
|
71 | | - public void write(Value v) throws IOException { |
72 | | - v.writeTo(this); |
73 | | - } |
74 | | - |
75 | | - public void write(MessagePackable v) throws IOException { |
76 | | - v.writeTo(this); |
77 | | - } |
78 | | - |
79 | | - /* TODO |
80 | | - public void write(boolean v) throws IOException { |
81 | | - writeBoolean(v); |
82 | | - } |
83 | | -
|
84 | | - public void write(byte v) throws IOException { |
85 | | - writeByte(v); |
86 | | - } |
87 | | -
|
88 | | - public void write(short v) throws IOException { |
89 | | - writeShort(v); |
90 | | - } |
91 | | -
|
92 | | - public void write(int v) throws IOException { |
93 | | - writeInt(v); |
94 | | - } |
95 | | -
|
96 | | - public void write(long v) throws IOException { |
97 | | - writeLong(v); |
98 | | - } |
99 | | -
|
100 | | - public void write(float v) throws IOException { |
101 | | - writeFloat(v); |
102 | | - } |
103 | | -
|
104 | | - public void write(double v) throws IOException { |
105 | | - writeDouble(v); |
106 | | - } |
107 | | -
|
108 | | - public void write(Boolean v) throws IOException { |
109 | | - if(v == null) { |
110 | | - writeNil(); |
111 | | - } else { |
112 | | - writeBoolean(v); |
113 | | - } |
114 | | - } |
115 | | -
|
116 | | - public void write(Byte v) throws IOException { |
117 | | - if(v == null) { |
118 | | - writeNil(); |
119 | | - } else { |
120 | | - writeByte(v); |
121 | | - } |
122 | | - } |
123 | | -
|
124 | | - public void write(Short v) throws IOException { |
125 | | - if(v == null) { |
126 | | - writeNil(); |
127 | | - } else { |
128 | | - writeShort(v); |
129 | | - } |
130 | | - } |
131 | | -
|
132 | | - public void write(Integer v) throws IOException { |
133 | | - if(v == null) { |
134 | | - writeNil(); |
135 | | - } else { |
136 | | - writeInt(v); |
137 | | - } |
138 | | - } |
139 | | -
|
140 | | - public void write(Long v) throws IOException { |
141 | | - if(v == null) { |
142 | | - writeNil(); |
143 | | - } else { |
144 | | - writeLong(v); |
145 | | - } |
146 | | - } |
147 | | -
|
148 | | - public void write(Float v) throws IOException { |
149 | | - if(v == null) { |
150 | | - writeNil(); |
151 | | - } else { |
152 | | - writeFloat(v); |
153 | | - } |
154 | | - } |
155 | | -
|
156 | | - public void write(Double v) throws IOException { |
157 | | - if(v == null) { |
158 | | - writeNil(); |
159 | | - } else { |
160 | | - writeDouble(v); |
161 | | - } |
162 | | - } |
163 | | -
|
164 | | - public abstract void write(String s) throws IOException; |
165 | | -
|
166 | | - public void write(byte[] b) throws IOException { |
167 | | - writeByteArray(b.length); |
168 | | - writeByteArray(b); |
169 | | - } |
170 | 74 |
|
171 | | - public void write(byte[] b, int off, int len) throws IOException { |
172 | | - writeByteArray(len); |
173 | | - writeByteArray(b, off, len); |
| 75 | + public Packer write(Object o) throws IOException { |
| 76 | + msgpack.getTemplate(o.getClass()).write(this, o); |
| 77 | + return this; |
174 | 78 | } |
175 | 79 |
|
176 | | - public void write(ByteBuffer b) throws IOException { |
177 | | - // TODO |
178 | | - } |
179 | | -
|
180 | | - public void write(MessagePackable o) throws IOException { |
181 | | - o.writeTo(this); |
| 80 | + public Packer write(Value v) throws IOException { |
| 81 | + v.writeTo(this); |
| 82 | + return this; |
182 | 83 | } |
183 | 84 |
|
184 | | - public abstract void write(Object o) throws IOException; |
185 | | - */ |
| 85 | +// public Packer write(Object o) throws IOException { |
| 86 | +// msgpack.getTemplate(o.getClass()).write(this, o); |
| 87 | +// return this; |
| 88 | +// } |
| 89 | +// |
| 90 | +// public Packer write(Value v) throws IOException { |
| 91 | +// v.writeTo(this); |
| 92 | +// return this; |
| 93 | +// } |
| 94 | +// |
| 95 | +// public Packer write(MessagePackable v) throws IOException { |
| 96 | +// v.writeTo(this); |
| 97 | +// return this; |
| 98 | +// } |
| 99 | +// |
| 100 | +// public Packer write(boolean v) throws IOException { |
| 101 | +// writeBoolean(v); |
| 102 | +// return this; |
| 103 | +// } |
| 104 | +// |
| 105 | +// public Packer write(byte v) throws IOException { |
| 106 | +// writeByte(v); |
| 107 | +// return this; |
| 108 | +// } |
| 109 | +// |
| 110 | +// public Packer write(short v) throws IOException { |
| 111 | +// writeShort(v); |
| 112 | +// return this; |
| 113 | +// } |
| 114 | +// |
| 115 | +// public Packer write(int v) throws IOException { |
| 116 | +// writeInt(v); |
| 117 | +// return this; |
| 118 | +// } |
| 119 | +// |
| 120 | +// public Packer write(long v) throws IOException { |
| 121 | +// writeLong(v); |
| 122 | +// return this; |
| 123 | +// } |
| 124 | +// |
| 125 | +// public Packer write(float v) throws IOException { |
| 126 | +// writeFloat(v); |
| 127 | +// return this; |
| 128 | +// } |
| 129 | +// |
| 130 | +// public Packer write(double v) throws IOException { |
| 131 | +// writeDouble(v); |
| 132 | +// return this; |
| 133 | +// } |
| 134 | +// |
| 135 | +// public Packer write(Boolean v) throws IOException { |
| 136 | +// if(v == null) { |
| 137 | +// writeNil(); |
| 138 | +// } else { |
| 139 | +// writeBoolean(v); |
| 140 | +// } |
| 141 | +// return this; |
| 142 | +// } |
| 143 | +// |
| 144 | +// public Packer write(Byte v) throws IOException { |
| 145 | +// if(v == null) { |
| 146 | +// writeNil(); |
| 147 | +// } else { |
| 148 | +// writeByte(v); |
| 149 | +// } |
| 150 | +// return this; |
| 151 | +// } |
| 152 | +// |
| 153 | +// public Packer write(Short v) throws IOException { |
| 154 | +// if(v == null) { |
| 155 | +// writeNil(); |
| 156 | +// } else { |
| 157 | +// writeShort(v); |
| 158 | +// } |
| 159 | +// return this; |
| 160 | +// } |
| 161 | +// |
| 162 | +// public Packer write(Integer v) throws IOException { |
| 163 | +// if(v == null) { |
| 164 | +// writeNil(); |
| 165 | +// } else { |
| 166 | +// writeInt(v); |
| 167 | +// } |
| 168 | +// return this; |
| 169 | +// } |
| 170 | +// |
| 171 | +// public Packer write(Long v) throws IOException { |
| 172 | +// if(v == null) { |
| 173 | +// writeNil(); |
| 174 | +// } else { |
| 175 | +// writeLong(v); |
| 176 | +// } |
| 177 | +// return this; |
| 178 | +// } |
| 179 | +// |
| 180 | +// public Packer write(Float v) throws IOException { |
| 181 | +// if(v == null) { |
| 182 | +// writeNil(); |
| 183 | +// } else { |
| 184 | +// writeFloat(v); |
| 185 | +// } |
| 186 | +// return this; |
| 187 | +// } |
| 188 | +// |
| 189 | +// public Packer write(Double v) throws IOException { |
| 190 | +// if(v == null) { |
| 191 | +// writeNil(); |
| 192 | +// } else { |
| 193 | +// writeDouble(v); |
| 194 | +// } |
| 195 | +// return this; |
| 196 | +// } |
| 197 | +// |
| 198 | +// public Packer write(String s) throws IOException { |
| 199 | +// writeString(s); |
| 200 | +// return this; |
| 201 | +// } |
| 202 | +// |
| 203 | +// public Packer write(byte[] b) throws IOException { |
| 204 | +// writeByteArray(b); |
| 205 | +// return this; |
| 206 | +// } |
| 207 | +// |
| 208 | +// public Packer write(byte[] b, int off, int len) throws IOException { |
| 209 | +// writeByteArray(b, off, len); |
| 210 | +// return this; |
| 211 | +// } |
| 212 | +// |
| 213 | +// //public Packer write(ByteBuffer b) throws IOException { |
| 214 | +// // writeByteBuffer(b); |
| 215 | +// // return this; |
| 216 | +// //} |
186 | 217 | } |
187 | 218 |
|
0 commit comments