+static void
+ofpbuf_init__(struct ofpbuf *b, size_t allocated, enum ofpbuf_source source)
+{
+ b->allocated = allocated;
+ b->source = source;
+ b->header = NULL;
+ b->msg = NULL;
+ list_poison(&b->list_node);
+}
+
+static void
+ofpbuf_use__(struct ofpbuf *b, void *base, size_t allocated, size_t size,
+ enum ofpbuf_source source)
+{
+ b->base = base;
+ b->data = base;
+ b->size = size;
+
+ ofpbuf_init__(b, allocated, source);
+}
+
+/* Initializes 'b' as an empty ofpbuf that contains the 'allocated' bytes of
+ * memory starting at 'base'. 'base' should be the first byte of a region
+ * obtained from malloc(). It will be freed (with free()) if 'b' is resized or
+ * freed. */
+static void
+ofpbuf_use(struct ofpbuf *b, void *base, size_t allocated)
+{
+ ofpbuf_use__(b, base, allocated, 0, OFPBUF_MALLOC);
+}
+
+/* Converts ds into ofpbuf 'b'. 'b' contains the 'ds->allocated' bytes of
+ * memory starting at 'ds->string'. 'ds' should not be modified any more.
+ * The memory allocated for 'ds' will be freed (with free()) if 'b' is
+ * resized or freed. */
+void
+ofpbuf_use_ds(struct ofpbuf *b, const struct ds *ds)
+{
+ ofpbuf_use__(b, ds->string, ds->allocated + 1, ds->length, OFPBUF_MALLOC);
+}
+