Created
March 19, 2017 13:37
-
-
Save MagnificentPako/90384d6ca7c90a9016df0aab75725983 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use "buffered" | |
class Frame | |
let _final: Bool | |
let _rsv: (Bool, Bool, Bool) | |
let _opcode: Opcode | |
let _use_mask: Bool | |
let _payload_type: U8 | |
let _payload_size: (U8 | U16 | U64) | |
let _mask_key: (None | U32) | |
let _data: Array[U8] val | |
new create(final': Bool, opcode': Opcode, data': String) => | |
_final = final' | |
_rsv = (false, false, false) | |
_opcode = opcode' | |
_use_mask = false | |
_payload_type = if data'.size() <= 126 then | |
0 else if data'.size() <= 65536 then | |
1 else | |
2 end end | |
_payload_size = data'.size().u64() | |
_mask_key = None | |
_data = data'.array() | |
fun build(): Array[ByteSeq] iso^ => | |
let wb = Writer | |
wb.u8(Byte.from_bits( | |
if _final then 1 else 0 end, | |
0, | |
0, | |
0, | |
1, | |
0, | |
0, | |
0 | |
)) | |
try if _payload_type == 0 then | |
let siz: U8 = _payload_size as U8 | |
wb.u8(siz) | |
else if _payload_type == 1 then | |
let siz: U16 = _payload_size as U16 | |
wb.u8(126) | |
else | |
wb.u8(127) | |
end end end | |
wb.done() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment