[erlang-questions] Text based protocols

Ulf Eliasson eliassou@REDACTED
Sun Apr 22 09:12:01 CEST 2007


I need to start using a proper e-mail client and not this webbased thing
that doesn't read the mailing list stuff in the header. I noticed to late that
the mail was sent to just Joern so here is what I sent to him with a with a
little bit added.

Hi,

Have you looked into yecc?
You can start here for a small example: http://www.erlang.org/faq/parsing.html

You don't describe the protocol in any detail so it's hard to say anything more
but I have used it for parsing text based protocols fast with great success.
That's what it's created for so ;).

To use yecc you need to write a tokenizer, but that is a task that can be
solved in a simple and fast way with just one pass of the string, for example
by writing/using a simple state machine.

One solution could also be to skip the yecc part, depending on how the protocol
look, and just use a state machine to read the string one character at a time
(or bigger chunks if that is possible, for example for the header) and parse it.
You/Erlang will need to read the string/data at least once anyway with all
solutions and it's fast to step through a list recursively.

This might not be the best solution for you because I don't know the protocol in
detail but I hope it helps, and for yecc there is man pages and also
documentation on the web, otherwise just ask here.

Ulf Eliasson
IT-University Göteborg
Mail: eliassou@REDACTED

Quoting Joern <opendev@REDACTED>:

> Hello erlang-questions,
>
> I am looking for an elegant solution for the parsing (and maybe the
> creation) of text based packets. A packet consists out of a fixed size
> header, a few magic characters and a payload of variable size.
>
> At first I tried to utilize the binary syntax but as e.g. the length
> indication in the header is encoded as a string I would have needed to
> convert back and forth all the time which did not seem worth the
> trouble. Parsing with io_lib:fread/2 works fine, but in case of errors
> I do not get the information which match failed and why it failed.
>
> Is there a suggestion how to handle the parsing of text based packets?
>
>
> Joern
> --
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>





More information about the erlang-questions mailing list