BSON
Parsing
Serde.SerdeBson.parse_bson — Function
parse_bson(x::Vector{UInt8}; dict_type = Dict{String,Any}, max_depth = 1000) -> AbstractDictDecode a BSON byte array into a dictionary without mapping to a target type.
Supported BSON types: Double (→ Float64), String (→ String), Document (→ Dict), Array (→ Vector), Binary (→ Vector{UInt8}), ObjectId (→ BSONObjectId), Boolean (→ Bool), DateTime (→ DateTime), Null (→ nothing), Regex (→ Regex), Int32/Int64 (→ Int64), Timestamp (→ BSONTimestamp), Decimal128 (→ BSONDecimal128).
Arguments
x::Vector{UInt8}: the raw BSON bytes. Must represent a top-level BSON document.
Keyword arguments
dict_type::Type{<:AbstractDict}: concrete dict type for objects (defaultDict{String,Any}).max_depth::Int = 1000: cap on nested-document recursion depth, which guards against stack overflow on adversarial inputs. Raise (or lower) freely; there is no hard limit.
Returns
An AbstractDict for the top-level document.
Throws
ParseError: ifxcontains invalid or unsupported BSON.
Examples
julia> bytes = to_bson(Dict("x" => 1, "y" => 2));
julia> parse_bson(bytes)
Dict{String, Any}("x" => 1, "y" => 2)See also: from_bson, try_from_bson.
Deserialization
Serde.SerdeBson.from_bson — Function
from_bson(::Type{T}, x::Vector{UInt8}) -> T
from_bson(strategy, ::Type{T}, x::Vector{UInt8}) -> T
from_bson(f::Function, x::Vector{UInt8}) -> AnyDecode a BSON byte array and deserialize it into type T.
Pass a context object strategy (e.g. CamelCase()) to apply global field-renaming.
Arguments
::Type{T}: target type to construct.x::Vector{UInt8}: raw BSON bytes.strategy: optional context object.
Returns
A value of type T.
Throws
ParseError: ifxis invalid BSON.MissingFieldError: if a required struct field is absent.TypeMismatchError: if a value cannot be coerced to the field type.
Examples
julia> struct Point; x::Int; y::Int; end
julia> bytes = to_bson(Point(1, 2));
julia> from_bson(Point, bytes)
Point(1, 2)See also: try_from_bson, to_bson, parse_bson.
Serde.SerdeBson.try_from_bson — Function
try_from_bson(::Type{T}, x::Vector{UInt8}) -> Union{T, SerdeError}
try_from_bson(strategy, ::Type{T}, x::Vector{UInt8}) -> Union{T, SerdeError}Like from_bson but returns a SerdeError instead of throwing on failure.
Returns
Ton success.- A
ParseErrororDeserErrorsubtype on failure.
See also: from_bson, SerdeError.
Serialization
Serde.SerdeBson.to_bson — Function
to_bson(data) -> Vector{UInt8}
to_bson(strategy, data) -> Vector{UInt8}Serialize data into a BSON byte array.
The top-level value is always encoded as a BSON document. Nested structs produce sub-documents. Vector{UInt8} fields are encoded as BSON binary. DateTime values use the BSON datetime type (milliseconds since Unix epoch). Regex values are encoded as BSON regex. nothing and missing are encoded as BSON null.
Pass a context object strategy (e.g. CamelCase()) to apply global field-renaming.
All serialization traits (Serde.ser_name, Serde.ser_value, Serde.ser_skip) are applied.
Arguments
data: the value to serialize (struct orAbstractDict).strategy: optional context object.
Returns
Vector{UInt8} — the raw BSON bytes.
Examples
julia> struct Point; x::Int; y::Int; end
julia> bytes = to_bson(Point(1, 2));
julia> from_bson(Point, bytes)
Point(1, 2)See also: from_bson.