Getting custom attributes through reflection.

93 views
Skip to first unread message

Zarian Waheed

unread,
Feb 18, 2016, 8:34:34 PM2/18/16
to FlatBuffers
Is there a way to get custom attributes defined on a field through reflection. For example can we get attribute "priority" as shown at:


I was taking a look at the reflection schema. It has table field defined as:

table Field {
    name:string (required, key);
    type:Type (required);
    id:ushort;
    offset:ushort;  // Offset into the vtable for tables, or into the struct.
    default_integer:long = 0;
    default_real:double = 0.0;
    deprecated:bool = false;
    required:bool = false;
    key:bool = false;
}

It has builtin attributes like deprecated, required etc. but I could not see anything for custom attributes. It will be helpful if we have a vector of Key/Value pair where Key is the attribute name and Value is the attribute value.

The use case I have it that I want to mark certain fields and have special processing for them whenever I encounter them using reflection.

Thanks,
Zarian.



Wouter van Oortmerssen

unread,
Feb 22, 2016, 4:48:06 PM2/22/16
to Zarian Waheed, FlatBuffers
Yes, attributes currently aren't stored in the reflection data, but I agree it would be good if they were.

Are you able to make a PR for this?

A vector of key/value pairs sounds good. They can be written using same key / sorted vector functionality as the array of Fields, etc., so they can be queried easily.

Important would be to not store any non-custom attributes, to save space, and make the attribute vector null (not present) when empty.

--
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...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Zarian Waheed

unread,
Feb 22, 2016, 9:27:52 PM2/22/16
to FlatBuffers, zarian...@gmail.com
I should be able to make a PR. We are using this at work so would I need to sign Corporate Contributor License Agreement?

Wouter van Oortmerssen

unread,
Feb 24, 2016, 4:37:13 PM2/24/16
to Zarian Waheed, FlatBuffers
I am not sure. Most everyone has signed the individual version (even if they work at a company), but I am not a lawyer :)

Wouter van Oortmerssen

unread,
Apr 13, 2016, 2:59:12 PM4/13/16
to Zarian Waheed, FlatBuffers
attributes were added to reflection data here: https://github.com/google/flatbuffers/commit/72fc45aa6acbc11052c6baa462fac26c5075392a

see test.cpp for an example.

Zarian Waheed

unread,
Apr 14, 2016, 6:26:03 PM4/14/16
to FlatBuffers, zarian...@gmail.com
Thanks. Sorry could not get around to doing it myself. Appreciate all your hard work :)
Reply all
Reply to author
Forward
0 new messages