On Jul 14, 5:02 pm, Torbjörn Gyllebring
<
torbjorn.gyllebr...@gmail.com> wrote:
> > No, you just parse the message until you find the length field, then
> > continue to parse the message until you get the requisite number of
> > fields. Although if a length field never comes (in a malformed or
> > malicious message), you're screwed, unless you impose a hard cap on
> > message length. However, you get the same problem here:
>
> Im way to unfamilar with the API to realize this was an "out of the
> box" option I was
> living by the assumption that nessages we're parsed and built
> completly in memory.
> If incremental building / streaming is easy then this route is
> absolutly a good one albeit maybe
> a tad hard to explain to your buddies. (Quite a funky FSM needed to
> keep track of thing I would suppose.. but, intresting).
You've actually pointed out a fatal flaw in my plan - the whole
message must be read before it's parsed. So in order for this to
work, the parser must be rewritten to support streaming. I'm
surprised it doesn't already, but hey, it gives the community
something to do. So I guess Jan will need your solution until that
happens.
> > > And simply send a stream like {meta, message, meta, message}
>
> > > That way you know that you can always read the next message by
> > > 1: read meta message
> > > 2: read meta.next_message_length bytes
> > > 3: parse message from known bytes
> > > repeat.
>
> > The meta.length field could just be really really big, making you read
> > in up to 4 gigs of data. Also, in this solution, you have to store
> > two separate messages on your server, unless you just store the
> > message, then regenerate meta every time you send it out.
>
> True. Need to take into consideration how large messages usually are.
> Actually I think the "meta" message would be more of an implementation
> detail of the
> communication channel than anything else depending on my consumer it
> might, or might not be
> needed, for a stream as talked about here it serves the role of a
> delimiter, otoh if we're sending it
> to some consumer that doesn't need it no need to keep it around.
Yup. You can do it either way - if the messages are immutable on your
end, you can store them alongside their meta, at the cost of
complexity and a bit more size, which ain't good if you have a ton of
messages. Or, you can just store the messages, and generate the meta
only when you send them out, at the cost of speed.
Also, I think I read that PB messages are designed to be small and
plentiful, but I doubt people will stick to that recommendation.