Mercurial > core / lisp/lib/dat/proto.lisp
changeset 263: |
b7183bfd7107 |
parent: |
11ef863e0ac0
|
child: |
78ef6145e272 |
author: |
Richard Westhaver <ellis@rwest.io> |
date: |
Fri, 05 Apr 2024 19:47:17 -0400 |
permissions: |
-rw-r--r-- |
description: |
add doc/readme.txt, more doc upgrades |
1 ;;; lib/dat/proto.lisp --- data (de)serialization 6 (in-package :dat/proto) 9 (define-condition dat-error (std-error) ()) 11 (define-condition serializer-error (dat-error) ()) 12 (define-condition deserializer-error (dat-error) ()) 13 (define-condition serde-error (dat-error) ()) 15 (defvar *serializable* 16 '(string simple-string octet-vector octet 17 char simple-array simple-vector array 19 "List of types which can be serialized to.") 21 (deftype serializable-type-designator () 22 `(or (member ,@*serializable*) 23 (cons (member ,@*serializable*) *))) 25 (defun serializable-type-p (x) 26 "Return non-nil if type X is serializable." 27 (typep x 'serializable-type-designator)) 29 (defgeneric serializable-p (self) 30 (:method ((self t)) nil) 31 (:documentation "Return non-nil of object SELF is serializable.")) 33 (defgeneric serialize (obj format &key) 34 (:documentation "Serialize OBJ to FORMAT, which is a SERIALIZABLE-TYPE-DESIGNATOR.")) 37 (defvar *deserializable* nil 38 "List of types which are DESERIALIZABLE-P") 40 (deftype deserializable-type-designator () 41 `(or (member ,@*deserializable*) 42 (cons (member ,@*deserializable*) *))) 44 (defun deserializable-type-p (x) 45 "Return non-nil if type X is deserializable." 46 (typep x 'deserializable-type-designator)) 48 (defgeneric deserializable-p (self) 49 (:method ((self t)) nil) 50 (:documentation "Return non-nil if object SELF is deserializable.")) 52 (defgeneric deserialize (from format &key) 53 (:documentation "Deserialize FROM into an object of type FORMAT, which is a 54 DESERIALIZABLE-TYPE-DESIGNATOR.")) 57 (defgeneric serde (from to) 58 (:documentation "Point-to-point serialization. 60 FROM and TO should both specialize on object instances. 62 Calling this function requires you to initialize the arguments instead 63 of relying on a type-designator format and generating an object in the