Skip to main content

Module ser

Module ser 

Source
Expand description

COS object serialization: Object values to PDF syntax bytes (ISO 32000 §7.3). Output is deterministic — dictionary keys are emitted in sorted order regardless of insertion order.

Streams are deliberately absent here: a stream is only legal as an indirect object and its /Length bookkeeping belongs to the Writer, so a nested Object::Stream is an error.

Functions§

serialize_dict
Serializes a dictionary with << … >> delimiters, keys sorted bytewise for deterministic output.
serialize_object
Serializes any non-stream object into out.
write_name
Writes a name object with its leading solidus, escaping every byte outside the regular range as #xx (delimiters, whitespace, # itself, and anything outside 0x21..=0x7E).
write_real
Writes a real number in plain decimal: no exponent, trailing zeros trimmed, -0 normalized to 0, non-finite values written as 0. Whole values write as integers (72 not 72.0).
write_real_f32
Like write_real, for f32 values (content-stream operands): the shortest decimal that parses back to the identical f32.
write_string
Writes a string object. Byte content that is printable ASCII (plus tab, newline and carriage return) uses the literal form with \-escapes; anything else uses the hex form. The choice is a pure function of the bytes, keeping output deterministic.