51 if ( self::$bigendian ===
null ) {
52 self::$bigendian =
pack(
'S', 1 ) ===
pack(
'n', 1 );
55 switch ( gettype(
$value ) ) {
60 return $value ?
"\xC3" :
"\xC2";
64 return self::$bigendian
69 $length = strlen(
$value );
72 } elseif ( $length <= 0xFFFF ) {
74 } elseif ( $length <= 0xFFFFFFFF ) {
77 throw new InvalidArgumentException( __METHOD__
78 .
": 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__
146 .
": array too long (length: $length, max: 4294967295)" );
150 foreach (
$value as $k => $v ) {
151 if ( $index !== $k || $index === $length ) {
157 $associative = $index !== $length;
159 if ( $associative ) {
160 if ( $length < 16 ) {
162 } elseif ( $length <= 0xFFFF ) {
167 foreach (
$value as $k => $v ) {
172 if ( $length < 16 ) {
174 } elseif ( $length <= 0xFFFF ) {
179 foreach (
$value as $v ) {
186 throw new InvalidArgumentException( __METHOD__ .
': unsupported type ' . gettype(
$value ) );