guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Pretty print bytevectors with its content in hex format


From: Olivier Dion
Subject: Re: Pretty print bytevectors with its content in hex format
Date: Fri, 30 Sep 2022 11:20:16 -0400

On Fri, 30 Sep 2022, Zhu Zihao <all_but_last@163.com> wrote:
> Hi, dear Guile users!
>
> I'm using Guile to play around with some binaries. In Guile, the
> bytevector prints its content in decimal format. Just like:
>
> #vu8(255 255 255 255)
>
> But, it's always more convenient if its content is printed in hex format
> like
>
> #vu8(#xff #xff #xff #xff)

Right.  The Guile printer has no option of that sort yet.  Quickly I
would think that this should work:
--8<---------------cut here---------------start------------->8---
(use-modules (oop goops))

(define-method (display (bv <bytevector>) port)
  (format port "#vu8(~{#x~x~})" (bytevector->u8-list bv)))
--8<---------------cut here---------------end--------------->8---

but I haven't tested it.

-- 
Olivier Dion
oldiob.dev



reply via email to

[Prev in Thread] Current Thread [Next in Thread]