The cl-pack Reference Manual

Table of Contents

Next: , Previous: , Up: (dir)   [Contents][Index]

The cl-pack Reference Manual

This is the cl-pack Reference Manual, version 0.2, generated automatically by Declt version 2.3 "Robert April" on Tue Feb 20 08:13:06 2018 GMT+0.


Next: , Previous: , Up: Top   [Contents][Index]

1 Introduction

cl-pack

www.cliki.net/cl-pack

cl-pack supplies Perl/PHP/Ruby/Python compatible pack() and unpack() functions to allow easy use of (binary format) protocols and files with the above mentioned languages and C. cl-pack was released by Dan Ballard under the BSD-3-Clause license.

The purpose of cl-pack is to take native Lisp data like numbers, floats, and strings and encode it in a safe binary format in string that can then be written to a file or exchanged with another program while unpack can extract data from binary formats and protocols.

cl-pack has nearly full support for all features offered by Perl's pack. It boasts full support for most data types and formating rules from numbers and string to formating rules and grouping and templates. cl-pack also supports endian safe floats as outlined by ruby. cl-pack is supports ASDF so as to make it easy to integrate into your existing system.

Instalation

cl-pack is available in QuickLisp

CL-USER> (ql:quickload "cl-pack")

Example:

CL-PACK> (pack "VgA*c*" #x41424344 161.99 " a string " 69 70 71)
;; => "DCBAC!ýq a string EFG"

CL-PACK> (unpack "B8H2Ng" "ABCDEFC!ýq")
;; => "01000001"
;; => "42"
;; => 1128547654
;; => 161.99

Documentation is currently a bit sparse, but is contained in cl-pack.lisp. Additionally, a good overview of pack and unpack functions can be seen at http://perldoc.perl.org/functions/pack.html.

Nearly every feature except a few esoteric ones are supported, check the documentation inside cl-pack.lisp if in doubt and if a feature you need isn't currently supported feel free to contact me and I'll see if I can add it.

Note I think the 0.2 release is about as feature complete as I feel I need to get at the moment so I'm pushing it out. If there are not major complaints, then in a bit it will be re-released as 1.0, and if there are complaints, well more code and another pre-1.0 release :smile:

Cavets cl-pack was developed on an x86 running Ubuntu with SBCL. It should be endian safe where required and conform to host CPU endianness where required but I haven't been able to test on anything but x86. I would hope that it would work with most Lisps out there. Please feel free to get a hold of me if you have issues that need fixing


Next: , Previous: , Up: Top   [Contents][Index]

2 Systems

The main system appears first, followed by any subsystem dependency.


Previous: , Up: Systems   [Contents][Index]

2.1 cl-pack

Author

Dan Ballard <dan@mindstab.net>

License

BSD-3-Clause

Description

Perl compatible binary pack() and unpack() library

Version

0.2

Dependency

ieee-floats

Source

cl-pack.asd (file)

Components

Next: , Previous: , Up: Top   [Contents][Index]

3 Files

Files are sorted by type and then listed depth-first from the systems components trees.


Previous: , Up: Files   [Contents][Index]

3.1 Lisp


Next: , Previous: , Up: Lisp files   [Contents][Index]

3.1.1 cl-pack.asd

Location

cl-pack.asd

Systems

cl-pack (system)

Packages

cl-pack-system


Next: , Previous: , Up: Lisp files   [Contents][Index]

3.1.2 cl-pack/package.lisp

Parent

cl-pack (system)

Location

package.lisp

Packages

cl-pack


Previous: , Up: Lisp files   [Contents][Index]

3.1.3 cl-pack/cl-pack.lisp

Parent

cl-pack (system)

Location

cl-pack.lisp

Exported Definitions
Internal Definitions

Next: , Previous: , Up: Top   [Contents][Index]

4 Packages

Packages are listed by definition order.


Next: , Previous: , Up: Packages   [Contents][Index]

4.1 cl-pack-system

Source

cl-pack.asd

Use List

Previous: , Up: Packages   [Contents][Index]

4.2 cl-pack

Source

package.lisp (file)

Use List
Exported Definitions
Internal Definitions

Next: , Previous: , Up: Top   [Contents][Index]

5 Definitions

Definitions are sorted by export status, category, package, and then by lexicographic order.


Next: , Previous: , Up: Definitions   [Contents][Index]

5.1 Exported definitions


Previous: , Up: Exported definitions   [Contents][Index]

5.1.1 Functions

Function: pack FORM &rest REST
Package

cl-pack

Source

cl-pack.lisp (file)

Function: unpack FORM STRING &key CONSUMED MODIFIERS
Package

cl-pack

Source

cl-pack.lisp (file)


Previous: , Up: Definitions   [Contents][Index]

5.2 Internal definitions


Next: , Previous: , Up: Internal definitions   [Contents][Index]

5.2.1 Macros

Macro: cut-str STR LEN NEW-STR
Package

cl-pack

Source

cl-pack.lisp (file)

Macro: def-form-parser FN-NAME (&rest EXTRA-ARGS) END-TEST FINAL-ITEM &rest BODY
Package

cl-pack

Source

cl-pack.lisp (file)

Macro: gen-modifiers-list ()
Package

cl-pack

Source

cl-pack.lisp (file)

Macro: handle-string (REPEATER REPEATER-STAR) STAR-BODY COUNT-BODY ELSE-BODY

macro for building string type bodies for case statements in pack() or unpack()

Package

cl-pack

Source

cl-pack.lisp (file)

Macro: inc-form ()

create a subseq of form that skips the current syntax object

Package

cl-pack

Source

cl-pack.lisp (file)

Macro: pack-int SIZE ENDIAN

Macro to define the pack function for an int

Package

cl-pack

Source

cl-pack.lisp (file)

Macro: pack-string (REPEATER REPEATER-STAR) STAR-BODY COUNT-BODY ELSE-BODY

macro for building string type bodies for case statements in pack()

Package

cl-pack

Source

cl-pack.lisp (file)

Macro: set-modifiers MODIFIERS
Package

cl-pack

Source

cl-pack.lisp (file)

Macro: unpack-int SIZE ENDIAN

Macro to define the unpack function for a signed int

Package

cl-pack

Source

cl-pack.lisp (file)

Macro: unpack-mod!-uint SIZE ENDIAN

macro to define a normal uint that with the ! modifier is a signed int

Package

cl-pack

Source

cl-pack.lisp (file)

Macro: unpack-string (REPEATER REPEATER-STAR) STAR-BODY COUNT-BODY ELSE-BODY

macro for building string type bodies for case statements in unpack()

Package

cl-pack

Source

cl-pack.lisp (file)

Macro: unpack-uint SIZE ENDIAN

Macro to define the unpack function for an unsigned int

Package

cl-pack

Source

cl-pack.lisp (file)


Previous: , Up: Internal definitions   [Contents][Index]

5.2.2 Functions

Function: 2hex-to-byte 2HEX &optional MAPPER

Turn a 2 hex digit string into a number unpacked by mapper

Package

cl-pack

Source

cl-pack.lisp (file)

Function: 8bits-to-byte 8BITS &optional BYTE-FORM

turns a string of 8 or less bits into a byte
byte-form specifies the packing order of bits into the byte, deaulting to decending order

Package

cl-pack

Source

cl-pack.lisp (file)

Function: ber-decode STRING

Take a BER number as a binary string and returns a number

Package

cl-pack

Source

cl-pack.lisp (file)

Function: ber-encode NUMBER

function to encode a BER number into a binary byte string

Package

cl-pack

Source

cl-pack.lisp (file)

Function: ber-str-length STRING
Package

cl-pack

Source

cl-pack.lisp (file)

Function: bit-pack BIT-STR &optional BYTE-FORM

pack a bit string into a byte string, decending order by default

Package

cl-pack

Source

cl-pack.lisp (file)

Function: bit-unpack BYTE-STR &optional UNPACK-FN

turn a string of bytes into an extended string of bits unpacked by unpack-fn

Package

cl-pack

Source

cl-pack.lisp (file)

Function: byte-to-2hex BYTE

Turn a byte into a string of 2 hex characters

Package

cl-pack

Source

cl-pack.lisp (file)

Function: byte-to-2hex-rev BYTE
Package

cl-pack

Source

cl-pack.lisp (file)

Function: byte-to-8bits BYTE

turns a byte into a string of bits

Package

cl-pack

Source

cl-pack.lisp (file)

Function: byte-to-8bits-rev BYTE

convert a byte to a bit string, lowest bit first

Package

cl-pack

Source

cl-pack.lisp (file)

Function: bytes-to-list BYTES LENGTH

bytes: Some binary data in lisp number form that ldb can access bytes-to-list pulls out 8bit bytes from bytes and turns them into their corresponding characters and returns the list of them

Package

cl-pack

Source

cl-pack.lisp (file)

Function: bytes-to-string BYTES LENGTH

puts length bytes from bytes into a string

Package

cl-pack

Source

cl-pack.lisp (file)

Function: bytes-to-string-rev BYTES LENGTH

puts length bytes from bytes into a reversed string

Package

cl-pack

Source

cl-pack.lisp (file)

Function: endian-type-to-func ENDIAN
Package

cl-pack

Source

cl-pack.lisp (file)

Function: find-matching-paren STR
Package

cl-pack

Source

cl-pack.lisp (file)

Function: hex-pack HEX-STR &optional MAPPER

turn a string of hex digits into a string of packed bytes, unpacking 2 hex digits at a time by mapper

Package

cl-pack

Source

cl-pack.lisp (file)

Function: hex-to-number HEX

turn a character of 0-9 or a-f or A-F into a hex digit of 0-15

Package

cl-pack

Source

cl-pack.lisp (file)

Function: hex-unpack BYTE-STR &optional HEX-UNPACK-FN

Turn a string of bytes into a string of hex digits

Package

cl-pack

Source

cl-pack.lisp (file)

Function: next-char FORM OFFSET

Get the next char from a string of null if offset is past end of string

Package

cl-pack

Source

cl-pack.lisp (file)

Function: strhead STR

returns a char that is the first char of str

Package

cl-pack

Source

cl-pack.lisp (file)

Function: string-to-bytes STRING LENGTH
Package

cl-pack

Source

cl-pack.lisp (file)

Function: string-to-bytes-rev STRING LENGTH
Package

cl-pack

Source

cl-pack.lisp (file)

Function: strtail STR

returns the rest of str

Package

cl-pack

Source

cl-pack.lisp (file)

Function: twos-complement NUMBER MAX-SIZE
Package

cl-pack

Source

cl-pack.lisp (file)

Function: un-endian-type-to-func ENDIAN
Package

cl-pack

Source

cl-pack.lisp (file)

Function: un-twos-complement NUMBER MAX-SIZE
Package

cl-pack

Source

cl-pack.lisp (file)

Function: unpack-bytes STRING LENGTH

takes length bytes from string and returns an int

Package

cl-pack

Source

cl-pack.lisp (file)


Previous: , Up: Top   [Contents][Index]

Appendix A Indexes


Next: , Previous: , Up: Indexes   [Contents][Index]

A.1 Concepts

Jump to:   C   F   L  
Index Entry  Section

C
cl-pack.asd: The cl-pack<dot>asd file
cl-pack/cl-pack.lisp: The cl-pack/cl-pack<dot>lisp file
cl-pack/package.lisp: The cl-pack/package<dot>lisp file

F
File, Lisp, cl-pack.asd: The cl-pack<dot>asd file
File, Lisp, cl-pack/cl-pack.lisp: The cl-pack/cl-pack<dot>lisp file
File, Lisp, cl-pack/package.lisp: The cl-pack/package<dot>lisp file

L
Lisp File, cl-pack.asd: The cl-pack<dot>asd file
Lisp File, cl-pack/cl-pack.lisp: The cl-pack/cl-pack<dot>lisp file
Lisp File, cl-pack/package.lisp: The cl-pack/package<dot>lisp file

Jump to:   C   F   L  

Next: , Previous: , Up: Indexes   [Contents][Index]

A.2 Functions

Jump to:   2   8  
B   C   D   E   F   G   H   I   M   N   P   S   T   U  
Index Entry  Section

2
2hex-to-byte: Internal functions

8
8bits-to-byte: Internal functions

B
ber-decode: Internal functions
ber-encode: Internal functions
ber-str-length: Internal functions
bit-pack: Internal functions
bit-unpack: Internal functions
byte-to-2hex: Internal functions
byte-to-2hex-rev: Internal functions
byte-to-8bits: Internal functions
byte-to-8bits-rev: Internal functions
bytes-to-list: Internal functions
bytes-to-string: Internal functions
bytes-to-string-rev: Internal functions

C
cut-str: Internal macros

D
def-form-parser: Internal macros

E
endian-type-to-func: Internal functions

F
find-matching-paren: Internal functions
Function, 2hex-to-byte: Internal functions
Function, 8bits-to-byte: Internal functions
Function, ber-decode: Internal functions
Function, ber-encode: Internal functions
Function, ber-str-length: Internal functions
Function, bit-pack: Internal functions
Function, bit-unpack: Internal functions
Function, byte-to-2hex: Internal functions
Function, byte-to-2hex-rev: Internal functions
Function, byte-to-8bits: Internal functions
Function, byte-to-8bits-rev: Internal functions
Function, bytes-to-list: Internal functions
Function, bytes-to-string: Internal functions
Function, bytes-to-string-rev: Internal functions
Function, endian-type-to-func: Internal functions
Function, find-matching-paren: Internal functions
Function, hex-pack: Internal functions
Function, hex-to-number: Internal functions
Function, hex-unpack: Internal functions
Function, next-char: Internal functions
Function, pack: Exported functions
Function, strhead: Internal functions
Function, string-to-bytes: Internal functions
Function, string-to-bytes-rev: Internal functions
Function, strtail: Internal functions
Function, twos-complement: Internal functions
Function, un-endian-type-to-func: Internal functions
Function, un-twos-complement: Internal functions
Function, unpack: Exported functions
Function, unpack-bytes: Internal functions

G
gen-modifiers-list: Internal macros

H
handle-string: Internal macros
hex-pack: Internal functions
hex-to-number: Internal functions
hex-unpack: Internal functions

I
inc-form: Internal macros

M
Macro, cut-str: Internal macros
Macro, def-form-parser: Internal macros
Macro, gen-modifiers-list: Internal macros
Macro, handle-string: Internal macros
Macro, inc-form: Internal macros
Macro, pack-int: Internal macros
Macro, pack-string: Internal macros
Macro, set-modifiers: Internal macros
Macro, unpack-int: Internal macros
Macro, unpack-mod!-uint: Internal macros
Macro, unpack-string: Internal macros
Macro, unpack-uint: Internal macros

N
next-char: Internal functions

P
pack: Exported functions
pack-int: Internal macros
pack-string: Internal macros

S
set-modifiers: Internal macros
strhead: Internal functions
string-to-bytes: Internal functions
string-to-bytes-rev: Internal functions
strtail: Internal functions

T
twos-complement: Internal functions

U
un-endian-type-to-func: Internal functions
un-twos-complement: Internal functions
unpack: Exported functions
unpack-bytes: Internal functions
unpack-int: Internal macros
unpack-mod!-uint: Internal macros
unpack-string: Internal macros
unpack-uint: Internal macros

Jump to:   2   8  
B   C   D   E   F   G   H   I   M   N   P   S   T   U  

Next: , Previous: , Up: Indexes   [Contents][Index]

A.3 Variables


Previous: , Up: Indexes   [Contents][Index]

A.4 Data types

Jump to:   C   P   S  
Index Entry  Section

C
cl-pack: The cl-pack system
cl-pack: The cl-pack package
cl-pack-system: The cl-pack-system package

P
Package, cl-pack: The cl-pack package
Package, cl-pack-system: The cl-pack-system package

S
System, cl-pack: The cl-pack system

Jump to:   C   P   S