September Morn Update
This commit is contained in:
parent
4e2d22a71d
commit
aac6731f2c
6856 changed files with 141342 additions and 21127 deletions
37
Task/Object-serialization/Phix/object-serialization.phix
Normal file
37
Task/Object-serialization/Phix/object-serialization.phix
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
include builtins\serialize.e
|
||||
|
||||
function randobj()
|
||||
-- test function (generate some random garbage)
|
||||
object res
|
||||
if rand(10)<=3 then -- make sequence[1..3]
|
||||
res = {}
|
||||
for i=1 to rand(3) do
|
||||
res = append(res,randobj())
|
||||
end for
|
||||
elsif rand(10)<=3 then -- make string
|
||||
res = repeat('A'+rand(10),rand(10))
|
||||
else
|
||||
res = rand(10)/2 -- half int/half float
|
||||
end if
|
||||
return res
|
||||
end function
|
||||
|
||||
object o1 = randobj(),
|
||||
o2 = randobj(),
|
||||
o3 = randobj()
|
||||
|
||||
pp({o1,o2,o3},{pp_Nest,1})
|
||||
integer fh = open("objects.dat", "wb")
|
||||
puts(fh, serialize(o1))
|
||||
puts(fh, serialize(o2))
|
||||
puts(fh, serialize(o3))
|
||||
close(fh)
|
||||
|
||||
?"==="
|
||||
|
||||
fh = open("objects.dat", "rb")
|
||||
?deserialize(fh)
|
||||
?deserialize(fh)
|
||||
?deserialize(fh)
|
||||
close(fh)
|
||||
{} = delete_file("objects.dat")
|
||||
Loading…
Add table
Add a link
Reference in a new issue