x.websocket: bring back shift operators (#8197)

pull/8199/head
Tomas Hellström 2021-01-19 10:42:59 +01:00 committed by GitHub
parent 927606dc39
commit da93666cd8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 11 deletions

View File

@ -1,7 +1,6 @@
module websocket module websocket
import encoding.utf8 import encoding.utf8
import math
const ( const (
header_len_offset = 2 // offset for lengthpart of websocket header header_len_offset = 2 // offset for lengthpart of websocket header
@ -254,7 +253,7 @@ pub fn (mut ws Client) parse_frame_header() ?Frame {
if frame.payload_len == 126 && bytes_read == u64(extended_payload16_end_byte) { if frame.payload_len == 126 && bytes_read == u64(extended_payload16_end_byte) {
frame.header_len += 2 frame.header_len += 2
frame.payload_len = 0 frame.payload_len = 0
frame.payload_len |= (buffer[2] * int(math.pow(2, 8))) frame.payload_len |= buffer[2] << 8
frame.payload_len |= buffer[3] frame.payload_len |= buffer[3]
frame.frame_size = frame.header_len + frame.payload_len frame.frame_size = frame.header_len + frame.payload_len
if !frame.has_mask { if !frame.has_mask {
@ -263,15 +262,17 @@ pub fn (mut ws Client) parse_frame_header() ?Frame {
} }
if frame.payload_len == 127 && bytes_read == u64(extended_payload64_end_byte) { if frame.payload_len == 127 && bytes_read == u64(extended_payload64_end_byte) {
frame.header_len += 8 frame.header_len += 8
frame.payload_len = 0 // these shift operators needs 64 bit on clang with -prod flag
frame.payload_len |= (buffer[2] * int(math.pow(2, 56))) mut payload_len := u64(0)
frame.payload_len |= (buffer[3] * int(math.pow(2, 48))) payload_len |= buffer[2] << 56
frame.payload_len |= (buffer[4] * int(math.pow(2, 40))) payload_len |= buffer[3] << 48
frame.payload_len |= (buffer[5] * int(math.pow(2, 32))) payload_len |= buffer[4] << 40
frame.payload_len |= (buffer[6] * int(math.pow(2, 24))) payload_len |= buffer[5] << 32
frame.payload_len |= (buffer[7] * int(math.pow(2, 16))) payload_len |= buffer[6] << 24
frame.payload_len |= (buffer[8] * int(math.pow(2, 8))) payload_len |= buffer[7] << 16
frame.payload_len |= buffer[9] payload_len |= buffer[8] << 8
payload_len |= buffer[9]
frame.payload_len = int(payload_len)
if !frame.has_mask { if !frame.has_mask {
break break
} }