diff --git a/core/io/io.odin b/core/io/io.odin index 47363bd28..0e39a4ef8 100644 --- a/core/io/io.odin +++ b/core/io/io.odin @@ -150,7 +150,7 @@ close :: proc(s: Closer) -> Error { return .None; } -flush :: proc(s: Flusher, p: []byte) -> Error { +flush :: proc(s: Flusher) -> Error { if s.stream_vtable != nil && s.impl_flush != nil { return s->impl_flush(); } @@ -158,7 +158,7 @@ flush :: proc(s: Flusher, p: []byte) -> Error { return .None; } -size :: proc(s: Stream, p: []byte) -> i64 { +size :: proc(s: Stream) -> i64 { if s.stream_vtable == nil { return 0; } @@ -267,7 +267,21 @@ read_byte :: proc(r: Byte_Reader) -> (byte, Error) { return b[0], err; } -write_byte :: proc(w: Byte_Writer, c: byte) -> Error { +write_byte :: proc{ + write_byte_to_byte_writer, + write_byte_to_writer, +}; + +write_byte_to_byte_writer :: proc(w: Byte_Writer, c: byte) -> Error { + return _write_byte(auto_cast w, c); +} + +write_byte_to_writer :: proc(w: Writer, c: byte) -> Error { + return _write_byte(auto_cast w, c); +} + +@(private) +_write_byte :: proc(w: Byte_Writer, c: byte) -> Error { if w.stream_vtable == nil { return .Empty; } diff --git a/core/io/util.odin b/core/io/util.odin index bf1c223b8..e714ac7d0 100644 --- a/core/io/util.odin +++ b/core/io/util.odin @@ -1,6 +1,18 @@ package io import "core:runtime" +import "core:strconv" + +write_u64 :: proc(w: Writer, i: u64, base: int = 10) -> (n: int, err: Error) { + buf: [32]byte; + s := strconv.append_bits(buf[:], u64(i), base, false, 64, strconv.digits, nil); + return write_string(w, s); +} +write_i64 :: proc(w: Writer, i: i64, base: int = 10) -> (n: int, err: Error) { + buf: [32]byte; + s := strconv.append_bits(buf[:], u64(i), base, true, 64, strconv.digits, nil); + return write_string(w, s); +} @(private) Tee_Reader :: struct {