unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Ian Price <ianprice90@googlemail.com>
To: Luiji Maryo <luiji@users.sourceforge.net>
Cc: Guile Mailing List <guile-user@gnu.org>
Subject: Re: Some I/O Questions
Date: Fri, 10 Feb 2012 20:05:09 +0000	[thread overview]
Message-ID: <874nuyzc7e.fsf@Kagami.home> (raw)
In-Reply-To: <CAAXjPiR2qHAeL8sTHWE+0b8agtDLwG+8g++WreyacPtR_bkcmA@mail.gmail.com> (Luiji Maryo's message of "Thu, 9 Feb 2012 22:50:05 -0500")

Luiji Maryo <luiji@users.sourceforge.net> writes:

> Hello,
>
> I have some questions regarding Guile I/O and byte order.
If you are dealing with binary data, you should be using bytevectors and
binary ports, rather than strings.

> 1. Is there an I/O function for reading a fixed set of bytes into a
> buffer, i.e. if I wanted to read a 56-byte string from a binary
> archive?

For this, In (ice-9 binary-ports) or (rnrs io ports), there is 'get-bytevector-n!'

> 2. Is there a way to specifically read a 8/16/32/64-bit string from a file/port?
For reading bytes you can use 'get-u8', and for reading multiple bytes
as a bytevector 'get-bytevector-n'. (rnrs bytevectors) contains
procedures for setting/getting 8/16/32/64 bit quantities.

> 3. Is there a built-in function for converting between byte orders
> (i.e. BSD-style htobe32 and such) or must I implement them myself?
(rnrs bytevectors) has procedures for dealing with endianness, at the
bytevector level. So I can, for instance, use
(bytevector-u16-ref bv index (native-endianness)) to extract a 16 bit
integer from a given index in a bytevector. If you wanted to specify a
particular endianness, I could use (endianness big) or (endianness
little).

For integers you could use ntohs, ntohl, htons, htonl, but that is
native endianness <-> network order only.

> 4. Is writing an archive manager using Guile for implementing archive
> formats a bad idea to start with?
Writing in Scheme is never a bad idea. ;-)

-- 
Ian Price

"Programming is like pinball. The reward for doing it well is
the opportunity to do it again" - from "The Wizardy Compiled"



      reply	other threads:[~2012-02-10 20:05 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-10  3:50 Some I/O Questions Luiji Maryo
2012-02-10 20:05 ` Ian Price [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=874nuyzc7e.fsf@Kagami.home \
    --to=ianprice90@googlemail.com \
    --cc=guile-user@gnu.org \
    --cc=luiji@users.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).