-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBuffers.java
171 lines (139 loc) · 4.71 KB
/
Buffers.java
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
package com.thebuerkle.mcboom;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
import java.nio.charset.CoderResult;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.util.CharsetUtil;
public final class Buffers {
public static boolean mc_bool(ChannelBuffer in) {
return in.readByte() == 1;
}
public static void mc_bool(ChannelBuffer out, boolean v) {
mc_byte(out, v ? 1 : 0);
}
public static byte mc_byte(ChannelBuffer in) {
return in.readByte();
}
public static void mc_byte(ChannelBuffer out, int v) {
out.writeByte(v);
}
public static byte[] mc_bytearray_2(ChannelBuffer in) {
int len = in.readShort();
byte[] result = new byte[len];
in.readBytes(result, 0, len);
return result;
}
public static void mc_bytearray_2(ChannelBuffer out, byte[] v) {
out.writeShort(v.length);
out.writeBytes(v);
}
public static byte[] mc_bytearray_4(ChannelBuffer in) {
int len = in.readInt();
byte[] result = new byte[len];
in.readBytes(result, 0, len);
return result;
}
public static byte[] mc_bytecoordarray(ChannelBuffer in) {
int len = in.readInt() * 3;
byte[] result = new byte[len];
in.readBytes(result, 0, len);
return result;
}
public static byte[] mc_chulk_bulk(ChannelBuffer in) {
int len = DataType.mc_chunk_bulk.size(in, in.readerIndex());
byte[] result = new byte[len];
in.readBytes(result, 0, len);
return result;
}
public static double mc_double(ChannelBuffer in) {
return in.readDouble();
}
public static void mc_double(ChannelBuffer out, double v) {
out.writeDouble(v);
}
public static float mc_float(ChannelBuffer in) {
return in.readFloat();
}
public static void mc_float(ChannelBuffer out, float v) {
out.writeFloat(v);
}
public static double mc_fixed_point(ChannelBuffer in) {
return in.readInt() / 32.0;
}
public static int mc_int(ChannelBuffer in) {
return in.readInt();
}
public static void mc_int(ChannelBuffer out, int v) {
out.writeInt(v);
}
public static int[] mc_intarray_1(ChannelBuffer in) {
int len = in.readByte();
int[] v = new int[len];
for (int i = 0; i < len; i++) {
v[i] = in.readInt();
}
return v;
}
public static long mc_long(ChannelBuffer in) {
return in.readLong();
}
public static void mc_long(ChannelBuffer out, long v) {
out.writeLong(v);
}
public static byte[] mc_metadata(ChannelBuffer in) {
int len = DataType.mc_metadata.size(in, in.readerIndex());
byte[] result = new byte[len];
in.readBytes(result, 0, len);
return result;
}
public static List<Property> mc_properties(ChannelBuffer in) {
int count = in.readInt();
List<Property> result = new ArrayList<>(count);
for (int i = 0; i < count; i++) {
String key = mc_string(in);
double value = mc_double(in);
int attrlen = mc_short(in);
List<Modifier> attrs = new ArrayList<>(attrlen);
for (int j = 0; j < attrlen; j++) {
attrs.add(new Modifier(new UUID(mc_long(in), mc_long(in)),
mc_double(in),
mc_byte(in)));
}
result.add(new Property(key, value, attrs));
}
return result;
}
public static short mc_short(ChannelBuffer in) {
return in.readShort();
}
public static void mc_short(ChannelBuffer out, int v) {
out.writeShort(v);
}
public static byte[] mc_slot(ChannelBuffer in) {
int len = DataType.mc_slot.size(in, in.readerIndex());
byte[] result = new byte[len];
in.readBytes(result, 0, len);
return result;
}
public static byte[] mc_slotarray(ChannelBuffer in) {
int len = DataType.mc_slotarray.size(in, in.readerIndex());
byte[] result = new byte[len];
in.readBytes(result, 0, len);
return result;
}
public static String mc_string(ChannelBuffer in) {
int len = 2 * in.readShort();
String result = in.toString(in.readerIndex(), len, CharsetUtil.UTF_16BE);
in.readerIndex(in.readerIndex() + len);
return result;
}
public static void mc_string(ChannelBuffer out, String v) {
ChannelBuffer str = ChannelBuffers.copiedBuffer(v, CharsetUtil.UTF_16BE);
out.writeShort(v.length());
out.writeBytes(str);
}
}