This is the mail archive of the
guile@sourceware.cygnus.com
mailing list for the Guile project.
Re: rfc 2045 base64 encoding/decoding module
>>>>> "sen" == sen ml <sen_ml@eccosys.com> writes:
sen> once i'm done w/ that, i'm hoping to work on the pack/unpack
sen> thing. i'm much more familiar w/ the perl version than the
sen> python one though so what i make may end up more perlish than
sen> pythonish (at least at first).
My suggestion would be to separate reading/writing binary data and
forming the perl/python-like structures.
Namely, I would make a separate module
(define-module (utils binary-io))
(export
;; native format
read-int read-short read-long
read-unsigned read-ushort read-ulong
;; fixed precision
read-int16 read-unsigned16
read-int32 read-unsigned32
;; variants with different "endiands"
read-int16/big-endian read-unsigned16/big-endian
read-int16/little-endian read-unsigned16/little-endian
read-int32/big-endian read-unsigned32/big-endian
read-int32/little-endian read-unsigned32/little-endian
;; floats
read-float read-double)
(export
;; native format
write-int write-short write-long
write-unsigned write-ushort write-ulong
;; fixed precision
write-int16 write-unsigned16
write-int32 write-unsigned32
;; variants with different "endiands"
write-int16/big-endian write-unsigned16/big-endian
write-int16/little-endian write-unsigned16/little-endian
write-int32/big-endian write-unsigned32/big-endian
write-int32/little-endian write-unsigned32/little-endian
;; floats
write-float write-double)
Of course, all these functions should read/write to/from ports.
Then, on the base of these functions, the perl-like and/or python-like
struct modules could be written.
I'm not sure, how it works with perl, but with python you generate
(by default) the actual C structure (represented as string), with the
proper alignment of components.
For example:
>>> import struct
>>> struct.pack("ch","A",2)
'A\000\002\000'
>>> struct.pack("cf","A",2)
'A\000\000\000\000\000\000@'
But you can switch off this behavior:
>>> struct.pack("=ch","A",2)
'A\002\000'
>>> struct.pack("=cf","A",2)
'A\000\000\000@'
Also, you can require big-endian/little-endian representation for
the whole string:
>>> struct.pack(">ch","A",2)
'A\000\002'
>>> struct.pack("<ch","A",2)
'A\002\000'
>>> struct.pack(">cf","A",2)
'A@\000\000\000'
>>> struct.pack("<cf","A",2)
'A\000\000\000@'
sen> i have the same question
sen> regarding whether the routines should operate on ports as
sen> compared to strings. any opinions?
With ports, it seems to be more flexible.
--
Best regards,
Valentin.