A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.racket-lang.org/reference/serialization.html below:

13.9 Serialization

13.9 Serialization🔗ℹ

Returns

#t

if

v

appears to be serializable, without checking the content of compound values, and

#f

otherwise. See

serialize

for an enumeration of serializable values.

(serialize       v      [ #:relative-directory relative-to       #:deserialize-relative-directory deserialize-relative-to])  
 â†’ any   v : serializable?    deserialize-relative-to   :         =   relative-to

Returns a value that encapsulates the value

v

. This value includes only readable values, so it can be written to a stream with

write

or

s-exp->fasl

, later read from a stream using

read

or

fasl->s-exp

, and then converted to a value like the original using

deserialize

. Serialization followed by deserialization produces a value with the same graph structure and mutability as the original value, but the serialized value is a plain tree (i.e., no sharing).

The following kinds of values are serializable:

Serialization succeeds for a compound value, such as a pair, only if all content of the value is serializable. If a value given to serialize is not completely serializable, the exn:fail:contract exception is raised.

If v contains a cycle (i.e., a collection of objects that are all reachable from each other), then v can be serialized only if the cycle includes a mutable value, where a prefab structure counts as mutable only if all of its fields are mutable.

If relative-to is not #f, then paths to serialize that extend the path in relative-to are recorded in relative and platform-independent form. The possible values and treatment of relative-to are the same as for current-write-relative-directory.

If deserialize-relative-to is not #f, then any paths to deserializers as extracted via prop:serializable are recorded in relative form. Note that relative-to and deserialize-relative-to are independent, but deserialize-relative-to defaults to relative-to.

The serialize and deserialize functions currently do not handle certain cyclic values that read and write can handle, such as '#0=(#0#).

See deserialize for information on the format of serialized data.

Changed in version 6.5.0.4 of package base: Added keywords and regexp values as serializable.
Changed in version 7.0.0.6: Added the #:relative-directory and #:deserialize-relative-directory arguments.

Given a value

v

that was produced by

serialize

, produces a value like the one given to

serialize

, including the same graph structure and mutability.

A serialized representation v is a list of six or seven elements:

The result of deserialize shares no mutable values with the argument to deserialize.

If a value provided to serialize is a simple tree (i.e., no sharing), then the fourth and fifth elements in the serialized representation will be empty.

Returns #t if v1 and v2 represent the same serialization information.

More precisely, it returns the same value that (equal? (deserialize v1) (deserialize v2)) would return if

A parameter whose value is called by

deserialize

before dynamically loading a module via

dynamic-require

. The two arguments provided to the procedure are the same as the arguments to be passed to

dynamic-require

. The procedure can raise an exception to disallow the

dynamic-require

.

The procedure can optionally return a pair containing a module-path and symbol. If returned, deserialize will use them as arguments to dynamic-require instead.

Changed in version 6.90.0.30 of package base: Adds optional return values for bindings.

Like

struct

, but instances of the structure type are serializable with

serialize

. This form is allowed only at the top level or in a module’s top level (so that deserialization information can be found later).

Serialization supports cycles involving the created structure type only when all fields are mutable (or when the cycle can be broken through some other mutable value).

In addition to the bindings generated by struct, serializable-struct binds deserialize-info:id-v0 to deserialization information. Furthermore, in a module context, it automatically provides this binding in a deserialize-info submodule using module+.

The serializable-struct form enables the construction of structure instances from places where id is not accessible, since deserialization must construct instances. Furthermore, serializable-struct provides limited access to field mutation, but only for instances generated through the deserialization information bound to deserialize-info:id-v0. See make-deserialize-info for more information.

Beware that the previous paragraph means that if a serializable struct is exported via contract-out, for example, the contracts are not checked during deserialization. Consider using struct-guard/c instead.

The -v0 suffix on the deserialization enables future versioning on the structure type through serializable-struct/versions.

When a supertype is supplied as maybe-super, compile-time information bound to the supertype identifier must include all of the supertype’s field accessors. If any field mutator is missing, the structure type will be treated as immutable for the purposes of marshaling (so cycles involving only instances of the structure type cannot be handled by the deserializer).

Examples:

  other-version-clause   =   (other-vers make-proc-expr             cycle-make-proc-expr)

Like

serializable-struct

, but the generated deserializer binding is

deserialize-info:id-vvers

. In addition,

deserialize-info:id-vother-vers

is bound for each

other-vers

. The

vers

and each

other-vers

must be a literal, exact, nonnegative integer.

Each make-proc-expr should produce a procedure, and the procedure should accept as many argument as fields in the corresponding version of the structure type, and it produces an instance of id. Each cycle-make-proc-expr should produce a procedure of no arguments; this procedure should return two values: an instance x of id (typically with #f for all fields) and a procedure that accepts another instance of id and copies its field values into x.

Examples:

Produces a deserialization information record to be used by

deserialize

. This information is normally tied to a particular structure because the structure has a

prop:serializable

property value that points to a top-level variable or module-exported variable that is bound to deserialization information.

The make procedure should accept as many arguments as the structure’s serializer put into a vector; normally, this is the number of fields in the structure. It should return an instance of the structure.

The cycle-make procedure should accept no arguments, and it should return two values: a structure instance x (with dummy field values) and an update procedure. The update procedure takes another structure instance generated by the make, and it transfers the field values of this instance into x.

This property identifies structures and structure types that are serializable. The property value should be constructed with

make-serialize-info

.

The to-vector procedure should accept a structure instance and produce a vector for the instance’s content.

The deserialize-id value indicates a binding for deserialize information, to either a module export or a top-level definition. It must be one of the following:

See make-deserialize-info and deserialize for more information.

The can-cycle? argument should be false if instances should not be serialized in such a way that deserialization requires creating a structure instance with dummy field values and then updating the instance later.

The dir argument should be a directory path that is used to resolve a module reference for the binding of deserialize-id. This directory path is used as a last resort when deserialize-id indicates a module that was loaded through a relative path with respect to the top level. Usually, it should be (or (current-load-relative-directory) (current-directory)).

Changed in version 7.0.0.6 of package base: Allow deserialize-id to be a procedure.

Examples:

> (define original-pie     (pie 'apple)) > original-pie

#<pie>

> pie-in-transit

'((3) 1 ((#f . pie-beam)) 0 () () (0 apple))

> beamed-up-pie

#<pie>

> (pie-type beamed-up-pie)

'apple

> (equal? beamed-up-pie original-pie)

#f

13.9.1 Serialization Structures🔗ℹ

Added in version 8.15.0.3 of package base.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4