Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add string compression to serializer

  • Loading branch information...
commit aaabff7afb96ae5cb2d488f36dfec8e8bbc8302e 1 parent da87872
Kevin Raison authored
1  constants.lisp
View
@@ -50,6 +50,7 @@
(defconstant +null+ 12)
(defconstant +blob+ 13) ;; Uninterpreted octets
(defconstant +dotted-list+ 14)
+(defconstant +compressed-string+ 15)
;; User-defined type identifiers for serializing. Start at 100
(defconstant +uuid+ 100)
(defconstant +triple+ 101)
7 deserialize.lisp
View
@@ -52,6 +52,13 @@
(setf (aref array i) (read-byte stream)))
(sb-ext:octets-to-string array)))
+(defmethod deserialize ((code (eql +compressed-string+)) stream)
+ (let* ((length (deserialize (read-byte stream) stream))
+ (array (make-array length :element-type '(unsigned-byte 8))))
+ (dotimes (i length)
+ (setf (aref array i) (read-byte stream)))
+ (sb-ext:octets-to-string (chipz:decompress nil 'chipz:zlib array))))
+
(defmethod deserialize ((code (eql +t+)) stream)
t)
2  globals.lisp
View
@@ -9,6 +9,8 @@
(defparameter *read-uncommitted* t)
+(defparameter *compression-enabled?* t)
+
;; Graphs
(defvar *graph* nil)
(defvar *graph-table* nil)
20 serialize.lisp
View
@@ -47,12 +47,20 @@
(serialize-integer (char-code char) stream))
(defmethod serialize ((string string) (stream stream))
- (let* ((unicode (sb-ext:string-to-octets string))
- (length (length unicode)))
- (write-byte +string+ stream)
- (serialize length stream)
- (dotimes (i length)
- (write-byte (aref unicode i) stream))))
+ (if *compression-enabled?*
+ (let* ((comp (salza2:compress-data
+ (sb-ext:string-to-octets string) 'salza2:zlib-compressor))
+ (length (length comp)))
+ (write-byte +compressed-string+ stream)
+ (serialize length stream)
+ (dotimes (i length)
+ (write-byte (aref comp i) stream)))
+ (let* ((unicode (sb-ext:string-to-octets string))
+ (length (length unicode)))
+ (write-byte +string+ stream)
+ (serialize length stream)
+ (dotimes (i length)
+ (write-byte (aref unicode i) stream)))))
(defmethod serialize ((symbol symbol) (stream stream))
(cond ((null symbol)
2  vivace-graph-v2.asd
View
@@ -16,6 +16,8 @@
:bordeaux-threads
;;:cl-btree-0.5
:cl-skip-list
+ :salza2
+ :chipz
:hunchentoot
:uuid
:ieee-floats
Please sign in to comment.
Something went wrong with that request. Please try again.