pycapnp - auto cast UUID to Text?

140 views
Skip to first unread message

Jon Haddad

unread,
Oct 4, 2015, 3:11:20 PM10/4/15
to Cap'n Proto
It would be convenient to be able to have UUIDs in responses auto cast to Text.  Is that possible?  It's not an enormous problem but I've noticed I've forgotten to cast it it almost every time.

Jon

Kenton Varda

unread,
Oct 6, 2015, 1:57:41 PM10/6/15
to Jon Haddad, Cap'n Proto
Hi Jon,

What format do you normally use to represent a UUID in a Cap'n Proto message? Data? List(something)? A dedicated struct type?

In order for them to "auto-cast" to text, it seems like we'd either need to add a dedicated UUID type or we'd need to devise a general way to extend the Cap'n Proto type system with hand-written types that can have arbitrary semantics. I would rather not have an explicit UUID type as it would complicated the language for something that most users don't need (e.g. Sandstorm does not use UUIDs anywhere). The latter idea -- making it possible to define a Cap'n Proto type which uses some specific hand-written wrapper in C++ or other languages -- is something I've wanted to do for a while, but it's a large-ish and complicated project and I'm not sure when I'll have time. :/

-Kenton

On Sun, Oct 4, 2015 at 12:11 PM, Jon Haddad <jonatha...@gmail.com> wrote:
It would be convenient to be able to have UUIDs in responses auto cast to Text.  Is that possible?  It's not an enormous problem but I've noticed I've forgotten to cast it it almost every time.

Jon

--
You received this message because you are subscribed to the Google Groups "Cap'n Proto" group.
To unsubscribe from this group and stop receiving emails from it, send an email to capnproto+...@googlegroups.com.
Visit this group at http://groups.google.com/group/capnproto.

Jon Haddad

unread,
Oct 6, 2015, 4:04:23 PM10/6/15
to Cap'n Proto, jonatha...@gmail.com
At the moment I just cast everything to a string.  I'd be ok with the option add a `.to_capnproto()` method on any classes I need, or something similar.  Maybe if the type isn't recognized it looks for that method?  

Would be easy to monkey patch UUID or any other type this way.  Honestly, I haven't thought it through too deeply.  The nice part about this is i could add that method to all my existing classes and just return them directly, and they could auto serialize to the struct they need to be.

There's a decent chance this is a terrible idea.  I don't know the internals well enough yet to be sure.

Jon

Jason Paryani

unread,
Oct 9, 2015, 3:33:43 PM10/9/15
to Jon Haddad, Cap'n Proto
Sorry, but which UUID are you talking about? Is this a custom field that is in your message type, or are you talking about `struct.schema.node.id`.

In either of those cases, the answer is no, there's no easy way to do automated transformations. I'd like to someday support transformations on fields through annotations, but I don't think that feature is coming anytime soon.

On Sun, Oct 4, 2015 at 12:11 PM, Jon Haddad <jonatha...@gmail.com> wrote:
It would be convenient to be able to have UUIDs in responses auto cast to Text.  Is that possible?  It's not an enormous problem but I've noticed I've forgotten to cast it it almost every time.

Jon

--

Jon Haddad

unread,
Oct 10, 2015, 11:37:21 AM10/10/15
to Cap'n Proto, jonatha...@gmail.com, jpar...@sandstorm.io
I'm referring to the built in UUID in Python.  

Reply all
Reply to author
Forward
0 new messages