websocket, utf: u8 fixes
parent
e97ebf8cfc
commit
ae6a25f44e
|
@ -3,7 +3,7 @@
|
|||
// that can be found in the LICENSE file.
|
||||
module builtin
|
||||
|
||||
pub fn utf8_char_len(b byte) int {
|
||||
pub fn utf8_char_len(b u8) int {
|
||||
return ((0xe5000000 >> ((b >> 3) & 0x1e)) & 3) + 1
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,7 @@ pub fn utf32_to_str(code u32) string {
|
|||
}
|
||||
|
||||
[manualfree; unsafe]
|
||||
pub fn utf32_to_str_no_malloc(code u32, buf &byte) string {
|
||||
pub fn utf32_to_str_no_malloc(code u32, buf &u8) string {
|
||||
unsafe {
|
||||
len := utf32_decode_to_buffer(code, buf)
|
||||
if len == 0 {
|
||||
|
@ -34,7 +34,7 @@ pub fn utf32_to_str_no_malloc(code u32, buf &byte) string {
|
|||
}
|
||||
|
||||
[manualfree; unsafe]
|
||||
pub fn utf32_decode_to_buffer(code u32, buf &byte) int {
|
||||
pub fn utf32_decode_to_buffer(code u32, buf &u8) int {
|
||||
unsafe {
|
||||
icode := int(code) // Prevents doing casts everywhere
|
||||
mut buffer := &u8(buf)
|
||||
|
@ -112,7 +112,7 @@ pub fn (_bytes []u8) utf8_to_utf32() ?rune {
|
|||
}
|
||||
|
||||
// Calculate length to read from the first byte
|
||||
fn utf8_len(c byte) int {
|
||||
fn utf8_len(c u8) int {
|
||||
mut b := 0
|
||||
mut x := c
|
||||
if (x & 240) != 0 {
|
||||
|
|
|
@ -86,7 +86,7 @@ fn (mut ws Client) read_payload(frame &Frame) ?[]u8 {
|
|||
return []u8{}
|
||||
}
|
||||
mut buffer := []u8{cap: frame.payload_len}
|
||||
mut read_buf := [1]byte{}
|
||||
mut read_buf := [1]u8{}
|
||||
mut bytes_read := 0
|
||||
for bytes_read < frame.payload_len {
|
||||
len := ws.socket_read_ptr(&read_buf[0], 1) ?
|
||||
|
@ -209,10 +209,10 @@ fn (ws Client) opcode_from_fragments() OPCode {
|
|||
|
||||
// parse_frame_header parses next message by decoding the incoming frames
|
||||
pub fn (mut ws Client) parse_frame_header() ?Frame {
|
||||
mut buffer := [256]byte{}
|
||||
mut buffer := [256]u8{}
|
||||
mut bytes_read := 0
|
||||
mut frame := Frame{}
|
||||
mut rbuff := [1]byte{}
|
||||
mut rbuff := [1]u8{}
|
||||
mut mask_end_byte := 0
|
||||
for ws.state == .open {
|
||||
read_bytes := ws.socket_read_ptr(&rbuff[0], 1) ?
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
type MyByte = byte
|
||||
type MyByte = u8
|
||||
|
||||
type MyInt = int
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ import strings
|
|||
// Encoder encodes the an `Any` type into JSON representation.
|
||||
// It provides parameters in order to change the end result.
|
||||
pub struct Encoder {
|
||||
newline byte
|
||||
newline u8
|
||||
newline_spaces_count int
|
||||
escape_unicode bool = true
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue