计算经经php打包以后的包体的长度

来源:互联网 发布:es6数组去重的方法 编辑:程序博客网 时间:2024/05/28 01:34

 

$body_bin = pack('LLCCa16LL', $user_id, $free_cost,  $is_vip, $buy_placei, md5($passwd, true), $mb_product_count, $tongbao_produc
t_count);                                                                                                                          

$pkg_len = strlen($body_bin);
echo "package length : $pkg_len\n";

结果是:34

解析:

  • a - NUL-padded string
  • A - SPACE-padded string
  • h - Hex string, low nibble first
  • H - Hex string, high nibble first
  • c - signed char
  • C - unsigned char
  • s - signed short (always 16 bit, machine byte order)
  • S - unsigned short (always 16 bit, machine byte order)
  • n - unsigned short (always 16 bit, big endian byte order)
  • v - unsigned short (always 16 bit, little endian byte order)
  • i - signed integer (machine dependent size and byte order)
  • I - unsigned integer (machine dependent size and byte order)
  • l - signed long (always 32 bit, machine byte order)
  • L - unsigned long (always 32 bit, machine byte order)
  • N - unsigned long (always 32 bit, big endian byte order)
  • V - unsigned long (always 32 bit, little endian byte order)
  • f - float (machine dependent size and representation)
  • d - double (machine dependent size and representation)
  • x - NUL byte
  • X - Back up one byte
  • @ - NUL-fill to absolute position

可以看出L代表unsigned long ,类型,占有4字节。C代表unsigned char类型,占有1字节。而“a+数字”就是 padded string 类型,长度为“数字”个字节的长度,所以a16

有长度为16个字节。

然后:4+4+1+1+16+4+4=34

原创粉丝点击