[cl-json-devel] Guidance requested: how to dispatch members to external decoders?
Hraban Luyat
hraban at 0brg.net
Sun Aug 14 12:24:02 UTC 2011
Hello,
As far as I understand the decoder API it is mostly geared towards
defining the decoder for an entire snippet in one place. I would like
to know what the recommended way is to separate the definition of the
decoder over separate modules.
The semantics of my incoming messages are thus:
object:
- "type": string denoting the type
- "payload": type-specific payload
I want to create a decoder that only extracts the type and uses that
to determine which decoder to send the payload to. Then it continues
with whatever lisp object the decoder returned.
What I thought would be appropriate is to create a generic function;
(defgeneric json->data (type payload))
and then simply register decoders as follows:
(defmethod json->data ((type (eq :foo)) payload)
"Decode message of type foo."
...)
(defmethod json->data ((type (eq :bar)) payload)
"Decode message of type bar."
...)
But now I am not really sure how to glue this together. What would you
recommend? Is this the right frame of mind at all or should I take a
totally different approach?
Thanks!
Hraban
More information about the cl-json-devel
mailing list