fix data_buffer:put_number
This commit is contained in:
parent
57356e1d64
commit
e247902cc6
@ -313,8 +313,8 @@ function bit_converter.bytes_to_uint16(bytes, order)
|
|||||||
|
|
||||||
return
|
return
|
||||||
bit.bor(
|
bit.bor(
|
||||||
bit.lshift(bytes[1], 8),
|
bit.lshift(bytes[2], 8),
|
||||||
bytes[2], 0)
|
bytes[1], 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
function bit_converter.bytes_to_int64(bytes, order)
|
function bit_converter.bytes_to_int64(bytes, order)
|
||||||
|
|||||||
@ -144,31 +144,31 @@ function data_buffer:put_number(num)
|
|||||||
|
|
||||||
if math.floor(num) ~= num then
|
if math.floor(num) ~= num then
|
||||||
type = TYPE_FLOAT64
|
type = TYPE_FLOAT64
|
||||||
bytes = bit_converter.float64_to_bytes(num)
|
bytes = bit_converter.float64_to_bytes(num, self.order)
|
||||||
elseif num == 0 then
|
elseif num == 0 then
|
||||||
type = TYPE_ZERO
|
type = TYPE_ZERO
|
||||||
bytes = { }
|
bytes = { }
|
||||||
elseif num > 0 then
|
elseif num > 0 then
|
||||||
if num <= MAX_UINT16 then
|
if num <= MAX_UINT16 then
|
||||||
type = TYPE_UINT16
|
type = TYPE_UINT16
|
||||||
bytes = bit_converter.uint16_to_bytes(num)
|
bytes = bit_converter.uint16_to_bytes(num, self.order)
|
||||||
elseif num <= MAX_UINT32 then
|
elseif num <= MAX_UINT32 then
|
||||||
type = TYPE_UINT32
|
type = TYPE_UINT32
|
||||||
bytes = bit_converter.uint32_to_bytes(num)
|
bytes = bit_converter.uint32_to_bytes(num, self.order)
|
||||||
elseif num <= MAX_INT64 then
|
elseif num <= MAX_INT64 then
|
||||||
type = TYPE_INT64
|
type = TYPE_INT64
|
||||||
bytes = bit_converter.int64_to_bytes(num)
|
bytes = bit_converter.int64_to_bytes(num, self.order)
|
||||||
end
|
end
|
||||||
elseif num < 0 then
|
elseif num < 0 then
|
||||||
if num >= MIN_INT16 then
|
if num >= MIN_INT16 then
|
||||||
type = TYPE_SINT16
|
type = TYPE_SINT16
|
||||||
bytes = bit_converter.sint16_to_bytes(num)
|
bytes = bit_converter.sint16_to_bytes(num, self.order)
|
||||||
elseif num >= MIN_INT32 then
|
elseif num >= MIN_INT32 then
|
||||||
type = TYPE_SINT32
|
type = TYPE_SINT32
|
||||||
bytes = bit_converter.sint32_to_bytes(num)
|
bytes = bit_converter.sint32_to_bytes(num, self.order)
|
||||||
elseif num >= MIN_INT64 then
|
elseif num >= MIN_INT64 then
|
||||||
type = TYPE_INT64
|
type = TYPE_INT64
|
||||||
bytes = bit_converter.int64_to_bytes(num)
|
bytes = bit_converter.int64_to_bytes(num, self.order)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user