[erlang-questions] {packet, PacketType} for little-signed packets

Torben Hoffmann torben.lehoff@REDACTED
Sun Jun 6 11:50:17 CEST 2010


Hi Pablo,

No clue on the patching of gen_tcp.

The mongodb wire protocol is not Erlang pattern matching friendly, since you
have to record the Length, then peel off the message inside your function
instead of doing the pattern matching directly in the function clause.
Not a major issue, just annoying.

Cheers,
Torben

On Sun, Jun 6, 2010 at 00:17, Pablo Platt <pablo.platt@REDACTED> wrote:

> Hi Torben
>
> I'm implementing mongodb wire protocol
> http://www.mongodb.org/display/DOCS/Mongo+Wire+Protocol
> The first 4 bytes in each message are int32 of the "total message size,
> including the 4 bytes of length"
> and all data is little-endian: "Note that like BSON documents, all data in
> the mongo wire protocol is little-endian."
>
> Is it possible to patch gen_tcp to support BSON?
> Is there a simpler solution?
>
> ------------------------------
> *From:* Torben Hoffmann <torben.lehoff@REDACTED>
> *To:* Pablo Platt <pablo.platt@REDACTED>; erlang-questions <
> erlang-questions@REDACTED>
> *Sent:* Sun, June 6, 2010 12:35:58 AM
> *Subject:* Re: [erlang-questions] {packet, PacketType} for little-signed
> packets
>
> Hi Pablo,
>
> I don't quite understand what your issue is, but it might be due to my lack
> of understanding of the gen_tcp details. If not I think you should rephrase
> your question.
>
> Anyway, I have a piece of advice based on your code sniplet.
>
> If you are defining the protocol yourself I would strongly suggest that you
> make Length equal to the size of the Message since it makes decoding a lot
> easier. I have dealt with Q.SIG and there the length in the PDU also
> depends
> on the size of the header which forces one to do the decoding in two steps
> instead of having the option to do it in one step in the function clause
> pattern match.
>
> Cheers,
> Torben
>
> On Sat, Jun 5, 2010 at 17:39, Pablo Platt <pablo.platt@REDACTED> wrote:
>
> > Hi
> >
> > Is there a way I can handle {packet, PacketType} for little-endian where
> > Packet = <<Length:32/little-signed,Message/binary>>
> > Length=4+byte_size(Message)
> >
> > I currently handle it manually but it'll be nice if gen_tcp could handle
> it
> > for me the way {packet, PacketType}
> > works for big-endian byte order.
> >
> > Thanks
> >
> >
> >
> >
>
>
>
>
> --
> http://www.linkedin.com/in/torbenhoffmann
>
>


-- 
http://www.linkedin.com/in/torbenhoffmann


More information about the erlang-questions mailing list