I can’t figure out how to read multiple bytes. I’m trying to read a 32-bit integer so that I can store it to be used by a class.

My (truncated) code:

(let ((version-buffer (byte 4 0)))
 (read-sequence version-buffer input-stream)
  (cond
    ((> version-buffer 10) (read-sequence minor-version-buffer input-stream)) (t t))
      (setf (navigation-mesh-version temp-mesh) `(,(version-buffer)) )
      )

EDIT: Truncated the code further.

@thann
mod
admin
link
fedilink
21M

I think if you trimmed the problem down to a couple of lines you’d get a better response =/

@Amicchan@lemmy.ml
creator
link
fedilink
21M

Good point. I should probably trim it.

@Amicchan@lemmy.ml
creator
link
fedilink
1
edit-2
1M

I managed to find a solution!

EDIT: (use setf instead of dpb, because dpb didn’t work for some reason.)

(let ((version 0))
  (dotimes (i 4 #|<- Read 4 Bytes.|# version) (setf (ldb (byte 8 (* 8 i)) version) (read-byte input-stream))))
  )
``

~~That code was less complicated than I thought it would be...~~

Ask specific questions about how to code something in lisp, scheme, racket, etc

Common-Lisp Resources

General lisp discussion on lemmy.ml

Create Post From:
lemmy.ml

  • 0 users online
  • 2 users / day
  • 1 user / week
  • 1 user / month
  • 2 users / 6 months
  • 6 subscribers
  • 2 Posts
  • 3 Comments
  • Modlog