LoginSignup
2
2

More than 5 years have passed since last update.

MessagePackの整数型のバリエーションとC#でそれに対応する型

Posted at
MsgPack型 C#型 (class) 範囲 プレフィクス
positive fixnum (7bit) sbyte (SByte) 0 〜 127 0xxxxxxx
negative fixnum (5bit) sbyte (SByte) -32 〜 -1 111yyyyy
uint 8bit byte (Byte) 0 〜 255 0xcc
uint 16bit ushort (UInt16) 0 〜 65,535 0xcd
uint 32bit uint (UInt32) 0 〜 4,294,967,295 0xce
uint 64bit ulong (UInt64) 0 〜 18,446,744,073,709,551,615 0xcf
int 8bit sbyte (SByte) -128 〜 127 0xd0
int 16bit short (Int16) -32,768 〜 32,767 0xd1
int 32bit int (Int32) −2,147,483,648 〜 2,147,483,647 0xd2
int 64bit long (Int64) -9,223,372,036,854,775,808 〜 9,223,372,036,854,775,807 0xd3

Rubyでの検証コード(参考)

msgpk_spec.rb
require 'msgpack'

numbers = [
  0,
  127,
  128,
  255,
  256,
  65535,
  65536,
  4294967295,
  4294967296,
  18446744073709551615,
  -1,
  -32,
  -33,
  -128,
  -129,
  -32768,
  -32769,
  -2147483648,
  -2147483649,
  -9223372036854775808
]

numbers.each do |num|
  puts "#{num} => #{MessagePack.dump(num).unpack('H*')}"
end

実行結果

0 => ["00"]
127 => ["f7"]
128 => ["cc08"]
255 => ["ccff"]
256 => ["dc1000"]
65535 => ["dcffff"]
65536 => ["ec00100000"]
4294967295 => ["ecffffffff"]
4294967296 => ["fc0000001000000000"]
18446744073709551615 => ["fcffffffffffffffff"]
-1 => ["ff"]
-32 => ["0e"]
-33 => ["0dfd"]
-128 => ["0d08"]
-129 => ["1dfff7"]
-32768 => ["1d0800"]
-32769 => ["2dfffff7ff"]
-2147483648 => ["2d08000000"]
-2147483649 => ["3dfffffffff7ffffff"]
-9223372036854775808 => ["3d0800000000000000"]
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2