net: byte fixes

Alexander Medvednikov 2022-04-15 15:55:39 +03:00 committed by Jef Roosens
parent f293874c05
commit bbfd6900fa
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
18 changed files with 54 additions and 65 deletions

View File

@ -92,13 +92,13 @@ fn (mut p Player) free() {
// > MUST be placed before the Sound data chunk (but not necessarily // > MUST be placed before the Sound data chunk (but not necessarily
// > contiguous to the Sound data chunk). // > contiguous to the Sound data chunk).
struct RIFFHeader { struct RIFFHeader {
riff [4]byte riff [4]u8
file_size u32 file_size u32
form_type [4]byte form_type [4]u8
} }
struct RIFFChunkHeader { struct RIFFChunkHeader {
chunk_type [4]byte chunk_type [4]u8
chunk_size u32 chunk_size u32
chunk_data voidptr chunk_data voidptr
} }
@ -113,7 +113,7 @@ struct RIFFFormat {
cbsize u16 // Size of the extension: 22 cbsize u16 // Size of the extension: 22
valid_bits_per_sample u16 // at most 8*M valid_bits_per_sample u16 // at most 8*M
channel_mask u32 // Speaker position mask channel_mask u32 // Speaker position mask
sub_format [16]byte // GUID sub_format [16]u8 // GUID
} }
fn read_wav_file_samples(fpath string) ?[]f32 { fn read_wav_file_samples(fpath string) ?[]f32 {

View File

@ -133,7 +133,7 @@ pub fn i64_str(n0 i64, base int) string {
} }
pub fn ptr_str(ptr voidptr) string { pub fn ptr_str(ptr voidptr) string {
buf := [16]byte{} buf := [16]u8{}
hex := i64_tos(buf, 15, i64(ptr), 16) hex := i64_tos(buf, 15, i64(ptr), 16)
res := '0x' + hex res := '0x' + hex
return res return res

View File

@ -71,13 +71,6 @@ fn decode_i64(root &C.cJSON) i64 {
return i64(root.valuedouble) // i64 is double in C return i64(root.valuedouble) // i64 is double in C
} }
fn decode_u8(root &C.cJSON) byte {
if isnil(root) {
return u8(0)
}
return u8(root.valueint)
}
fn decode_u8(root &C.cJSON) u8 { fn decode_u8(root &C.cJSON) u8 {
if isnil(root) { if isnil(root) {
return u8(0) return u8(0)
@ -168,10 +161,6 @@ fn encode_i64(val i64) &C.cJSON {
return C.cJSON_CreateNumber(val) return C.cJSON_CreateNumber(val)
} }
fn encode_u8(val byte) &C.cJSON {
return C.cJSON_CreateNumber(val)
}
fn encode_u8(val u8) &C.cJSON { fn encode_u8(val u8) &C.cJSON {
return C.cJSON_CreateNumber(val) return C.cJSON_CreateNumber(val)
} }

View File

@ -10,13 +10,13 @@ union AddrData {
} }
const ( const (
addr_ip6_any = [16]byte{init: u8(0)} addr_ip6_any = [16]u8{init: u8(0)}
addr_ip_any = [4]byte{init: u8(0)} addr_ip_any = [4]u8{init: u8(0)}
) )
fn new_ip6(port u16, addr [16]byte) Addr { fn new_ip6(port u16, addr [16]u8) Addr {
a := Addr{ a := Addr{
f: u16(AddrFamily.ip6) f: u8(AddrFamily.ip6)
addr: AddrData{ addr: AddrData{
Ip6: Ip6{ Ip6: Ip6{
port: u16(C.htons(port)) port: u16(C.htons(port))
@ -29,9 +29,9 @@ fn new_ip6(port u16, addr [16]byte) Addr {
return a return a
} }
fn new_ip(port u16, addr [4]byte) Addr { fn new_ip(port u16, addr [4]u8) Addr {
a := Addr{ a := Addr{
f: u16(AddrFamily.ip) f: u8(AddrFamily.ip)
addr: AddrData{ addr: AddrData{
Ip: Ip{ Ip: Ip{
port: u16(C.htons(port)) port: u16(C.htons(port))
@ -133,7 +133,7 @@ pub fn resolve_addrs(addr string, family AddrFamily, @type SocketType) ?[]Addr {
return [ return [
Addr{ Addr{
f: u16(AddrFamily.unix) f: u8(AddrFamily.unix)
addr: AddrData{ addr: AddrData{
Unix: resolved Unix: resolved
} }

View File

@ -38,20 +38,20 @@ mut:
struct Ip6 { struct Ip6 {
port u16 port u16
flow_info u32 flow_info u32
addr [16]byte addr [16]u8
scope_id u32 scope_id u32
} }
[_pack: '1'] [_pack: '1']
struct Ip { struct Ip {
port u16 port u16
addr [4]byte addr [4]u8
// Pad to size so that socket functions // Pad to size so that socket functions
// dont complain to us (see in.h and bind()) // dont complain to us (see in.h and bind())
// TODO(emily): I would really like to use // TODO(emily): I would really like to use
// some constant calculations here // some constant calculations here
// so that this doesnt have to be hardcoded // so that this doesnt have to be hardcoded
sin_pad [8]byte sin_pad [8]u8
} }
struct Unix { struct Unix {

View File

@ -21,7 +21,7 @@ mut:
sin6_family byte // 1 sin6_family byte // 1
sin6_port u16 // 2 sin6_port u16 // 2
sin6_flowinfo u32 // 4 sin6_flowinfo u32 // 4
sin6_addr [16]byte // 16 sin6_addr [16]u8 // 16
sin6_scope_id u32 // 4 sin6_scope_id u32 // 4
} }
@ -45,20 +45,20 @@ mut:
struct Ip6 { struct Ip6 {
port u16 port u16
flow_info u32 flow_info u32
addr [16]byte addr [16]u8
scope_id u32 scope_id u32
} }
[_pack: '1'] [_pack: '1']
struct Ip { struct Ip {
port u16 port u16
addr [4]byte addr [4]u8
// Pad to size so that socket functions // Pad to size so that socket functions
// dont complain to us (see in.h and bind()) // dont complain to us (see in.h and bind())
// TODO(emily): I would really like to use // TODO(emily): I would really like to use
// some constant calculations here // some constant calculations here
// so that this doesnt have to be hardcoded // so that this doesnt have to be hardcoded
sin_pad [8]byte sin_pad [8]u8
} }
struct Unix { struct Unix {

View File

@ -26,7 +26,7 @@ mut:
sin6_family byte // 1 sin6_family byte // 1
sin6_port u16 // 2 sin6_port u16 // 2
sin6_flowinfo u32 // 4 sin6_flowinfo u32 // 4
sin6_addr [16]byte // 16 sin6_addr [16]u8 // 16
sin6_scope_id u32 // 4 sin6_scope_id u32 // 4
} }
@ -50,20 +50,20 @@ mut:
struct Ip6 { struct Ip6 {
port u16 port u16
flow_info u32 flow_info u32
addr [16]byte addr [16]u8
scope_id u32 scope_id u32
} }
[_pack: '1'] [_pack: '1']
struct Ip { struct Ip {
port u16 port u16
addr [4]byte addr [4]u8
// Pad to size so that socket functions // Pad to size so that socket functions
// dont complain to us (see in.h and bind()) // dont complain to us (see in.h and bind())
// TODO(emily): I would really like to use // TODO(emily): I would really like to use
// some constant calculations here // some constant calculations here
// so that this doesnt have to be hardcoded // so that this doesnt have to be hardcoded
sin_pad [8]byte sin_pad [8]u8
} }
struct Unix { struct Unix {

View File

@ -24,7 +24,7 @@ mut:
sin6_family byte // 1 sin6_family byte // 1
sin6_port u16 // 2 sin6_port u16 // 2
sin6_flowinfo u32 // 4 sin6_flowinfo u32 // 4
sin6_addr [16]byte // 16 sin6_addr [16]u8 // 16
sin6_scope_id u32 // 4 sin6_scope_id u32 // 4
} }
@ -48,20 +48,20 @@ mut:
struct Ip6 { struct Ip6 {
port u16 port u16
flow_info u32 flow_info u32
addr [16]byte addr [16]u8
scope_id u32 scope_id u32
} }
[_pack: '1'] [_pack: '1']
struct Ip { struct Ip {
port u16 port u16
addr [4]byte addr [4]u8
// Pad to size so that socket functions // Pad to size so that socket functions
// dont complain to us (see in.h and bind()) // dont complain to us (see in.h and bind())
// TODO(emily): I would really like to use // TODO(emily): I would really like to use
// some constant calculations here // some constant calculations here
// so that this doesnt have to be hardcoded // so that this doesnt have to be hardcoded
sin_pad [8]byte sin_pad [8]u8
} }
struct Unix { struct Unix {

View File

@ -38,20 +38,20 @@ mut:
struct Ip6 { struct Ip6 {
port u16 port u16
flow_info u32 flow_info u32
addr [16]byte addr [16]u8
scope_id u32 scope_id u32
} }
[_pack: '1'] [_pack: '1']
struct Ip { struct Ip {
port u16 port u16
addr [4]byte addr [4]u8
// Pad to size so that socket functions // Pad to size so that socket functions
// dont complain to us (see in.h and bind()) // dont complain to us (see in.h and bind())
// TODO(emily): I would really like to use // TODO(emily): I would really like to use
// some constant calculations here // some constant calculations here
// so that this doesnt have to be hardcoded // so that this doesnt have to be hardcoded
sin_pad [8]byte sin_pad [8]u8
} }
struct Unix { struct Unix {

View File

@ -26,7 +26,7 @@ mut:
sin6_family byte // 1 sin6_family byte // 1
sin6_port u16 // 2 sin6_port u16 // 2
sin6_flowinfo u32 // 4 sin6_flowinfo u32 // 4
sin6_addr [16]byte // 16 sin6_addr [16]u8 // 16
sin6_scope_id u32 // 4 sin6_scope_id u32 // 4
} }
@ -50,20 +50,20 @@ mut:
struct Ip6 { struct Ip6 {
port u16 port u16
flow_info u32 flow_info u32
addr [16]byte addr [16]u8
scope_id u32 scope_id u32
} }
[_pack: '1'] [_pack: '1']
struct Ip { struct Ip {
port u16 port u16
addr [4]byte addr [4]u8
// Pad to size so that socket functions // Pad to size so that socket functions
// dont complain to us (see in.h and bind()) // dont complain to us (see in.h and bind())
// TODO(emily): I would really like to use // TODO(emily): I would really like to use
// some constant calculations here // some constant calculations here
// so that this doesnt have to be hardcoded // so that this doesnt have to be hardcoded
sin_pad [8]byte sin_pad [8]u8
} }
struct Unix { struct Unix {

View File

@ -24,7 +24,7 @@ mut:
sin6_family byte // 1 sin6_family byte // 1
sin6_port u16 // 2 sin6_port u16 // 2
sin6_flowinfo u32 // 4 sin6_flowinfo u32 // 4
sin6_addr [16]byte // 16 sin6_addr [16]u8 // 16
sin6_scope_id u32 // 4 sin6_scope_id u32 // 4
} }
@ -48,20 +48,20 @@ mut:
struct Ip6 { struct Ip6 {
port u16 port u16
flow_info u32 flow_info u32
addr [16]byte addr [16]u8
scope_id u32 scope_id u32
} }
[_pack: '1'] [_pack: '1']
struct Ip { struct Ip {
port u16 port u16
addr [4]byte addr [4]u8
// Pad to size so that socket functions // Pad to size so that socket functions
// dont complain to us (see in.h and bind()) // dont complain to us (see in.h and bind())
// TODO(emily): I would really like to use // TODO(emily): I would really like to use
// some constant calculations here // some constant calculations here
// so that this doesnt have to be hardcoded // so that this doesnt have to be hardcoded
sin_pad [8]byte sin_pad [8]u8
} }
struct Unix { struct Unix {

View File

@ -38,15 +38,15 @@ mut:
struct Ip6 { struct Ip6 {
port u16 port u16
flow_info u32 flow_info u32
addr [16]byte addr [16]u8
scope_id u32 scope_id u32
} }
[_pack: '1'] [_pack: '1']
struct Ip { struct Ip {
port u16 port u16
addr [4]byte addr [4]u8
sin_pad [8]byte sin_pad [8]u8
} }
struct Unix { struct Unix {

View File

@ -177,7 +177,7 @@ pub fn (c &Cookie) str() string {
return b.str() return b.str()
} }
fn sanitize(valid fn (byte) bool, v string) string { fn sanitize(valid fn (u8) bool, v string) string {
mut ok := true mut ok := true
for i in 0 .. v.len { for i in 0 .. v.len {
if valid(v[i]) { if valid(v[i]) {
@ -222,11 +222,11 @@ fn sanitize_cookie_path(v string) string {
return sanitize(valid_cookie_path_byte, v) return sanitize(valid_cookie_path_byte, v)
} }
fn valid_cookie_value_u8(b byte) bool { fn valid_cookie_value_byte(b u8) bool {
return 0x20 <= b && b < 0x7f && b != `"` && b != `;` && b != `\\` return 0x20 <= b && b < 0x7f && b != `"` && b != `;` && b != `\\`
} }
fn valid_cookie_path_u8(b byte) bool { fn valid_cookie_path_byte(b u8) bool {
return 0x20 <= b && b < 0x7f && b != `!` return 0x20 <= b && b < 0x7f && b != `!`
} }
@ -300,7 +300,7 @@ fn parse_cookie_value(_raw string, allow_double_quote bool) ?string {
raw = raw.substr(1, raw.len - 1) raw = raw.substr(1, raw.len - 1)
} }
for i in 0 .. raw.len { for i in 0 .. raw.len {
if !valid_cookie_value_u8(raw[i]) { if !valid_cookie_value_byte(raw[i]) {
return error('http.cookie: invalid cookie value') return error('http.cookie: invalid cookie value')
} }
} }

View File

@ -29,7 +29,7 @@ mut:
opcode OPCode // interpretation of the payload data opcode OPCode // interpretation of the payload data
has_mask bool // true if the payload data is masked has_mask bool // true if the payload data is masked
payload_len int // payload length payload_len int // payload length
masking_key [4]byte // all frames from client to server is masked with this key masking_key [4]u8 // all frames from client to server is masked with this key
} }
const ( const (

View File

@ -39,7 +39,6 @@ pub const (
pub type Primitive = InfixType pub type Primitive = InfixType
| bool | bool
| byte
| f32 | f32
| f64 | f64
| i16 | i16
@ -51,6 +50,7 @@ pub type Primitive = InfixType
| u16 | u16
| u32 | u32
| u64 | u64
| u8
pub enum OperationKind { pub enum OperationKind {
neq // != neq // !=
@ -467,7 +467,7 @@ pub fn i64_to_primitive(b i64) Primitive {
return Primitive(b) return Primitive(b)
} }
pub fn byte_to_primitive(b byte) Primitive { pub fn u8_to_primitive(b u8) Primitive {
return Primitive(b) return Primitive(b)
} }

View File

@ -92,10 +92,10 @@ fn pg_stmt_match(mut types []u32, mut vals []&char, mut lens []int, mut formats
lens << int(sizeof(bool)) lens << int(sizeof(bool))
formats << 1 formats << 1
} }
byte { u8 {
types << u32(Oid.t_char) types << u32(Oid.t_char)
vals << &char(&(d as byte)) vals << &char(&(d as u8))
lens << int(sizeof(byte)) lens << int(sizeof(u8))
formats << 1 formats << 1
} }
u16 { u16 {

View File

@ -1405,7 +1405,7 @@ pub fn (mut t Table) complete_interface_check() {
// //
// `123 > panic()` // `123 > panic()`
// //
// `128 > [16]byte` // `128 > [16]u8`
// //
// `608 > [76]byte` // `608 > [76]byte`
pub fn (mut t Table) bitsize_to_type(bit_size int) Type { pub fn (mut t Table) bitsize_to_type(bit_size int) Type {

View File

@ -1,7 +1,7 @@
type Block = [8]byte type Block = [8]u8
fn test_alias_fixed_array() { fn test_alias_fixed_array() {
a := [8]byte{init: 22} a := [8]u8{init: 22}
ret := get(Block(a)) ret := get(Block(a))
println(ret) println(ret)
assert ret == 'Block([22, 22, 22, 22, 22, 22, 22, 22])' assert ret == 'Block([22, 22, 22, 22, 22, 22, 22, 22])'