reddmetrics/forma-clj — pull request #45 by eightysteele (2012-06-01 13:50:37+00:00)
Title: New Thrift API for creating, accessing, and unpacking Thrift objects.

This pull request rides on Sam's Thrift refactor in f4249ab9c06326acf02eb3dd47d73c16fec1e355. It basically just adds a `forma.thrift` namespace with a very simple API for creating, accessing, and unpacking our Thrift objects (defined in the `dev/forma.thrift` IDL). See docs in the `forma.thrift` namespace for usage examples. Tests are in `test/forma/thrift_test.clj`

Here's a quick overview of the API. We have functions for creating Thrift objects:

```clojure
NeighborValue*
FireValue*
ModisChunkLocation*
ModisPixelLocation*
TimeSeries*
FormaValue*
DataChunk*
```

Here's creating a `TimeSeries`:

```clojure
(TimeSeries* 0 1 [1.0 2.0 3.0])
;; #)>
```

To unpack Thrift objects, use the `unpack` function which returns a vector of Thrift object field values in the order specified in the IDL. Here's unpacking a `TimeSeries`:

```clojure
(def ts (TimeSeries* 0 1 [1.0 2.0 3.0]))
(unpack ts)
;; [0 1 #>]
```

Here's unpacking the `TimeSeries` series field:

```clojure
(unpack (get-series ts)
;; [1.0 2.0 3.0]
```

Finally, in a Cascalog query, sometimes you want to wrap the results of `unpack` in a vector. For that just use the `unpack*` function which wraps results in a vector.