]>
Commit | Line | Data |
---|---|---|
ed9b544e | 1 | -module(proto). |
2 | ||
91668668 | 3 | -export([parse/2]). |
ed9b544e | 4 | |
5 | parse(empty, "+OK") -> | |
6 | ok; | |
7 | parse(empty, "+PONG") -> | |
8 | pong; | |
91668668 | 9 | parse(empty, ":0") -> |
ed9b544e | 10 | false; |
91668668 | 11 | parse(empty, ":1") -> |
ed9b544e | 12 | true; |
ed9b544e | 13 | parse(empty, "-" ++ Message) -> |
ed9b544e | 14 | {error, Message}; |
91668668 | 15 | parse(empty, "$-1") -> |
16 | {read, nil}; | |
17 | parse(empty, "*-1") -> | |
18 | {hold, nil}; | |
19 | parse(empty, "$" ++ BulkSize) -> | |
20 | {read, list_to_integer(BulkSize)}; | |
21 | parse(read, "$" ++ BulkSize) -> | |
22 | {read, list_to_integer(BulkSize)}; | |
23 | parse(empty, "*" ++ MultiBulkSize) -> | |
24 | {hold, list_to_integer(MultiBulkSize)}; | |
25 | parse(empty, Message) -> | |
26 | convert(Message). | |
27 | ||
28 | convert(":" ++ Message) -> | |
29 | list_to_integer(Message); | |
30 | % in case the message is not OK or PONG it's a | |
31 | % real value that we don't know how to convert | |
32 | % to an atom, so just pass it as is and remove | |
33 | % the + | |
34 | convert("+" ++ Message) -> | |
35 | Message; | |
36 | convert(Message) -> | |
ed9b544e | 37 | Message. |
38 |