[erlang-questions] Decoding term_to_binary in javascript

Bob Gustafson bobgus@REDACTED
Wed Nov 16 16:29:29 CET 2011


You might check to see how Ruby 1.9.2 handles encoding.

There is an attribute - encoding - which is attached to files and
strings of the form (utf-8, usascii, iso-8859-15, etc.)

A program also has a default encoding - this is taken from the current
locale setting. This default can be overwritten by adding a (Ruby)
comment at the top of the program file of the form '# coding: UTF-8'

By checking the encoding of incoming files or strings, it is possible to
transcode from one encoding scheme to another (not possible in all
cases).

Check "The Well-Grounded Rubyist" by David A. Black, pp 229-231

Encodings were not handled very well in Ruby 1.8.7, so perhaps Erlang
also needs some beefing up in this area.



On Tue, 2011-11-15 at 14:54 -0800, Andrew Berman wrote:
> What happens if you use the dataFilter function on jQuery.ajax?  The
> docs say:
> 
> A function to be used to handle the raw response data of
> XMLHttpRequest.This is a pre-filtering function to sanitize the
> response. You should return the sanitized data. The function accepts
> two arguments: The raw data returned from the server and the
> 'dataType' parameter.
> 
> 
> Just thinking you could decode the response in that function.
> 
> 
> Never tried it though....
> 
> 
> --Andrew
> 
> On Tue, Nov 15, 2011 at 12:42 PM, Joe Armstrong <erlang@REDACTED>
> wrote:
>         To anser my own question it's not so easy.
>         
>         
>         A bert encoded term starts <<131, ...>>
>         
>         
>         Now 131 is not a single byte UTF8 character -  when I make
>         an ajax call from jquery in the browser the ajax stuff tryoes
>         to convert the blob containing a <<128,...>> to a utf8 string
>         and the decoding fails.
>         
>         
>         There are some html5 extensions -- something like
>         
>         
>              var r = new XMLHttpRequest();
>              r.open("GET", "get_bert", true);          
>              r.responseType = "arraybuffer"   
>          
>               r.onload = function(e) {   // XHR2
>                  var arr = new Uint8Array(this.response);
>         
>         
>         seems to work - but the exiting libraries cannot decode
>         a Unit8Array :-(
>         
>         
>         Why the heck sockets and ajax calls can't just sent back
>         sequences of bytes and not mess with them is a mystery to me
>         
>         
>         /Joe
>         
>         
>         On Tue, Nov 15, 2011 at 2:56 PM, Joe Armstrong
>         <erlang@REDACTED> wrote:
>                 This looks good.
>                 
>                 
>                 Another question.
>                 
>                 
>                 Has anybody an example client-server example of bert?
>                 
>                 
>                 I'm thinking:
>                 
>                 
>                            server in erlang  = bert +
>                 mochiweb/misultin/cowboy/yaws ...
>                            client in browser = jquery + bert
>                 
>                 
>                 Id like to make an ajax RPC from the client that
>                 returns a bert blob
>                 unpacks the blob and displays the result.
>                 
>                 
>                 
>                 
>                 /Joe
>                 
>                 On Tue, Nov 15, 2011 at 1:35 PM, Ulf Wiger
>                 <ulf@REDACTED> wrote:
>                 
>                 
>                         
>                         If you can settle for BERT, I think there are
>                         some JavaScript implementations out there:
>                         
>                         https://github.com/rtomayko/node-bertrpc/blob/master/src/bert.js
>                         
>                         BR,
>                         Ulf W
>                         
>                         On 15 Nov 2011, at 12:57, Joe Armstrong wrote:
>                         
>                         
>                         
>                         > I'd like to send a term_to_binary encoded
>                         term to a web client and decode it in
>                         javascript.
>                         >
>                         > If I could do this it would eliminate the
>                         impedance mismatch between server-side
>                         databases
>                         > and client code in a browser. I want to
>                         totally eliminate conversions to and from
>                         JSON. Just send
>                         > raw blobs containing term_to_binary encoded
>                         data and pluck what I want in the client.
>                         >
>                         > I would not necessarily want to decode the
>                         entire blob, I might just want to extract a
>                         specific item
>                         > So for example if In Erlang I created a blob
>                         by saying
>                         >
>                         >       Blob =
>                         term_to_binary({thing,"foo","bar",["baz"]})
>                         >
>                         > I'd like to send this to a browser and in
>                         Javascript say:
>                         >
>                         >      var z =
>                         mylib_hd(my_lib_element(4,Blob))
>                         >
>                         > Whereby z would be the javascript string
>                         "baz".
>                         >
>                         > Has anybody implemented anything like this?
>                         >
>                         > /Joe
>                         >
>                         >
>                         >
>                         
>                         
>                         >
>                         _______________________________________________
>                         > erlang-questions mailing list
>                         > erlang-questions@REDACTED
>                         >
>                         http://erlang.org/mailman/listinfo/erlang-questions
>                         
>                         
>                 
>                 
>         
>         
>         
>         _______________________________________________
>         erlang-questions mailing list
>         erlang-questions@REDACTED
>         http://erlang.org/mailman/listinfo/erlang-questions
>         
> 
> 
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions





More information about the erlang-questions mailing list