~theothornhill/cl-bare

05edb876c8ac38ca2dd822b8a18ecf0e0d887117 — Theodor Thornhill 3 years ago 9634a35
Try to defeat silly indentation
1 files changed, 64 insertions(+), 82 deletions(-)

M src/bare.lisp
M src/bare.lisp => src/bare.lisp +64 -82
@@ 21,29 21,24 @@
         (setf value (ash value -7)))
  (write-byte value stream))

(defbinary uint
    ()
    (value 0 :type (custom
                    :reader (lambda (stream)
                              (read-uvarint stream))
                    :writer (lambda (object stream)
                              (write-uvarint object stream)))))

(defbinary u8
    ()
    (value 0 :type 8))

(defbinary u16
    ()
    (value 0 :type 16))

(defbinary u32
    ()
    (value 0 :type 32))

(defbinary u64
    ()
    (value 0 :type 64))
(defbinary uint ()
  (value 0 :type (custom
                  :reader (lambda (stream)
                            (read-uvarint stream))
                  :writer (lambda (object stream)
                            (write-uvarint object stream)))))

(defbinary u8 ()
  (value 0 :type 8))

(defbinary u16 ()
  (value 0 :type 16))

(defbinary u32 ()
  (value 0 :type 32))

(defbinary u64 ()
  (value 0 :type 64))

(defun zigzag (value)
  (- (* 2 (abs value))


@@ 65,37 60,30 @@
  "Write a VALUE into STREAM as a signed varint."
  (write-uvarint (zigzag value) stream))

(defbinary int
    ()
    (value 0 :type (custom
                    :reader (lambda (stream)
                              (read-varint stream))
                    :writer (lambda (object stream)
                              (write-varint object stream)))))
(defbinary int ()
  (value 0 :type (custom
                  :reader (lambda (stream)
                            (read-varint stream))
                  :writer (lambda (object stream)
                            (write-varint object stream)))))

(defbinary i8
    ()
    (value 0 :type -8))
(defbinary i8 ()
  (value 0 :type -8))

(defbinary i16
    ()
    (value 0 :type -16))
(defbinary i16 ()
  (value 0 :type -16))

(defbinary i32
    ()
    (value 0 :type -32))
(defbinary i32 ()
  (value 0 :type -32))

(defbinary i64
    ()
    (value 0 :type -64))
(defbinary i64 ()
  (value 0 :type -64))

(defbinary f32
    ()
    (value 0.0f0 :type (single-float)))
(defbinary f32 ()
  (value 0.0f0 :type (single-float)))

(defbinary f64
    ()
    (value 0.0d0 :type (double-float)))
(defbinary f64 ()
  (value 0.0d0 :type (double-float)))

(defun read-bool (stream)
  (values (not (zerop (read-integer 1 stream)))


@@ 105,46 93,40 @@
  (let ((val (if value 1 0)))
    (write-integer val 1 stream)))

(defbinary bool
    ()
    (value 0 :type (custom
                    :reader (lambda (stream)
                              (read-bool stream))
                    :writer (lambda (object stream)
                              (write-bool object stream)))))

(defbinary enum
    ()
    (value 0 :type (uint)))

(defbinary str
    ()
    (size 0 :type (uint))
    (value "" :type (fixed-string
                     (slot-value size 'value)
                     :external-format :utf-8)))
(defbinary bool ()
  (value 0 :type (custom
                  :reader (lambda (stream)
                            (read-bool stream))
                  :writer (lambda (object stream)
                            (write-bool object stream)))))

(defbinary enum ()
  (value 0 :type (uint)))

(defbinary str ()
  (size 0 :type (uint))
  (value "" :type (fixed-string
                   (slot-value size 'value)
                   :external-format :utf-8)))

(defvar *data-length* 1
  "Length for the arbitrary length DATA type.

Set this dynamically in the function calling the DATA defbinary.")

(defbinary data
    ()
    (size 0 :type (uint))
    (value #() :type (simple-array
                      (unsigned-byte 8)
                      ((slot-value size 'value)))))

(defbinary data-fixed
    ()
    (value #() :type (simple-array
                      (unsigned-byte 8)
                      (*data-length*))))

(defbinary void
    ()
    (value nil :type null))
(defbinary data ()
  (size 0 :type (uint))
  (value #() :type (simple-array
                    (unsigned-byte 8)
                    ((slot-value size 'value)))))

(defbinary data-fixed ()
  (value #() :type (simple-array
                    (unsigned-byte 8)
                    (*data-length*))))

(defbinary void ()
  (value nil :type null))


;;; Aggregate types