Module: MTProto::Binary

Instance Method Summary collapse

Instance Method Details

#b_u32(bytes) ⇒ Object



5
6
7
# File 'lib/mtproto/binary.rb', line 5

def b_u32(bytes)
  bytes[0] | (bytes[1] << 8) | (bytes[2] << 16) | (bytes[3] << 24)
end

#b_u64(bytes) ⇒ Object



9
10
11
# File 'lib/mtproto/binary.rb', line 9

def b_u64(bytes)
  b_u32(bytes[0, 4]) | (b_u32(bytes[4, 4]) << 32)
end

#u32_b(value) ⇒ Object



13
14
15
# File 'lib/mtproto/binary.rb', line 13

def u32_b(value)
  [value & 0xff, (value >> 8) & 0xff, (value >> 16) & 0xff, (value >> 24) & 0xff]
end

#u64_b(value) ⇒ Object



17
18
19
# File 'lib/mtproto/binary.rb', line 17

def u64_b(value)
  u32_b(value & 0xffffffff) + u32_b(value >> 32)
end