@@ -31,7 +31,7 @@ Serializer(io::IO) = Serializer{typeof(io)}(io)
31
31
32
32
const n_int_literals = 33
33
33
const n_reserved_slots = 24
34
- const n_reserved_tags = 12
34
+ const n_reserved_tags = 11
35
35
36
36
const TAGS = Any[
37
37
Symbol, Int8, UInt8, Int16, UInt16, Int32, UInt32, Int64, UInt64, Int128, UInt128,
@@ -56,6 +56,7 @@ const TAGS = Any[
56
56
Symbol, # REF_OBJECT_TAG
57
57
Symbol, # FULL_GLOBALREF_TAG
58
58
Symbol, # HEADER_TAG
59
+ Symbol, # IDDICT_TAG
59
60
fill (Symbol, n_reserved_tags)... ,
60
61
61
62
(), Bool, Any, Bottom, Core. TypeofBottom, Type, svec (), Tuple{}, false , true , nothing ,
@@ -75,7 +76,7 @@ const TAGS = Any[
75
76
76
77
@assert length (TAGS) == 255
77
78
78
- const ser_version = 8 # do not make changes without bumping the version #!
79
+ const ser_version = 9 # do not make changes without bumping the version #!
79
80
80
81
const NTAGS = length (TAGS)
81
82
@@ -133,6 +134,7 @@ const OBJECT_TAG = Int32(o0+12)
133
134
const REF_OBJECT_TAG = Int32 (o0+ 13 )
134
135
const FULL_GLOBALREF_TAG = Int32 (o0+ 14 )
135
136
const HEADER_TAG = Int32 (o0+ 15 )
137
+ const IDDICT_TAG = Int32 (o0+ 16 )
136
138
137
139
writetag (s:: IO , tag) = (write (s, UInt8 (tag)); nothing )
138
140
@@ -327,15 +329,26 @@ function serialize(s::AbstractSerializer, ex::Expr)
327
329
end
328
330
end
329
331
330
- function serialize (s:: AbstractSerializer , d:: Dict )
331
- serialize_cycle_header (s, d) && return
332
+ function serialize_dict_data (s:: AbstractSerializer , d:: AbstractDict )
332
333
write (s. io, Int32 (length (d)))
333
334
for (k,v) in d
334
335
serialize (s, k)
335
336
serialize (s, v)
336
337
end
337
338
end
338
339
340
+ function serialize (s:: AbstractSerializer , d:: Dict )
341
+ serialize_cycle_header (s, d) && return
342
+ serialize_dict_data (s, d)
343
+ end
344
+
345
+ function serialize (s:: AbstractSerializer , d:: IdDict )
346
+ serialize_cycle (s, d) && return
347
+ writetag (s. io, IDDICT_TAG)
348
+ serialize_type_data (s, typeof (d))
349
+ serialize_dict_data (s, d)
350
+ end
351
+
339
352
function serialize_mod_names (s:: AbstractSerializer , m:: Module )
340
353
p = parentmodule (m)
341
354
if p === m || m === Base
@@ -851,6 +864,11 @@ function handle_deserialize(s::AbstractSerializer, b::Int32)
851
864
return read (s. io, Float64)
852
865
elseif b == INT8_TAG+ 13
853
866
return read (s. io, Char)
867
+ elseif b == IDDICT_TAG
868
+ slot = s. counter; s. counter += 1
869
+ push! (s. pending_refs, slot)
870
+ t = deserialize (s)
871
+ return deserialize_dict (s, t)
854
872
end
855
873
t = desertag (b):: DataType
856
874
if t. mutable && length (t. types) > 0 # manual specialization of fieldcount
@@ -1303,7 +1321,7 @@ function deserialize(s::AbstractSerializer, t::DataType)
1303
1321
end
1304
1322
end
1305
1323
1306
- function deserialize (s:: AbstractSerializer , T:: Type{Dict{K,V}} ) where {K,V}
1324
+ function deserialize_dict (s:: AbstractSerializer , T:: Type{<:AbstractDict} )
1307
1325
n = read (s. io, Int32)
1308
1326
t = T (); sizehint! (t, n)
1309
1327
deserialize_cycle (s, t)
@@ -1315,6 +1333,10 @@ function deserialize(s::AbstractSerializer, T::Type{Dict{K,V}}) where {K,V}
1315
1333
return t
1316
1334
end
1317
1335
1336
+ function deserialize (s:: AbstractSerializer , T:: Type{Dict{K,V}} ) where {K,V}
1337
+ return deserialize_dict (s, T)
1338
+ end
1339
+
1318
1340
deserialize (s:: AbstractSerializer , :: Type{BigInt} ) = parse (BigInt, deserialize (s), base = 62 )
1319
1341
1320
1342
function deserialize (s:: AbstractSerializer , t:: Type{Regex} )
0 commit comments