refactor: use 'byte' instead of 'uint8' in ringbuffer example

Signed-off-by: Christopher Arndt <chris@chrisarndt.de>
This commit is contained in:
Christopher Arndt 2025-01-20 00:10:31 +01:00
parent ad7014da09
commit 1fa9a68ee6
1 changed files with 8 additions and 8 deletions

View File

@ -9,35 +9,35 @@ proc main() =
let size = 32 let size = 32
var read, written: int var read, written: int
var data = [0x64.uint8, 0x65, 0x61, 0x64, 0x62, 0x65, 0x65, 0x66] var data = [0x64.byte, 0x65, 0x61, 0x64, 0x62, 0x65, 0x65, 0x66]
var recvBuf: array[8, uint8] var recvBuf: array[8, byte]
let rb = ringbufferCreate(size.csize_t) let rb = ringbufferCreate(size.csize_t)
debug fmt"Created ringbuffer of {size} bytes size." debug fmt"Created ringbuffer of {size} bytes size."
doAssert ringbufferReadSpace(rb) == 0 doAssert ringbufferReadSpace(rb) == 0
written = cast[int](ringbufferWrite(rb, cast[cstring](data.addr), 4)) written = ringbufferWrite(rb, cast[cstring](data.addr), 4).int
doAssert written == 4 doAssert written == 4
debug fmt"Written {written} bytes to ringbuffer." debug fmt"Written {written} bytes to ringbuffer."
doAssert ringbufferReadSpace(rb) == 4 doAssert ringbufferReadSpace(rb) == 4
written = cast[int](ringbufferWrite(rb, cast[cstring](data[4].addr), 4)) written = ringbufferWrite(rb, cast[cstring](data[4].addr), 4).int
doAssert written == 4 doAssert written == 4
debug fmt"Written {written} bytes to ringbuffer." debug fmt"Written {written} bytes to ringbuffer."
doAssert ringbufferReadSpace(rb) == 8 doAssert ringbufferReadSpace(rb) == 8
read = cast[int](ringbufferRead(rb, cast[cstring](recvBuf.addr), 4)) read = ringbufferRead(rb, cast[cstring](recvBuf.addr), 4).int
doAssert read == 4 doAssert read == 4
debug fmt"Read {read} bytes from ringbuffer into receive buffer: {recvBuf}" debug fmt"Read {read} bytes from ringbuffer. Receive buffer: {recvBuf}"
doAssert ringbufferReadSpace(rb) == 4 doAssert ringbufferReadSpace(rb) == 4
read = cast[int](ringbufferRead(rb, cast[cstring](recvBuf[4].addr), 4)) read = ringbufferRead(rb, cast[cstring](recvBuf[4].addr), 4).int
doAssert read == 4 doAssert read == 4
debug fmt"Read {read} bytes from ringbuffer into receive buffer: {recvBuf}" debug fmt"Read {read} bytes from ringbuffer. Receive buffer: {recvBuf}"
doAssert ringbufferReadSpace(rb) == 0 doAssert ringbufferReadSpace(rb) == 0