leon 1.0.8 → 1.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/io.rb +3 -3
- data/lib/string-buffer.rb +17 -17
- metadata +1 -1
data/lib/io.rb
CHANGED
@@ -193,11 +193,11 @@ module LEON
|
|
193
193
|
elsif v.is_a? Fixnum
|
194
194
|
if v < 0
|
195
195
|
v = v.abs
|
196
|
-
if v
|
196
|
+
if v <= (1 << 7)
|
197
197
|
return Constants::CHAR
|
198
|
-
elsif v
|
198
|
+
elsif v <= (1 << 15)
|
199
199
|
return Constants::SHORT
|
200
|
-
elsif v
|
200
|
+
elsif v <= (1 << 31)
|
201
201
|
return Constants::INT
|
202
202
|
end
|
203
203
|
return Constants::DOUBLE
|
data/lib/string-buffer.rb
CHANGED
@@ -10,7 +10,7 @@ module LEON
|
|
10
10
|
return ret
|
11
11
|
end
|
12
12
|
if type === Constants::CHAR
|
13
|
-
return v < 0 ? StringBuffer.bytes(complement(-v, 8), Constants::UNSIGNED_CHAR) : StringBuffer.bytes(v, Constants::UNSIGNED_CHAR)
|
13
|
+
return v < 0 ? StringBuffer.bytes(StringBuffer.complement(-v, 8), Constants::UNSIGNED_CHAR) : StringBuffer.bytes(v, Constants::UNSIGNED_CHAR)
|
14
14
|
end
|
15
15
|
if type === Constants::UNSIGNED_SHORT
|
16
16
|
ret.push(v >> 8)
|
@@ -18,7 +18,7 @@ module LEON
|
|
18
18
|
return ret
|
19
19
|
end
|
20
20
|
if type === Constants::SHORT
|
21
|
-
return v < 0 ? StringBuffer.bytes(complement(-v, 16), Constants::UNSIGNED_SHORT) : StringBuffer.bytes(v, Constants::UNSIGNED_SHORT)
|
21
|
+
return v < 0 ? StringBuffer.bytes(StringBuffer.complement(-v, 16), Constants::UNSIGNED_SHORT) : StringBuffer.bytes(v, Constants::UNSIGNED_SHORT)
|
22
22
|
end
|
23
23
|
if type === Constants::UNSIGNED_INT
|
24
24
|
ret.push(v >> 24)
|
@@ -28,7 +28,7 @@ module LEON
|
|
28
28
|
return ret
|
29
29
|
end
|
30
30
|
if type === Constants::INT
|
31
|
-
return v < 0 ? StringBuffer.bytes(complement(-v, 32), Constants::UNSIGNED_INT) : StringBuffer.bytes(v, Constants::UNSIGNED_INT)
|
31
|
+
return v < 0 ? StringBuffer.bytes(StringBuffer.complement(-v, 32), Constants::UNSIGNED_INT) : StringBuffer.bytes(v, Constants::UNSIGNED_INT)
|
32
32
|
end
|
33
33
|
if type === Constants::FLOAT
|
34
34
|
exp = 127
|
@@ -134,7 +134,7 @@ module LEON
|
|
134
134
|
return i + 1
|
135
135
|
end
|
136
136
|
def writeInt8(v, i)
|
137
|
-
v = (v < 0 ? complement(-v, 8) : v)
|
137
|
+
v = (v < 0 ? StringBuffer.complement(-v, 8) : v)
|
138
138
|
return writeUInt8(v, i)
|
139
139
|
end
|
140
140
|
def writeUInt16LE(v, i)
|
@@ -166,12 +166,12 @@ module LEON
|
|
166
166
|
return i + 2
|
167
167
|
end
|
168
168
|
def writeInt16LE(v, i)
|
169
|
-
v = (v < 0 ? complement(-v, 16) : v)
|
170
|
-
return writeUInt16LE(v)
|
169
|
+
v = (v < 0 ? StringBuffer.complement(-v, 16) : v)
|
170
|
+
return writeUInt16LE(v, i)
|
171
171
|
end
|
172
172
|
def writeInt16BE(v, i)
|
173
|
-
v = (v < 0 ? complement(-v, 16) : v)
|
174
|
-
return writeUInt16BE(v)
|
173
|
+
v = (v < 0 ? StringBuffer.complement(-v, 16) : v)
|
174
|
+
return writeUInt16BE(v, i)
|
175
175
|
end
|
176
176
|
def writeUInt32LE(v, i)
|
177
177
|
bytez = StringBuffer.bytes(v, Constants::UNSIGNED_INT)
|
@@ -202,12 +202,12 @@ module LEON
|
|
202
202
|
return i + 4
|
203
203
|
end
|
204
204
|
def writeInt32LE(v, i)
|
205
|
-
v = (v < 0 ? complement(-v, i) : v)
|
206
|
-
return writeUInt32LE(v)
|
205
|
+
v = (v < 0 ? StringBuffer.complement(-v, i) : v)
|
206
|
+
return writeUInt32LE(v, i)
|
207
207
|
end
|
208
208
|
def writeInt32BE(v, i)
|
209
|
-
v = (v < 0 ? complement(-v, i) : v)
|
210
|
-
return writeUInt32BE(v)
|
209
|
+
v = (v < 0 ? StringBuffer.complement(-v, i) : v)
|
210
|
+
return writeUInt32BE(v, i)
|
211
211
|
end
|
212
212
|
def writeFloatLE(v, i)
|
213
213
|
bytez = StringBuffer.bytes(v, Constants::FLOAT)
|
@@ -248,7 +248,7 @@ module LEON
|
|
248
248
|
def readInt8(i)
|
249
249
|
v = readUInt8(i)
|
250
250
|
if (0x80 & v) != 0
|
251
|
-
return -complement(v, 8)
|
251
|
+
return -StringBuffer.complement(v, 8)
|
252
252
|
end
|
253
253
|
return v
|
254
254
|
end
|
@@ -263,14 +263,14 @@ module LEON
|
|
263
263
|
def readInt16LE(i)
|
264
264
|
v = readUInt16LE(i)
|
265
265
|
if (v & 0x8000) != 0
|
266
|
-
return -complement(v, 16)
|
266
|
+
return -StringBuffer.complement(v, 16)
|
267
267
|
end
|
268
268
|
return v
|
269
269
|
end
|
270
270
|
def readInt16BE(i)
|
271
271
|
v = readUInt16BE(i)
|
272
272
|
if (v & 0x8000) != 0
|
273
|
-
return -complement(v, 16)
|
273
|
+
return -StringBuffer.complement(v, 16)
|
274
274
|
end
|
275
275
|
return v
|
276
276
|
end
|
@@ -285,14 +285,14 @@ module LEON
|
|
285
285
|
def readInt32LE(i)
|
286
286
|
v = readUInt32LE(i)
|
287
287
|
if (v & 0x80000000) != 0
|
288
|
-
return -complement(v, 32)
|
288
|
+
return -StringBuffer.complement(v, 32)
|
289
289
|
end
|
290
290
|
return v
|
291
291
|
end
|
292
292
|
def readInt32BE(i)
|
293
293
|
v = readUInt32BE(i)
|
294
294
|
if (v & 0x80000000) != 0
|
295
|
-
return -complement(v, 32)
|
295
|
+
return -StringBuffer.complement(v, 32)
|
296
296
|
end
|
297
297
|
return v
|
298
298
|
end
|