fix data_buffer:put_number

This commit is contained in:
MihailRis 2025-01-21 02:30:59 +03:00
parent 57356e1d64
commit e247902cc6
2 changed files with 9 additions and 9 deletions

View File

@ -313,8 +313,8 @@ function bit_converter.bytes_to_uint16(bytes, order)
return
bit.bor(
bit.lshift(bytes[1], 8),
bytes[2], 0)
bit.lshift(bytes[2], 8),
bytes[1], 0)
end
function bit_converter.bytes_to_int64(bytes, order)

View File

@ -144,31 +144,31 @@ function data_buffer:put_number(num)
if math.floor(num) ~= num then
type = TYPE_FLOAT64
bytes = bit_converter.float64_to_bytes(num)
bytes = bit_converter.float64_to_bytes(num, self.order)
elseif num == 0 then
type = TYPE_ZERO
bytes = { }
elseif num > 0 then
if num <= MAX_UINT16 then
type = TYPE_UINT16
bytes = bit_converter.uint16_to_bytes(num)
bytes = bit_converter.uint16_to_bytes(num, self.order)
elseif num <= MAX_UINT32 then
type = TYPE_UINT32
bytes = bit_converter.uint32_to_bytes(num)
bytes = bit_converter.uint32_to_bytes(num, self.order)
elseif num <= MAX_INT64 then
type = TYPE_INT64
bytes = bit_converter.int64_to_bytes(num)
bytes = bit_converter.int64_to_bytes(num, self.order)
end
elseif num < 0 then
if num >= MIN_INT16 then
type = TYPE_SINT16
bytes = bit_converter.sint16_to_bytes(num)
bytes = bit_converter.sint16_to_bytes(num, self.order)
elseif num >= MIN_INT32 then
type = TYPE_SINT32
bytes = bit_converter.sint32_to_bytes(num)
bytes = bit_converter.sint32_to_bytes(num, self.order)
elseif num >= MIN_INT64 then
type = TYPE_INT64
bytes = bit_converter.int64_to_bytes(num)
bytes = bit_converter.int64_to_bytes(num, self.order)
end
end