> On Thu, Mar 13, 2014 at 02:46:43PM +0900, YAMAMOTO Takashi wrote: >> > @@ -230,19 +230,24 @@ class StringifyMixin(object): >> > return cls._get_default_decoder(decode_string) >> > >> > @classmethod >> > - def _decode_value(cls, k, json_value, decode_string=base64.b64decode): >> > - return cls._get_decoder(k, decode_string)(json_value) >> > + def _decode_value(cls, k, json_value, decode_string=base64.b64decode, >> > + **additional_args): >> > + try: >> > + return cls._get_decoder(k, decode_string)(json_value) >> > + except TypeError: >> > + return cls._get_decoder(k, decode_string)(json_value, >> > + **additional_args) >> >> how about overriding ofproto_parser.StringifyMixin._decode_value >> and make it test isinstance(cls, MsgBase) instead of this try-except? > > I had a bit of trouble getting that idea to work, but I came up with > another one which seems to work. > > My idea is to create a subclass of MsgBase which overrides _decode_value() > but nothing else. Then, messages that allow messages inside them > are subclasses this new class rather than MsgBase. > > To illustrate my idea the incremental patch I have on top of the entire > series is below.
looks like a good idea to me. YAMAMOTO Takashi > > diff --git a/ryu/lib/stringify.py b/ryu/lib/stringify.py > index 4c01168..77de2b8 100644 > --- a/ryu/lib/stringify.py > +++ b/ryu/lib/stringify.py > @@ -232,11 +232,7 @@ class StringifyMixin(object): > @classmethod > def _decode_value(cls, k, json_value, decode_string=base64.b64decode, > **additional_args): > - try: > - return cls._get_decoder(k, decode_string)(json_value) > - except TypeError: > - return cls._get_decoder(k, decode_string)(json_value, > - **additional_args) > + return cls._get_decoder(k, decode_string)(json_value) > > @classmethod > def _get_default_decoder(cls, decode_string): > diff --git a/ryu/ofproto/ofproto_parser.py b/ryu/ofproto/ofproto_parser.py > index a95f9a4..8bdedfa 100644 > --- a/ryu/ofproto/ofproto_parser.py > +++ b/ryu/ofproto/ofproto_parser.py > @@ -14,6 +14,7 @@ > # See the License for the specific language governing permissions and > # limitations under the License. > > +import base64 > import collections > import logging > import struct > @@ -203,6 +204,13 @@ class MsgBase(StringifyMixin): > self._serialize_header() > > > +class MsgInMsgBase(MsgBase): > + @classmethod > + def _decode_value(cls, k, json_value, decode_string=base64.b64decode, > + **additional_args): > + return cls._get_decoder(k, decode_string)(json_value, > + **additional_args) > + > def msg_pack_into(fmt, buf, offset, *args): > if len(buf) < offset: > buf += bytearray(offset - len(buf)) > diff --git a/ryu/ofproto/ofproto_v1_4_parser.py > b/ryu/ofproto/ofproto_v1_4_parser.py > index 5e644dd..013cd9a 100644 > --- a/ryu/ofproto/ofproto_v1_4_parser.py > +++ b/ryu/ofproto/ofproto_v1_4_parser.py > @@ -20,7 +20,8 @@ import itertools > from ryu.lib import addrconv > from ryu.lib import mac > from ryu import utils > -from ofproto_parser import StringifyMixin, MsgBase, msg_pack_into, > msg_str_attr > +from ofproto_parser import (StringifyMixin, MsgBase, MsgInMsgBase, > + msg_pack_into, msg_str_attr) > from . import ether > from . import ofproto_parser > from . import ofproto_common > @@ -4481,7 +4482,7 @@ class OFPTableStatus(MsgBase): > > > @_set_msg_type(ofproto.OFPT_REQUESTFORWARD) > -class OFPRequestForward(MsgBase): > +class OFPRequestForward(MsgInMsgBase): > """ > Forwarded request message > > @@ -5901,7 +5902,7 @@ class OFPBundleCtrlMsg(MsgBase): > > > @_set_msg_type(ofproto.OFPT_BUNDLE_ADD_MESSAGE) > -class OFPBundleAddMsg(MsgBase): > +class OFPBundleAddMsg(MsgInMsgBase): > """ > Bundle control message > > > ------------------------------------------------------------------------------ > Learn Graph Databases - Download FREE O'Reilly Book > "Graph Databases" is the definitive new guide to graph databases and their > applications. Written by three acclaimed leaders in the field, > this first edition is now available. Download your free book today! > http://p.sf.net/sfu/13534_NeoTech > _______________________________________________ > Ryu-devel mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/ryu-devel ------------------------------------------------------------------------------ Learn Graph Databases - Download FREE O'Reilly Book "Graph Databases" is the definitive new guide to graph databases and their applications. Written by three acclaimed leaders in the field, this first edition is now available. Download your free book today! http://p.sf.net/sfu/13534_NeoTech _______________________________________________ Ryu-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ryu-devel
