class HexaPDF::Serializer

Parent

Knows how to serialize Ruby objects for a PDF file.

For normal serialization purposes, the serialize or serialize_to_io methods should be used. However, if the type of the object to be serialized is known, a specialized serialization method like serialize_float can be used.

Additionally, an object for encrypting strings and streams while serializing can be set via the encrypter= method. The assigned object has to respond to encrypt_string(str, ind_obj) (where the string is part of the indirect object; returns the encrypted string) and encrypt_stream(stream) (returns a fiber that represents the encrypted stream).

How This Class Works

The main public interface consists of the serialize and serialize_to_io methods which accept an object and return its serialized form. During serialization of this object it is accessible by individual serialization methods via the @object instance variable (useful if the object is a composed object).

Internally, the __serialize method is used for invoking the correct serialization method based on the class of a given object. It is also used for serializing individual parts of a composed object.

Therefore the serializer contains one serialization method for each class it needs to serialize. The naming scheme of these methods is based on the class name: The full class name is converted to lowercase, the namespace separator ‘::’ is replaced with a single underscore and the string “serialize_” is then prepended.

Examples:

NilClass                 => serialize_nilclass
TrueClass                => serialize_trueclass
HexaPDF::Object          => serialize_hexapdf_object

If no serialization method for a specific class is found, the ancestors classes are tried.

See: PDF2.0 s7.3

Attributes

encrypter[RW]

The encrypter to use for encrypting strings and streams. If nil, strings and streams are not encrypted.

Default: nil

Public Class Methods

new()

Creates a new Serializer object.

Public Instance Methods

serialize(obj)

Returns the serialized form of the given object.

For developers: While the object is serialized, methods can use the instance variable @object to obtain information about or use the object in case it is a composed object.

serialize_array(obj)

Serializes an Array object.

See: PDF2.0 s7.3.6

serialize_basicobject(obj)

Raises an error to provide better failure messages.

serialize_date(obj)
serialize_datetime(obj)
serialize_falseclass(_obj)

Serializes the false value.

See: PDF2.0 s7.3.2

serialize_float(obj)

Serializes a Float object.

See: PDF2.0 s7.3.3

serialize_hash(obj)

Serializes a Hash object (i.e. a PDF dictionary object).

See: PDF2.0 s7.3.7

serialize_integer(obj)

Serializes an Integer object.

See: PDF2.0 s7.3.3

serialize_nilclass(_obj)

Serializes the nil value.

See: PDF2.0 s7.3.9

serialize_numeric(obj)

Serializes a Numeric object (either Integer or Float).

This method should be used for cases where it is known that the object is either an Integer or a Float.

See: PDF2.0 s7.3.3

serialize_string(obj)

Serializes a String object.

See: PDF2.0 s7.3.4

serialize_symbol(obj)

Serializes a Symbol object (i.e. a PDF name object).

See: PDF2.0 s7.3.5

serialize_time(obj)

The ISO PDF specification differs in respect to the supported date format. When converting to a date string, a format suitable for both is output.

See: PDF2.0 s7.9.4, ADB1.7 3.8.3

serialize_to_io(obj, io)

Serializes the given object and writes it to the IO.

Also see: serialize

serialize_trueclass(_obj)

Serializes the true value.

See: PDF2.0 s7.3.2