Changeset 4091 for trunk/lisp/emacs-lisp/bindat.el
- Timestamp:
- 05/27/06 10:35:24 (2 years ago)
- Files:
-
- trunk/lisp/emacs-lisp/bindat.el (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lisp/emacs-lisp/bindat.el
r4037 r4091 172 172 ;; | DEREF 173 173 174 ;; DEREF ::= ( [NAME | INTEGER]... ) -- Field NAME or Array index relative to175 ;; current structure spec.174 ;; DEREF ::= ( [NAME | INTEGER]... ) -- Field NAME or Array index relative 175 ;; to current structure spec. 176 176 ;; -- see bindat-get-field 177 177 … … 346 346 (defun bindat-unpack (spec raw-data &optional pos) 347 347 "Return structured data according to SPEC for binary data in RAW-DATA. 348 RAW-DATA is a string or vector. Optional third arg POS specifies the 349 starting offset in RAW-DATA." 348 RAW-DATA is a unibyte string or vector. Optional third arg POS specifies 349 the starting offset in RAW-DATA." 350 (when (multibyte-string-p raw-data) 351 (error "String is multibyte")) 350 352 (unless pos (setq pos 0)) 351 353 (bindat--unpack-group spec)) … … 416 418 (let ((index 0)) 417 419 (while (< index len) 418 (bindat--length-group (nth index (bindat-get-field struct field)) (nthcdr tail item)) 420 (bindat--length-group 421 (nth index (bindat-get-field struct field)) 422 (nthcdr tail item)) 419 423 (setq index (1+ index))))) 420 424 ((eq type 'union) … … 437 441 438 442 (defun bindat-length (spec struct) 439 "Calculate raw-data length for STRUCT according to bindat specificationSPEC."443 "Calculate raw-data length for STRUCT according to bindat SPEC." 440 444 (let ((pos 0)) 441 445 (bindat--length-group struct spec) … … 558 562 (let ((index 0)) 559 563 (while (< index len) 560 (bindat--pack-group (nth index (bindat-get-field struct field)) (nthcdr tail item)) 564 (bindat--pack-group 565 (nth index (bindat-get-field struct field)) 566 (nthcdr tail item)) 561 567 (setq index (1+ index))))) 562 568 ((eq type 'union) … … 578 584 (defun bindat-pack (spec struct &optional raw-data pos) 579 585 "Return binary data packed according to SPEC for structured data STRUCT. 580 Optional third arg RAW-DATA is a pre-allocated string or vector to unpack into.581 Optional fourth arg POS is the starting offset into RAW-DATA. 582 Note: The result is a multibyte string; use `string-make-unibyte' on it 583 to make it unibyte if necessary." 586 Optional third arg RAW-DATA is a pre-allocated unibyte string or vector to 587 pack into. Optional fourth arg POS is the starting offset into RAW-DATA." 588 (when (multibyte-string-p raw-data) 589 (error "Pre-allocated string is multibyte")) 584 590 (let ((no-return raw-data)) 585 591 (unless pos (setq pos 0)) 586 (unless raw-data (setq raw-data (make-vector (+ pos (bindat-length spec struct)) 0))) 592 (unless raw-data 593 (setq raw-data (make-vector (+ pos (bindat-length spec struct)) 0))) 587 594 (bindat--pack-group struct spec) 588 595 (if no-return nil (concat raw-data))))
