基本的なデータ型 > エンコードされた整数

エンコードされた整数

SWF 9 以降では、エンコードされた可変長サイズの整数がサポートされます。 エンコードされた整数型は 1 種類だけです。

エンコードされた整数

コメント
EncodedU32 可変長サイズのエンコードされた 32-bit 符号無し整数

この、 32-bit 符号無しのエンコードされた整数値は、保存領域が可変長になっています。 数値の大きさにより、 EncodedU32 型は 1 ~ 5 バイトの間で長さが変化します (大きな値ほど大きな保存領域が要る)。 エンコードの方式:

  • 最上位ビットがセットされていたら、次のバイトにデータが続く
  • 最上位ビットがセットされていなかったら、そこでデータを終了する
  • 残り 7 bit に値が入る

EncodedU32 型の数は、次のようなアルゴリズムで元の数に戻すことができます。

int GetEncodedU32(unsigned char*& pos)
{
 int result = pos[0];
 if (!(result & 0x00000080))
 {
  pos++;
  return result;
 }
 result = (result & 0x0000007f) | pos[1]<<7;
 if (!(result & 0x00004000))
 {
  pos += 2;
  return result;
 }
 result = (result & 0x00003fff) | pos[2]<<14;
 if (!(result & 0x00200000))
 {
  pos += 3;
  return result;
 }
 result = (result & 0x001fffff) | pos[3]<<21;
 if (!(result & 0x10000000))
 {
  pos += 4;
  return result;
 }
 result = (result & 0x0fffffff) | pos[4]<<28;
 pos += 5;
 return result;
}

移動

最終更新:2017年02月20日 20:32