[erlang-questions] encoding packets a style+efficiency question

Kenneth Lundin kenneth.lundin@REDACTED
Tue Jul 26 15:38:28 CEST 2011


I suppose you arleady know that there is a tftp implementation included in the
Erlang/OTP distribution.

You find the documentation here.
http://www.erlang.org/doc/man/tftp.html

/Kenneth Erlang/OTP Ericsson

On Tue, Jul 26, 2011 at 9:36 AM, Anupam Kapoor <anupam.kapoor@REDACTED> wrote:
> hi all,
>
> i have been playing with an implementation of tftp
> (rfc-1350). encoding/decoding tftp-pdu's is trivial with erlang's bit
> syntax.
>
> there seem to be couple of approaches to encoding/decoding tftp-pdu's:
>
>   1. use native "in-place" encode/decode
>   2. have a 'generic' encode/decode routine which accepts
>         - a list of pdu primitives e.g. 'byte'/'string' etc. and
>         - a list of corresponding values
>      and returns the binary packet.
>
>      for example, encoding a tftp-data packet looks like this:
>          ,----
>          | %% encode data packet
>          | encode_data_pkt(BlkNum, Data) ->
>          |     encode_packet([?BYTE, ?BYTE, ?RAW],
> [?TFTP_OPCODE_DATA, BlkNum, Data]).
>          `----
>
> to me, approach #2 seems pretty close to rfc's packet-format
> specification. for example, the data-packet is shown as
>
>           2 bytes     2 bytes      n bytes
>           ----------------------------------
>          | Opcode |   Block #  |   Data     |
>           ----------------------------------
>
> can you please provide your suggestion on whether #2 might be a good
> approach to follow for complicated protocols e.g. gtp-v2 which defines a
> large number of messages ? also, are there better (increasing order of
> readability, performance etc.) approaches for doing this ?
>
> thank you
> kind regards
> anupam
>
> ps: the attached file contains encoders for tftp messages...
>
> --
> In the beginning was the lambda, and the lambda was with Emacs, and
> Emacs was the lambda.
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
>



More information about the erlang-questions mailing list