Skip to content

Commit 8beafa1

Browse files
committed
fix erlang
1 parent e79c4f1 commit 8beafa1

File tree

1 file changed

+17
-57
lines changed

1 file changed

+17
-57
lines changed

parsers/erlang/ewp_request.erl

+17-57
Original file line numberDiff line numberDiff line change
@@ -7,62 +7,37 @@
77
-record(ewp_request,{
88
proto,
99
version,
10-
command,
11-
compression,
12-
response_compression,
13-
has_body = false,
10+
envelope_kind,
1411
header,
1512
body
1613
}).
17-
%ewp_request:parse("EWP 0.1 PING none none 2 2 H\ntest").
18-
parse_compression(RespCompStr) ->
19-
parse_compression(RespCompStr,[]).
20-
21-
parse_compression(RespCompStr,Prog) ->
22-
23-
Index = string:str(RespCompStr,","),
24-
if
25-
Index < 1 ->
26-
[RespCompStr];
27-
true ->
28-
29-
parse_compression(string:substr(RespCompStr,Index+1),[Prog|string:slice(RespCompStr,0,Index)])
30-
end
31-
32-
.
3314

3415
parse(In) ->
3516
Index = str(In,"\n"),
3617
RequestLine = string:slice(In,0,Index-1),
3718
RequestBody = string:substr(In,Index+1),
3819
Request = string:tokens(RequestLine," "),
3920
if
40-
length(Request) < 7 ->
21+
length(Request) < 5 ->
4122
exit("Not enough items");
4223
true ->
4324
ok
4425
end,
4526
Proto = lists:nth(1,Request),
4627
Version = lists:nth(2,Request),
47-
Command = lists:nth(3,Request),
48-
Compression = lists:nth(4,Request),
49-
ResponseCompression = parse_compression(lists:nth(5,Request)),
50-
HasBody = length(Request) == 7,
51-
Header = string:slice(RequestBody,0,list_to_integer(lists:nth(6,Request))),
28+
EnvelopeKind = lists:nth(3,Request),
29+
Header = string:slice(RequestBody,0,list_to_integer(lists:nth(4,Request))),
5230
if
5331
length(Request) == 8 ->
5432
Body = "";
5533
true ->
56-
Body = string:slice(RequestBody,list_to_integer(lists:nth(6,Request)),list_to_integer(lists:nth(7,Request)))
34+
Body = string:slice(RequestBody,list_to_integer(lists:nth(4,Request)),list_to_integer(lists:nth(5,Request)))
5735

5836
end,
5937
#ewp_request{
6038
proto = Proto,
6139
version = Version,
62-
command = Command,
63-
compression = Compression,
64-
response_compression = ResponseCompression,
65-
has_body = HasBody,
40+
envelope_kind = EnvelopeKind,
6641
header = Header,
6742
body = Body
6843
}
@@ -71,30 +46,15 @@ parse(In) ->
7146
%ewp_request:marshal(ewp_request:parse("EWP 0.1 PING none none 2 2 H\ntest")).
7247
%ewp_request:marshal(ewp_request:parse("EWP 0.1 PING none none 2 2\ntest")).
7348
marshal(State)->
74-
if
75-
State#ewp_request.has_body ->
76-
binary_to_list(erlang:iolist_to_binary(io_lib:format("~s ~s ~s ~s ~s ~p ~p\n~s~s",[
77-
State#ewp_request.proto,
78-
State#ewp_request.version,
79-
State#ewp_request.command,
80-
State#ewp_request.compression,
81-
lists:join(",",State#ewp_request.response_compression),
82-
string:len(State#ewp_request.header),
83-
string:len(State#ewp_request.body),
84-
State#ewp_request.header,
85-
State#ewp_request.body
86-
])));
87-
true ->
88-
binary_to_list(erlang:iolist_to_binary(io_lib:format("~s ~s ~s ~s ~s ~p ~p H\n~s~s",[
89-
State#ewp_request.proto,
90-
State#ewp_request.version,
91-
State#ewp_request.command,
92-
State#ewp_request.compression,
93-
lists:join(",",State#ewp_request.response_compression),
94-
string:len(State#ewp_request.header),
95-
string:len(State#ewp_request.body),
96-
State#ewp_request.header,
97-
State#ewp_request.body
98-
])))
99-
end
49+
50+
binary_to_list(erlang:iolist_to_binary(io_lib:format("~s ~s ~s ~p ~p\n~s~s",[
51+
State#ewp_request.proto,
52+
State#ewp_request.version,
53+
State#ewp_request.envelope_kind,
54+
string:len(State#ewp_request.header),
55+
string:len(State#ewp_request.body),
56+
State#ewp_request.header,
57+
State#ewp_request.body
58+
])))
59+
10060
.

0 commit comments

Comments
 (0)