Skip to content

Commit 7e85914

Browse files
authored
document compatibility properties of serialize (#41520)
1 parent 1cda795 commit 7e85914

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

stdlib/Serialization/src/Serialization.jl

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -749,14 +749,25 @@ end
749749
serialize(stream::IO, value)
750750
751751
Write an arbitrary value to a stream in an opaque format, such that it can be read back by
752-
[`deserialize`](@ref). The read-back value will be as identical as possible to the original.
753-
In general, this process will not work if the reading and writing are done by different
754-
versions of Julia, or an instance of Julia with a different system image. `Ptr` values are
755-
serialized as all-zero bit patterns (`NULL`).
752+
[`deserialize`](@ref). The read-back value will be as identical as possible to the original,
753+
but note that `Ptr` values are serialized as all-zero bit patterns (`NULL`).
756754
757755
An 8-byte identifying header is written to the stream first. To avoid writing the header,
758756
construct a `Serializer` and use it as the first argument to `serialize` instead.
759757
See also [`Serialization.writeheader`](@ref).
758+
759+
The data format can change in minor (1.x) Julia releases, but files written by prior 1.x
760+
versions will remain readable. The main exception to this is when the definition of a
761+
type in an external package changes. If that occurs, it may be necessary to specify
762+
an explicit compatible version of the affected package in your environment.
763+
Renaming functions, even private functions, inside packages can also put existing files
764+
out of sync. Anonymous functions require special care: because their names are automatically
765+
generated, minor code changes can cause them to be renamed.
766+
Serializing anonymous functions should be avoided in files intended for long-term storage.
767+
768+
In some cases, the word size (32- or 64-bit) of the reading and writing machines must match.
769+
In rarer cases the OS or architecture must also match, for example when using packages
770+
that contain platform-dependent code.
760771
"""
761772
function serialize(s::IO, x)
762773
ss = Serializer(s)
@@ -781,8 +792,8 @@ serialize(filename::AbstractString, x) = open(io->serialize(io, x), filename, "w
781792
782793
Read a value written by [`serialize`](@ref). `deserialize` assumes the binary data read from
783794
`stream` is correct and has been serialized by a compatible implementation of [`serialize`](@ref).
784-
It has been designed with simplicity and performance as a goal and does not validate
785-
the data read. Malformed data can result in process termination. The caller has to ensure
795+
`deserialize` is designed for simplicity and performance, and so does not validate
796+
the data read. Malformed data can result in process termination. The caller must ensure
786797
the integrity and correctness of data read from `stream`.
787798
"""
788799
deserialize(s::IO) = deserialize(Serializer(s))

0 commit comments

Comments
 (0)