deserialize

deserialize(stream)

Read a value written by serialize.

Examples

  1. Deserialize a single value from a stream:

    julia> io = IOBuffer();
    julia> serialize(io, 42);
    julia> seekstart(io);
    julia> deserialize(io)
    42

    This example demonstrates deserializing a single value (42) from the IOBuffer stream.

  2. Deserialize an array from a file:

    julia> file = open("data.bin", "r");
    julia> arr = deserialize(file);
    julia> close(file);

    In this example, the deserialize function is used to read and deserialize an array from a binary file named "data.bin".

  3. Deserialize a complex object:
    julia> io = IOBuffer();
    julia> serialize(io, Dict("name" => "Julia", "version" => v"1.7.0"));
    julia> seekstart(io);
    julia> obj = deserialize(io)
    Dict{String,VersionNumber} with 2 entries:
     "version" => v"1.7.0"
     "name"    => "Julia"

    This example shows deserializing a complex object (a dictionary in this case) from the IOBuffer stream.

Common mistake example:

julia> data = "42";
julia> deserialize(data)
ERROR: MethodError: no method matching deserialize(::String)

In this example, the deserialize function is being used on a string ("42") instead of a stream object. It's important to pass a valid stream object to the deserialize function for successful deserialization.

See Also

deserialize, eachline, eof, fd, flush, IOBuffer, ismarked, isopen, isreadonly, mark, nb_available, open, pipeline, position, read, read!, readavailable, readbytes, readbytes!, readline, redirect_stderr, redirect_stdin, reset, seek, seekend, seekstart, serialize, skip, skipchars, TextDisplay, unmark, write, writemime,

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field
Details

Checking you are not a robot: