Merge branch 'master' into funnel

Conflicts:
	java_gen/java_type.py
	java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/U16.java
	java_gen/templates/of_factory_interface.java
diff --git a/java_gen/java_model.py b/java_gen/java_model.py
index 2963f2d..19ac5bc 100644
--- a/java_gen/java_model.py
+++ b/java_gen/java_model.py
@@ -893,9 +893,9 @@
     @property
     def priv_value(self):
         if self.name == "version":
-            return self.msg.version.int_version
+            return self.java_type.format_value(self.msg.version.int_version, pub_type=False)
         elif self.name == "length" or self.name == "len":
-            return self.msg.length
+            return self.java_type.format_value(self.msg.length, pub_type=False)
         else:
             return self.java_type.format_value(self.member.value, pub_type=False)
 
diff --git a/java_gen/java_type.py b/java_gen/java_type.py
index 6de71ba..907e8c8 100644
--- a/java_gen/java_type.py
+++ b/java_gen/java_type.py
@@ -38,12 +38,12 @@
 ### info table about java primitive types, for casting literals in the source code
 # { name : (signed?, length_in_bits) }
 java_primitives_info = {
-        'boolean' : (False, 8),
-        'byte' : (True, 8),
-        'char' : (False, 16),
-        'short' : (True, 16),
-        'int' : (True, 32),
-        'long' : (True, 64),
+        'boolean' : (False, 8, False),
+        'byte' : (True, 8, True),
+        'char' : (False, 16, True),
+        'short' : (True, 16, True),
+        'int' : (True, 32, False),
+        'long' : (True, 64, False),
 }
 
 def format_primitive_literal(t, value):
@@ -52,7 +52,7 @@
         appropriately for correct representation despite Java's
         signed-craziness
     """
-    signed, bits = java_primitives_info[t]
+    signed, bits, cast_needed = java_primitives_info[t]
     max = (1 << bits)-1
     if value > max:
         raise Exception("Value %d to large for type %s" % (value, t))
@@ -65,20 +65,21 @@
                 return str((1 << bits) - value)
             else:
                 return "(%s) 0x%x" % (t, value)
-        else:
-            return "0x%x%s" % (value, "L" if t=="long" else "")
+    return "%s0x%x%s" % ("(%s) " % t if cast_needed else "", value, "L" if t=="long" else "")
+
 
 ANY = 0xFFFFFFFFFFFFFFFF
 
 class VersionOp:
-    def __init__(self, version=ANY, read=None, write=None, default=None):
+    def __init__(self, version=ANY, read=None, write=None, default=None, funnel=None):
         self.version = version
         self.read = read
         self.write = write
         self.default = default
+        self.funnel = funnel
 
     def __str__(self):
-        return "[Version: %d, Read: '%s', Write: '%s', Default: '%s' ]" % (self.version, self.read, self.write, self.default )
+        return "[Version: %d, Read: '%s', Write: '%s', Default: '%s', Funnel: '%s' ]" % (self.version, self.read, self.write, self.default, self.funnel )
 
 ### FIXME: This class should really be cleaned up
 class JType(object):
@@ -94,7 +95,11 @@
         self.priv_type = priv_type  # the internal storage type
         self.ops = {}
 
-    def op(self, version=ANY, read=None, write=None, default=None, pub_type=ANY):
+    def set_priv_type(self, priv_type):
+        self.priv_type = priv_type
+        return self
+
+    def op(self, version=ANY, read=None, write=None, default=None, funnel=None, pub_type=ANY):
         """
         define operations to be performed for reading and writing this type
         (when read_op, write_op is called). The operations 'read' and 'write'
@@ -110,7 +115,7 @@
 
         pub_types = [ pub_type ] if pub_type is not ANY else [ False, True ]
         for pub_type in pub_types:
-            self.ops[(version, pub_type)] = VersionOp(version, read, write, default)
+            self.ops[(version, pub_type)] = VersionOp(version, read, write, default, funnel)
         return self
 
     def format_value(self, value, pub_type=True):
@@ -136,6 +141,24 @@
         """ Is the private type different from the public one?"""
         return self.pub_type != self.priv_type
 
+    def get_op(self, op_type, version, pub_type, default_value, arguments):
+        ver = ANY if version is None else version.int_version
+
+        if not "version" in arguments:
+            arguments["version"] = version.of_version
+
+        def lookup(ver, pub_type):
+            if (ver, pub_type) in self.ops:
+                return getattr(self.ops[(ver, pub_type)], op_type)
+            else:
+                return None
+
+        _op = lookup(ver, pub_type) or lookup(ANY, pub_type) or default_value
+        if callable(_op):
+            return _op(**arguments)
+        else:
+            return reduce(lambda a,repl: a.replace("$%s" % repl[0], str(repl[1])),  arguments.items(), _op)
+
     def read_op(self, version=None, length=None, pub_type=True):
         """ return a Java stanza that reads a value of this JType from ChannelBuffer bb.
         @param version int - OF wire version to generate expression for
@@ -149,20 +172,12 @@
              # assumes that
              # (1) length of the message has been read to 'length'
              # (2) readerIndex at the start of the message has been stored in 'start'
-            length = "length - (bb.readerIndex() - start)";
+            length = "length - (bb.readerIndex() - start)"
 
-        ver = ANY if version is None else version.int_version
-        _read_op = None
-        if (ver, pub_type) in self.ops:
-            _read_op = self.ops[(ver, pub_type)].read or self.ops[(ANY, pub_type)].read
-        elif (ANY, pub_type) in self.ops:
-            _read_op = self.ops[(ANY, pub_type)].read
-        if _read_op is None:
-            _read_op = 'ChannelUtilsVer$version.read%s(bb)' % self.pub_type
-        if callable(_read_op):
-            return _read_op(version)
-        else:
-            return _read_op.replace("$length", str(length)).replace("$version", version.of_version)
+        return self.get_op("read", version, pub_type,
+            default_value='ChannelUtilsVer$version.read%s(bb)' % self.pub_type,
+            arguments=dict(length=length)
+            )
 
     def write_op(self, version=None, name=None, pub_type=True):
         """ return a Java stanza that writes a value of this JType contained in Java expression
@@ -172,37 +187,22 @@
         @param pub_type boolean use this JTypes 'public' (True), or private (False) representation
         @return string containing generated Java expression.
         """
-        ver = ANY if version is None else version.int_version
-        _write_op = None
-        if (ver, pub_type) in self.ops:
-            _write_op = self.ops[(ver, pub_type)].write or self.ops[(ANY, pub_type)].write
-        elif (ANY, pub_type) in self.ops:
-            _write_op = self.ops[(ANY, pub_type)].write
-        if _write_op is None:
 
-            _write_op = 'ChannelUtilsVer$version.write%s(bb, $name)' % self.pub_type
-        if callable(_write_op):
-            return _write_op(version, name)
-        else:
-            return _write_op.replace("$name", str(name)).replace("$version", version.of_version)
+        return self.get_op("write", version, pub_type,
+            default_value='ChannelUtilsVer$version.write%s(bb, $name)' % self.pub_type,
+            arguments=dict(name=name)
+            )
+
 
     def default_op(self, version=None, pub_type=True):
         """ return a Java stanza that returns a default value of this JType.
         @param version JavaOFVersion
         @return string containing generated Java expression.
         """
-        ver = ANY if version is None else version.int_version
-        _default_op = None
-        if (ver, pub_type) in self.ops:
-            _default_op = self.ops[(ver, pub_type)].default or self.ops[(ANY, pub_type)].default
-        elif (ANY, pub_type) in self.ops:
-            _default_op = self.ops[(ANY, pub_type)].default
-        if _default_op is None:
-            _default_op = self.format_value(0) if self.is_primitive else "null"
-        if callable(_default_op):
-            return _default_op(version, name)
-        else:
-            return _default_op.replace("$version", version.of_version)
+        return self.get_op("default", version, pub_type,
+            arguments = dict(),
+            default_value = self.format_value(0) if self.is_primitive else "null"
+        )
 
     def skip_op(self, version=None, length=None):
         """ return a java stanza that skips an instance of JType in the input ChannelBuffer 'bb'.
@@ -211,18 +211,68 @@
             Currently just delegates to read_op + throws away the result."""
         return self.read_op(version, length)
 
+    def funnel_op(self, version=None, name=None, pub_type=True):
+        t = self.pub_type if pub_type else self.priv_type
+        return self.get_op("funnel", version, pub_type,
+            arguments = dict(name=name),
+            default_value =  '$name.putTo(sink)' if not self._is_primitive(pub_type) else "sink.put{}($name)".format(t[0].upper() + t[1:])
+        )
+
     @property
     def is_primitive(self):
+        return self._is_primitive()
+
+    def _is_primitive(self, pub_type=True):
         """ return true if the pub_type is a java primitive type (and thus needs
         special treatment, because it doesn't have methods)"""
-        return self.pub_type in java_primitive_types
+        t = self.pub_type if pub_type else self.priv_type
+        return t in java_primitive_types
 
     @property
     def is_array(self):
-        """ return true iff the pub_type is a Java array (and thus requires special
-        treatment for equals / toString etc.) """
-        return self.pub_type.endswith("[]")
+        return self._is_array()
 
+    def _is_array(self, pub_type=True):
+        t = self.pub_type if pub_type else self.priv_type
+        return t.endswith("[]")
+
+# Create a default mapping for a list type. Type defauls to List<${java_mapping_of_name}>
+def gen_enum_jtype(java_name, is_bitmask=False):
+    if is_bitmask:
+        java_type = "Set<{}>".format(java_name)
+        default_value = "ImmutableSet.<{}>of()".format(java_name)
+    else:
+        java_type = java_name
+        default_value = "null"
+
+    serializer = "{}SerializerVer$version".format(java_name)
+
+    return JType(java_type)\
+            .op(read="{}.readFrom(bb)".format(serializer),
+                write="{}.writeTo(bb, $name)".format(serializer),
+                default=default_value,
+                funnel="{}.putTo($name, sink)".format(serializer)
+               )
+
+def gen_list_jtype(java_base_name):
+    # read op assumes the class has a public final static field READER that implements
+    # OFMessageReader<$class> i.e., can deserialize an instance of class from a ChannelBuffer
+    # write op assumes class implements Writeable
+    return JType("List<{}>".format(java_base_name)) \
+        .op(
+            read= 'ChannelUtils.readList(bb, $length, {}Ver$version.READER)'.format(java_base_name), \
+            write='ChannelUtils.writeList(bb, $name)',
+            default="ImmutableList.<{}>of()".format(java_base_name),
+            funnel='FunnelUtils.putList($name, sink)'
+            )
+
+def gen_fixed_length_string_jtype(length):
+    return JType('String').op(
+              read='ChannelUtils.readFixedLengthString(bb, {})'.format(length),
+              write='ChannelUtils.writeFixedLengthString(bb, $name, {})'.format(length),
+              default='""',
+              funnel='sink.putUnencodedChars($name)'
+            )
 
 ##### Predefined JType mappings
 # FIXME: This list needs to be pruned / cleaned up. Most of these are schematic.
@@ -231,7 +281,11 @@
         .op(read='U8.f(bb.readByte())', write='bb.writeByte(U8.t($name))', pub_type=True) \
         .op(read='bb.readByte()', write='bb.writeByte($name)', pub_type=False)
 u8_list =  JType('List<U8>') \
-        .op(read='ChannelUtils.readList(bb, $length, U8.READER)', write='ChannelUtils.writeList(bb, $name)')
+        .op(read='ChannelUtils.readList(bb, $length, U8.READER)',
+            write='ChannelUtils.writeList(bb, $name)',
+            default='ImmutableList.<U8>of()',
+            funnel='FunnelUtils.putList($name, sink)'
+           )
 u16 = JType('int', 'short') \
         .op(read='U16.f(bb.readShort())', write='bb.writeShort(U16.t($name))', pub_type=True) \
         .op(read='bb.readShort()', write='bb.writeShort($name)', pub_type=False)
@@ -242,7 +296,8 @@
         .op(
                 read='ChannelUtils.readList(bb, $length, U32.READER)',
                 write='ChannelUtils.writeList(bb, $name)',
-                default="ImmutableList.<U32>of()");
+                default="ImmutableList.<U32>of()",
+                funnel="FunnelUtils.putList($name, sink)")
 u8obj = JType('U8', 'U8') \
         .op(read='U8.of(bb.readByte())', write='bb.writeByte($name.getRaw())', default="U8.ZERO")
 u32obj = JType('U32', 'U32') \
@@ -255,33 +310,20 @@
 # the same OFPort, but with a default value of ZERO, only for OF10 match
 of_port_match_v1 = JType("OFPort") \
          .op(version=1, read="OFPort.read2Bytes(bb)", write="$name.write2Bytes(bb)", default="OFPort.ZERO")
-actions_list = JType('List<OFAction>') \
-        .op(read='ChannelUtils.readList(bb, $length, OFActionVer$version.READER)',
-            write='ChannelUtils.writeList(bb, $name);',
-            default='ImmutableList.<OFAction>of()')
-instructions_list = JType('List<OFInstruction>') \
-        .op(read='ChannelUtils.readList(bb, $length, OFInstructionVer$version.READER)', \
-            write='ChannelUtils.writeList(bb, $name)',
-            default='ImmutableList.<OFInstruction>of()')
-buckets_list = JType('List<OFBucket>') \
-        .op(read='ChannelUtils.readList(bb, $length, OFBucketVer$version.READER)',
-            write='ChannelUtils.writeList(bb, $name)',
-            default='ImmutableList.<OFBucket>of()')
-port_desc_list = JType('List<OFPortDesc>') \
-        .op(read='ChannelUtils.readList(bb, $length, OFPortDescVer$version.READER)',
-            write='ChannelUtils.writeList(bb, $name)',
-            default='ImmutableList.<OFPortDesc>of()')
+actions_list = gen_list_jtype("OFAction")
+instructions_list = gen_list_jtype("OFInstruction")
+buckets_list = gen_list_jtype("OFBucket")
+port_desc_list = gen_list_jtype("OFPortDesc")
+packet_queue_list = gen_list_jtype("OFPacketQueue")
 port_desc = JType('OFPortDesc') \
         .op(read='OFPortDescVer$version.READER.readFrom(bb)', \
             write='$name.writeTo(bb)')
-packet_queue_list = JType('List<OFPacketQueue>') \
-        .op(read='ChannelUtils.readList(bb, $length, OFPacketQueueVer$version.READER)',
-            write='ChannelUtils.writeList(bb, $name);',
-            default='ImmutableList.<OFPacketQueue>of()')
-octets = JType('byte[]') \
+octets = JType('byte[]')\
         .op(read='ChannelUtils.readBytes(bb, $length)', \
             write='bb.writeBytes($name)', \
-            default="new byte[0]");
+            default="new byte[0]",
+            funnel="sink.putBytes($name)"
+            );
 of_match = JType('Match') \
         .op(read='ChannelUtilsVer$version.readOFMatch(bb)', \
             write='$name.writeTo(bb)',
@@ -293,22 +335,11 @@
         .op(read="MacAddress.read6Bytes(bb)", \
             write="$name.write6Bytes(bb)",
             default="MacAddress.NONE")
-port_name = JType('String') \
-        .op(read='ChannelUtils.readFixedLengthString(bb, 16)', \
-            write='ChannelUtils.writeFixedLengthString(bb, $name, 16)',
-            default='""')
-desc_str = JType('String') \
-        .op(read='ChannelUtils.readFixedLengthString(bb, 256)', \
-            write='ChannelUtils.writeFixedLengthString(bb, $name, 256)',
-            default='""')
-serial_num = JType('String') \
-        .op(read='ChannelUtils.readFixedLengthString(bb, 32)', \
-            write='ChannelUtils.writeFixedLengthString(bb, $name, 32)',
-            default='""')
-table_name = JType('String') \
-        .op(read='ChannelUtils.readFixedLengthString(bb, 32)', \
-            write='ChannelUtils.writeFixedLengthString(bb, $name, 32)',
-            default='""')
+
+port_name = gen_fixed_length_string_jtype(16)
+desc_str = gen_fixed_length_string_jtype(256)
+serial_num = gen_fixed_length_string_jtype(32)
+table_name = gen_fixed_length_string_jtype(32)
 ipv4 = JType("IPv4Address") \
         .op(read="IPv4Address.read4Bytes(bb)", \
             write="$name.write4Bytes(bb)",
@@ -317,9 +348,7 @@
         .op(read="IPv6Address.read16Bytes(bb)", \
             write="$name.write16Bytes(bb)",
             default='IPv6Address.NONE')
-packetin_reason = JType("OFPacketInReason")\
-        .op(read="OFPacketInReasonSerializerVer$version.readFrom(bb)",
-            write="OFPacketInReasonSerializerVer$version.writeTo(bb, $name)")
+packetin_reason = gen_enum_jtype("OFPacketInReason")
 transport_port = JType("TransportPort")\
         .op(read="TransportPort.read2Bytes(bb)",
             write="$name.write2Bytes(bb)",
@@ -403,6 +432,16 @@
 
 port_speed = JType("PortSpeed")
 error_type = JType("OFErrorType")
+of_type = JType("OFType", 'byte') \
+            .op(read='bb.readByte()', write='bb.writeByte($name)')
+action_type= gen_enum_jtype("OFActionType")\
+               .set_priv_type("short")\
+               .op(read='bb.readShort()', write='bb.writeShort($name)', pub_type=False)
+instruction_type = gen_enum_jtype("OFInstructionType")\
+               .set_priv_type('short') \
+               .op(read='bb.readShort()', write='bb.writeShort($name)', pub_type=False)
+buffer_id = JType("OFBufferId") \
+            .op(read="OFBufferId.of(bb.readInt())", write="bb.writeInt($name.getInt())", default="OFBufferId.NO_BUFFER")
 boolean = JType("boolean", "byte") \
         .op(read='(bb.readByte() != 0)',
             write='bb.writeByte($name ? 1 : 0)',
@@ -411,6 +450,11 @@
         .op(read='DatapathId.of(bb.readLong())',
             write='bb.writeLong($name.getLong())',
             default='DatapathId.NONE')
+action_type_set = JType("Set<OFActionType>") \
+        .op(read='ChannelUtilsVer10.readSupportedActions(bb)',
+            write='ChannelUtilsVer10.writeSupportedActions(bb, $name)',
+            default='ImmutableSet.<OFActionType>of()',
+            funnel='ChannelUtilsVer10.putSupportedActionsTo($name, sink)')
 
 generic_t = JType("T")
 
@@ -497,7 +541,7 @@
         'of_oxm_mpls_label_masked' : { 'value' : u32obj, 'value_mask' : u32obj },
         'of_oxm_mpls_tc' : { 'value' : u8obj },
         'of_oxm_mpls_tc_masked' : { 'value' : u8obj, 'value_mask' : u8obj },
-        
+
         'of_oxm_bsn_in_ports_128' : { 'value': port_bitmap },
         'of_oxm_bsn_in_ports_128_masked' : { 'value': port_bitmap, 'value_mask': port_bitmap },
 
@@ -519,41 +563,20 @@
     for protocol in of_g.ir.values():
         for enum in protocol.enums:
             java_name = name_c_to_caps_camel(re.sub(r'_t$', "", enum.name))
-            if enum.is_bitmask:
-                java_type = "Set<{}>".format(java_name)
-                default_value = "ImmutableSet.<{}>of()".format(java_name)
-            else:
-                java_type = java_name
-                default_value = "null"
-            enum_types[enum.name] = \
-                    JType(java_type)\
-                      .op(read="{}SerializerVer$version.readFrom(bb)".format(java_name),
-                          write="{}SerializerVer$version.writeTo(bb, $name)".format(java_name),
-                          default=default_value)
+
+            enum_types[enum.name] = gen_enum_jtype(java_name, enum.is_bitmask)
     return enum_types
 
 def make_match_field_jtype(sub_type_name="?"):
     return JType("MatchField<{}>".format(sub_type_name))
 
 
-# Create a default mapping for a list type. Type defauls to List<${java_mapping_of_name}>
-def make_standard_list_jtype(c_type):
+def list_cname_to_java_name(c_type):
     m = re.match(r'list\(of_([a-zA-Z_]+)_t\)', c_type)
     if not m:
         raise Exception("Not a recgonized standard list type declaration: %s" % c_type)
     base_name = m.group(1)
-    java_base_name = name_c_to_caps_camel(base_name)
-
-    # read op assumes the class has a public final static field READER that implements
-    # OFMessageReader<$class> i.e., can deserialize an instance of class from a ChannelBuffer
-    # write op assumes class implements Writeable
-    return JType("List<OF{}>".format(java_base_name)) \
-        .op(
-            read= 'ChannelUtils.readList(bb, $length, OF{}Ver$version.READER)'.format(java_base_name), \
-            write='ChannelUtils.writeList(bb, $name)',
-            default="ImmutableList.<OF{}>of()".format(java_base_name)
-            )
-
+    return "OF" + name_c_to_caps_camel(base_name)
 
 
 #### main entry point for conversion of LOXI types (c_types) Java types.
@@ -565,12 +588,9 @@
     if obj_name in exceptions and field_name in exceptions[obj_name]:
         return exceptions[obj_name][field_name]
     elif ( obj_name == "of_header" or loxi_utils.class_is_message(obj_name)) and field_name == "type" and c_type == "uint8_t":
-        return JType("OFType", 'byte') \
-            .op(read='bb.readByte()', write='bb.writeByte($name)')
+        return of_type
     elif field_name == "type" and re.match(r'of_action.*', obj_name):
-        return JType("OFActionType", 'short') \
-            .op(read='bb.readShort()', write='bb.writeShort($name)', pub_type=False)\
-            .op(read="OFActionTypeSerializerVer$version.readFrom(bb)", write="OFActionTypeSerializerVer$version.writeTo(bb, $name)", pub_type=True)
+        return action_type
     elif field_name == "err_type":
         return JType("OFErrorType", 'short') \
             .op(read='bb.readShort()', write='bb.writeShort($name)')
@@ -578,9 +598,7 @@
         return JType("OFStatsType", 'short') \
             .op(read='bb.readShort()', write='bb.writeShort($name)')
     elif field_name == "type" and re.match(r'of_instruction.*', obj_name):
-        return JType("OFInstructionType", 'short') \
-            .op(read='bb.readShort()', write='bb.writeShort($name)', pub_type=False)\
-            .op(read="OFInstructionTypeSerializerVer$version.readFrom(bb)", write="OFInstructionTypeSerializerVer$version.writeTo(bb, $name)", pub_type=True)
+        return instruction_type
     elif obj_name in ("of_flow_add", "of_flow_modify", "of_flow_modify_strict", "of_delete_strict") and  field_name == "table_id" and c_type == "uint8_t":
         return table_id_default_zero
     elif field_name == "table_id" and c_type == "uint8_t":
@@ -588,19 +606,15 @@
     elif field_name == "version" and c_type == "uint8_t":
         return of_version
     elif field_name == "buffer_id" and c_type == "uint32_t":
-        return JType("OFBufferId") \
-            .op(read="OFBufferId.of(bb.readInt())", write="bb.writeInt($name.getInt())", default="OFBufferId.NO_BUFFER")
+        return buffer_id
     elif field_name == 'datapath_id':
         return datapath_id
     elif field_name == 'actions' and obj_name == 'of_features_reply':
-        return JType("Set<OFActionType>") \
-            .op(read='ChannelUtilsVer10.readSupportedActions(bb)',
-                write='ChannelUtilsVer10.writeSupportedActions(bb, $name)',
-                default='ImmutableSet.<OFActionType>of()')
+        return action_type_set
     elif c_type in default_mtype_to_jtype_convert_map:
         return default_mtype_to_jtype_convert_map[c_type]
     elif re.match(r'list\(of_([a-zA-Z_]+)_t\)', c_type):
-        return make_standard_list_jtype(c_type)
+        return gen_list_jtype(list_cname_to_java_name(c_type))
     elif c_type in enum_java_types():
         return enum_java_types()[c_type]
     else:
diff --git a/java_gen/pre-written/pom.xml b/java_gen/pre-written/pom.xml
index ea9a43f..17f14ab 100644
--- a/java_gen/pre-written/pom.xml
+++ b/java_gen/pre-written/pom.xml
@@ -53,7 +53,7 @@
         <dependency>
             <groupId>com.google.guava</groupId>
             <artifactId>guava</artifactId>
-            <version>14.0.1</version>
+            <version>15.0</version>
         </dependency>
     </dependencies>
     <build>
diff --git a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/protocol/OFMatchBmap.java b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/protocol/OFMatchBmap.java
index e17796a..68ca86d 100644
--- a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/protocol/OFMatchBmap.java
+++ b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/protocol/OFMatchBmap.java
@@ -1,5 +1,13 @@
 package org.projectfloodlight.openflow.protocol;
 
-public class OFMatchBmap {
+import org.projectfloodlight.openflow.types.PrimitiveSinkable;
+
+import com.google.common.hash.PrimitiveSink;
+
+public class OFMatchBmap implements PrimitiveSinkable{
+
+    @Override
+    public void putTo(PrimitiveSink sink) {
+    }
 
 }
diff --git a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/protocol/OFObject.java b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/protocol/OFObject.java
index 852b803..5d37987 100644
--- a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/protocol/OFObject.java
+++ b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/protocol/OFObject.java
@@ -1,9 +1,11 @@
 package org.projectfloodlight.openflow.protocol;
 
+import org.projectfloodlight.openflow.types.PrimitiveSinkable;
+
 
 /**
  * Base interface of all OpenFlow objects (e.g., messages, actions, stats, etc.)
  */
-public interface OFObject extends Writeable {
+public interface OFObject extends Writeable, PrimitiveSinkable {
     OFVersion getVersion();
 }
diff --git a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/protocol/OFOxmList.java b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/protocol/OFOxmList.java
index ac48c8d..c6ba116 100644
--- a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/protocol/OFOxmList.java
+++ b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/protocol/OFOxmList.java
@@ -9,13 +9,15 @@
 import org.projectfloodlight.openflow.exceptions.OFParseError;
 import org.projectfloodlight.openflow.protocol.match.MatchField;
 import org.projectfloodlight.openflow.protocol.match.MatchFields;
-import org.projectfloodlight.openflow.types.OFValueType;
-import org.projectfloodlight.openflow.util.ChannelUtils;
 import org.projectfloodlight.openflow.protocol.oxm.OFOxm;
+import org.projectfloodlight.openflow.types.OFValueType;
+import org.projectfloodlight.openflow.types.PrimitiveSinkable;
+import org.projectfloodlight.openflow.util.ChannelUtils;
 
 import com.google.common.collect.ImmutableMap;
+import com.google.common.hash.PrimitiveSink;
 
-public class OFOxmList implements Iterable<OFOxm<?>>, Writeable {
+public class OFOxmList implements Iterable<OFOxm<?>>, Writeable, PrimitiveSinkable {
     private final Map<MatchFields, OFOxm<?>> oxmMap;
 
     public final static OFOxmList EMPTY = new OFOxmList(ImmutableMap.<MatchFields, OFOxm<?>>of());
@@ -124,5 +126,12 @@
         return "OFOxmList" + oxmMap;
     }
 
+    @Override
+    public void putTo(PrimitiveSink sink) {
+        for (OFOxm<?> o : this) {
+            o.putTo(sink);
+        }
+    }
+
 
 }
diff --git a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/protocol/ver10/ChannelUtilsVer10.java b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/protocol/ver10/ChannelUtilsVer10.java
index 3f2f23f..ed7c0c8 100644
--- a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/protocol/ver10/ChannelUtilsVer10.java
+++ b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/protocol/ver10/ChannelUtilsVer10.java
@@ -5,10 +5,11 @@
 
 import org.jboss.netty.buffer.ChannelBuffer;
 import org.projectfloodlight.openflow.exceptions.OFParseError;
-import org.projectfloodlight.openflow.protocol.match.Match;
-import org.projectfloodlight.openflow.protocol.ver10.OFMatchV1Ver10;
 import org.projectfloodlight.openflow.protocol.OFActionType;
 import org.projectfloodlight.openflow.protocol.OFBsnVportQInQ;
+import org.projectfloodlight.openflow.protocol.match.Match;
+
+import com.google.common.hash.PrimitiveSink;
 
 /**
  * Collection of helper functions for reading and writing into ChannelBuffers
@@ -62,8 +63,7 @@
         return supportedActions;
     }
 
-    public static void writeSupportedActions(ChannelBuffer bb,
-            Set<OFActionType> supportedActions) {
+    public static int supportedActionsToWire(Set<OFActionType> supportedActions) {
         int supportedActionsVal = 0;
         if (supportedActions.contains(OFActionType.OUTPUT))
             supportedActionsVal |= (1 << OFActionTypeSerializerVer10.OUTPUT_VAL);
@@ -89,6 +89,15 @@
             supportedActionsVal |= (1 << OFActionTypeSerializerVer10.SET_TP_DST_VAL);
         if (supportedActions.contains(OFActionType.ENQUEUE))
             supportedActionsVal |= (1 << OFActionTypeSerializerVer10.ENQUEUE_VAL);
-        bb.writeInt(supportedActionsVal);
+        return supportedActionsVal;
     }
+
+    public static void putSupportedActionsTo(Set<OFActionType> supportedActions, PrimitiveSink sink) {
+        sink.putInt(supportedActionsToWire(supportedActions));
+    }
+
+    public static void writeSupportedActions(ChannelBuffer bb, Set<OFActionType> supportedActions) {
+        bb.writeInt(supportedActionsToWire(supportedActions));
+    }
+
 }
diff --git a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/ArpOpcode.java b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/ArpOpcode.java
index 2a33a0e..88e5fe9 100644
--- a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/ArpOpcode.java
+++ b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/ArpOpcode.java
@@ -2,6 +2,7 @@
 
 import org.jboss.netty.buffer.ChannelBuffer;
 
+import com.google.common.hash.PrimitiveSink;
 import com.google.common.primitives.UnsignedInts;
 
 public class ArpOpcode implements OFValueType<ArpOpcode> {
@@ -189,4 +190,9 @@
         return UnsignedInts.compare(opcode, o.opcode);
     }
 
+    @Override
+    public void putTo(PrimitiveSink sink) {
+        sink.putShort((short) this.opcode);
+    }
+
 }
\ No newline at end of file
diff --git a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/ClassId.java b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/ClassId.java
index a6f2106..72ed3da 100644
--- a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/ClassId.java
+++ b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/ClassId.java
@@ -2,6 +2,7 @@
 
 import javax.annotation.concurrent.Immutable;
 
+import com.google.common.hash.PrimitiveSink;
 import com.google.common.primitives.UnsignedInts;
 
 @Immutable
@@ -68,4 +69,9 @@
     public int compareTo(ClassId o) {
         return UnsignedInts.compare(rawValue, rawValue);
     }
+
+    @Override
+    public void putTo(PrimitiveSink sink) {
+        sink.putInt(rawValue);
+    }
 }
diff --git a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/DatapathId.java b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/DatapathId.java
index aa7191a..4d64f83 100644
--- a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/DatapathId.java
+++ b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/DatapathId.java
@@ -2,13 +2,15 @@
 
 import org.projectfloodlight.openflow.util.HexString;
 
+import com.google.common.hash.PrimitiveSink;
+
 /**
  * Abstraction of a datapath ID that can be set and/or accessed as either a
  * long value or a colon-separated string.
- * 
+ *
  * @author Rob Vaterlaus <rob.vaterlaus@bigswitch.com>
  */
-public class DatapathId {
+public class DatapathId implements PrimitiveSinkable {
 
     public static final DatapathId NONE = new DatapathId(0);
 
@@ -60,4 +62,9 @@
             return false;
         return true;
     }
+
+    @Override
+    public void putTo(PrimitiveSink sink) {
+        sink.putLong(rawValue);
+    }
 }
diff --git a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/EthType.java b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/EthType.java
index 7031a0d..c5f4f86 100644
--- a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/EthType.java
+++ b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/EthType.java
@@ -2,6 +2,7 @@
 
 import org.jboss.netty.buffer.ChannelBuffer;
 
+import com.google.common.hash.PrimitiveSink;
 import com.google.common.primitives.UnsignedInts;
 
 
@@ -260,5 +261,10 @@
         return UnsignedInts.compare(rawValue, o.rawValue);
     }
 
+    @Override
+    public void putTo(PrimitiveSink sink) {
+        sink.putInt(rawValue);
+    }
+
 
 }
diff --git a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/ICMPv4Code.java b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/ICMPv4Code.java
index c66486f..6466eee 100644
--- a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/ICMPv4Code.java
+++ b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/ICMPv4Code.java
@@ -2,6 +2,7 @@
 
 import org.jboss.netty.buffer.ChannelBuffer;
 
+import com.google.common.hash.PrimitiveSink;
 import com.google.common.primitives.Shorts;
 
 /**
@@ -84,4 +85,9 @@
     public int compareTo(ICMPv4Code o) {
         return Shorts.compare(code, o.code);
     }
+
+    @Override
+    public void putTo(PrimitiveSink sink) {
+        sink.putShort(code);
+    }
 }
diff --git a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/ICMPv4Type.java b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/ICMPv4Type.java
index 594aaec..9768aee 100644
--- a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/ICMPv4Type.java
+++ b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/ICMPv4Type.java
@@ -2,6 +2,7 @@
 
 import org.jboss.netty.buffer.ChannelBuffer;
 
+import com.google.common.hash.PrimitiveSink;
 import com.google.common.primitives.Shorts;
 
 public class ICMPv4Type implements OFValueType<ICMPv4Type> {
@@ -193,4 +194,10 @@
     public int compareTo(ICMPv4Type o) {
         return Shorts.compare(type, o.type);
     }
+
+    @Override
+    public void putTo(PrimitiveSink sink) {
+        sink.putShort(type);
+    }
+
 }
diff --git a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IPv4Address.java b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IPv4Address.java
index 77b792f..51d10f3 100644
--- a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IPv4Address.java
+++ b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IPv4Address.java
@@ -4,6 +4,7 @@
 
 import org.jboss.netty.buffer.ChannelBuffer;
 
+import com.google.common.hash.PrimitiveSink;
 import com.google.common.primitives.UnsignedInts;
 
 
@@ -152,4 +153,10 @@
     public int compareTo(IPv4Address o) {
         return UnsignedInts.compare(rawValue, o.rawValue);
     }
+
+    @Override
+    public void putTo(PrimitiveSink sink) {
+        sink.putInt(rawValue);
+    }
+
 }
diff --git a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IPv6Address.java b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IPv6Address.java
index b58de1a..1aad85b 100644
--- a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IPv6Address.java
+++ b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IPv6Address.java
@@ -5,6 +5,7 @@
 import org.jboss.netty.buffer.ChannelBuffer;
 import org.projectfloodlight.openflow.exceptions.OFParseError;
 
+import com.google.common.hash.PrimitiveSink;
 import com.google.common.primitives.Longs;
 
 /**
@@ -308,4 +309,10 @@
         else
             return Longs.compare(raw2, o.raw2);
     }
+
+    @Override
+    public void putTo(PrimitiveSink sink) {
+        sink.putLong(raw1);
+        sink.putLong(raw2);
+    }
 }
diff --git a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IPv6FlowLabel.java b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IPv6FlowLabel.java
index 45bbf4b..de49b51 100644
--- a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IPv6FlowLabel.java
+++ b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IPv6FlowLabel.java
@@ -3,6 +3,7 @@
 import org.jboss.netty.buffer.ChannelBuffer;
 import org.projectfloodlight.openflow.exceptions.OFParseError;
 
+import com.google.common.hash.PrimitiveSink;
 import com.google.common.primitives.UnsignedInts;
 
 public class IPv6FlowLabel implements OFValueType<IPv6FlowLabel> {
@@ -76,4 +77,9 @@
     public int compareTo(IPv6FlowLabel o) {
         return UnsignedInts.compare(label, o.label);
     }
+
+    @Override
+    public void putTo(PrimitiveSink sink) {
+        sink.putInt(this.label);
+    }
 }
diff --git a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IpDscp.java b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IpDscp.java
index ec78315..27596b7 100644
--- a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IpDscp.java
+++ b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IpDscp.java
@@ -3,6 +3,8 @@
 import org.jboss.netty.buffer.ChannelBuffer;
 import org.projectfloodlight.openflow.exceptions.OFParseError;
 
+import com.google.common.hash.PrimitiveSink;
+
 public enum IpDscp implements OFValueType<IpDscp> {
     DSCP_0((byte)0),
     DSCP_1((byte)1),
@@ -244,4 +246,9 @@
     public byte getDscpValue() {
         return dscp;
     }
+
+    @Override
+    public void putTo(PrimitiveSink sink) {
+        sink.putByte(dscp);
+    }
 }
diff --git a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IpEcn.java b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IpEcn.java
index 7e1cdf0..654df01 100644
--- a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IpEcn.java
+++ b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IpEcn.java
@@ -3,6 +3,8 @@
 import org.jboss.netty.buffer.ChannelBuffer;
 import org.projectfloodlight.openflow.exceptions.OFParseError;
 
+import com.google.common.hash.PrimitiveSink;
+
 public enum IpEcn implements OFValueType<IpEcn> {
     ECN_00((byte)0),
     ECN_01((byte)1),
@@ -63,4 +65,9 @@
     public byte getEcnValue() {
         return ecn;
     }
+
+    @Override
+    public void putTo(PrimitiveSink sink) {
+        sink.putByte(ecn);
+    }
 }
diff --git a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IpProtocol.java b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IpProtocol.java
index f0f79ec..e417e3a 100644
--- a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IpProtocol.java
+++ b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IpProtocol.java
@@ -2,6 +2,7 @@
 
 import org.jboss.netty.buffer.ChannelBuffer;
 
+import com.google.common.hash.PrimitiveSink;
 import com.google.common.primitives.Shorts;
 
 /**
@@ -655,4 +656,10 @@
         return Shorts.compare(proto, o.proto);
     }
 
+
+    @Override
+    public void putTo(PrimitiveSink sink) {
+        sink.putShort(proto);
+    }
+
 }
\ No newline at end of file
diff --git a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/LagId.java b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/LagId.java
index b7f7f67..2046d71 100644
--- a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/LagId.java
+++ b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/LagId.java
@@ -4,6 +4,7 @@
 
 import org.jboss.netty.buffer.ChannelBuffer;
 
+import com.google.common.hash.PrimitiveSink;
 import com.google.common.primitives.UnsignedInts;
 
 @Immutable
@@ -72,4 +73,9 @@
     public LagId applyMask(LagId mask) {
         return LagId.of(rawValue & mask.rawValue);
     }
+
+    @Override
+    public void putTo(PrimitiveSink sink) {
+        sink.putInt(rawValue);
+    }
 }
diff --git a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/MacAddress.java b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/MacAddress.java
index 87be7c2..8b2bc53 100644
--- a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/MacAddress.java
+++ b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/MacAddress.java
@@ -4,6 +4,7 @@
 import org.projectfloodlight.openflow.exceptions.OFParseError;
 import org.projectfloodlight.openflow.util.HexString;
 
+import com.google.common.hash.PrimitiveSink;
 import com.google.common.primitives.Longs;
 
 /**
@@ -138,6 +139,12 @@
         return Longs.compare(rawValue, o.rawValue);
     }
 
+    @Override
+    public void putTo(PrimitiveSink sink) {
+        sink.putInt((int) (this.rawValue >> 16));
+        sink.putShort((short) (this.rawValue & 0xFFFF));
+    }
+
 
 
 }
diff --git a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/Masked.java b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/Masked.java
index 4d88793..ea2317a 100644
--- a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/Masked.java
+++ b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/Masked.java
@@ -1,5 +1,7 @@
 package org.projectfloodlight.openflow.types;
 
+import com.google.common.hash.PrimitiveSink;
+
 
 
 public class Masked<T extends OFValueType<T>> implements OFValueType<Masked<T>> {
@@ -66,4 +68,10 @@
         else
             return mask.compareTo(o.mask);
     }
+
+    @Override
+    public void putTo(PrimitiveSink sink) {
+        value.putTo(sink);
+        mask.putTo(sink);
+    }
 }
diff --git a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/OFBitMask128.java b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/OFBitMask128.java
index 2827a72..5cec233 100644
--- a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/OFBitMask128.java
+++ b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/OFBitMask128.java
@@ -2,6 +2,8 @@
 
 import org.jboss.netty.buffer.ChannelBuffer;
 
+import com.google.common.hash.PrimitiveSink;
+
 public class OFBitMask128 implements OFValueType<OFBitMask128> {
 
     static final int LENGTH = 16;
@@ -89,4 +91,10 @@
         return Long.signum(this.raw2 - o.raw2);
     }
 
+    @Override
+    public void putTo(PrimitiveSink sink) {
+        sink.putLong(raw1);
+        sink.putLong(raw2);
+    }
+
 }
diff --git a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/OFBufferId.java b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/OFBufferId.java
index f541b61..f255e7b 100644
--- a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/OFBufferId.java
+++ b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/OFBufferId.java
@@ -4,6 +4,7 @@
 import org.projectfloodlight.openflow.annotations.Immutable;
 import org.projectfloodlight.openflow.exceptions.OFParseError;
 
+import com.google.common.hash.PrimitiveSink;
 import com.google.common.primitives.UnsignedInts;
 
 /**
@@ -12,7 +13,7 @@
  * @author Rob Vaterlaus <rob.vaterlaus@bigswitch.com>
  */
 @Immutable
-public class OFBufferId implements Comparable<OFBufferId> {
+public class OFBufferId implements Comparable<OFBufferId>, PrimitiveSinkable {
     public static final OFBufferId NO_BUFFER = new OFBufferId(0xFFFFFFFF);
 
     private final int rawValue;
@@ -62,4 +63,9 @@
     public int compareTo(OFBufferId o) {
         return UnsignedInts.compare(rawValue, o.rawValue);
     }
+
+    @Override
+    public void putTo(PrimitiveSink sink) {
+        sink.putInt(rawValue);
+    }
 }
diff --git a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/OFMetadata.java b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/OFMetadata.java
index 0844d89..d1a23df 100644
--- a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/OFMetadata.java
+++ b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/OFMetadata.java
@@ -2,6 +2,8 @@
 
 import org.jboss.netty.buffer.ChannelBuffer;
 
+import com.google.common.hash.PrimitiveSink;
+
 public class OFMetadata implements OFValueType<OFMetadata> {
 
     static int LENGTH = 8;
@@ -67,4 +69,9 @@
     public int compareTo(OFMetadata o) {
         return u64.compareTo(o.u64);
     }
+
+    @Override
+    public void putTo(PrimitiveSink sink) {
+        u64.putTo(sink);
+    }
 }
diff --git a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/OFPort.java b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/OFPort.java
index 0028cd8..155a9db 100644
--- a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/OFPort.java
+++ b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/OFPort.java
@@ -4,6 +4,7 @@
 import org.projectfloodlight.openflow.annotations.Immutable;
 import org.projectfloodlight.openflow.exceptions.OFParseError;
 
+import com.google.common.hash.PrimitiveSink;
 import com.google.common.primitives.UnsignedInts;
 
 /**
@@ -554,4 +555,9 @@
     public int compareTo(OFPort o) {
         return UnsignedInts.compare(this.portNumber, o.portNumber);
     }
+
+    @Override
+    public void putTo(PrimitiveSink sink) {
+        sink.putInt(portNumber);
+    }
 }
diff --git a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/OFValueType.java b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/OFValueType.java
index 3d8d1cd..03e84dd 100644
--- a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/OFValueType.java
+++ b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/OFValueType.java
@@ -3,8 +3,9 @@
 
 
 
-public interface OFValueType<T extends OFValueType<T>> extends Comparable<T> {
+public interface OFValueType<T extends OFValueType<T>> extends Comparable<T>, PrimitiveSinkable {
     public int getLength();
 
     public T applyMask(T mask);
+
 }
diff --git a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/PrimitiveSinkable.java b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/PrimitiveSinkable.java
new file mode 100644
index 0000000..e50cb75
--- /dev/null
+++ b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/PrimitiveSinkable.java
@@ -0,0 +1,7 @@
+package org.projectfloodlight.openflow.types;
+
+import com.google.common.hash.PrimitiveSink;
+
+public interface PrimitiveSinkable {
+    public void putTo(PrimitiveSink sink);
+}
diff --git a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/TableId.java b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/TableId.java
index 698bc8e..950087d 100644
--- a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/TableId.java
+++ b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/TableId.java
@@ -3,6 +3,7 @@
 import org.jboss.netty.buffer.ChannelBuffer;
 import org.projectfloodlight.openflow.exceptions.OFParseError;
 
+import com.google.common.hash.PrimitiveSink;
 import com.google.common.primitives.Shorts;
 
 public class TableId implements OFValueType<TableId>, Comparable<TableId> {
@@ -91,4 +92,9 @@
         return Shorts.compare(this.id, other.id);
     }
 
+    @Override
+    public void putTo(PrimitiveSink sink) {
+        sink.putByte((byte) id);
+    }
+
 }
diff --git a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/TransportPort.java b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/TransportPort.java
index 540ad1a..01019b0 100644
--- a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/TransportPort.java
+++ b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/TransportPort.java
@@ -3,6 +3,7 @@
 import org.jboss.netty.buffer.ChannelBuffer;
 import org.projectfloodlight.openflow.exceptions.OFParseError;
 
+import com.google.common.hash.PrimitiveSink;
 import com.google.common.primitives.Ints;
 
 /**
@@ -87,4 +88,9 @@
         return Ints.compare(port,  o.port);
     }
 
+    @Override
+    public void putTo(PrimitiveSink sink) {
+        sink.putShort((short) port);
+    }
+
 }
diff --git a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/U16.java b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/U16.java
index 2f8bfee..9de7e14 100644
--- a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/U16.java
+++ b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/U16.java
@@ -22,6 +22,7 @@
 import org.projectfloodlight.openflow.protocol.OFMessageReader;
 import org.projectfloodlight.openflow.protocol.Writeable;
 
+import com.google.common.hash.PrimitiveSink;
 import com.google.common.primitives.Ints;
 
 public class U16 implements Writeable, OFValueType<U16> {
@@ -117,4 +118,9 @@
     public int compareTo(U16 o) {
         return Ints.compare(f(raw), f(o.raw));
     }
+
+    @Override
+    public void putTo(PrimitiveSink sink) {
+        sink.putShort(raw);
+    }
 }
diff --git a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/U32.java b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/U32.java
index daf5fa6..9fafc30 100644
--- a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/U32.java
+++ b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/U32.java
@@ -22,6 +22,7 @@
 import org.projectfloodlight.openflow.protocol.OFMessageReader;
 import org.projectfloodlight.openflow.protocol.Writeable;
 
+import com.google.common.hash.PrimitiveSink;
 import com.google.common.primitives.UnsignedInts;
 
 public class U32 implements Writeable, OFValueType<U32> {
@@ -117,4 +118,7 @@
         return UnsignedInts.compare(raw, o.raw);
     }
 
-}
+    @Override
+    public void putTo(PrimitiveSink sink) {
+        sink.putInt(raw);
+    }}
diff --git a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/U64.java b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/U64.java
index 8cd577f..d77d700 100644
--- a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/U64.java
+++ b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/U64.java
@@ -22,6 +22,7 @@
 import org.jboss.netty.buffer.ChannelBuffer;
 import org.projectfloodlight.openflow.protocol.Writeable;
 
+import com.google.common.hash.PrimitiveSink;
 import com.google.common.primitives.UnsignedLongs;
 
 public class U64 implements Writeable, OFValueType<U64> {
@@ -120,4 +121,8 @@
         return UnsignedLongs.compare(raw, o.raw);
     }
 
+    @Override
+    public void putTo(PrimitiveSink sink) {
+        sink.putLong(raw);
+    }
 }
diff --git a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/U8.java b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/U8.java
index b85627e..078a846 100644
--- a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/U8.java
+++ b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/U8.java
@@ -22,6 +22,7 @@
 import org.projectfloodlight.openflow.protocol.OFMessageReader;
 import org.projectfloodlight.openflow.protocol.Writeable;
 
+import com.google.common.hash.PrimitiveSink;
 import com.google.common.primitives.UnsignedBytes;
 
 public class U8 implements Writeable, OFValueType<U8> {
@@ -119,4 +120,8 @@
         return UnsignedBytes.compare(raw, o.raw);
     }
 
-}
+    @Override
+    public void putTo(PrimitiveSink sink) {
+        sink.putByte(raw);
+    }
+ }
diff --git a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/VRF.java b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/VRF.java
index 10e2ebc..b3f187f 100644
--- a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/VRF.java
+++ b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/VRF.java
@@ -4,6 +4,7 @@
 
 import org.jboss.netty.buffer.ChannelBuffer;
 
+import com.google.common.hash.PrimitiveSink;
 import com.google.common.primitives.UnsignedInts;
 
 @Immutable
@@ -75,4 +76,9 @@
     public int compareTo(VRF o) {
         return UnsignedInts.compare(rawValue, o.rawValue);
     }
+
+    @Override
+    public void putTo(PrimitiveSink sink) {
+        sink.putInt(rawValue);
+    }
 }
diff --git a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/VlanPcp.java b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/VlanPcp.java
index dcc7d60..cbb7004 100644
--- a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/VlanPcp.java
+++ b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/VlanPcp.java
@@ -3,6 +3,7 @@
 import org.jboss.netty.buffer.ChannelBuffer;
 import org.projectfloodlight.openflow.exceptions.OFParseError;
 
+import com.google.common.hash.PrimitiveSink;
 import com.google.common.primitives.UnsignedBytes;
 
 public class VlanPcp implements OFValueType<VlanPcp> {
@@ -74,5 +75,8 @@
     public int compareTo(VlanPcp o) {
         return UnsignedBytes.compare(pcp, o.pcp);
     }
-
+    @Override
+    public void putTo(PrimitiveSink sink) {
+        sink.putByte(pcp);
+    }
 }
diff --git a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/VlanVid.java b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/VlanVid.java
index 6bd7581..d370711 100644
--- a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/VlanVid.java
+++ b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/VlanVid.java
@@ -3,6 +3,7 @@
 import org.jboss.netty.buffer.ChannelBuffer;
 import org.projectfloodlight.openflow.exceptions.OFParseError;
 
+import com.google.common.hash.PrimitiveSink;
 import com.google.common.primitives.Shorts;
 
 /** Represents an OpenFlow Vlan VID, as specified by the OpenFlow 1.3 spec.
@@ -159,5 +160,8 @@
     public int compareTo(VlanVid o) {
         return Shorts.compare(vid, o.vid);
     }
-
+    @Override
+    public void putTo(PrimitiveSink sink) {
+        sink.putShort(vid);
+    }
 }
diff --git a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/util/FunnelUtils.java b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/util/FunnelUtils.java
new file mode 100644
index 0000000..f62d7f9
--- /dev/null
+++ b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/util/FunnelUtils.java
@@ -0,0 +1,14 @@
+package org.projectfloodlight.openflow.util;
+
+import java.util.List;
+
+import org.projectfloodlight.openflow.types.PrimitiveSinkable;
+
+import com.google.common.hash.PrimitiveSink;
+
+public class FunnelUtils {
+    public static void putList(List<? extends PrimitiveSinkable> sinkables, PrimitiveSink sink) {
+        for(PrimitiveSinkable p: sinkables)
+            p.putTo(sink);
+    }
+}
diff --git a/java_gen/templates/_imports.java b/java_gen/templates/_imports.java
index 7fd0719..55e9a2d 100644
--- a/java_gen/templates/_imports.java
+++ b/java_gen/templates/_imports.java
@@ -1,5 +1,6 @@
 import java.util.Arrays;
 import java.util.Collections;
+import java.util.EnumSet;
 import java.util.List;
 import java.util.Set;
 import java.util.Map;
@@ -18,3 +19,5 @@
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Sets;
+import com.google.common.hash.Funnel;
+import com.google.common.hash.PrimitiveSink;
diff --git a/java_gen/templates/const_serializer.java b/java_gen/templates/const_serializer.java
index 5710f9c..12ff28a 100644
--- a/java_gen/templates/const_serializer.java
+++ b/java_gen/templates/const_serializer.java
@@ -33,10 +33,7 @@
 
 package ${package};
 
-import org.projectfloodlight.openflow.types.*;
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.projectfloodlight.openflow.exceptions.OFParseError;
-import org.projectfloodlight.openflow.protocol.OFVersion;
+//:: include('_imports.java')
 import ${enum.package}.${enum.name};
 
 public class ${class_name} {
@@ -60,6 +57,10 @@
         ${wire_type.write_op(version=version, name="toWireValue(e)")};
     }
 
+    public static void putTo(${enum.name} e, PrimitiveSink sink) {
+        ${wire_type.funnel_op(version=version, name="toWireValue(e)")};
+    }
+
     public static ${enum.name} ofWireValue(${int_wire_type} val) {
         switch(val) {
         //:: for entry, _ in entries:
@@ -71,6 +72,7 @@
         }
     }
 
+
     public static ${int_wire_type} toWireValue(${enum.name} e) {
         switch(e) {
         //:: for entry, _ in entries:
diff --git a/java_gen/templates/const_set_serializer.java b/java_gen/templates/const_set_serializer.java
index 4fcff22..4c624ee 100644
--- a/java_gen/templates/const_set_serializer.java
+++ b/java_gen/templates/const_set_serializer.java
@@ -33,14 +33,8 @@
 
 package ${package};
 
-import java.util.Collections;
-import java.util.EnumSet;
-import java.util.Set;
+//:: include('_imports.java')
 
-import org.projectfloodlight.openflow.types.*;
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.projectfloodlight.openflow.exceptions.OFParseError;
-import org.projectfloodlight.openflow.protocol.OFVersion;
 import ${enum.package}.${enum.name};
 
 public class ${class_name} {
@@ -64,6 +58,11 @@
         ${wire_type.write_op(version=version, name="toWireValue(set)")};
     }
 
+    public static void putTo(Set<${enum.name}> set, PrimitiveSink sink) {
+        ${wire_type.funnel_op(version=version, name="toWireValue(set)")};
+    }
+
+
     public static Set<${enum.name}> ofWireValue(${int_wire_type} val) {
         EnumSet<${enum.name}> set = EnumSet.noneOf(${enum.name}.class);
 
diff --git a/java_gen/templates/of_class.java b/java_gen/templates/of_class.java
index 458d3f0..ef927fd 100644
--- a/java_gen/templates/of_class.java
+++ b/java_gen/templates/of_class.java
@@ -247,6 +247,33 @@
         }
     }
 
+    public void putTo(PrimitiveSink sink) {
+        FUNNEL.funnel(this, sink);
+    }
+
+    final static ${impl_class}Funnel FUNNEL = new ${impl_class}Funnel();
+    static class ${impl_class}Funnel implements Funnel<${impl_class}> {
+        private static final long serialVersionUID = 1L;
+        @Override
+        public void funnel(${impl_class} message, PrimitiveSink sink) {
+//:: for prop in msg.members:
+//:: if prop.is_virtual:
+//::    continue
+//:: elif prop.is_data:
+            ${prop.java_type.funnel_op(version, "message." + prop.name, pub_type=True)};
+//:: elif prop.is_pad:
+            // skip pad (${prop.length} bytes)
+//:: elif prop.is_fixed_value:
+            // fixed value property ${prop.name} = ${prop.value}
+            ${prop.java_type.funnel_op(version, prop.priv_value, pub_type=False)};
+//:: else:
+            // FIXME: skip funnel of ${prop.name}
+//:: #endif
+//:: #endfor
+        }
+    }
+
+
     public void writeTo(ChannelBuffer bb) {
         WRITER.write(bb, this);
     }