Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 39 and 401]

LICENSE This file is part of CFPropertyList.

Author: Rodney Rehm <rodney.rehm@medialize.de>
Author: Christian Kruse <cjk@wwwtech.de>
Copyright: Copyright © 2018 Teclib
License: MIT
File Size: 1231 lines (41 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: CFBinaryPropertyList  - X-Ref

Facility for reading and writing binary PropertyLists. Ported from {@link http://www.opensource.apple.com/source/CF/CF-476.15/CFBinaryPList.c CFBinaryPList.c}.

readBinaryNullType($length)   X-Ref
Read a „null type” (filler byte, true, false, 0 byte)

param: $length The byte itself
return: the byte value (e.g. CFBoolean(true), CFBoolean(false), 0 or 15)

make64Int($hi, $lo)   X-Ref
Create an 64 bit integer using bcmath or gmp

param: int $hi The higher word
param: int $lo The lower word
return: mixed The integer (as int if possible, as string if not possible)

readBinaryInt($length)   X-Ref
Read an integer value

param: integer $length The length (in bytes) of the integer value, coded as „set bit $length to 1”
return: CFNumber The integer value

readBinaryReal($length)   X-Ref
Read a real value

param: integer $length The length (in bytes) of the integer value, coded as „set bit $length to 1”
return: CFNumber The real value

readBinaryDate($length)   X-Ref
Read a date value

param: integer $length The length (in bytes) of the integer value, coded as „set bit $length to 1”
return: CFDate The date value

readBinaryData($length)   X-Ref
Read a data value

param: integer $length The length (in bytes) of the integer value, coded as „set bit $length to 1”
return: CFData The data value

readBinaryString($length)   X-Ref
Read a string value, usually coded as utf8

param: integer $length The length (in bytes) of the string value
return: CFString The string value, utf8 encoded

convertCharset($string, $fromCharset, $toCharset = 'UTF-8')   X-Ref
Convert the given string from one charset to another.
Trying to use MBString, Iconv, Recode - in that particular order.

param: string $string the string to convert
param: string $fromCharset the charset the given string is currently encoded in
param: string $toCharset the charset to convert to, defaults to UTF-8
return: string the converted string

charsetStrlen($string, $charset = "UTF-8")   X-Ref
Count characters considering character set
Trying to use MBString, Iconv - in that particular order.

param: string $string the string to convert
param: string $charset the charset the given string is currently encoded in
return: integer The number of characters in that string

readBinaryUnicodeString($length)   X-Ref
Read a unicode string value, coded as UTF-16BE

param: integer $length The length (in bytes) of the string value
return: CFString The string value, utf8 encoded

readBinaryArray($length)   X-Ref
Read an array value, including contained objects

param: integer $length The number of contained objects
return: CFArray The array value, including the objects

readBinaryDict($length)   X-Ref
Read a dictionary value, including contained objects

param: integer $length The number of contained objects
return: CFDictionary The dictionary value, including the objects

readBinaryObject()   X-Ref
Read an object type byte, decode it and delegate to the correct reader function

return: mixed The value of the delegate reader, so any of the CFType subclasses

readBinaryObjectAt($pos)   X-Ref
Read an object type byte at position $pos, decode it and delegate to the correct reader function

param: integer $pos The table position in the offsets table
return: mixed The value of the delegate reader, so any of the CFType subclasses

parseBinaryString()   X-Ref
Parse a binary plist string

return: void

readBinaryStream($stream)   X-Ref
Read a binary plist stream

param: resource $stream The stream to read
return: void

parseBinary($content = null)   X-Ref
parse a binary plist string

param: string $content The stream to read, defaults to {@link $this->content}
return: void

readBinary($file)   X-Ref
Read a binary plist file

param: string $file The file to read
return: void

bytesSizeInt($int)   X-Ref
calculate the bytes needed for a size integer value

param: integer $int The integer value to calculate
return: integer The number of bytes needed

bytesInt($int)   X-Ref
Calculate the byte needed for a „normal” integer value

param: integer $int The integer value
return: integer The number of bytes needed + 1 (because of the „marker byte”)

packItWithSize($nbytes, $int)   X-Ref
„pack” a value (i.e. write the binary representation as big endian to a string) with the specified size

param: integer $nbytes The number of bytes to pack
param: integer $int The integer value to pack
return: string The packed value as string

unpackWithSize($nbytes, $buff)   X-Ref
„unpack” multiple values of the specified size (i.e. get the integers from their binary representation) from a string

param: integer $nbytes The number of bytes of each value to unpack
param: integer $buff The string packed with integer values
return: array The unpacked integers

bytesNeeded($count_objects)   X-Ref
Calculate the bytes needed to save the number of objects

param: integer $count_objects The number of objects
return: integer The number of bytes

intBytes($int)   X-Ref
Code an integer to byte representation

param: integer $int The integer value
return: string The packed byte value

typeBytes($type, $type_len)   X-Ref
Code an type byte, consisting of the type marker and the length of the type

param: string $type The type byte value (i.e. "d" for dictionaries)
param: integer $type_len The length of the type
return: string The packed type byte value

uniqueAndCountValues($value)   X-Ref
Count number of objects and create a unique table for strings

param: $value The value to count and unique
return: void

toBinary()   X-Ref
Convert CFPropertyList to binary format; since we have to count our objects we simply unique CFDictionary and CFArray

return: string The binary plist content

binaryStrlen($val)   X-Ref
Counts the number of bytes the string will have when coded; utf-16be if non-ascii characters are present.

param: string $val The string value
return: integer The length of the coded string in bytes

stringToBinary($val)   X-Ref
Uniques and transforms a string value to binary format and adds it to the object table

param: string $val The string value
return: integer The position in the object table

intToBinary($value)   X-Ref
Codes an integer to binary format

param: integer $value The integer value
return: string the coded integer

realToBinary($val)   X-Ref
Codes a real value to binary format

param: float $val The real value
return: string The coded real

uidToBinary($value)   X-Ref
No description

numToBinary($value)   X-Ref
Converts a numeric value to binary and adds it to the object table

param: numeric $value The numeric value
return: integer The position in the object table

dateToBinary($val)   X-Ref
Convert date value (apple format) to binary and adds it to the object table

param: integer $value The date value
return: integer The position of the coded value in the object table

boolToBinary($val)   X-Ref
Convert a bool value to binary and add it to the object table

param: bool $val The boolean value
return: integer The position in the object table

dataToBinary($val)   X-Ref
Convert data value to binary format and add it to the object table

param: string $val The data value
return: integer The position in the object table

arrayToBinary($val)   X-Ref
Convert array to binary format and add it to the object table

param: CFArray $val The array to convert
return: integer The position in the object table

dictToBinary($val)   X-Ref
Convert dictionary to binary format and add it to the object table

param: CFDictionary $val The dict to convert
return: integer The position in the object table