Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

peek-char method of flexi-streams:in-memory-stream #43

Open
ccqpein opened this issue Mar 10, 2021 · 2 comments
Open

peek-char method of flexi-streams:in-memory-stream #43

ccqpein opened this issue Mar 10, 2021 · 2 comments

Comments

@ccqpein
Copy link

ccqpein commented Mar 10, 2021

Hi guys, I am trying to run JSON parser (yason:parse) with flexi-streams:in-memory-stream directly, because (yason:parse) can accept string steam input directly.

Then SBCL gives me the error when I did it. After checking the code of yason::parse and the error message, I found there are two generic functions of SBCL that needed to be implemented: SB-GRAY:STREAM-READ-CHAR and SB-GRAY:STREAM-PEEK-CHAR

So I tried to implement by code:

(defmethod SB-GRAY:STREAM-READ-CHAR ((s flexi-streams:in-memory-stream))
  (code-char (read-byte s)))

(defmethod SB-GRAY:STREAM-PEEK-CHAR ((s flexi-streams:in-memory-stream))
  (let ((char (code-char (flexi-streams:peek-byte s))))
    char))

Then yason:parse works fine with flexi-streams:in-memory-stream (at least now).

Do you guys trying to implement peek-char for flexi-streams:in-memory-stream? My code just work, I am not sure I met all hidden details of flexi-streams:in-memory-stream. It would be nice if flexi-stream has peek-char natively.

Thanks

@stassats
Copy link
Member

code-char doesn't seem right, though.

@fjl
Copy link
Contributor

fjl commented Jul 29, 2021

I think this issue should be closed. in-memory-stream is explicitly a binary stream with no support for characters.
To get characters, a flexi-stream needs to be used on top of the in-memory-stream:

(flexi-streams:with-input-from-sequence (mem input-sequence)
  (let ((text (flexi-streams:make-flexi-stream mem :external-format :utf-8)))
    (yason:parse text)))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants