Common Lisp Package: COM.INFORMATIMAGO.COMMON-LISP.DATA-ENCODING.DATA-ENCODING

This package exports functions to encode and decode data in a byte vector buffer. License: AGPL3 Copyright Pascal J. Bourguignon 2002 - 2012 This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/>

README:

FUNCTION

Public

ENCTYPE-INSTANCE (ENCTYPE)

ENCTYPE: A sexp denoting the enctype. enctype ::= (record lisp-type [:size size] (offset name enc-type)...) (array element-enc-type dimensions) (string size ...) (number encoding [parameters]) (defined-type ...) defined-type RETURN: An instance of a subclass of enctype representing the enctype.

ENCTYPE-READ (ENCNAME ENCTYPE STREAM)

DO: Read from the STREAM a value of type ENCTYPE. RETURN: The decoded list value.

ENCTYPE-WRITE (ENCNAME ENCTYPE STREAM VALUE)

DO: Write to the STREAM a value of type ENCTYPE.

MAKE-ENCTYPE (NAME ARGS DEFINITION)

DO: Makes an enctype template. NAME: Name of the template. ARGS: DEFINITION: RETURN: NAME

Private

FIELD-NAME (INSTANCE)

@arg[extid]{A @class{extid}} @return[sytemid]{puri:uri or nil} Returns the System ID part of this External ID.

FIELD-OFFSET (INSTANCE)

@arg[extid]{A @class{extid}} @return[sytemid]{puri:uri or nil} Returns the System ID part of this External ID.

FIELD-TYPE (INSTANCE)

@arg[extid]{A @class{extid}} @return[sytemid]{puri:uri or nil} Returns the System ID part of this External ID.

MAKE-ENCTYPE-INSTANCE (ENCTYPE)

ENCTYPE: A sexp denoting the enctype. enctype ::= (record lisp-type [:size size] (offset name enc-type)...) (array element-enc-type dimensions) (string size ...) (number encoding [parameters]) (defined-type ...) RETURN: An instance of a subclass of enctype representing the enctype.

STANDARD-DECODE-STRING (BYTE-VECTOR ENCODING &KEY (START 0) (END NIL))

PRE: (eq encoding :standard-ascii) DO: This function decodes a byte vector containing only ASCII codes of COMMON-LISP standard characters into a string.

STANDARD-ENCODE-STRING (STRING ENCODING &KEY (START 0) (END NIL))

PRE: (eq encoding :standard-ascii) DO: This function encodes a string containing only COMMON-LISP standard characters into an ASCII code byte vector.

Undocumented

COPY-FIELD (INSTANCE)

DEFINED-ENCTYPE (SEXP)

EVEN-LIST-P (LIST)

SETFFIELD-NAME (NEW-VALUE INSTANCE)

SETFFIELD-OFFSET (NEW-VALUE INSTANCE)

FIELD-P (OBJECT)

SETFFIELD-TYPE (NEW-VALUE INSTANCE)

INTEGER-FROM-BCD (BCD)

INTEGER-TO-BCD (VALUE)

MAKE-FIELD (&KEY ((OFFSET DUM1111) 0) ((NAME DUM1112) NIL) ((TYPE DUM1113) NIL))

PURGE

MACRO

Public

DEF-ENCRECORD (NAME-AND-OPTIONS &REST DOC-AND-FIELDS)

DO: Defines an enctype template for a record type, a lisp structure with the same name, a reader and a writer functions.

DEF-ENCTYPE (NAME ARGS DEFINITION)

DO: Defines an enctype template.

GENERIC-FUNCTION

Public

SIZE-OF-ENCTYPE (SELF)

RETURN: The size in bytes of the ENCTYPE.

Private

Undocumented

DEFAULT-VALUE (SELF)

GET-VALUE (SELF BUFFER OFFSET)

MAXIMUM-LENGTH (SELF)

NUMBER-OF-DIGIT (SELF)

SET-VALUE (SELF BUFFER OFFSET RECORD)

TO-LISP-TYPE (SELF)

WRITE-VALUE (SELF BUFFER OFFSET VALUE)

SLOT-ACCESSOR

Private

ALLOCATED-SIZE (OBJECT)

The total number of bytes where the string is stored.

SETFALLOCATED-SIZE (NEW-VALUE OBJECT)

The total number of bytes where the string is stored.

ELEMENT-TYPE (OBJECT)

The enctype instance of the type of the elements

SETFELEMENT-TYPE (NEW-VALUE OBJECT)

The enctype instance of the type of the elements

ENCODING (OBJECT)

The encoding used to convert between strings and byte vectors. The :standard encoding use the ASCII code on the COMMON-LISP standard characters. The presence of any other character throws an error.

SETFENCODING (NEW-VALUE OBJECT)

The encoding used to convert between strings and byte vectors. The :standard encoding use the ASCII code on the COMMON-LISP standard characters. The presence of any other character throws an error.

ENDIAN (OBJECT)

The endian, either :big, :little or whatnot.

SETFENDIAN (NEW-VALUE OBJECT)

The endian, either :big, :little or whatnot.

FIELDS (OBJECT)

A list of field structures in no particular order.

SETFFIELDS (NEW-VALUE OBJECT)

A list of field structures in no particular order.

GREEN-LENGTH (OBJECT)

The enctype used to store the green length. The PAD-CODE is used to ease processing by external programs.

SETFGREEN-LENGTH (NEW-VALUE OBJECT)

The enctype used to store the green length. The PAD-CODE is used to ease processing by external programs.

IF-SMALLER (OBJECT)

When NIL, the maximum length for the string is one less the allocated size, and the terminator character is always present.

SETFIF-SMALLER (NEW-VALUE OBJECT)

When NIL, the maximum length for the string is one less the allocated size, and the terminator character is always present.

LISP-TYPE (OBJECT)

The name of the class whose instances store the record fields. We need to use a class instead of a structure to be able to dynamically set and retrieve the values of the fields.

SETFLISP-TYPE (NEW-VALUE OBJECT)

The name of the class whose instances store the record fields. We need to use a class instead of a structure to be able to dynamically set and retrieve the values of the fields.

MODULO (OBJECT)

1+the maximum value

SETFMODULO (NEW-VALUE OBJECT)

1+the maximum value

NAME (OBJECT)

The root name of the type.

SETFNAME (NEW-VALUE OBJECT)

The root name of the type.

PAD-CODE (OBJECT)

The code used as terminator or to pad the string.

SETFPAD-CODE (NEW-VALUE OBJECT)

The code used as terminator or to pad the string.

SIZE (OBJECT)

Number of bytes used by a number in this representation.

SETFSIZE (NEW-VALUE OBJECT)

Number of bytes used by a number in this representation.

STRIP (OBJECT)

The PAD-CODE must be removed in the lisp string.

SETFSTRIP (NEW-VALUE OBJECT)

The PAD-CODE must be removed in the lisp string.

Undocumented

DIMENSIONS (OBJECT)

SETFDIMENSIONS (NEW-VALUE OBJECT)

VARIABLE

Private

*ENCTYPE-DEFINITIONS*

The type definitions

*ENCTYPE-INSTANCES*

A cache for all the enctypes seen, mapping the enctype descriptor to the clos instance representing it.

+STANDARD-CHARACTERS+

A string containing all the COMMON-LISP standard characters, first newline, then from ASCII space to ASCII tilde in order. The COMMON-LISP implementation does not necessarily use the ASCII encoding for its strings. Our STANDARD-DECODE-STRING and STANDARD-ENCODE-STRING functions will take care to convert these characters to and from the ASCII encoding.

+STRING-ENCTYPE-DEFAULT-ENCODING+

The encoding used by default when string enctypes are created without specifying an encoding. If you want to use another encoding (implementation dependant values), you must set DECODE-STRING and ENCODE-STRING to functions that can handle it.

DECODE-STRING

The function used to decode strings.

ENCODE-STRING

The function used to encode strings.

CLASS

Private

ARRAY-ENCTYPE

An array type.

BINARY-CODED-DECIMAL-INTEGER-ENCTYPE

A binary-coded-decimal signed integer type.

ENCTYPE

An abstract encoded type.

GREEN-LENGTH-STRING-ENCTYPE

NUMBER-ENCTYPE

An abstract number type.

ONE-COMPLEMENT-INTEGER-ENCTYPE

A one-complement signed integer type.

PADDED-STRING-ENCTYPE

RECORD-ENCTYPE

A record type.

STRING-ENCTYPE

TERMINATED-STRING-ENCTYPE

TWO-COMPLEMENT-INTEGER-ENCTYPE

A two-complement signed integer type.

UNSIGNED-INTEGER-ENCTYPE

A binary unsigned integer type.

Undocumented

FIELD

CONSTANT

Private

+ASCII-CR+

Code of ASCII CR

+ASCII-LF+

Code of ASCII LF