[HILTI] Spicy Parsing WebSockets - how to end a list
Fernandez, Mark I
mfernandez at mitre.org
Thu Jul 27 12:09:08 PDT 2017
Is the sink executing as you intend? If not, it could be because when the hook “on %init” is executed when the routine is initialized, but at that time, the element “wss_data” has not been parsed yet. Perhaps try:
on wss_data {
self.sub.connect(new Sub());
self.sub.write(self.wss_data);
}
Mark
From: hilti-bounces at ICSI.Berkeley.EDU [mailto:hilti-bounces at ICSI.Berkeley.EDU] On Behalf Of Jennifer Gates
Sent: Thursday, July 27, 2017 2:56 PM
To: Robin Sommer <robin at icir.org>
Cc: hilti at ICSI.Berkeley.EDU
Subject: Re: [HILTI] Spicy Parsing WebSockets - how to end a list
Thanks for the response. Unfortunately, the &eod doesn't work with a list, just with bytes. Because the end of the connection is simply the end of the last byte of actual data, there is no look-ahead token for the list to work. At least that is what it seems to me.
Last night I started down another path. I am trying to use a sink construct. Here is some of the code:
export type WS_Handshake_Success = unit {
success : /^(HTTP|http)/;
dvalue : DataValue;
svrheaders : list<Header> ;
end_of_hdrs : /\x0d\x0a\x0d\x0a/;
wss_data : bytes &eod &convert=terminate($$) &transient -> self.sub;
on %init {
self.sub.connect(new Sub());
}
var sub: sink;
};
export type Sub = unit {
ws_msgs : list<WS_Message>;
: DataEnd;
};
The terminate function appends a byte sequence (constant DataEnd) to the raw bytes that I can then use to identify the end of the data when parsing the messages in the Sub unit. That way the WS_Messages are properly parsed within the Sub unit.
The only piece that I'm working on now is how to put that parsed data back into the original WS_Handshake unit. Right now a "print self" statement of the WS_Handshake just lists sub=<sink>. To get the individual list items to show I need to print the sub unit.
Is there a way to make the Sub unit a part of the WS_Handshake unit?
Thank you,
Jenn
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ICSI.Berkeley.EDU/pipermail/hilti/attachments/20170727/c35009df/attachment.html
More information about the HILTI
mailing list