Correction: this actually is what I'm trying to do:
(defn get-payload-from-recursive-header-frame
[[hlenlen & raw-bytes]]
(let [hlen (apply + (take hlenlen raw-bytes))]
(take hlen (drop hlenlen raw-bytes))))
Or with the headers preserved:
(defn get-payload-from-recursive-header-frame-with-intermediate
[[hlenlen & raw-bytes]]
(let [hlens (take hlenlen raw-bytes)
hlen (apply + hlens)]
{:header-length hlenlen
:segment-lengths hlens
:payload (take hlen (drop hlenlen raw-bytes))}))
Though after playing around some more it seems the gloss.core/header function
might be the place to put this.
-ken
--
--------
On Fri, Oct 10, 2014 at 10:32:59AM -0700, john walker wrote:
> What information do you want after this is decoded? Do you want the sum of
> byte0 ... byten, as well as the actual payload? Do you also want the
> header-length?
>
> On Thursday, October 9, 2014 11:34:59 PM UTC-7, Ken Restivo wrote:
> >
> > I'm playing around with Gloss, trying to decode a packet, part of which
> > has the following nested struture:
> >
> > header-length (1 byte, value n)
> > byte0 ... byten (count defined by that header-length byte)
> > actual payload (length of which is the sum of the values of the
> > above bytes)
> >
> > So instead of a fixed-size value (uint16, uint32, uint64, etc) defining
> > the size of the payload, there's a variable-length list of bytes (up to
> > 255), which has to be summed, to determine the length of the payload.
> >
> > Pretty easy to do imperatively, but I got lost in the dense forest of
> > gloss's abstractions, and couldn't figure out if it makes sense to try to
> > handle a case like this with it.
> >
> > -ken
> >
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to [email protected]
> Note that posts from new members are moderated - please be patient with your
> first post.
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.