This repository was archived by the owner on Jul 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.lua
More file actions
137 lines (88 loc) · 1.75 KB
/
Copy pathmain.lua
File metadata and controls
137 lines (88 loc) · 1.75 KB
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
pcall(function() require "import" end)
-- require module and use global env
-- only use true in the debug env
require "table_serialize" (true)
local dump = dump or print
local main_dir=debug.getinfo(function()end).short_src
if main_dir~=nil then
main_dir = main_dir:match("(.+)/main.lua")
end
local test_path
if main_dir~=nil then
test_path=main_dir.."/test.ltb"
else
test_path="test.ltb"
end
do
ByteStream(test_path,"w")
:writeInt(1243)
:close()
end
do
local stream=
ByteStream(test_path,"r") --
print(stream:readInt())
stream:close()
end
do
require "table_serialize"
local t = {
test=13,
aaa="6767",
[676]=4646,
t = {},
a = "t",
cc=function ()
end,
x = { a = 36 }
}
t.t.t=t
local reader=table_serialize.Reader(t,"t")
local lr=reader:convertToIrTable()
local writer=table_serialize.Writer(test_path)
writer:write(lr)
writer:close()
end
do
-- signature 15bytes
-- integrity 6bytes
-- end_int 8bytes
-- end_num 8bytes (double)
-- version 4bytes (int)
local stream=
ByteStream(test_path,"r") --
--stream:read(15)
-- (stream:read(6))
-- (stream:readLong())
-- (stream:readDouble())
-- (stream:readInt())
stream:close()
end
do
local reader=Reader(test_path,"rb")
local lr=reader:convertToIrTable()
local source_table=IrConvert.convertIrToTable(lr)
print(dump(source_table))
end
do
local String = String or function() end
local t = {
test=13,
aaa="6767",
[676]=4646,
t = {},
a = "t",
test=String(),
cc=function ()
end,
x = { a = 36 }
}
t.t.t=t
local binary=Serialize.serialize(
t,"wb",test_path)
print(binary)
end
do
local lr=Serialize.unSerialize(test_path,"rb")
print(dump(lr))
end