Add support for writing cstrings

This commit is contained in:
Zahary Karadjov 2021-11-04 11:54:55 +02:00
commit 1b561a9e71
2 changed files with 24 additions and 12 deletions

View file

@ -9,6 +9,9 @@ proc bytes(s: string): seq[byte] =
result = newSeqOfCap[byte](s.len)
for c in s: result.add byte(c)
proc bytes(s: cstring): seq[byte] =
for c in s: result.add byte(c)
template bytes(c: char): byte = byte(c)
template bytes(b: seq[byte]): seq[byte] = b
template bytes[N, T](b: array[N, T]): seq[byte] = @b
@ -58,14 +61,11 @@ suite "output stream":
template output(val: auto) {.dirty.} =
nimSeq.add bytes(val)
memStream.write val
smallPageSizeStream.write val
largePageSizeStream.write val
fileStream.write val
unbufferedFileStream.write val
streamWritingToExistingBuffer.write val
template outputText(val: auto) =
@ -154,6 +154,15 @@ suite "output stream":
checkOutputsMatch()
test "cstrings":
for i in 1 .. 100:
output cstring("cstring sent by output ")
output cstring("")
outputText cstring("cstring sent by outputText ")
outputText cstring("")
checkOutputsMatch()
test "memcpy":
var x = 0x42'u8