msgpack :: MsgPackSerializer :: cache_metadata_strings
Should strings declaring the objects type and attributes name be cached?msgpack :: MsgPackSerializer :: cache_metadata_strings=
Should strings declaring the objects type and attributes name be cached?msgpack :: MsgPackSerializer :: plain_msgpack
Write plain MessagePack without metadata for deserialization?msgpack :: MsgPackSerializer :: plain_msgpack=
Write plain MessagePack without metadata for deserialization?msgpack $ MsgPackSerializer :: SELF
Type of this instance, automatically specialized in every classmsgpack $ MsgPackSerializer :: current_object
The object currently serialized byserialized
msgpack $ MsgPackSerializer :: serialize
Entry point method of this service, serialize theobject
msgpack $ MsgPackSerializer :: serialize_attribute
Serialize an attribute to compose a serializable objectmsgpack $ MsgPackSerializer :: serialize_reference
Serialize an object, with full serialization or a simple referenceserialization :: CachingSerializer :: cache=
Cache of known objectsmsgpack :: MsgPackSerializer :: cache_metadata_strings
Should strings declaring the objects type and attributes name be cached?msgpack :: MsgPackSerializer :: cache_metadata_strings=
Should strings declaring the objects type and attributes name be cached?core :: Object :: class_factory
Implementation used byget_class
to create the specific class.
serialization :: Serializer :: current_object
The object currently serialized byserialized
msgpack :: MsgPackEngine :: defaultinit
core :: Object :: defaultinit
msgpack :: MsgPackEngine :: ext_typ_byte
ext type byte to identify a byte, defaults to 0x7Eu8 or '|'msgpack :: MsgPackEngine :: ext_typ_byte=
ext type byte to identify a byte, defaults to 0x7Eu8 or '|'msgpack :: MsgPackEngine :: ext_typ_char
ext type byte to identify a char, defaults to 0x7Cu8 or '~'msgpack :: MsgPackEngine :: ext_typ_char=
ext type byte to identify a char, defaults to 0x7Cu8 or '~'msgpack :: MsgPackEngine :: ext_typ_obj
ext type byte for object definitions, defaults to 0x7Bu8 or '{'msgpack :: MsgPackEngine :: ext_typ_obj=
ext type byte for object definitions, defaults to 0x7Bu8 or '{'msgpack :: MsgPackEngine :: ext_typ_ref
ext type byte for object references, defaults to 0x7Du8 or '}'msgpack :: MsgPackEngine :: ext_typ_ref=
ext type byte for object references, defaults to 0x7Du8 or '}'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 :: CachingSerializer :: link
Link the cache ofself
with deserializer
core :: Object :: output_class_name
Display class name on stdout (debug only).msgpack :: MsgPackSerializer :: plain_msgpack
Write plain MessagePack without metadata for deserialization?msgpack :: MsgPackSerializer :: plain_msgpack=
Write plain MessagePack without metadata for deserialization?serialization :: Serializer :: serialize
Entry point method of this service, serialize theobject
serialization :: Serializer :: serialize_attribute
Serialize an attribute to compose a serializable objectserialization :: Serializer :: serialize_core
The method is called when a standardvalue
is serialized
serialization :: Serializer :: serialize_reference
Serialize an object, with full serialization or a simple referenceserialization :: Serializer :: try_to_serialize
Serializevalue
is possible, i.e. it is Serializable
or null
serialization :: Serializer :: warn
Warn of problems and potential errors (such as if an attribute
# MessagePack deserialization engine
class MsgPackSerializer
super CachingSerializer
super MsgPackEngine
# Target writing stream
var stream: Writer
# Write plain MessagePack without metadata for deserialization?
#
# If `false`, the default, serialize to support deserialization:
#
# * Each object is encapsulated in an array that contains metadata and
# the actual object attributes in a map. The metadata includes the type
# name and references to already serialized object. This information
# supports deserializing the message, including cycles.
# * Preserve the Nit `Char` and `Byte` types as an object.
# * The generated MessagePack is standard and can be read by non-Nit programs.
# However, it contains some complexity that may make it harder to use.
#
# If `true`, serialize only the real data or non-Nit programs:
#
# * Nit objects are serialized to pure and standard MessagePack so they can
# be easily read by non-Nit programs.
# * Nit objects are serialized at every reference, so they may be duplicated.
# It is easier to read but it creates a larger output and it does not support
# cycles. Cyclic references are replaced by `null`.
# * The serialized data can only be deserialized to their expected static
# types, losing the knowledge of their dynamic type.
var plain_msgpack = false is writable
# Should strings declaring the objects type and attributes name be cached?
#
# If `true` metadata strings are cached using `cache`.
# The first occurrence is written as an object declaration,
# successive occurrences are written as an object reference.
#
# If `false`, the default, metadata strings are written as pure MessagePack
# strings, without their own metadata.
#
# Using the cache may save some space by avoiding the repetition of
# names used by many types or attributes.
# However, it adds complexity to the generated message and may be less
# safe for versioning.
var cache_metadata_strings = false is writable
# List of the current open objects, the first is the main target of the serialization
#
# Used only when `plain_msgpack == true` to detect cycles in serialization.
private var open_objects = new Array[Object]
redef var current_object = null
redef fun serialize(object)
do
if object == null then
stream.write_msgpack_null
else
if plain_msgpack then
for o in open_objects do
if object.is_same_serialized(o) then
# Cycle, can't be managed in plain_msgpack mode
warn "Cycle detected in serialized object, replacing reference with 'null'."
stream.write_msgpack_null
return
end
end
open_objects.add object
end
var last_object = current_object
current_object = object
object.accept_msgpack_serializer self
current_object = last_object
if plain_msgpack then open_objects.pop
end
end
redef fun serialize_attribute(name, value)
do
serialize_meta_string name
super
end
redef fun serialize_reference(object)
do
if not plain_msgpack and cache.has_object(object) then
# if already serialized, add local reference
var id = cache.id_for(object)
stream.write_msgpack_ext(ext_typ_ref, id.to_bytes)
else
# serialize
serialize object
end
end
private fun serialize_meta_string(type_name: String)
do
if plain_msgpack or not cache_metadata_strings then
# String only version
stream.write_msgpack_str type_name
return
end
if cache.has_object(type_name) then
# if already serialized, add reference
var id = cache.id_for(type_name)
stream.write_msgpack_ext(ext_typ_ref, id.to_bytes)
else
# serialize
var id = cache.new_id_for(type_name)
stream.write_msgpack_array 2 # obj+id, type_name
stream.write_msgpack_ext(ext_typ_obj, id.to_bytes)
stream.write_msgpack_str type_name
end
end
end
lib/msgpack/serialization_write.nit:31,1--149,3