Reduce frame size

This commit is contained in:
lxsang 2020-11-29 13:29:26 +01:00
parent 51ab2d13a3
commit 929efb45bf
8 changed files with 26 additions and 27 deletions

View File

@ -5,4 +5,5 @@ talk to server side applications via the [`antd-tunnel-pligin`](https://github.c
using a single websocket API. using a single websocket API.
## Changes log ## Changes log
- v0.1.4-a Reduce frame overhead
- v0.1.3-a Remove magic number in the frame to reduce frame overhead - v0.1.3-a Remove magic number in the frame to reduce frame overhead

View File

@ -5,4 +5,5 @@ talk to server side applications via the [`antd-tunnel-pligin`](https://github.c
using a single websocket API. using a single websocket API.
## Changes log ## Changes log
- v0.1.4-a Reduce frame overhead
- v0.1.3-a Remove magic number in the frame to reduce frame overhead - v0.1.3-a Remove magic number in the frame to reduce frame overhead

File diff suppressed because one or more lines are too long

View File

@ -9,7 +9,7 @@
"author": "Xuan Sang LE", "author": "Xuan Sang LE",
"email": "xsang.le@lxsang.me" "email": "xsang.le@lxsang.me"
}, },
"version":"0.1.3-a", "version":"0.1.4-a",
"category":"Library", "category":"Library",
"iconclass":"fa fa-adn", "iconclass":"fa fa-adn",
"mimes":["none"], "mimes":["none"],

Binary file not shown.

View File

@ -12,49 +12,45 @@ class Msg
as_raw:() -> as_raw:() ->
length = 13 + @header.size length = 11 + @header.size
arr = new Uint8Array(length) arr = new Uint8Array(length)
#arr.set(Msg.MAGIC_START, 0) arr.set(Msg.MAGIC_START, 0)
arr[0] = @header.type arr[2] = @header.type
bytes = Msg.bytes_of @header.cid bytes = Msg.bytes_of @header.cid
arr.set(bytes,1) arr.set(bytes,3)
bytes = Msg.bytes_of @header.sid bytes = Msg.bytes_of @header.sid
arr.set(bytes,5) arr.set(bytes,5)
bytes = Msg.bytes_of @header.size bytes = Msg.bytes_of @header.size
arr.set(bytes,9) arr.set(bytes,7)
if @data if @data
arr.set(@data, 13) arr.set(@data, 9)
# arr.set(Msg.MAGIC_END, @header.size + 13) arr.set(Msg.MAGIC_END, @header.size + 9)
arr.buffer arr.buffer
Msg.decode = (raw) -> Msg.decode = (raw) ->
new Promise (resolve, reject) -> new Promise (resolve, reject) ->
msg = new Msg() msg = new Msg()
#if(Msg.int_from(Msg.MAGIC_START, 0) != Msg.int_from(raw, 0)) if(Msg.int_from(Msg.MAGIC_START, 0) != Msg.int_from(raw, 0))
# return reject("Unmatch message begin magic number") return reject("Unmatch message begin magic number")
msg.header.type = raw[0] msg.header.type = raw[2]
msg.header.cid = Msg.int_from(raw, 1) msg.header.cid = Msg.int_from(raw, 3)
msg.header.sid = Msg.int_from(raw,5) msg.header.sid = Msg.int_from(raw,5)
msg.header.size = Msg.int_from(raw, 9) msg.header.size = Msg.int_from(raw, 7)
msg.data = raw.slice(13, 13+msg.header.size) msg.data = raw.slice(9, 9+msg.header.size)
#if(Msg.int_from(Msg.MAGIC_END, 0) != Msg.int_from(raw, 17+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") return reject("Unmatch message end magic number")
resolve msg resolve msg
Msg.bytes_of = (x) -> Msg.bytes_of = (x) ->
bytes=new Uint8Array(4) bytes=new Uint8Array(2)
bytes[0]=x & (255) bytes[0]=x & (255)
x=x>>8 x=x>>8
bytes[1]=x & (255) bytes[1]=x & (255)
x=x>>8
bytes[2]=x & (255)
x=x>>8
bytes[3]=x & (255)
bytes bytes
Msg.int_from = (bytes, offset) -> 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.OK = 0
Msg.ERROR = 1 Msg.ERROR = 1
@ -63,8 +59,8 @@ Msg.CLOSE = 5
Msg.SUBSCRIBE = 2 Msg.SUBSCRIBE = 2
Msg.UNSUBSCRIBE = 3 Msg.UNSUBSCRIBE = 3
Msg.CTRL = 7 Msg.CTRL = 7
#Msg.MAGIC_END = [ 0x41, 0x4e, 0x54, 0x44] Msg.MAGIC_END = [0x44, 0x54]
#Msg.MAGIC_START = [0x44, 0x54, 0x4e, 0x41 ] Msg.MAGIC_START = [0x4e, 0x41 ]
class Subscriber class Subscriber
constructor: (@channel) -> constructor: (@channel) ->
@ -178,6 +174,7 @@ class AntunnelApi
.catch (e) => .catch (e) =>
v.onerror(e) for k,v of @pending when v.onerror v.onerror(e) for k,v of @pending when v.onerror
v.onerror(e) for k,v of @subscribers when v.onerror v.onerror(e) for k,v of @subscribers when v.onerror
console.log e
subscribe: (sub) -> subscribe: (sub) ->

View File

@ -9,7 +9,7 @@
"author": "Xuan Sang LE", "author": "Xuan Sang LE",
"email": "xsang.le@lxsang.me" "email": "xsang.le@lxsang.me"
}, },
"version":"0.1.3-a", "version":"0.1.4-a",
"category":"Library", "category":"Library",
"iconclass":"fa fa-adn", "iconclass":"fa fa-adn",
"mimes":["none"], "mimes":["none"],

View File

@ -23,7 +23,7 @@
"description": "https://raw.githubusercontent.com/lxsang/antosdk-apps/master/Antunnel/README.md", "description": "https://raw.githubusercontent.com/lxsang/antosdk-apps/master/Antunnel/README.md",
"category": "Library", "category": "Library",
"author": "Xuan Sang LE", "author": "Xuan Sang LE",
"version": "0.1.3-a", "version": "0.1.4-a",
"download": "https://raw.githubusercontent.com/lxsang/antosdk-apps/master/Antunnel/build/release/Antunnel.zip" "download": "https://raw.githubusercontent.com/lxsang/antosdk-apps/master/Antunnel/build/release/Antunnel.zip"
}, },
{ {