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
import encoding.utf8
import math
const (
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) {
frame.header_len += 2
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.frame_size = frame.header_len + frame.payload_len
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) {
frame.header_len += 8
frame.payload_len = 0
frame.payload_len |= (buffer[2] * int(math.pow(2, 56)))
frame.payload_len |= (buffer[3] * int(math.pow(2, 48)))
frame.payload_len |= (buffer[4] * int(math.pow(2, 40)))
frame.payload_len |= (buffer[5] * int(math.pow(2, 32)))
frame.payload_len |= (buffer[6] * int(math.pow(2, 24)))
frame.payload_len |= (buffer[7] * int(math.pow(2, 16)))
frame.payload_len |= (buffer[8] * int(math.pow(2, 8)))
frame.payload_len |= buffer[9]
// these shift operators needs 64 bit on clang with -prod flag
mut payload_len := u64(0)
payload_len |= buffer[2] << 56
payload_len |= buffer[3] << 48
payload_len |= buffer[4] << 40
payload_len |= buffer[5] << 32
payload_len |= buffer[6] << 24
payload_len |= buffer[7] << 16
payload_len |= buffer[8] << 8
payload_len |= buffer[9]
frame.payload_len = int(payload_len)
if !frame.has_mask {
break
}