From: Flori on
I need Google protocol-buffers <http://code.google.com/p/protobuf/>
for communication in our current project and was disappointed to see
that there seems to be no Tcl language-binding (but for many other
languages there is).
Since the en-/de-coding is simple <http://code.google.com/intl/de/apis/
protocolbuffers/docs/encoding.html>, I just wanted to do it myself.
But then I was disappointed again, because to correctly implement it
in Tcl I have to read bytes from a channel not chars and there seems
to be no way to accomplish this in Tcl!

Do I really have to descend to C?
Shouldn't we have a way to read bytes from a channel in plain Tcl?

Any suggestions?
regards,
Florian
From: Arjen Markus on
On 20 jan, 13:09, Flori <Florian_M...(a)yahoo.de> wrote:
> I need Google protocol-buffers <http://code.google.com/p/protobuf/>
> for communication in our current project and was disappointed to see
> that there seems to be no Tcl language-binding (but for many other
> languages there is).
> Since the en-/de-coding is simple <http://code.google.com/intl/de/apis/
> protocolbuffers/docs/encoding.html>, I just wanted to do it myself.
> But then I was disappointed again, because to correctly implement it
> in Tcl I have to read bytes from a channel not chars and there seems
> to be no way to accomplish this in Tcl!
>
> Do I really have to descend to C?
> Shouldn't we have a way to read bytes from a channel in plain Tcl?
>
> Any suggestions?
> regards,
> Florian

Have you setting the channel options to translation binary (via
fconfigure)?

Regards,

Arjen
From: miguel sofer on
Flori wrote:
> But then I was disappointed again, because to correctly implement it
> in Tcl I have to read bytes from a channel not chars and there seems
> to be no way to accomplish this in Tcl!
>
> Do I really have to descend to C?
> Shouldn't we have a way to read bytes from a channel in plain Tcl?
>
> Any suggestions?

Look at
chan configure $chan -translation binary

http://www.tcl.tk/man/tcl8.5/TclCmd/chan.htm
From: Eric Hassold on
Le 20/01/2010 13:09, Flori a �crit :
> I need Google protocol-buffers<http://code.google.com/p/protobuf/>
> for communication in our current project and was disappointed to see
> that there seems to be no Tcl language-binding (but for many other
> languages there is).
> Since the en-/de-coding is simple<http://code.google.com/intl/de/apis/
> protocolbuffers/docs/encoding.html>, I just wanted to do it myself.
> But then I was disappointed again, because to correctly implement it
> in Tcl I have to read bytes from a channel not chars and there seems
> to be no way to accomplish this in Tcl!
>
> Do I really have to descend to C?
> Shouldn't we have a way to read bytes from a channel in plain Tcl?
>

Hello,

Yes, we should...and we have.

fconfigure $chan -translation binary -encoding binary
set buf [read $chan $nbytes]

then buf is a byte array. Use [binary] command to parse it, or string
operations, since EIAS, including bytearrays.

Eric
From: Alexandre Ferrieux on
On Jan 20, 1:09 pm, Flori <Florian_M...(a)yahoo.de> wrote:
>
> in Tcl I have to read bytes from a channel not chars and there seems
> to be no way to accomplish this in Tcl!

I wonder where you got that myth. Google may be biased towards Python,
they are everything but idiots. Disinformation must come form
elsewhere...

By the way, thanks for the heads-up on protobuf, never heard of it
before.
While the protocol is thoroughly described and rather simple, the
encoding of varints, the zigzag mapping, etc. don't strike me as the
most machine-efficient thing ever. Of course you're saving bytes here
and there, but the need to shuffle bits at every corner costs you
cycles. I don't predict a world domination by protobuf too soon ;-)

-Alex
 |  Next  |  Last
Pages: 1 2
Prev: for loop variable scope
Next: Slimming down a tclkit