sorawee
2019-7-6 07:54:32

It seems that make-input-port will always provide a mutable byte string of length 1. Is there a way to support several bytes? The documentation at https://docs.racket-lang.org/reference/customport.html kinda implies that it’s possible (“a mutable byte string to receive read bytes”)

(define foo
  (make-input-port
   'ones
   (lambda (s)
     (bytes-set! s 0 (char->integer #\1))
     (bytes-set! s 1 (char->integer #\2))
     2)
   #f
   void))

(read-string 5 foo)
; bytes-set!: index is out of range
;   index: 1
;   valid range: [0, 0]
;   byte string: #"1"

baris.aydek
2019-7-6 11:21:46

@baris.aydek has joined the channel


ryanc
2019-7-6 11:38:40

@sorawee When I try that example and print the length of the buffer, there is a read for 5 bytes first, then 3, then 1.


sorawee
2019-7-6 11:41:59

Ah, I see. I need to (read-string n foo) where n is even


srenatus088
2019-7-6 15:20:49

@srenatus088 has joined the channel


zacromero3
2019-7-6 17:49:36

@zacromero3 has joined the channel


veesey
2019-7-7 04:13:18

@veesey has joined the channel