This commit is contained in:
2020-07-04 14:41:25 +08:00
parent 70c346d2c1
commit a8f02e4da5
3748 changed files with 587372 additions and 0 deletions

View File

@@ -0,0 +1,365 @@
do
require("public.class")
require("bio.BioType")
BioInputStream = {}
local B2Type = BioType.B2Type;
local IntB2TypeValueMap = BioType.IntB2TypeValueMap;
local StringB2TypeLenMap = BioType.StringB2TypeLenMap
local MapB2TypeSizeMap = BioType.MapB2TypeSizeMap
local ListB2TypeSizeMap = BioType.ListB2TypeSizeMap
local type = type
local sub = string.sub
local strbyte = string.byte
local strchar = string.char
--===================================================
--===================================================
--===================================================
-- 数据流
LuaB2InputStream = class("LuaB2InputStream");
function LuaB2InputStream:ctor(v)
self.bytes = v;
self.pos = 1;
end
function LuaB2InputStream:init(v)
self.bytes = v;
self.pos = 1;
end
function LuaB2InputStream:readByte()
local ret = strbyte(self.bytes, self.pos);
self.pos = self.pos + 1;
return ret;
end
function LuaB2InputStream:readBytes(len)
local ret = strbyte(self.bytes, self.pos, self.pos + len - 1);
self.pos = self.pos + len;
return ret;
end
function LuaB2InputStream:readString(len)
local ret = sub(self.bytes, self.pos, self.pos + len - 1);
self.pos = self.pos + len;
return ret;
end
function LuaB2InputStream:release()
self.bytes = nil;
self.pos = 1;
end
--===================================================
--===================================================
--===================================================
---public Void readObject (LuaB2InputStream s)
---@param optional LuaB2InputStream s
--[[
local is = LuaB2InputStream.new(os:toBytes());
local result = BioInputStream.readObject(is)
--]]
function BioInputStream.readObject (s)
local tag = BioInputStream.ReadByteTag(s);
if tag == B2Type.NULL then
return nil;
else
-- decode map
local mapSize = MapB2TypeSizeMap[tag]
if mapSize then
return BioInputStream.readMap(s, mapSize);
elseif tag == B2Type.HASHTABLE then
local len = BioInputStream.readInt(s);
return BioInputStream.readMap(s, len);
end
end
-- decode int
local intVal = IntB2TypeValueMap[tag]
if intVal then
return intVal;
elseif tag == B2Type.INT_N1 then
return -1;
elseif tag == B2Type.INT_8B then
local int = 0;
local int0 = BioInputStream.ReadByte(s)
if int0 >= 128 then
--字节是负数,里面存放的1字节是负数的补码,比如读出来是128 128=1000 0000对应signed char 是 -127而127=0111 1111
int = int0 - 256;
else
int = int0;
end
return int;
elseif tag == B2Type.INT_16B then
local int = 0;
--INT_16B
local int0 = BioInputStream.ReadByte(s)
local int1 = BioInputStream.ReadByte(s)
if int0 >= 128 then
--字节是负数,里面存放的2字节是负数的补码
int = (int0 * 256 + int1) - 65536;
else
int = (int0 * 256 + int1);
end
return int;
elseif tag == B2Type.INT_32B then
local int = 0;
--INT_32B
local int0 = BioInputStream.ReadByte(s)
local int1 = BioInputStream.ReadByte(s)
local int2 = BioInputStream.ReadByte(s)
local int3 = BioInputStream.ReadByte(s)
--字节是负数,里面存放的4字节是负数的补码
if int0 >= 128 then
int = (int0 * 16777216 + int1 * 65536 + int2 * 256 + int3) - 4294967296;
else
int = (int0 * 16777216 + int1 * 65536 + int2 * 256 + int3);
end
return int;
end
-- decode string
local strLen = StringB2TypeLenMap[tag]
if strLen then
return s:readString(strLen);
elseif tag == B2Type.STR then
strLen = BioInputStream.readInt(s);
return s:readString(strLen);
end
if tag == B2Type.BOOLEAN_TRUE then
return true;
elseif tag == B2Type.BOOLEAN_FALSE then
return false;
elseif tag == B2Type.BYTE_0 then
return 0;
elseif tag == B2Type.BYTE then
return BioInputStream.ReadByte(s);
elseif tag == B2Type.BYTES_0 then
return 0;
elseif tag == B2Type.BYTES then
local len = BioInputStream.readInt(s);
return BioInputStream.ReadBytes(s, len);
end
-- decode list
local listLen = ListB2TypeSizeMap[tag]
if listLen then
return BioInputStream.readList(s, listLen);
elseif tag == B2Type.VECTOR then
local len = BioInputStream.readInt(s);
return BioInputStream.readList(s, len);
end
if tag == B2Type.SHORT_0 then
return 0;
elseif tag == B2Type.SHORT_8B then
local int = 0;
local int0 = BioInputStream.ReadByte(s)
if int0 >= 128 then
--字节是负数,里面存放的1字节是负数的补码,比如读出来是128 128=1000 0000对应signed char 是 -127而127=0111 1111
int = int0 - 256;
else
int = int0;
end
return int;
elseif tag == B2Type.SHORT_16B then
local int = 0;
--INT_16B
local int0 = BioInputStream.ReadByte(s)
local int1 = BioInputStream.ReadByte(s)
if int0 >= 128 then
--字节是负数,里面存放的2字节是负数的补码
int = (int0 * 256 + int1) - 65536;
else
int = (int0 * 256 + int1);
end
return int;
elseif tag == B2Type.LONG_0 then
return 0;
elseif tag == B2Type.LONG_8B then
local int = 0;
local int0 = BioInputStream.ReadByte(s)
if int0 >= 128 then
--字节是负数,里面存放的1字节是负数的补码,比如读出来是128 128=1000 0000对应signed char 是 -127而127=0111 1111
int = int0 - 256;
else
int = int0;
end
return int;
elseif tag == B2Type.LONG_16B then
local int = 0;
--INT_16B
local int0 = BioInputStream.ReadByte(s)
local int1 = BioInputStream.ReadByte(s)
if int0 >= 128 then
--字节是负数,里面存放的2字节是负数的补码
int = (int0 * 256 + int1) - 65536;
else
int = (int0 * 256 + int1);
end
return int;
elseif tag == B2Type.LONG_32B then
local int = 0;
--INT_32B
local int0 = BioInputStream.ReadByte(s)
local int1 = BioInputStream.ReadByte(s)
local int2 = BioInputStream.ReadByte(s)
local int3 = BioInputStream.ReadByte(s)
--字节是负数,里面存放的4字节是负数的补码
if int0 >= 128 then
int = (int0 * 16777216 + int1 * 65536 + int2 * 256 + int3) - 4294967296;
else
int = (int0 * 16777216 + int1 * 65536 + int2 * 256 + int3);
end
return int;
elseif tag == B2Type.LONG_64B then
local int = 0
local int0 = BioInputStream.ReadByte(s)
local int1 = BioInputStream.ReadByte(s)
local int2 = BioInputStream.ReadByte(s)
local int3 = BioInputStream.ReadByte(s)
local int4 = BioInputStream.ReadByte(s)
local int5 = BioInputStream.ReadByte(s)
local int6 = BioInputStream.ReadByte(s)
local int7 = BioInputStream.ReadByte(s)
--字节是负数,里面存放的4字节是负数的补码
if int0 >= 128 then
--? 1 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 = (9223372036854775807 * 4 + 3)
--lua里表示不出来了只能这样写。
--实际上 大于900719925474099152bit) 的 long long 64在lua这边已经不是精确值了
int = (int0 * 72057594037927936 + int1 * 281474976710656 + int2 * 1099511627776 + int3 * 4294967296 + int4 * 16777216 + int5 * 65536 + int6 * 256 + int7) - (9223372036854775807 * 4 + 3);
else
int = (int0 * 72057594037927936 + int1 * 281474976710656 + int2 * 1099511627776 + int3 * 4294967296 + int4 * 16777216 + int5 * 65536 + int6 * 256 + int7)
end
return int
elseif tag == B2Type.DOUBLE_0 then
return 0;
elseif tag == B2Type.DOUBLE_64B then
local str = BioInputStream.readString(s)
return tonumber(str);
elseif tag == B2Type.INT_B2 then
return BioInputStream.readInt(s);
else
--//throw new IOException("unknow tag error then" + tag);
print("bio2 unknon type then==" .. tostring(tag));
end
return 0;
end
function BioInputStream.ReadByte(s)
if s == nil then
return nil;
end
return s:readByte();
end
function BioInputStream.ReadByteTag(s)
if s == nil then
return nil;
end
local int0 = s:readByte()
local int = 0;
if int0 >= 128 then
--字节是负数,里面存放的1字节是负数的补码,比如读出来是128 128=1000 0000对应signed char 是 -127而127=0111 1111
int = int0 - 256;
else
int = int0;
end
return int;
end
function BioInputStream.ReadBytes(s, len)
return s:readBytes(len);
end
function BioInputStream.readMap(s, n)
if n == nil or n <= 0 then
return {}
end
local ret = {};
for i = 1, n do
local key = BioInputStream.readObject(s);
local val = BioInputStream.readObject(s);
ret [key] = val;
end
return ret;
end
function BioInputStream.readString(s)
local tag = BioInputStream.ReadByteTag(s);
local strLen = StringB2TypeLenMap[tag]
if strLen then
return s:readString(strLen)
elseif tag == B2Type.STR then
strLen = BioInputStream.readInt(s);
return s:readString(strLen)
end
return "";
end
function BioInputStream.readInt(s)
local tag = BioInputStream.ReadByteTag(s);
local intVal = IntB2TypeValueMap[tag]
if intVal then
return intVal;
elseif tag == B2Type.INT_N1 then
return -1;
elseif tag == B2Type.INT_8B then
local int = 0;
local int0 = BioInputStream.ReadByte(s)
if int0 >= 128 then
--字节是负数,里面存放的1字节是负数的补码,比如读出来是128 128=1000 0000对应signed char 是 -127而127=0111 1111
int = int0 - 256;
else
int = int0;
end
return int;
elseif tag == B2Type.INT_16B then
local int = 0;
--INT_16B
local int0 = BioInputStream.ReadByte(s)
local int1 = BioInputStream.ReadByte(s)
if int0 >= 128 then
--字节是负数,里面存放的2字节是负数的补码
int = (int0 * 256 + int1) - 65536;
else
int = (int0 * 256 + int1);
end
return int;
elseif tag == B2Type.INT_32B then
local int = 0;
--INT_32B
local int0 = BioInputStream.ReadByte(s)
local int1 = BioInputStream.ReadByte(s)
local int2 = BioInputStream.ReadByte(s)
local int3 = BioInputStream.ReadByte(s)
--字节是负数,里面存放的4字节是负数的补码
if int0 >= 128 then
int = (int0 * 16777216 + int1 * 65536 + int2 * 256 + int3) - 4294967296;
else
int = (int0 * 16777216 + int1 * 65536 + int2 * 256 + int3);
end
return int;
end
return 0;
end
function BioInputStream.readList(s, n)
if n == nil or n <= 0 then
return {}
end
local ret = {};
for i = 1, n do
local val = BioInputStream.readObject(s);
table.insert(ret, val);
end
return ret;
end
--------------------------------------------
return BioInputStream;
end

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: a77446b9516174488972afb59d51d2ab
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,334 @@
do
require("public.class")
require("bio.BioType")
BioOutputStream = {}
local B2Type = BioType.B2Type;
local IntB2TypeList = BioType.IntB2TypeList;
local StringB2TypeList = BioType.StringB2TypeList;
local MapB2TypeList = BioType.MapB2TypeList;
local ListB2TypeList = BioType.ListB2TypeList
local type = type
local sub = string.sub
local strupper = string.upper;
local strlen = string.len;
local strbyte = string.byte
local strchar = string.char
local floorInt = math.floor
--===================================================
--===================================================
-- 数据流
LuaB2OutputStream = class("LuaB2OutputStream");
function LuaB2OutputStream:ctor(v)
self.content = {}
end
function LuaB2OutputStream:init(v)
self.content = {}
end
function LuaB2OutputStream:writeByte(v)
table.insert(self.content, strchar(v))
end
function LuaB2OutputStream:writeString(v)
table.insert(self.content, v)
end
function LuaB2OutputStream:toBytes()
--local ret = "";
--for i, v in ipairs(self.content) do
-- ret = ret .. v;
--end
return table.concat(self.content, "");
end
function LuaB2OutputStream:release()
self.content = {};
end
--===================================================
--===================================================
--===================================================
-- 原始数据类型
BioOutputStream.DataType = {
NIL = "nil",
BOOLEAN = "boolean",
STRING = "string",
NUMBER = "number",
LONG = "long",
DOUBLE = "double",
USERDATA = "userdata",
FUNCTION = "function",
THREAD = "thread",
TABLE = "table",
INT4B = "int4b",
INT16B = "int16b",
INT32B = "int32b",
}
---@public 取得数据的类型主要是对number做了处理
function BioOutputStream.getDataType(obj)
--nil, boolean, number, string, userdata, function, thread, table
local val = nil;
local t = type(obj);
val = BioOutputStream.DataType[strupper(type(obj))];
if val == nil then
val = "undefined";
end
return val;
end
function BioOutputStream.getNumberType(obj)
local val = nil;
local t = type(obj);
if t == "number" then
local minInt = floorInt(obj);
if minInt == obj then
-- 说明是整数
if (obj >= -128 and obj <= 127) then
val = BioOutputStream.DataType.INT4B
elseif (obj >= -32768 and obj <= 32767) then
val = BioOutputStream.DataType.INT16B
elseif (obj >= -2147483648 and obj <= 2147483647) then
val = BioOutputStream.DataType.INT32B
else
val = BioOutputStream.DataType.LONG
end
else
val = BioOutputStream.DataType.DOUBLE
end
end
return val;
end
---@public 返回table是否为一个array 第二返回值如查是array的时候是table的count
function BioOutputStream.isArray(t)
if t == nil then
return false, 0;
end
local i = 0
local ret = true;
for _ in pairs(t) do
i = i + 1
if t[i] == nil then
ret = false
end
end
return ret, i
end
--===================================================
---public Void writeObject (LuaB2OutputStream os, obj)
---@param optional LuaB2OutputStream os
---@param optional object obj
--[[
local os = LuaB2OutputStream.new();
BioOutputStream.writeObject(os, map)
local bytes = os:toBytes()
--]]
function BioOutputStream.writeObject (os, obj)
if os == nil then
os = LuaB2OutputStream.new();
end
local objType = BioOutputStream.getDataType(obj)
if (objType == BioOutputStream.DataType.NIL) then
BioOutputStream.writeNil(os)
elseif (objType == BioOutputStream.DataType.TABLE) then
BioOutputStream.writeMap(os, obj);
elseif (objType == BioOutputStream.DataType.NUMBER) then
BioOutputStream.writeNumber(os, obj);
elseif (objType == BioOutputStream.DataType.STRING) then
BioOutputStream.writeString(os, obj);
elseif (objType == BioOutputStream.DataType.BOOLEAN) then
BioOutputStream.writeBoolean(os, obj);
else
--//throw new IOException("unsupported obj then" + obj);
print("B2IO unsupported error then type=[" .. tostring(objType) .. "] val=[" .. obj .. "]");
end
end
function BioOutputStream.writeNil(os)
BioOutputStream.WriteByte(os, B2Type.NULL);
return os;
end
function BioOutputStream.WriteByte(os, v)
local v2 = v;
if v < 0 then
v2 = v + 256;
end
os:writeByte(v2)
return os;
end
function BioOutputStream.writeNumber(os, v)
local numType = BioOutputStream.getNumberType(v)
if numType == BioOutputStream.DataType.INT4B or
numType == BioOutputStream.DataType.INT16B or
numType == BioOutputStream.DataType.INT32B then
BioOutputStream.writeInt(os, v)
elseif numType == BioOutputStream.DataType.LONG then
BioOutputStream.writeLong(os, v);
elseif numType == BioOutputStream.DataType.DOUBLE then
BioOutputStream.writeDouble(os, v);
end
return os;
end
function BioOutputStream.writeInt(os, v)
if v == -1 then
BioOutputStream.WriteByte(os, B2Type.INT_N1);
elseif v >= 0 and v <= 32 then
local t = IntB2TypeList[v + 1]
BioOutputStream.WriteByte(os, t);
else
if (v >= -128 and v <= 127) then
BioOutputStream.WriteByte(os, B2Type.INT_8B);
BioOutputStream.WriteByte(os, v);
elseif (v >= -32768 and v <= 32767) then
BioOutputStream.WriteByte(os, B2Type.INT_16B);
local v2 = v;
--if v < 0 then
-- v2 = v + 65536
--end
BioOutputStream.WriteByte(os, math.floor(v2 / 256));
BioOutputStream.WriteByte(os, v2 % 256);
else
BioOutputStream.WriteByte(os, B2Type.INT_32B);
local v2 = v;
--if v < 0 then
-- v2 = v + 4294967296
--end
BioOutputStream.WriteByte(os, math.floor(v2 / 16777216));
v2 = v2 % 16777216
BioOutputStream.WriteByte(os, math.floor(v2 / 65536));
v2 = v2 % 65536
BioOutputStream.WriteByte(os, math.floor(v2 / 256));
BioOutputStream.WriteByte(os, v2 % 256);
end
end
return os;
end
function BioOutputStream.writeLong(os, v)
BioOutputStream.WriteByte(os, B2Type.LONG_64B);
local v2 = v;
--if v < 0 then
-- v2 = v + 4294967296
--end
BioOutputStream.WriteByte(os, math.floor(v2 / 72057594037927936));
v2 = v2 % 72057594037927936
BioOutputStream.WriteByte(os, math.floor(v2 / 281474976710656));
v2 = v2 % 281474976710656
BioOutputStream.WriteByte(os, math.floor(v2 / 1099511627776));
v2 = v2 % 1099511627776
BioOutputStream.WriteByte(os, math.floor(v2 / 4294967296));
v2 = v2 % 4294967296
BioOutputStream.WriteByte(os, math.floor(v2 / 16777216));
v2 = v2 % 16777216
BioOutputStream.WriteByte(os, math.floor(v2 / 65536));
v2 = v2 % 65536
BioOutputStream.WriteByte(os, math.floor(v2 / 256));
BioOutputStream.WriteByte(os, v2 % 256);
return os;
end
function BioOutputStream.writeDouble(os, v)
BioOutputStream.WriteByte(os, B2Type.DOUBLE_64B);
BioOutputStream.writeString(os, tostring(v));
return os;
end
function BioOutputStream.writeString(os, v)
if (v == nil) then
BioOutputStream.writeNil(os);
return os;
end
local len = strlen(v);
local t = StringB2TypeList[len + 1]
if t then
BioOutputStream.WriteByte(os, t);
os:writeString(v);
else
BioOutputStream.WriteByte(os, B2Type.STR);
BioOutputStream.writeInt(os, len);
os:writeString(v);
end
end
function BioOutputStream.writeBoolean(os, v)
if v then
BioOutputStream.WriteByte(os, B2Type.BOOLEAN_TRUE);
else
BioOutputStream.WriteByte(os, B2Type.BOOLEAN_FALSE);
end
return os;
end
function BioOutputStream.writeMap(os, v)
if (v == nil) then
BioOutputStream.writeNil(os);
end
local isArray, len = BioOutputStream.isArray(v)
if isArray then
if len <= 24 then
BioOutputStream.WriteByte(os, ListB2TypeList[len + 1]);
else
BioOutputStream.WriteByte(os, B2Type.VECTOR);
BioOutputStream.writeInt(os, len);
end
for i, val in ipairs(v) do
BioOutputStream.writeObject(os, val);
end
else
if len <= 15 then
BioOutputStream.WriteByte(os, MapB2TypeList[len + 1]);
else
BioOutputStream.WriteByte(os, B2Type.HASHTABLE);
BioOutputStream.writeInt(os, len);
end
for key, val in pairs(v) do
BioOutputStream.writeObject(os, key);
BioOutputStream.writeObject(os, val);
end
end
end
--两个字节的and 操作
function BioOutputStream.byte_xor(a, b)
local bit_value_tb = {
[8] = 2 ^ 7;
[7] = 2 ^ 6;
[6] = 2 ^ 5;
[5] = 2 ^ 4;
[4] = 2 ^ 3;
[3] = 2 ^ 2;
[2] = 2 ^ 1;
[1] = 2 ^ 0; };
local value = 0;
for i = 8, 1, -1 do
local bit_value = bit_value_tb[i];
if a >= bit_value and b < bit_value then
value = value + bit_value;
elseif a < bit_value and b >= bit_value then
value = value + bit_value;
end
if a >= bit_value then
a = a - bit_value;
end
if b >= bit_value then
b = b - bit_value;
end
end
return value;
end
--------------------------------------------
return BioOutputStream;
end

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 70efb61333b284cdbb77ccc003ce2f27
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,399 @@
do
BioType = {}
-- bio的类型定义
BioType.B2Type = {
--//null
NULL = 0,
--//bool
BOOLEAN_TRUE = 1,
BOOLEAN_FALSE = 2,
--// byte
BYTE_0 = 3,
BYTE = 4,
--// short
SHORT_0 = 5,
SHORT_8B = 6,
SHORT_16B = 7,
--//int b32 b24 b16 b8
INT_0 = 8,
INT_8B = 9,
INT_16B = 10,
INT_32B = 11,
INT_N1 = 12,
INT_1 = 13,
INT_2 = 14,
INT_3 = 15,
INT_4 = 16,
INT_5 = 17,
INT_6 = 18,
INT_7 = 19,
INT_8 = 20,
INT_9 = 21,
INT_10 = 22,
INT_11 = 23,
INT_12 = 24,
INT_13 = 25,
INT_14 = 26,
INT_15 = 27,
INT_16 = 28,
INT_17 = 29,
INT_18 = 30,
INT_19 = 31,
INT_20 = 32,
INT_21 = 33,
INT_22 = 34,
INT_23 = 35,
INT_24 = 36,
INT_25 = 37,
INT_26 = 38,
INT_27 = 39,
INT_28 = 40,
INT_29 = 41,
INT_30 = 42,
INT_31 = 43,
INT_32 = 44,
--//long b64 b56 b48 b40 b32 b24 b16 b8
LONG_0 = 45,
LONG_8B = 46,
LONG_16B = 47,
LONG_32B = 48,
LONG_64B = 49,
--//double b64 b56 b48 b40 b32 b24 b16 b8
DOUBLE_0 = 50,
--// DOUBLE_8B = 51,
--// DOUBLE_16B = 52,
--// DOUBLE_32B = 53,
DOUBLE_64B = 54,
--//STR [bytes]
STR_0 = 55,
STR = 56,
STR_1 = 57,
STR_2 = 58,
STR_3 = 59,
STR_4 = 60,
STR_5 = 61,
STR_6 = 62,
STR_7 = 63,
STR_8 = 64,
STR_9 = 65,
STR_10 = 66,
STR_11 = 67,
STR_12 = 68,
STR_13 = 69,
STR_14 = 70,
STR_15 = 71,
STR_16 = 72,
STR_17 = 73,
STR_18 = 74,
STR_19 = 75,
STR_20 = 76,
STR_21 = 77,
STR_22 = 78,
STR_23 = 79,
STR_24 = 80,
STR_25 = 81,
STR_26 = 82,
--//Bytes [int len, byte[]]
BYTES_0 = 83,
BYTES = 84,
--//VECTOR [int len, v...]
VECTOR_0 = 85,
VECTOR = 86,
VECTOR_1 = 87,
VECTOR_2 = 88,
VECTOR_3 = 89,
VECTOR_4 = 90,
VECTOR_5 = 91,
VECTOR_6 = 92,
VECTOR_7 = 93,
VECTOR_8 = 94,
VECTOR_9 = 95,
VECTOR_10 = 96,
VECTOR_11 = 97,
VECTOR_12 = 98,
VECTOR_13 = 99,
VECTOR_14 = 100,
VECTOR_15 = 101,
VECTOR_16 = 102,
VECTOR_17 = 103,
VECTOR_18 = 104,
VECTOR_19 = 105,
VECTOR_20 = 106,
VECTOR_21 = 107,
VECTOR_22 = 108,
VECTOR_23 = 109,
VECTOR_24 = 110,
--//HASHTABLE [int len, k, v...]
HASHTABLE_0 = 111,
HASHTABLE = 112,
HASHTABLE_1 = 113,
HASHTABLE_2 = 114,
HASHTABLE_3 = 115,
HASHTABLE_4 = 116,
HASHTABLE_5 = 117,
HASHTABLE_6 = 118,
HASHTABLE_7 = 119,
HASHTABLE_8 = 120,
HASHTABLE_9 = 121,
HASHTABLE_10 = 122,
HASHTABLE_11 = 123,
HASHTABLE_12 = 124,
HASHTABLE_13 = 125,
HASHTABLE_14 = 126,
HASHTABLE_15 = 127,
--// int[]
INT_ARRAY = -9,
INT_ARRAY_0 = -10,
INT_ARRAY_1 = -11,
INT_ARRAY_2 = -12,
INT_ARRAY_3 = -13,
INT_ARRAY_4 = -14,
INT_ARRAY_5 = -15,
INT_ARRAY_6 = -16,
INT_ARRAY_7 = -17,
INT_ARRAY_8 = -18,
INT_ARRAY_9 = -19,
INT_ARRAY_10 = -20,
INT_ARRAY_11 = -21,
INT_ARRAY_12 = -22,
INT_ARRAY_13 = -23,
INT_ARRAY_14 = -24,
INT_ARRAY_15 = -25,
INT_ARRAY_16 = -26,
--// int[][]
INT_2D_ARRAY = -29,
INT_2D_ARRAY_0 = -30,
JAVA_DATE = -31,
JAVA_OBJECT = -32,
--//b2int
INT_B2 = -33,
}
local B2Type = BioType.B2Type;
BioType.IntB2TypeList = {
B2Type.INT_0,
B2Type.INT_1,
B2Type.INT_2,
B2Type.INT_3,
B2Type.INT_4,
B2Type.INT_5,
B2Type.INT_6,
B2Type.INT_7,
B2Type.INT_8,
B2Type.INT_9,
B2Type.INT_10,
B2Type.INT_11,
B2Type.INT_12,
B2Type.INT_13,
B2Type.INT_14,
B2Type.INT_15,
B2Type.INT_16,
B2Type.INT_17,
B2Type.INT_18,
B2Type.INT_19,
B2Type.INT_20,
B2Type.INT_21,
B2Type.INT_22,
B2Type.INT_23,
B2Type.INT_24,
B2Type.INT_25,
B2Type.INT_26,
B2Type.INT_27,
B2Type.INT_28,
B2Type.INT_29,
B2Type.INT_30,
B2Type.INT_31,
B2Type.INT_32,
}
BioType.IntB2TypeValueMap = {
[B2Type.INT_0] = 0,
[B2Type.INT_1] = 1,
[B2Type.INT_2] = 2,
[B2Type.INT_3] = 3,
[B2Type.INT_4] = 4,
[B2Type.INT_5] = 5,
[B2Type.INT_6] = 6,
[B2Type.INT_7] = 7,
[B2Type.INT_8] = 8,
[B2Type.INT_9] = 9,
[B2Type.INT_10] = 10,
[B2Type.INT_11] = 11,
[B2Type.INT_12] = 12,
[B2Type.INT_13] = 13,
[B2Type.INT_14] = 14,
[B2Type.INT_15] = 15,
[B2Type.INT_16] = 16,
[B2Type.INT_17] = 17,
[B2Type.INT_18] = 18,
[B2Type.INT_19] = 19,
[B2Type.INT_20] = 20,
[B2Type.INT_21] = 21,
[B2Type.INT_22] = 22,
[B2Type.INT_23] = 23,
[B2Type.INT_24] = 24,
[B2Type.INT_25] = 25,
[B2Type.INT_26] = 26,
[B2Type.INT_27] = 27,
[B2Type.INT_28] = 28,
[B2Type.INT_29] = 29,
[B2Type.INT_30] = 30,
[B2Type.INT_31] = 31,
[B2Type.INT_32] = 32,
}
BioType.StringB2TypeList = {
B2Type.STR_0,
B2Type.STR_1,
B2Type.STR_2,
B2Type.STR_3,
B2Type.STR_4,
B2Type.STR_5,
B2Type.STR_6,
B2Type.STR_7,
B2Type.STR_8,
B2Type.STR_9,
B2Type.STR_10,
B2Type.STR_11,
B2Type.STR_12,
B2Type.STR_13,
B2Type.STR_14,
B2Type.STR_15,
B2Type.STR_16,
B2Type.STR_17,
B2Type.STR_18,
B2Type.STR_19,
B2Type.STR_20,
B2Type.STR_21,
B2Type.STR_22,
B2Type.STR_23,
B2Type.STR_24,
B2Type.STR_25,
B2Type.STR_26,
}
BioType.StringB2TypeLenMap = {
[B2Type.STR_0] = 0,
[B2Type.STR_1] = 1,
[B2Type.STR_2] = 2,
[B2Type.STR_3] = 3,
[B2Type.STR_4] = 4,
[B2Type.STR_5] = 5,
[B2Type.STR_6] = 6,
[B2Type.STR_7] = 7,
[B2Type.STR_8] = 8,
[B2Type.STR_9] = 9,
[B2Type.STR_10] = 10,
[B2Type.STR_11] = 11,
[B2Type.STR_12] = 12,
[B2Type.STR_13] = 13,
[B2Type.STR_14] = 14,
[B2Type.STR_15] = 15,
[B2Type.STR_16] = 16,
[B2Type.STR_17] = 17,
[B2Type.STR_18] = 18,
[B2Type.STR_19] = 19,
[B2Type.STR_20] = 20,
[B2Type.STR_21] = 21,
[B2Type.STR_22] = 22,
[B2Type.STR_23] = 23,
[B2Type.STR_24] = 24,
[B2Type.STR_25] = 25,
[B2Type.STR_26] = 26,
}
BioType.MapB2TypeList = {
B2Type.HASHTABLE_0,
B2Type.HASHTABLE_1,
B2Type.HASHTABLE_2,
B2Type.HASHTABLE_3,
B2Type.HASHTABLE_4,
B2Type.HASHTABLE_5,
B2Type.HASHTABLE_6,
B2Type.HASHTABLE_7,
B2Type.HASHTABLE_8,
B2Type.HASHTABLE_9,
B2Type.HASHTABLE_10,
B2Type.HASHTABLE_11,
B2Type.HASHTABLE_12,
B2Type.HASHTABLE_13,
B2Type.HASHTABLE_14,
B2Type.HASHTABLE_15,
}
BioType.MapB2TypeSizeMap = {
[B2Type.HASHTABLE_0] = 0,
[B2Type.HASHTABLE_1] = 1,
[B2Type.HASHTABLE_2] = 2,
[B2Type.HASHTABLE_3] = 3,
[B2Type.HASHTABLE_4] = 4,
[B2Type.HASHTABLE_5] = 5,
[B2Type.HASHTABLE_6] = 6,
[B2Type.HASHTABLE_7] = 7,
[B2Type.HASHTABLE_8] = 8,
[B2Type.HASHTABLE_9] = 9,
[B2Type.HASHTABLE_10] = 10,
[B2Type.HASHTABLE_11] = 11,
[B2Type.HASHTABLE_12] = 12,
[B2Type.HASHTABLE_13] = 13,
[B2Type.HASHTABLE_14] = 14,
[B2Type.HASHTABLE_15] = 15,
}
BioType.ListB2TypeList = {
B2Type.VECTOR_0,
B2Type.VECTOR_1,
B2Type.VECTOR_2,
B2Type.VECTOR_3,
B2Type.VECTOR_4,
B2Type.VECTOR_5,
B2Type.VECTOR_6,
B2Type.VECTOR_7,
B2Type.VECTOR_8,
B2Type.VECTOR_9,
B2Type.VECTOR_10,
B2Type.VECTOR_11,
B2Type.VECTOR_12,
B2Type.VECTOR_13,
B2Type.VECTOR_14,
B2Type.VECTOR_15,
B2Type.VECTOR_16,
B2Type.VECTOR_17,
B2Type.VECTOR_18,
B2Type.VECTOR_19,
B2Type.VECTOR_20,
B2Type.VECTOR_21,
B2Type.VECTOR_22,
B2Type.VECTOR_23,
B2Type.VECTOR_24,
}
BioType.ListB2TypeSizeMap = {
[B2Type.VECTOR_0] = 0,
[B2Type.VECTOR_1] = 1,
[B2Type.VECTOR_2] = 2,
[B2Type.VECTOR_3] = 3,
[B2Type.VECTOR_4] = 4,
[B2Type.VECTOR_5] = 5,
[B2Type.VECTOR_6] = 6,
[B2Type.VECTOR_7] = 7,
[B2Type.VECTOR_8] = 8,
[B2Type.VECTOR_9] = 9,
[B2Type.VECTOR_10] = 10,
[B2Type.VECTOR_11] = 11,
[B2Type.VECTOR_12] = 12,
[B2Type.VECTOR_13] = 13,
[B2Type.VECTOR_14] = 14,
[B2Type.VECTOR_15] = 15,
[B2Type.VECTOR_16] = 16,
[B2Type.VECTOR_17] = 17,
[B2Type.VECTOR_18] = 18,
[B2Type.VECTOR_19] = 19,
[B2Type.VECTOR_20] = 20,
[B2Type.VECTOR_21] = 21,
[B2Type.VECTOR_22] = 22,
[B2Type.VECTOR_23] = 23,
[B2Type.VECTOR_24] = 24,
}
return BioType;
end

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: e28d0450accc245d396635c32688a32b
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,135 @@
-- bio 工具
do
require("bio.BioInputStream")
require("bio.BioOutputStream")
require("public.CLLPool")
BioUtl = {}
---@type LuaB2InputStream
local inputStreemPool
local outputStreemPool
local isInited = false
function BioUtl.init()
if isInited then
return
end
isInited = true
inputStreemPool = CLLPool.new(LuaB2InputStream)
outputStreemPool = CLLPool.new(LuaB2OutputStream)
end
function BioUtl.writeObject(obj)
BioUtl.init()
--local os = LuaB2OutputStream.new()
local os = outputStreemPool:borrow()
os:init()
local status, result = pcall(BioOutputStream.writeObject, os, obj)
if status then
local bytes = os:toBytes()
os:release()
--os = nil
outputStreemPool:retObj(os)
return bytes
else
os:release()
outputStreemPool:retObj(os)
print(result)
return nil
end
end
function BioUtl.readObject(bytes)
if bytes == nil then
printe("BioUtl.readObject, the param is nil")
return nil
end
BioUtl.init()
--local is = LuaB2InputStream.new(bytes)
local is = inputStreemPool:borrow()
is:init(bytes)
local status, result = pcall(BioInputStream.readObject, is)
if status then
local readLen = is.pos - 1 -- 读取了多长
is:release()
--is = nil
inputStreemPool:retObj(is)
return result, readLen
else
is:release()
inputStreemPool:retObj(is)
print(result)
return nil
end
end
function BioUtl.int2bio(val)
BioUtl.init()
--local os = LuaB2OutputStream.new()
local os = outputStreemPool:borrow()
os:init()
local status, result = pcall(BioOutputStream.writeInt, os, val)
if status then
local bytes = os:toBytes()
os:release()
--os = nil
outputStreemPool:retObj(os)
return bytes
else
os:release()
outputStreemPool:retObj(os)
print(result)
return nil
end
end
function BioUtl.bio2int(bytes)
if bytes == nil then
return 0
end
return BioUtl.bio2number(bytes)
end
function BioUtl.long2bio(val)
BioUtl.init()
--local os = LuaB2OutputStream.new()
local os = outputStreemPool:borrow()
os:init()
local status, result = pcall(BioOutputStream.writeLong, os, val)
if status then
local bytes = os:toBytes()
os:release()
--os = nil
outputStreemPool:retObj(os)
return bytes
else
os:release()
outputStreemPool:retObj(os)
print(result)
return nil
end
end
function BioUtl.bio2long(bytes)
return BioUtl.bio2number(bytes)
end
function BioUtl.bio2number(bytes)
if bytes == nil then
return 0
end
local n = BioUtl.readObject(bytes)
if type(n) == "number" then
return n
else
return 0
end
end
function BioUtl.number2bio(n)
return BioUtl.writeObject(n)
end
--------------------------------------------
return BioUtl
end

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 6ed9f33789c144029b119d18897f794a
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: