Anonymous avatar Anonymous committed a967185

Implement string encoding. Add README.

Comments (0)

Files changed (3)

+bert = BERT.encode(t[:foo,42,666,t[12,[],t[255,:bar],111222333444555666]])
+
+bert.each_byte{|c| print c, ' '}
+
+131 104 4 100 0 3 102 111 111 97 42 98 0 0 2 154 104 4 97 12 106 104 2 97 255 100 0 3 98 97 114 110 8 0 146 131 13 124 31 36 139 1
+scheme-bert
+===========
+
+scheme-bert is a BERT (Binary ERlang Term) serialization library for Scheme. BERT is based on Erlang's [External Term Format](http://www.erlang.org/doc/apps/erts/erl_ext_dist.html).
+
+See the BERT specification at [bert-rpc.org](http://bert-rpc.org).
+
+Instances of the following Ruby classes will be automatically converted to the
+proper simple BERT type:
+
+* integer? (fixnum and bignum)
+* symbol?
+* list?
+* string?
+* vector?
+
+Instances of the following Ruby classes will be automatically converted to the
+proper complex BERT type:
+
+* 'nil
+* #t
+* #f
+* hashtable?
+
+TODO
+----
+Implement encoding of these objects:
+
+* flonum?
+* time?
+* pregexp?
+
+
+Installation
+------------
+
+    Installation for Racket:
+
+    $ plt-r6rs --install erl-ext-types.ss
+
+    Then just (import (encode))
+
+
+Usage
+-----
+
+    (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"
+
+
+Copyright
+---------
+
+Copyright (c) 2010 Yasir M. Arsanukaev. See LICENSE for details.
 #!r6rs
 
-(import (mzlib pregexp)
-        (rnrs base) 
+(import (rnrs base) 
         (rnrs bytevectors) 
         (rnrs lists) 
         (rnrs hashtables)
         (rnrs io ports)
         (rnrs control)
         (rnrs arithmetic bitwise)
+        (rnrs arithmetic flonums)
+        (mzlib pregexp)
         (erl-ext-types))
 
 
   (put-u8 outpr (bitwise-and #xff (bitwise-arithmetic-shift-right long 8)))
   (put-u8 outpr (bitwise-and long #xff)))
 
+(define (write-binary outpr data)
+  (write-1 outpr BIN)
+  (let ((b (string->bytevector data (native-transcoder))))
+    (write-4 outpr (bytevector-length b))
+    (put-bytevector outpr b)))
+
 (define (write-str outpr str)
   (put-bytevector outpr (string->bytevector str (native-transcoder))))
 
      (write-atom outpr obj))
     ((integer? obj)
      (write-fixnum outpr obj))
+    ((string? obj)
+     (write-binary outpr obj))
     (else (error "write-any-raw" "Not implemented."))))
 
 (define (write-any outpr obj)
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.