Skip to content

Conversation

@mgi
Copy link

@mgi mgi commented Mar 15, 2017

Hi, I'm using this library and needed a way to obtain the size of a binary class. This is what those patches do.

You can define how the byte size is calculated in define-binary-type. For example:

(define-binary-type unsigned-integer (bytes bits-per-byte)
  (:reader (in)
    (loop with value = 0
       for low-bit downfrom (* bits-per-byte (1- bytes)) to 0 by bits-per-byte do
         (setf (ldb (byte bits-per-byte low-bit) value) (read-byte in))
       finally (return value)))
  (:writer (out value)
    (loop for low-bit downfrom (* bits-per-byte (1- bytes)) to 0 by bits-per-byte
	  do (write-byte (ldb (byte bits-per-byte low-bit) value) out)))
  (:size () bytes))
(define-binary-type u2 () (unsigned-integer :bytes 2 :bits-per-byte 8))

then define a binary class that use it:

(define-binary-class foo () ((a u2) (b u2)))

and finally obtain the byte size of such object:

(object-size 'foo)

mgi added 3 commits March 14, 2017 17:50
a :reader, a :writer and a :size (or any combination of them). For
example:

;; Just a reader and a size for this unsigned integer
(define-binary-type unsigned-integer (bytes bits-per-byte)
  (:reader (in)
    (loop with value = 0
       for low-bit downfrom (* bits-per-byte (1- bytes)) to 0 by bits-per-byte do
         (setf (ldb (byte bits-per-byte low-bit) value) (read-byte in))
       finally (return value)))
  (:size () bytes))

A not present :reader, :writer or :size will error out at call time.
one can obtain the byte size of a binary class object.
@mgi
Copy link
Author

mgi commented Jun 14, 2017

ping?

@mgi
Copy link
Author

mgi commented Oct 26, 2017

pong?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant