From 4493f369ddb54c1f284a47483bf162d65115ad7a Mon Sep 17 00:00:00 2001 From: Jakob Ketterl Date: Fri, 19 Jul 2019 17:01:50 +0200 Subject: [PATCH] enable 64-bit frames for large amounts of data --- owrx/websocket.py | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/owrx/websocket.py b/owrx/websocket.py index a247b2a..360f28b 100644 --- a/owrx/websocket.py +++ b/owrx/websocket.py @@ -23,10 +23,31 @@ class WebSocketConnection(object): def get_header(self, size, opcode): ws_first_byte = 0b10000000 | (opcode & 0x0F) - if (size > 125): - return bytes([ws_first_byte, 126, (size>>8) & 0xff, size & 0xff]) + if (size > 2**16 - 1): + # frame size can be increased up to 2^64 by setting the size to 127 + # anything beyond that would need to be segmented into frames. i don't really think we'll need more. + return bytes([ + ws_first_byte, + 127, + (size >> 56) & 0xff, + (size >> 48) & 0xff, + (size >> 40) & 0xff, + (size >> 32) & 0xff, + (size >> 24) & 0xff, + (size >> 16) & 0xff, + (size >> 8) & 0xff, + size & 0xff + ]) + elif (size > 125): + # up to 2^16 can be sent using the extended payload size field by putting the size to 126 + return bytes([ + ws_first_byte, + 126, + (size >> 8) & 0xff, + size & 0xff + ]) else: - # 256 bytes binary message in a single unmasked frame + # 125 bytes binary message in a single unmasked frame return bytes([ws_first_byte, size]) def send(self, data):