Named stats

10 views
Skip to first unread message

Brian Corrigan

unread,
Aug 24, 2016, 9:05:59 PM8/24/16
to FlatBuffers
Hey Team - 

I have an API where I'd like to accept an arbitrary list of metric values, where the key is always a name, and the value is Any of the supported types.  Imagine a list of events, but in Flatbuffers.

````JSON
{
  timestamp: 1472086911,
  events: [
    { name: "count", value: 12 },
    { name: "activity_type", value: "walking" }
  ]
}
````

You get the idea.. Basically an event is always a name (string), value (Any), and value_type.

What's a good strategy to have a table where the rows contain a column with a run-time type.  I think there's some trick to using Unions here that is not immediately apparent to me.  Would I do this:

union Event { IntEvent, StringEvent, DoubleEvent }

And that sorta thing?


Wouter van Oortmerssen

unread,
Aug 24, 2016, 9:12:42 PM8/24/16
to Brian Corrigan, FlatBuffers
Yes, unions is what you want. To put them in a vector, you have to wrap the union in a table though.

Alternatively, if the amount of event types is limited or really simple, you can also consider sticking all possible event data in a single table (with an enum value if needed) and simply omitting data that is not relevant for the current event.

--
You received this message because you are subscribed to the Google Groups "FlatBuffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flatbuffers+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages