Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
25
Task/Object-serialization/Nim/object-serialization.nim
Normal file
25
Task/Object-serialization/Nim/object-serialization.nim
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import marshal, streams
|
||||
|
||||
type
|
||||
Base = object of RootObj
|
||||
name: string
|
||||
Descendant = object of Base
|
||||
proc newBase(): Base = Base(name: "base")
|
||||
proc newDescendant(): Descendant = Descendant(name: "descend")
|
||||
proc print(obj: Base) =
|
||||
echo(obj.name)
|
||||
|
||||
var
|
||||
base = newBase()
|
||||
descendant = newDescendant()
|
||||
print(base)
|
||||
print(descendant)
|
||||
|
||||
var strm = newFileStream("objects.dat", fmWrite)
|
||||
store(strm, (base, descendant))
|
||||
strm.close()
|
||||
|
||||
var t: (Base, Descendant)
|
||||
load(newFileStream("objects.dat", fmRead), t)
|
||||
print(t[0])
|
||||
print(t[1])
|
||||
Loading…
Add table
Add a link
Reference in a new issue