-/* Copyright (c) 2008 The Board of Trustees of The Leland Stanford
+/* Copyright (c) 2008, 2009 The Board of Trustees of The Leland Stanford
* Junior University
*
* We are making the OpenFlow specification and associated documentation
assert(size <= ofpbuf_headroom(b));
}
+/* Trims the size of 'b' to fit its actual content. */
+void
+ofpbuf_trim(struct ofpbuf *b)
+{
+ /* XXX These could be supported, but the current client doesn't care. */
+ assert(b->data == b->base);
+ assert(b->l2 == NULL && b->l3 == NULL && b->l4 == NULL && b->l7 == NULL);
+ if (b->allocated > b->size) {
+ b->base = b->data = xrealloc(b->base, b->size);
+ b->allocated = b->size;
+ }
+}
+
/* Appends 'size' bytes of data to the tail end of 'b', reallocating and
* copying its data if necessary. Returns a pointer to the first byte of the
* new data, which is left uninitialized. */
-/* Copyright (c) 2008 The Board of Trustees of The Leland Stanford
+/* Copyright (c) 2008, 2009 The Board of Trustees of The Leland Stanford
* Junior University
*
* We are making the OpenFlow specification and associated documentation
size_t ofpbuf_tailroom(struct ofpbuf *);
void ofpbuf_prealloc_headroom(struct ofpbuf *, size_t);
void ofpbuf_prealloc_tailroom(struct ofpbuf *, size_t);
+void ofpbuf_trim(struct ofpbuf *);
void ofpbuf_clear(struct ofpbuf *);
void *ofpbuf_pull(struct ofpbuf *, size_t);