loci: factor out of_object_attach

This code was duplicated by bind and list operations, and will be used for
match deserialization..
diff --git a/c_gen/c_code_gen.py b/c_gen/c_code_gen.py
index ba232fd..3c25807 100644
--- a/c_gen/c_code_gen.py
+++ b/c_gen/c_code_gen.py
@@ -1462,10 +1462,7 @@
     /* Initialize child */
     %(m_type)s_init(%(m_name)s, obj->version, 0, 1);
     /* Attach to parent */
-    %(m_name)s->parent = (of_object_t *)obj;
-    %(m_name)s->wbuf = obj->wbuf;
-    %(m_name)s->obj_offset = abs_offset;
-    %(m_name)s->length = cur_len;
+    of_object_attach(obj, %(m_name)s, offset, cur_len);
     of_object_wire_init(%(m_name)s, OF_OXM, 0);
 """ % dict(m_type=m_type[:-2], m_name=m_name))
     elif m_type == "of_bsn_vport_header_t":
@@ -1473,10 +1470,7 @@
     /* Initialize child */
     %(m_type)s_init(%(m_name)s, obj->version, 0, 1);
     /* Attach to parent */
-    %(m_name)s->parent = (of_object_t *)obj;
-    %(m_name)s->wbuf = obj->wbuf;
-    %(m_name)s->obj_offset = abs_offset;
-    %(m_name)s->length = cur_len;
+    of_object_attach(obj, %(m_name)s, offset, cur_len);
     of_object_wire_init(%(m_name)s, OF_BSN_VPORT, 0);
 """ % dict(m_type=m_type[:-2], m_name=m_name))
     else:
@@ -1484,10 +1478,7 @@
     /* Initialize child */
     %(m_type)s_init(%(m_name)s, obj->version, 0, 1);
     /* Attach to parent */
-    %(m_name)s->parent = (of_object_t *)obj;
-    %(m_name)s->wbuf = obj->wbuf;
-    %(m_name)s->obj_offset = abs_offset;
-    %(m_name)s->length = cur_len;
+    of_object_attach(obj, %(m_name)s, offset, cur_len);
 """ % dict(m_type=m_type[:-2], m_name=m_name))
 
 
diff --git a/c_gen/templates/of_object.c b/c_gen/templates/of_object.c
index 39a6790..b0d3e14 100644
--- a/c_gen/templates/of_object.c
+++ b/c_gen/templates/of_object.c
@@ -254,7 +254,6 @@
  * @param offset The offset at which to attach the child RELATIVE 
  * TO THE PARENT in the buffer
  * @param bytes The amount of the buffer dedicated to the child; see below
- * @param inc_ref_count Should the ref count of the parent be incremented
  * 
  * This is used for 'get' accessors for composite types as well as
  * iterator functions for lists, both read (first/next) and write
@@ -276,14 +275,7 @@
 object_child_attach(of_object_t *parent, of_object_t *child, 
                        int offset, int bytes)
 {
-    of_wire_buffer_t *wbuf; /* Pointer to common wire buffer manager */
-
-    child->parent = parent;
-    wbuf = parent->wbuf;
-
-    /* Set up the child's wire buf to point to same as parent */
-    child->wbuf = wbuf;
-    child->obj_offset = parent->obj_offset + offset;
+    of_object_attach(parent, child, offset, bytes);
 
     /*
      * bytes determines if this is a read or write setup.
@@ -296,8 +288,7 @@
         /* Set up space for the child in the parent's buffer */
         tot_bytes = parent->obj_offset + offset + bytes;
 
-        of_wire_buffer_grow(wbuf, tot_bytes);
-        child->length = bytes;
+        of_wire_buffer_grow(parent->wbuf, tot_bytes);
     }
     /* if bytes == 0 don't do anything */
 }
diff --git a/c_gen/templates/of_object.h b/c_gen/templates/of_object.h
index d299537..0ca415b 100644
--- a/c_gen/templates/of_object.h
+++ b/c_gen/templates/of_object.h
@@ -132,4 +132,22 @@
     of_wire_buffer_t wbuf;
 };
 
+/**
+ * Connect a child to a parent at the wire buffer level
+ *
+ * @param parent The top level object to bind to
+ * @param child The sub-object connecting to the parent
+ * @param offset The offset at which to attach the child RELATIVE
+ * TO THE PARENT in the buffer
+ * @param bytes The amount of the buffer dedicated to the child
+ */
+static inline void
+of_object_attach(of_object_t *parent, of_object_t *child, int offset, int length)
+{
+    child->parent = parent;
+    child->wbuf = parent->wbuf;
+    child->obj_offset = parent->obj_offset + offset;
+    child->length = length;
+}
+
 #endif /* _OF_OBJECT_H_ */