| Command line handling | categories I/O, Modules and System Interface Serialization |
Platform Miscellaneous |
XL CLAIRE distribution comes with the module Serialize that provide generic mechanism (using CLAIRE reflection) for writing/reading CLAIRE data structures to/from a communication port. The ability to convert a data structure to a binary stream can be used for Inter Process Communication (IPC) to exchange objects over a network or to store on the hard disk a set of object that belong to a user session. For instance :
| b :: blob!() (serialize(b, 12), serialize(b, list(12))) (assert(unserialize(b) = 12) (assert(unserialize(b) = list(12)) |
| A <: ephemeral_object() B <: ephemeral_object(a:A) b :: blob!() (serialize(b, false, B(a = A()))) (assert(known?(a, unserialize(b)))) |
| serialize(b, x) <=> serialize(b, false, x) |
| [fork_apply(p:property, l:list) : any -> let s := socketpair() // create a pipe in (if forker?() // parent process : (fclose(s[2]), let x := (try unserialize(s[1]) // read the result on the pipe catch any exception!()), // and catch the error if any st := waitpid(forked()) // wait for child termination in (if (st[1] != WEXITED & st[3] != 0) error("fork_apply(~S, ~S) failed with ~S", p, l, st), fclose(s[1]), case x (exception close(x)), x)) else // child process : (fclose(s[1]), try serialize(s[2], apply(p, l)) // actually apply catch any serialize(s[2], exception!()), exit(0), 0))] |
| let c := client!("host.domain.com", 10000), ctx := serialize_context!() in (while (...) (serialize(c, ctx, ...), ...)) |
| categories | Serialization | normal dispatch | [XL] Serialize method |
serialize(p, self) is equivalent to serialize(p, true, self)
| categories | Serialization | normal dispatch | [XL] Serialize method |
When top? is true serialize(p,top?,self) writes on p a binary representation of self. When top? is false serialize(p,top?,self) writes on p the object tree starting at self (that is the object self and related objects). The data written on p can then be handle with unserialize to build back the object tree.
| categories | Serialization | normal dispatch | [XL] Serialize method |
unserialize(p) creates an object tree from a serialized data stream (as done with serialize). The calling process should have a correct reading environment, that is the same class definition that was used by the process that serialized the data.