Changeset 35386 in project


Ignore:
Timestamp:
04/09/18 22:43:14 (8 months ago)
Author:
kon
Message:

add blob-utils module (wider bv api)

Location:
release/4/blob-utils/trunk
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • release/4/blob-utils/trunk/blob-set-int.scm

    r35230 r35386  
    154154
    155155) ;module blob-set-int
    156 
    157 
    158 #| ;Useful API?
    159 ;;; Blob, String, & U8Vector Bytevector
    160 
    161 ;;
    162 
    163 (define (get-bv-alias loc obj)
    164   (cond
    165     ((blob? obj)
    166       obj )
    167     ((string? obj)
    168       obj )
    169     ((u8vector? obj)
    170       (u8vector->blob/shared obj) )
    171     (else
    172         (error-argument-type loc obj "blob, u8vector, or string" obj) ) ) )
    173 
    174 #; ;Too Many options
    175 (define (get-byte-order loc obj)
    176   (case obj
    177         ((big-endian be big msb)
    178           'big-endian )
    179         ((little-endian le little lsb)
    180           'little-endian )
    181     (else
    182         (error-argument-type loc obj "symbol in {big-endian be big msb little-endian le little lsb}" obj) ) ) )
    183 
    184 ;; 8
    185 
    186 (define (set-u8! bv uint idx)
    187         (blob-set-u8! (get-bv-alias 'set-u8! bv) uint idx) )
    188 
    189 ;; Little Endian 16, 32, & 64
    190 
    191 (define (set-u16-le! bv uint #!optional (idx 0))
    192   (blob-set-u16-le! (get-bv-alias 'set-u16-le! bv) uint idx) )
    193 
    194 (define (set-u32-le! bv uint #!optional (idx 0))
    195   (blob-set-u32-le! (get-bv-alias 'set-u32-le! bv) uint idx) )
    196 
    197 (define (set-u64-le! bv uint #!optional (idx 0))
    198   (blob-set-u64-le! (get-bv-alias 'set-u64-le! bv) uint idx) )
    199 
    200 ;; Big Endian 16, 32, & 64
    201 
    202 (define (set-u16-be! bv uint #!optional (idx 0))
    203   (blob-set-u16-be! (get-bv-alias 'set-u16-be! bv) uint idx) )
    204 
    205 (define (set-u32-be! bv uint #!optional (idx 0))
    206   (blob-set-u32-be! (get-bv-alias 'set-u32-be! bv) uint idx) )
    207 
    208 (define (set-u64-be! bv uint #!optional (idx 0))
    209   (blob-set-u64-be! (get-bv-alias 'set-u64-be! bv) uint idx) )
    210 
    211 ;; Both Endian 16, 32, & 64
    212 
    213 (define (set-u16! bv uint #!optional (idx 0) (order (machine-byte-order)))
    214         (let ((bv (get-bv-alias 'set-u16! bv)))
    215                 (case (get-byte-order 'set-u16! order)
    216                         ((little-endian)
    217                           (blob-set-u16-le! bv uint idx) )
    218                         ((big-endian)
    219                           (blob-set-u16-be! bv uint idx) ) ) ) )
    220 
    221 (define (set-u32! bv uint #!optional (idx 0) (order (machine-byte-order)))
    222         (let ((bv (get-bv-alias 'set-u32! bv)))
    223                 (case (get-byte-order 'set-u32! order)
    224                         ((little-endian)
    225                           (blob-set-u32-le! bv uint idx) )
    226                         ((big-endian)
    227                           (blob-set-u32-be! bv uint idx) ) ) ) )
    228 
    229 (define (set-u64! bv uint #!optional (idx 0) (order (machine-byte-order)))
    230         (let ((bv (get-bv-alias 'set-u64! bv)))
    231                 (case (get-byte-order 'set-u64! order)
    232                         ((little-endian)
    233                           (blob-set-u64-le! bv uint idx) )
    234                         ((big-endian)
    235                           (blob-set-u64-be! bv uint idx) ) ) ) )
    236 |#
  • release/4/blob-utils/trunk/blob-utils.meta

    r35230 r35386  
    88 (synopsis "Blob Utilities")
    99 (depends
    10         ;to-hex
    11         (string-utils "1.2.2")
     10        (string-utils "1.2.2")  ;to-hex
    1211        (check-errors "2.1.0")
    1312        (setup-helper "1.5.2"))
    1413 (test-depends test)
    1514 (files
    16         "blob-utils.meta" "blob-utils.setup"
    17         "blob-set-int.scm" "blob-hexadecimal.scm"
     15  "blob-utils.meta" "blob-utils.setup"
     16  "blob-utils.scm"
     17  "blob-set-int.scm"
     18  "blob-hexadecimal.scm"
     19  "pack-integer.scm"
    1820        "tests/run.scm" "tests/blob-utils-test.scm") )
  • release/4/blob-utils/trunk/blob-utils.setup

    r35230 r35386  
    55(verify-extension-name "blob-utils")
    66
    7 (setup-shared+static-extension-module 'blob-set-int (extension-version "1.1.0")
     7(setup-shared+static-extension-module 'blob-set-int (extension-version "1.2.0")
    88  #:types? #t
    99  #:inline? #t
    1010  #:compile-options '(
    11     -optimize-level 3 -debug-level 2
     11    -scrutinize -specialize
     12    -optimize-level 3 -debug-level 1
    1213    -no-procedure-checks -no-argc-checks -no-bound-checks))
    1314
    14 (setup-shared-extension-module 'blob-hexadecimal (extension-version "1.1.0")
     15(setup-shared+static-extension-module 'blob-hexadecimal (extension-version "1.2.0")
    1516  #:types? #t
    1617  #:inline? #t
    1718  #:compile-options '(
    18     -optimize-level 3 -debug-level 2
     19    -scrutinize -specialize
     20    -optimize-level 3 -debug-level 1
    1921    -no-procedure-checks))
    2022
    21 (setup-shared-extension-module 'pack-integer (extension-version "1.1.0")
     23(setup-shared+static-extension-module 'pack-integer (extension-version "1.2.0")
    2224  #:types? #t
    2325  #:inline? #t
    2426  #:compile-options '(
    25     -optimize-level 3 -debug-level 2
     27    -scrutinize -specialize
     28    -optimize-level 3 -debug-level 1
    2629    -no-procedure-checks))
    2730
    28 (install-extension-tag 'blob-utils (extension-version "1.1.0"))
     31(setup-shared+static-extension-module 'blob-utils (extension-version "1.2.0")
     32  #:types? #t
     33  #:inline? #t
     34  #:compile-options '(
     35    -scrutinize -specialize
     36    -optimize-level 3 -debug-level 1
     37    -no-procedure-checks))
  • release/4/blob-utils/trunk/tests/blob-utils-test.scm

    r35230 r35386  
    11(use test)
    2 
    3 (use blob-hexadecimal)
    42
    53(test-begin "Blob Utils")
     
    75(use blob-set-int)
    86
    9 (test-group "Set Int"
     7(test-group "Low-Level Set UInt"
    108  (let ((blb (make-blob 10)))
    11     (blob-set-u16-le! blb 1542)
     9    (blob-set-u16-le! blb #x0606)
    1210    (let ((str (blob->string blb)))
    1311      (test "low byte set" (integer->char #x06) (string-ref str 0)) ) )
    1412)
     13
     14(use blob-hexadecimal)
    1515
    1616(test-group "-> Hex"
     
    2626    (test-assert (string? res))
    2727    (test "byte set" (integer->char #x2d) (string-ref res 0)) )
    28   (let ((res (pack-integer 1542 #:kind 'blob #:order 'little-endian)))
     28  (let ((res (pack-integer #x0606 #:kind 'blob #:order 'little-endian)))
    2929    (test-assert (blob? res))
    3030    (let ((str (blob->string res)))
     
    3232)
    3333
     34(use blob-utils)
     35
     36(test-group "Set Int"
     37  (let ((blb (make-blob 10)))
     38    (bytes-set-s16! blb 0 #x0606)
     39    (let ((str (blob->string blb)))
     40      (test "low byte set" (integer->char #x06) (string-ref str 0)) ) )
     41)
     42
     43(test-group "-> Hex"
     44        (test "414243444546" (bytes->hexstring "ABCDEF"))
     45        (test "4243444546" (bytes->hexstring "ABCDEF" 1))
     46        (test "4243" (bytes->hexstring "ABCDEF" 1 3))
     47)
     48
    3449(test-end)
    3550
Note: See TracChangeset for help on using the changeset viewer.