Data::Plist::BinaryWriter - write binary property lists from Perl data structures
# Create new my $write = Data::Plist::BinaryWriter->new(); # Writing to a string ($ret is binary output) my $ret = $write->write($data); # Writing to a file C<$filename> $write->write($filename, $data);
Data::Plist::BinaryWriter takes perl data structures, serializes them (see "SERIALIZED DATA" in Data::Plist) and recursively writes to a given filehandle in Apple's binary property list format.
Data::Plist::BinaryWriter
Takes a perl data structure $data, serializes it (see "SERIALIZED DATA" in Data::Plist) and writes it to the given filehandle $fh in Apple's binary property list format.
$data
$fh
The format starts with "bplist00" and contains a 32-byte trailer. The 32-byte trailer consists of the size of the offset objects in the offset table, the size of the indices of the offset table, the number of objects in the binary file, the index of top object in the binary file and the offset table offset.
Takes serialized data structure $data (see "SERIALIZED DATA" in Data::Plist) and checks its type. Checks the object against previously written objects. If no match is found, calls the appropriate write_ method. Returns the index into the offset table of the offset object that points to the data's position in the binary file.
Takes a string representing the object's type $type and an integer indicating its size $length. Returns their binary representation.
$type
$length
Each object in the binary file is preceded by a byte - the higher nybble denoting its type and the lower its size. For objects whose size is equal to or great than 15, the lower byte contains an f and an integer object is added right after the first byte containing the object's actual size.
Takes an integer $int and an optional type $type (used for writing UIDs, since they're essentially the same). Returns the index into the offset table of the offset object that points to the integer's location in the binary file.
$int
Takes a string $string and returns the index into the offset table of the offset object that points to its location in the binary file. It is encoded in the file using UTF-8.
$string
Takes a string $ustring and returns the index into the offset table of the offset object that points to its location in the binary file.
$ustring
While ustrings are technically supposed to be stored in UTF-16, there is no known reason for them to not be written as UTF-8 encoded strings instead; thus, for simplicity, all ustrings are written as strings.
ustrings
string
ustring
Takes a hash reference $dict and recursively processes each of its keys and values. Stores indices into the offset table of the offset objects pointing to its keys and values in the binary file. Returns the index into the offset table of the offset object that points to its location in the binary file.
$dict
Take an array reference $array and recursively processes its contents. Stores the indices into the offset table of the offset objects pointing to its value. Returns the index into the offset table of the offset object that points to its location in the binary file.
$array
Takes a UID $id and returns the index into the offset table of the offset object that points to its location in the binary file. Passes the UID off to "write_integer" for actual writing, since they're processed in the same manner, simply with different types.
$id
Takes a float $real and an optional type $type (used for writing dates, since they're essentially the same), and returns the index into the offset table of the offset object that points to its location in the binary file. The bytes of the float are packed in reverse.
$real
Takes a date $date and returns the index into the offset table of the offset object that points to its location in the binary file. Passes the date off to "write_real" for actual writing, since they're processed in the same manner, simply with different types.
$date
Takes a null $null and passes it to "write_misc", along with an integer indicating what type of misc it is. The null belongs to the misc category (see "write_misc").
$null
Takes a false $false and passes it to "write_misc", along with an integer indicating what type of misc it is. The false belongs to the misc category (see "write_misc").
$false
Takes a true $true and passes it to "write_misc", along with an integer indicating what type of misc it is. The true belongs to the misc category (see "write_misc").
$true
Takes a fill $fill and passes it to "write_misc", along with an integer indicating what type of misc it is. The fill belongs to the misc category (see "write_misc").
$fill
Takes an integer indicating an object belonging to the misc category $type (false, null, true or fill) and returns the index into the offset table of the offset object that points to its location in the file.
Miscs are a group of data types not easily represented in Perl, and they are written with the only header byte containing a 0 to indicate that they are a misc and their misc type.
Takes some binary data $data and returns the index into the offset table of the offset object that points to its location in the file. Doesn't attempt to process the data at all.
Recursively counts the number of objects in a serialized data structure $data. Does not take into account duplicates, so this number might be slightly higher than the number of objects that is indicated in the 32-byte trailer.
Does the actual writing to the binary file. Takes some binary data $obj and writes it to the filehandle. Also adds the location of the binary data to the offset table and returns the index into the offset table of the current object.
$obj
Calculates the number of bytes necessary to encode an integer $int. Returns a power of 2 indicating the number of bytes.
Calculates the number of bytes necessary to encode an integer $int. Returns the actual number of bytes.
Takes either a power of 2 or a number of bytes $int and returns the format pack() needs for encoding.
To install Data::Plist, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Data::Plist
CPAN shell
perl -MCPAN -e shell install Data::Plist
For more information on module installation, please visit the detailed CPAN module installation guide.