You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Dotan N." <di...@gmail.com> on 2012/03/26 01:20:19 UTC
javascript and binary protocol
Hi all,
I've been examining using the javascript (_not_ node.js) version of
generated code, in order to interface with a binary protocol server (over
HTTP).
>From my initial view of the standard generated client code for javascript,
there is json serialization/deserialization built in, which won't work (and
so I verify in Thrift docs).
So officially I saw that there is no javascript + HTTP + binary combination
that is supported.
I started implementing such a thing myself, with
https://developer.mozilla.org/en/JavaScript_typed_arrays/DataView
as the base buffer.
Around half an hour into that, I felt that it is a time consuming, and
possibly an error prone process. So before investing more time into it I
felt I better verify that what I want to do will even work.
So my questions
- why isn't there such a javascript implementation supporting binary over
HTTP? is there some kind of technical show stopper to it? (encoding is not
a problem once i set it as user-specified, then my bytes should arrive
as-is and not mangled)
- is there anything like it in the open that I can reuse (instead of
reinvent)
- coming from not knowing thrift codebase at all, is there anything to ease
the process of building one from scratch?
Thanks!
Re: javascript and binary protocol
Posted by "Dotan N." <di...@gmail.com>.
Hi Fred,
Thanks a lot! I'll definitely check that!
Regarding no byte array in browser - it seems that with css3 and WebGL this
is becoming an old saying. There probably is a byte array in your browser
right now. This is from chrome stable (16).
b = new ArrayBuffer(20);
ArrayBuffer
d = new DataView(b)
DataView
d.getUint8(0)
0
d.setUint8(0, 3)
undefined
d.getUint8(0)
3
--
Dotan, @jondot <http://twitter.com/jondot>
On Mon, Mar 26, 2012 at 4:50 AM, Fred Potter <fp...@gmail.com> wrote:
>
> Hi Dotan,
>
> This won't be directly useful for you, but a couple of years ago I did a
> port of the ObjC bindings to Objective-J (this is Javascript with
> Objective-C syntax). Maybe it'll at least be a helpful reference if you
> keep building the plain JS version.
>
> The code is here:
>
> https://github.com/pieceable/thrift/tree/master/lib/cappuccino/Framework/Thrift
>
> And, there's a sample app here:
> https://github.com/pieceable/thrift-cappuccino-rails-example
>
> It uses the binary protocol over HTTP, but with the twist that the HTTP
> requests/responses get base64 encoded. And, because there's no byte array
> types in browser-side JS, it just used a regular array of numbers for the
> byte buffers.
>
> I think I'd start from the nodejs implementation and go from there.
> You're going to be able to reuse a lot of the compiler/codegen work
> they've done. It looks like much of their runtime library implementation
> will carry over, too.
>
> Best,
> Fred
>
>
>
> On Sunday, March 25, 2012 at 4:20 PM, Dotan N. wrote:
>
> > Hi all,
> > I've been examining using the javascript (_not_ node.js) version of
> > generated code, in order to interface with a binary protocol server (over
> > HTTP).
> >
> > From my initial view of the standard generated client code for
> javascript,
> > there is json serialization/deserialization built in, which won't work
> (and
> > so I verify in Thrift docs).
> >
> > So officially I saw that there is no javascript + HTTP + binary
> combination
> > that is supported.
> >
> > I started implementing such a thing myself, with
> > https://developer.mozilla.org/en/JavaScript_typed_arrays/DataView
> > as the base buffer.
> >
> > Around half an hour into that, I felt that it is a time consuming, and
> > possibly an error prone process. So before investing more time into it I
> > felt I better verify that what I want to do will even work.
> >
> > So my questions
> >
> > - why isn't there such a javascript implementation supporting binary over
> > HTTP? is there some kind of technical show stopper to it? (encoding is
> not
> > a problem once i set it as user-specified, then my bytes should arrive
> > as-is and not mangled)
> > - is there anything like it in the open that I can reuse (instead of
> > reinvent)
> > - coming from not knowing thrift codebase at all, is there anything to
> ease
> > the process of building one from scratch?
> >
> >
> > Thanks!
>
>
Re: javascript and binary protocol
Posted by Fred Potter <fp...@gmail.com>.
Hi Dotan,
This won't be directly useful for you, but a couple of years ago I did a port of the ObjC bindings to Objective-J (this is Javascript with Objective-C syntax). Maybe it'll at least be a helpful reference if you keep building the plain JS version.
The code is here:
https://github.com/pieceable/thrift/tree/master/lib/cappuccino/Framework/Thrift
And, there's a sample app here:
https://github.com/pieceable/thrift-cappuccino-rails-example
It uses the binary protocol over HTTP, but with the twist that the HTTP requests/responses get base64 encoded. And, because there's no byte array types in browser-side JS, it just used a regular array of numbers for the byte buffers.
I think I'd start from the nodejs implementation and go from there. You're going to be able to reuse a lot of the compiler/codegen work they've done. It looks like much of their runtime library implementation will carry over, too.
Best,
Fred
On Sunday, March 25, 2012 at 4:20 PM, Dotan N. wrote:
> Hi all,
> I've been examining using the javascript (_not_ node.js) version of
> generated code, in order to interface with a binary protocol server (over
> HTTP).
>
> From my initial view of the standard generated client code for javascript,
> there is json serialization/deserialization built in, which won't work (and
> so I verify in Thrift docs).
>
> So officially I saw that there is no javascript + HTTP + binary combination
> that is supported.
>
> I started implementing such a thing myself, with
> https://developer.mozilla.org/en/JavaScript_typed_arrays/DataView
> as the base buffer.
>
> Around half an hour into that, I felt that it is a time consuming, and
> possibly an error prone process. So before investing more time into it I
> felt I better verify that what I want to do will even work.
>
> So my questions
>
> - why isn't there such a javascript implementation supporting binary over
> HTTP? is there some kind of technical show stopper to it? (encoding is not
> a problem once i set it as user-specified, then my bytes should arrive
> as-is and not mangled)
> - is there anything like it in the open that I can reuse (instead of
> reinvent)
> - coming from not knowing thrift codebase at all, is there anything to ease
> the process of building one from scratch?
>
>
> Thanks!