Commits

Anonymous committed 263480b

Fix erroneous read-erl-string, add test case for it.
Fix write-list: byte-list length shouldn't exceed 65535 bytes since length field is an unsigned 2 byte integer.
Readme tweaks.

Comments (0)

Files changed (3)

 
     $ plt-r6rs --install ./src/scheme-bert.ss
 
-(see http://docs.racket-lang.org/r6rs/Installing_Libraries.html for more info)
+(see [Installing Libraries](http://docs.racket-lang.org/r6rs/Installing_Libraries.html) for more info)
 
 Usage
 -----
 Issue `(import (scheme-bert))` in your REPL or put this in head of your source file.
 You will also probably want to import some other libraries such as `bytevectors`.
 
-
-    (encode (vector 'foo 42 666 (vector 12 '() (vector 255 'bar) 111222333444555666)))
-    =>
+    > (bert-encode (vector 'foo 42 666 (vector 12 '() (vector 255 'bar) 111222333444555666)))
     #"\203h\4d\0\3fooa*b\0\0\2\232h\4a\fjh\2a\377d\0\3barn\b\0\222\203\r|\37$\213\1"
 
+    > (bert-decode #"\203m\0\0\0001Most people would rather die than think; many do.")
+    "Most people would rather die than think; many do."    
+
+Caveats
+-------
+
+Regular expressions conversion is not supported, because evey Scheme comes with its own regexp implementation and I haven't found any portable library which allows to get source regexp after one is compiled.
+
+Trivia
+------
+Please, drop me an email to yarsanukaev AT gmail DOT com if you used or intend to use the library in your project ;-)
 
 Copyright
 ---------

src/scheme-bert.ss

            (cond
              ((null? data)
               (write-1 outpr ERL_NIL))
-             ((fold/and (lambda (x) (isbyte? x)) data)
+             ((and (<= (length data) 65535)
+                   (fold/and (lambda (x) (isbyte? x)) data))
               (write-1 outpr ERL_STRING)
               (write-2 outpr (length data))
               (for-each (lambda (x) (write-1 outpr x)) data))
            '())   ; empty list
          
          (define (read-erl-string inp)
-           (read-str inp (read-short inp)))
+           (bytevector->u8-list (read-n inp (read-short inp))))
          
          (define (read-bin inp)
            (read-str inp (read-int inp)))
         ;(only (chezscheme) time-nanosecond time-second time? make-time)
         )
 
+; calling of these procs independently is useful: 
+; test-encoder, test-decoder, test-bert
+
 (define (fold/and proc lst)
   (cond
     ((null? lst)
                             "Failed: " (number->string (length fail))))
     (newline) (display "Encoder test done.") (newline)))
 
+(define (test-decoder)
+  (let* ((result (list (test-decoder-string)))
+         (suc (filter (lambda (x) x) result))
+         (fail (filter not result)))
+    (display "=== Performing decoder test ===") (newline)
+    (display (string-append "Successful: " 
+                            (number->string (length suc))
+                            ". " 
+                            "Failed: " (number->string (length fail))))
+    (newline) (display "Decoder test done.") (newline)))
+
 (define (test-bert)
   (let* ((result (list (test-hash)))
          (suc (filter (lambda (x) x) result))
                             (number->string (length suc))
                             ". " 
                             "Failed: " (number->string (length fail))))
-    (newline) (display "Tests done.") (newline)))
+    (newline) (display "Test done.") (newline)))
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; Encoder test cases
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; Decoder test cases
 ;;
-
+(define (test-decoder-string)
+  (checkthis "test-decoder-string"
+             "Flying Spaghetti Monster"
+             (bert-decode
+              (u8-list->bytevector '(131 109 0 0 0 24 70 108 121 105 
+                                         110 103 32 83 112 97 103 104 
+                                         101 116 116 105 32 77 111 110 
+                                         115 116 101 114)))))
+  
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; Roundtrip (encode->decode and vice versa) test cases
 ;;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.