After this is decoded, I want the the payload, and it'd be nice to have the 
length too but not necessary.

Described in clojure instead of prose:

(defn get-payload-from-recursive-header-frame
  [[hlenlen & raw-bytes]]
  (let [hlen (apply + (take hlenlen raw-bytes))]
    (drop hlenlen raw-bytes)))

Alternately, if I wanted to try to preserve the headers too:

(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 (drop hlenlen raw-bytes)}))


Assuming "raw-bytes" is the whole packet including the header. In fact, I 
tested the above on some sample data and confirmed it works... without gloss.

I'll bet there's a place where I could just slot in one of the above functions 
within the gloss framework and it'd work, but I have not been able to figure 
out exactly where.

-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 clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> 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 clojure+unsubscr...@googlegroups.com.
> 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 clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
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 clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to