52 if ( self::$bigendian ===
null ) {
53 self::$bigendian =
pack(
'S', 1 ) ===
pack(
'n', 1 );
56 switch ( gettype(
$value ) ) {
61 return $value ?
"\xC3" :
"\xC2";
65 return self::$bigendian
70 $length = strlen(
$value );
73 } elseif ( $length <= 0xFFFF ) {
75 } elseif ( $length <= 0xFFFFFFFF ) {
78 throw new InvalidArgumentException( __METHOD__ .
": string too long (length: $length; max: 4294967295)" );
94 if (
$value <= 0xFFFFFFFF ) {
98 if (
$value <= 0xFFFFFFFFFFFFFFFF ) {
100 $hi = (
$value & 0xFFFFFFFF00000000 ) >> 32;
101 $lo =
$value & 0xFFFFFFFF;
102 return self::$bigendian
103 ?
pack(
'CNN', 0xCF, $lo, $hi )
104 :
pack(
'CNN', 0xCF, $hi, $lo );
115 if (
$value >= -0x8000 ) {
118 return self::$bigendian
119 ?
pack(
'Ca2', 0xD1, $p )
120 :
pack(
'Ca2', 0xD1, strrev( $p ) );
122 if (
$value >= -0x80000000 ) {
125 return self::$bigendian
126 ?
pack(
'Ca4', 0xD2, $p )
127 :
pack(
'Ca4', 0xD2, strrev( $p ) );
129 if (
$value >= -0x8000000000000000 ) {
133 $p2 =
pack(
'l', (
$value >> 32 ) & 0xFFFFFFFF );
134 return self::$bigendian
135 ?
pack(
'Ca4a4', 0xD3, $p1, $p2 )
136 :
pack(
'Ca4a4', 0xD3, strrev( $p2 ), strrev( $p1 ) );
139 throw new InvalidArgumentException( __METHOD__ .
": invalid integer '$value'" );
143 $length = count(
$value );
144 if ( $length > 0xFFFFFFFF ) {
145 throw new InvalidArgumentException( __METHOD__ .
": array too long (length: $length, max: 4294967295)" );
150 if ( $index !== $k || $index === $length ) {
156 $associative = $index !== $length;
158 if ( $associative ) {
159 if ( $length < 16 ) {
160 $buffer .=
pack(
'C', 0x80 | $length );
161 } elseif ( $length <= 0xFFFF ) {
162 $buffer .=
pack(
'Cn', 0xDE, $length );
164 $buffer .=
pack(
'CN', 0xDF, $length );
171 if ( $length < 16 ) {
172 $buffer .=
pack(
'C', 0x90 | $length );
173 } elseif ( $length <= 0xFFFF ) {
174 $buffer .=
pack(
'Cn', 0xDC, $length );
176 $buffer .=
pack(
'CN', 0xDD, $length );
185 throw new InvalidArgumentException( __METHOD__ .
': unsupported type ' . gettype(
$value ) );