Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
50
Task/Object-serialization/Objeck/object-serialization.objeck
Normal file
50
Task/Object-serialization/Objeck/object-serialization.objeck
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
bundle Default {
|
||||
class Thingy {
|
||||
@id : Int;
|
||||
|
||||
New(id : Int) {
|
||||
@id := id;
|
||||
}
|
||||
|
||||
method : public : Print() ~ Nil {
|
||||
@id->PrintLine();
|
||||
}
|
||||
}
|
||||
|
||||
class Person from Thingy {
|
||||
@name : String;
|
||||
|
||||
New(id : Int, name : String) {
|
||||
Parent(id);
|
||||
@name := name;
|
||||
}
|
||||
|
||||
method : public : Print() ~ Nil {
|
||||
@id->PrintLine();
|
||||
@name->PrintLine();
|
||||
}
|
||||
}
|
||||
|
||||
class Serial {
|
||||
function : Main(args : String[]) ~ Nil {
|
||||
t := Thingy->New(7);
|
||||
p := Person->New(13, "Bush");
|
||||
|
||||
s := IO.Serializer->New();
|
||||
s->Write(t->As(Base));
|
||||
s->Write(p->As(Base));
|
||||
|
||||
writer := IO.FileWriter->New("objects.dat");
|
||||
writer->WriteBuffer(s->Serialize());
|
||||
writer->Close();
|
||||
|
||||
buffer := IO.FileReader->ReadBinaryFile("objects.dat");
|
||||
d := IO.Deserializer->New(buffer);
|
||||
|
||||
t2 := d->ReadObject()->As(Thingy);
|
||||
t2->Print();
|
||||
p2 := d->ReadObject()->As(Person);
|
||||
p2->Print();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue