mirror of
https://github.com/antos-rde/antosdk-apps.git
synced 2025-08-28 06:42:35 +02:00
Reduce frame size
This commit is contained in:
@@ -12,49 +12,45 @@ class Msg
|
||||
|
||||
|
||||
as_raw:() ->
|
||||
length = 13 + @header.size
|
||||
length = 11 + @header.size
|
||||
arr = new Uint8Array(length)
|
||||
#arr.set(Msg.MAGIC_START, 0)
|
||||
arr[0] = @header.type
|
||||
arr.set(Msg.MAGIC_START, 0)
|
||||
arr[2] = @header.type
|
||||
bytes = Msg.bytes_of @header.cid
|
||||
arr.set(bytes,1)
|
||||
arr.set(bytes,3)
|
||||
bytes = Msg.bytes_of @header.sid
|
||||
arr.set(bytes,5)
|
||||
bytes = Msg.bytes_of @header.size
|
||||
arr.set(bytes,9)
|
||||
arr.set(bytes,7)
|
||||
if @data
|
||||
arr.set(@data, 13)
|
||||
# arr.set(Msg.MAGIC_END, @header.size + 13)
|
||||
arr.set(@data, 9)
|
||||
arr.set(Msg.MAGIC_END, @header.size + 9)
|
||||
arr.buffer
|
||||
|
||||
Msg.decode = (raw) ->
|
||||
new Promise (resolve, reject) ->
|
||||
msg = new Msg()
|
||||
#if(Msg.int_from(Msg.MAGIC_START, 0) != Msg.int_from(raw, 0))
|
||||
# return reject("Unmatch message begin magic number")
|
||||
msg.header.type = raw[0]
|
||||
msg.header.cid = Msg.int_from(raw, 1)
|
||||
if(Msg.int_from(Msg.MAGIC_START, 0) != Msg.int_from(raw, 0))
|
||||
return reject("Unmatch message begin magic number")
|
||||
msg.header.type = raw[2]
|
||||
msg.header.cid = Msg.int_from(raw, 3)
|
||||
msg.header.sid = Msg.int_from(raw,5)
|
||||
msg.header.size = Msg.int_from(raw, 9)
|
||||
msg.data = raw.slice(13, 13+msg.header.size)
|
||||
#if(Msg.int_from(Msg.MAGIC_END, 0) != Msg.int_from(raw, 17+msg.header.size))
|
||||
# return reject("Unmatch message end magic number")
|
||||
msg.header.size = Msg.int_from(raw, 7)
|
||||
msg.data = raw.slice(9, 9+msg.header.size)
|
||||
if(Msg.int_from(Msg.MAGIC_END, 0) != Msg.int_from(raw, 9+msg.header.size))
|
||||
return reject("Unmatch message end magic number")
|
||||
resolve msg
|
||||
|
||||
|
||||
Msg.bytes_of = (x) ->
|
||||
bytes=new Uint8Array(4)
|
||||
bytes=new Uint8Array(2)
|
||||
bytes[0]=x & (255)
|
||||
x=x>>8
|
||||
bytes[1]=x & (255)
|
||||
x=x>>8
|
||||
bytes[2]=x & (255)
|
||||
x=x>>8
|
||||
bytes[3]=x & (255)
|
||||
bytes
|
||||
|
||||
Msg.int_from = (bytes, offset) ->
|
||||
(bytes[offset] | (bytes[offset+1]<<8) | (bytes[offset+2]<<16) | (bytes[offset+3] << 24))
|
||||
(bytes[offset] | (bytes[offset+1]<<8))
|
||||
|
||||
Msg.OK = 0
|
||||
Msg.ERROR = 1
|
||||
@@ -63,8 +59,8 @@ Msg.CLOSE = 5
|
||||
Msg.SUBSCRIBE = 2
|
||||
Msg.UNSUBSCRIBE = 3
|
||||
Msg.CTRL = 7
|
||||
#Msg.MAGIC_END = [ 0x41, 0x4e, 0x54, 0x44]
|
||||
#Msg.MAGIC_START = [0x44, 0x54, 0x4e, 0x41 ]
|
||||
Msg.MAGIC_END = [0x44, 0x54]
|
||||
Msg.MAGIC_START = [0x4e, 0x41 ]
|
||||
|
||||
class Subscriber
|
||||
constructor: (@channel) ->
|
||||
@@ -178,6 +174,7 @@ class AntunnelApi
|
||||
.catch (e) =>
|
||||
v.onerror(e) for k,v of @pending when v.onerror
|
||||
v.onerror(e) for k,v of @subscribers when v.onerror
|
||||
console.log e
|
||||
|
||||
|
||||
subscribe: (sub) ->
|
||||
|
Reference in New Issue
Block a user