Used by Serializer
to avoid duplicating objects, by serializing them once,
then using a reference.
serialization :: SerializerCache :: has_object
Isobject
known?
serialization :: SerializerCache :: id_for
Get the id forobject
serialization :: SerializerCache :: new_id_for
Get a new id forobject
and store it
serialization :: SerializerCache :: next_available_id
Get a free id to associate to an object in the cacheserialization :: SerializerCache :: sent
Map of already serialized objects to the reference idserialization :: SerializerCache :: sent=
Map of already serialized objects to the reference idserialization $ SerializerCache :: SELF
Type of this instance, automatically specialized in every classcore :: Object :: class_factory
Implementation used byget_class
to create the specific class.
core :: Object :: defaultinit
serialization :: SerializerCache :: has_object
Isobject
known?
serialization :: SerializerCache :: id_for
Get the id forobject
core :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
serialization :: SerializerCache :: new_id_for
Get a new id forobject
and store it
serialization :: SerializerCache :: next_available_id
Get a free id to associate to an object in the cachecore :: Object :: output_class_name
Display class name on stdout (debug only).serialization :: SerializerCache :: sent
Map of already serialized objects to the reference idserialization :: SerializerCache :: sent=
Map of already serialized objects to the reference id
# Cache of sent objects
#
# Used by `Serializer` to avoid duplicating objects, by serializing them once,
# then using a reference.
class SerializerCache
# Map of already serialized objects to the reference id
protected var sent: Map[Serializable, Int] = new StrictHashMap[Serializable, Int]
# Is `object` known?
fun has_object(object: Serializable): Bool do return sent.keys.has(object)
# Get the id for `object`
#
# Require: `has_object(object)`
fun id_for(object: Serializable): Int
do
assert sent.keys.has(object)
return sent[object]
end
# Get a new id for `object` and store it
#
# Require: `not has_object(object)`
fun new_id_for(object: Serializable): Int
do
var id = next_available_id
sent[object] = id
return id
end
# Get a free id to associate to an object in the cache
protected fun next_available_id: Int do return sent.length
end
lib/serialization/caching.nit:52,1--84,3