2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 | Copyright (c) 1998-2010 Zend Technologies Ltd. (http://www.zend.com) |
7 +----------------------------------------------------------------------+
8 | This source file is subject to version 2.00 of the Zend license, |
9 | that is bundled with this package in the file LICENSE, and is |
10 | available through the world-wide-web at the following url: |
11 | http://www.zend.com/license/2_00.txt. |
12 | If you did not receive a copy of the Zend license and are unable to |
13 | obtain it through the world-wide-web, please send a note to |
14 | license@zend.com so we can mail you a copy immediately. |
15 +----------------------------------------------------------------------+
18 #ifndef incl_HPHP_ZEND_PACK_H_
19 #define incl_HPHP_ZEND_PACK_H_
24 ///////////////////////////////////////////////////////////////////////////////
32 * Implemented formats are A, a, h, H, c, C, s, S, i, I, l, L, n, N, f, d,
39 * Takes one or more arguments and packs them into a binary string according
40 * to the format argument. pack() idea stolen from Perl (implemented formats
41 * behave the same as there).
43 Variant
pack(const String
& fmt
, const Array
& argv
);
46 * Unpack binary string into named array elements according to format
49 * unpack() is based on Perl's unpack(), but is modified a bit from there.
50 * Rather than depending on error-prone ordered lists or syntactically
51 * unpleasant pass-by-reference, we return an object with named parameters
52 * (like *_fetch_object()). Syntax is "f[repeat]name/...", where "f" is the
53 * formatter char (like pack()), "[repeat]" is the optional repeater
54 * argument, and "name" is the name of the variable to use.
55 * Example: "c2chars/nints" will return an object with fields
56 * chars1, chars2, and ints.
57 * Numeric pack types will return numbers, a and A will return strings,
58 * f and d will return doubles.
60 Variant
unpack(const String
& fmt
, const String
& data
);
63 // Whether machine is little endian
64 char machine_little_endian
;
66 // Mapping of byte from char (8bit) to int32 for machine endian
69 // Mappings of bytes from int (machine dependent) to int for machine endian
70 int64_t int_map
[sizeof(int)];
72 // Mappings of bytes from shorts (16bit) for all endian environments
73 int64_t machine_endian_short_map
[2];
74 int64_t big_endian_short_map
[2];
75 int64_t little_endian_short_map
[2];
77 // Mappings of bytes from int32s (32bit) for all endian environments
78 int64_t machine_endian_int32_map
[4];
79 int64_t big_endian_int32_map
[4];
80 int64_t little_endian_int32_map
[4];
82 /* Mappings of bytes from int64s (64bit) for all endian environments */
83 int64_t machine_endian_int64_map
[8];
84 int64_t big_endian_int64_map
[8];
85 int64_t little_endian_int64_map
[8];
87 void pack(const Variant
& val
, int64_t size
, int64_t *map
, char *output
);
88 int64_t unpack(const char *data
, int64_t size
, int issigned
, int64_t *map
);
91 ///////////////////////////////////////////////////////////////////////////////
94 #endif // incl_HPHP_ZEND_PACK_H_