Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- buffer = new Buffer [0xAA,0xBB, 0xAA,0xBB,0xCC,0xDD]
- big =
- Buffer::pos = -1
- Buffer::unpack = (struct) ->
- packet = {}
- for field of struct
- val = 0
- for i in [struct[field].size-1..0]
- val|=(@[@pos+=1]<<(i<<3))
- packet[field] =
- if not struct[field].signed or not struct[field].signed?
- val &((1<<(struct[field].size<<2))-1)
- else (((~val&((1<<(struct[field].size<<2))-1))+1)*-1)
- packet
- packet = buffer.unpack
- itemID : (size:2)
- interfaceID : (size:4)
- console.log packet.itemID.toString 16
- console.log packet.interfaceID.toString 16
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement