From b3f547563e0bff9d55684be2a017c86af72e4ba9 Mon Sep 17 00:00:00 2001 From: Alexander Plavin Date: Thu, 4 Dec 2025 15:15:11 -0500 Subject: [PATCH 1/3] add single-argument (de)serialize methods operating on vectors of bytes --- stdlib/Serialization/src/Serialization.jl | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/stdlib/Serialization/src/Serialization.jl b/stdlib/Serialization/src/Serialization.jl index ee40ebdd4abad..2c0cc5edf43f2 100644 --- a/stdlib/Serialization/src/Serialization.jl +++ b/stdlib/Serialization/src/Serialization.jl @@ -824,6 +824,12 @@ Open a file and serialize the given value to it. """ serialize(filename::AbstractString, x) = open(io->serialize(io, x), filename, "w") +function serialize(x)::Vector{UInt8} + buf = IOBuffer() + serialize(buf, x) + return take!(buf) +end + ## deserializing values ## """ @@ -847,6 +853,8 @@ Open a file and deserialize its contents. """ deserialize(filename::AbstractString) = open(deserialize, filename) +deserialize(data::Vector{UInt8}) = deserialize(IOBuffer(data)) + function deserialize(s::AbstractSerializer) handle_deserialize(s, Int32(read(s.io, UInt8)::UInt8)) end From 189e8bca873c3a988ad8e8ed36b4d6bacb9c8849 Mon Sep 17 00:00:00 2001 From: Alexander Plavin Date: Fri, 5 Dec 2025 17:37:20 -0500 Subject: [PATCH 2/3] add docstrings --- stdlib/Serialization/src/Serialization.jl | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/stdlib/Serialization/src/Serialization.jl b/stdlib/Serialization/src/Serialization.jl index 2c0cc5edf43f2..32279e0283ede 100644 --- a/stdlib/Serialization/src/Serialization.jl +++ b/stdlib/Serialization/src/Serialization.jl @@ -824,6 +824,16 @@ Open a file and serialize the given value to it. """ serialize(filename::AbstractString, x) = open(io->serialize(io, x), filename, "w") +""" + serialize(value) -> Vector{UInt8} + +Serialize the given value to a byte vector and return it. + +See [`serialize(::IO, value)`](@ref serialize(::IO, ::Any)) for more details on serialization format and caveats. + +!!! compat "Julia 1.13" + This method is available as of Julia 1.13. +""" function serialize(x)::Vector{UInt8} buf = IOBuffer() serialize(buf, x) @@ -853,6 +863,16 @@ Open a file and deserialize its contents. """ deserialize(filename::AbstractString) = open(deserialize, filename) +""" + deserialize(data::Vector{UInt8}) + +Deserialize the given byte vector and return the resulting value. + +See [`deserialize(::IO)`](@ref deserialize(::IO)) for more details and caveats. + +!!! compat "Julia 1.13" + This method is available as of Julia 1.13. +""" deserialize(data::Vector{UInt8}) = deserialize(IOBuffer(data)) function deserialize(s::AbstractSerializer) From 618a275a9f7d865aabd30d6729d284e5a81eb241 Mon Sep 17 00:00:00 2001 From: Alexander Plavin Date: Fri, 5 Dec 2025 17:40:09 -0500 Subject: [PATCH 3/3] add tests --- stdlib/Serialization/test/runtests.jl | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/stdlib/Serialization/test/runtests.jl b/stdlib/Serialization/test/runtests.jl index e341c6e3eb9ec..27c78f92f5e54 100644 --- a/stdlib/Serialization/test/runtests.jl +++ b/stdlib/Serialization/test/runtests.jl @@ -657,6 +657,12 @@ end @test l2.parts === () end +# serialize to and deserialize from Vector{UInt8} +@testset "Vector{UInt8}" begin + @test serialize([1, 2, 3]) isa Vector{UInt8} + @test deserialize(serialize([1, 2, 3])) == [1, 2, 3] +end + @testset "Docstrings" begin undoc = Docs.undocumented_names(Serialization) @test_broken isempty(undoc)