deserialize
deserialize(stream)
Read a value written by serialize
.
Examples
-
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 theIOBuffer
stream. -
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". - 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.