unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Some I/O Questions
@ 2012-02-10  3:50 Luiji Maryo
  2012-02-10 20:05 ` Ian Price
  0 siblings, 1 reply; 2+ messages in thread
From: Luiji Maryo @ 2012-02-10  3:50 UTC (permalink / raw)
  To: Guile Mailing List

Hello,

I have some questions regarding Guile I/O and byte order.

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?
2. Is there a way to specifically read a 8/16/32/64-bit string from a file/port?
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?
4. Is writing an archive manager using Guile for implementing archive
formats a bad idea to start with?

Thank you for your time,
- LM <luiji@users.sourceforge.net>

http://entertainingsoftware.com/



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Some I/O Questions
  2012-02-10  3:50 Some I/O Questions Luiji Maryo
@ 2012-02-10 20:05 ` Ian Price
  0 siblings, 0 replies; 2+ messages in thread
From: Ian Price @ 2012-02-10 20:05 UTC (permalink / raw)
  To: Luiji Maryo; +Cc: Guile Mailing List

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"



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-02-10 20:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-10  3:50 Some I/O Questions Luiji Maryo
2012-02-10 20:05 ` Ian Price

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).