Serialization

Serialization.serializeFunction
serialize(stream::IO, value)

Write an arbitrary value to a stream in an opaque format, such that it can be read back by deserialize. The read-back value will be as identical as possible to the original, but note that Ptr values are serialized as all-zero bit patterns (NULL).

An 8-byte identifying header is written to the stream first. To avoid writing the header, construct a Serializer and use it as the first argument to serialize instead. See also Serialization.writeheader.

The data format can change in minor (1.x) Julia releases, but files written by prior 1.x versions will remain readable. The main exception to this is when the definition of a type in an external package changes. If that occurs, it may be necessary to specify an explicit compatible version of the affected package in your environment. Renaming functions, even private functions, inside packages can also put existing files out of sync. Anonymous functions require special care: because their names are automatically generated, minor code changes can cause them to be renamed. Serializing anonymous functions should be avoided in files intended for long-term storage.

In some cases, the word size (32- or 64-bit) of the reading and writing machines must match. In rarer cases the OS or architecture must also match, for example when using packages that contain platform-dependent code.

serialize(filename::AbstractString, value)

Open a file and serialize the given value to it.

Julia 1.1

This method is available as of Julia 1.1.

Serialization.deserializeFunction
deserialize(stream)

Read a value written by serialize. deserialize assumes the binary data read from stream is correct and has been serialized by a compatible implementation of serialize. deserialize is designed for simplicity and performance, and so does not validate the data read. Malformed data can result in process termination. The caller must ensure the integrity and correctness of data read from stream.

deserialize(filename::AbstractString)

Open a file and deserialize its contents.

Julia 1.1

This method is available as of Julia 1.1.

Serialization.writeheaderFunction
Serialization.writeheader(s::AbstractSerializer)

Write an identifying header to the specified serializer. The header consists of 8 bytes as follows:

OffsetDescription
0tag byte (0x37)
1-2signature bytes "JL"
3protocol version
4bits 0-1: endianness: 0 = little, 1 = big
4bits 2-3: platform: 0 = 32-bit, 1 = 64-bit
5-7reserved