From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Matt Wette Newsgroups: gmane.lisp.guile.user Subject: Re: [potluck dish] the (potluck struct) module Date: Tue, 16 Feb 2016 05:53:32 -0800 Message-ID: References: <87mvr8ood1.fsf@gnu.org> <2AD1455C-EC47-447D-BC5D-43EABC71D484@verizon.net> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 (Mac OS X Mail 8.2 \(2104\)) Content-Type: multipart/alternative; boundary="Apple-Mail=_666412FE-3827-4FC5-A863-D1FA6218CBD1" X-Trace: ger.gmane.org 1455630870 13557 80.91.229.3 (16 Feb 2016 13:54:30 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 16 Feb 2016 13:54:30 +0000 (UTC) To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Tue Feb 16 14:54:15 2016 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1aVg4r-000626-8p for guile-user@m.gmane.org; Tue, 16 Feb 2016 14:54:05 +0100 Original-Received: from localhost ([::1]:46166 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aVg4q-0004qO-HD for guile-user@m.gmane.org; Tue, 16 Feb 2016 08:54:04 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:50109) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aVg4f-0004pv-Tj for guile-user@gnu.org; Tue, 16 Feb 2016 08:53:55 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aVg4c-0004iM-KM for guile-user@gnu.org; Tue, 16 Feb 2016 08:53:53 -0500 Original-Received: from vms173017pub.verizon.net ([206.46.173.17]:63685) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aVg4c-0004iH-Cc for guile-user@gnu.org; Tue, 16 Feb 2016 08:53:50 -0500 Original-Received: from vz-proxy-m004.mx.aol.com ([64.236.83.2]) by vms173017.mailsrvcs.net (Oracle Communications Messaging Server 7.0.5.32.0 64bit (built Jul 16 2014)) with ESMTPA id <0O2N002V37X9UV30@vms173017.mailsrvcs.net> for guile-user@gnu.org; Tue, 16 Feb 2016 07:53:34 -0600 (CST) X-CMAE-Score: 0 X-CMAE-Analysis: v=2.1 cv=WpDWSorv c=1 sm=1 tr=0 a=EDCZS3Slg7tGr17y9w9vtg==:117 a=jFJIQSaiL_oA:10 a=8AHkEIZyAAAA:8 a=dTd7GxXkrIBoxKJQ78cA:9 a=AJLE-iCdRoTDNNjt:21 a=S4vt8M43LemG4N_A:21 a=CjuIK1q_8ugA:10 a=oqfLY-r8HhgA:10 a=mqk8gmcpsA2MIvUkFKsA:9 a=2_zAI5wEnSTX-rRL:21 a=BdcnXYpssqIqAtLQ:21 a=QaIf8X-ftkdd6-9x:21 a=_W_S_7VecoQA:10 Original-Received: by 72.87.204.128 with SMTP id 6d31f3c7; Tue, 16 Feb 2016 13:53:34 GMT In-reply-to: <2AD1455C-EC47-447D-BC5D-43EABC71D484@verizon.net> X-Mailer: Apple Mail (2.2104) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 206.46.173.17 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:12405 Archived-At: --Apple-Mail=_666412FE-3827-4FC5-A863-D1FA6218CBD1 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii First message got garbled. Redo: If you have used the Python struct module then this will look familiar. Otherwise, check out https://docs.python.org/2/library/struct.html Attached are three files: * struct.scm: the source code * struct.texi: documentation * struct.test: test code Struct Module ============= The '(potluck struct)' module provides procedures for packing and unpacking scheme data to and from bytevectors based on a format string. (use-modules (potluck struct)) ;; pack two unsigned shorts and a double float in big endian order (define data (pack ">2Hd" 3 22 34.0)) (write data) (newline) ==> #vu8(0 3 0 22 64 65 0 0 0 0 0 0) ;; verify using unpack (write (unpack ">2Hd" data)) (newline) ==> (3 22 34.0) -- Scheme Procedure: pack format vals ... Return a bytevector that contains encoded data from VALS, based on the string FORMAT. -- Scheme Procedure: unpack format bvec Return a list of scheme objects decoded from the bytevector BVEC, based on the string FORMAT. -- Scheme Procedure: packed-size format Return the number of bytes represented by the string FORMAT. The _format_ string used for PACK and UNPACK is constructed as a sequence of digits, representing a repeat count, and codes, representing the binary content. The string may optionally begin with a special character that represents the endianness: = native endianness < little-endian > big-endian ! network order -- i.e., big-endian Type codes used in the format string are interpreted as follows: x blank byte c 8-bit character ? boolean b signed 8-bit integer B unsigned 8-bit integer h signed 16-bit integer H unsigned 16-bit integer i signed 32-bit integer I unsigned 32-bit integer l signed 32-bit integer L unsigned 32-bit integer q signed 64-bit integer Q unsigned 64-bit integer f 32-bit IEEE floating point d 64-bit IEEE floating point s string The following issues remain to be addressed: string padding 'pack' assumes that the string length in the format is the same as in the passed string. Non-conformance is not trapped as an error. --Apple-Mail=_666412FE-3827-4FC5-A863-D1FA6218CBD1 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii First message got garbled. =  Redo:

If you have used the Python = struct module then this will look familiar.
<= div class=3D"">
Attached are three files:
* struct.scm: the source = code 
* = struct.texi: documentation 
* struct.test: test code

Struct Module
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D

The '(potluck struct)' module provides procedures for packing = and
unpacking = scheme data to and from bytevectors based on a format = string.

     (use-modules (potluck = struct))

     ;; pack two unsigned shorts and a double = float in big endian order
     (define data (pack ">2Hd" 3 22 = 34.0))
  =    (write data) (newline)
     =3D=3D>
     #vu8(0 3 = 0 22 64 65 0 0 0 0 0 0)

     ;; verify using = unpack
  =    (write (unpack ">2Hd" data)) (newline)
    =  =3D=3D>
     (3 22 34.0)

 -- Scheme Procedure: pack format vals = ...
  =    Return a bytevector that contains encoded data from VALS, = based on
     the string FORMAT.

 -- Scheme Procedure: unpack format = bvec
  =    Return a list of scheme objects decoded from the bytevector = BVEC,
  =    based on the string FORMAT.

 -- Scheme Procedure: = packed-size format
     Return the number of bytes represented by = the string FORMAT.

   The _format_ string used for PACK = and UNPACK is constructed as a
sequence of digits, representing a repeat = count, and codes, representing
the binary content.

The string may optionally begin with a special character that = represents
the= endianness:
    =3D        native = endianness
    <       =  little-endian
    >       =  big-endian
    !        network order -- = i.e., big-endian

Type codes used in the format string are = interpreted as follows:
    x        blank = byte
  =   c        8-bit character
    ?     =    boolean
    b        signed 8-bit = integer
 =   B        unsigned 8-bit = integer
 =   h        signed 16-bit = integer
 =   H        unsigned 16-bit = integer
 =   i        signed 32-bit = integer
 =   I        unsigned 32-bit = integer
 =   l        signed 32-bit = integer
 =   L        unsigned 32-bit = integer
 =   q        signed 64-bit = integer
 =   Q        unsigned 64-bit = integer
 =   f        32-bit IEEE floating = point
  =   d        64-bit IEEE floating = point
  =   s        string

   The following issues remain to be = addressed:
string padding
     'pack' assumes that the string length in = the format is the same as
     in the passed string. =  Non-conformance is not trapped as an error.

= --Apple-Mail=_666412FE-3827-4FC5-A863-D1FA6218CBD1--