Add a reference counted buffer implementation.

This implementation introduces the notion of a 'slice'. A slice is
simply a sub-buffer of the original buffer. Slices refer to their
parent buffer so no memory is copied and slice creation becomes an
O(1) operation. Although I'm introducing a new concept, in practice,
a slice is indistinguishable from a buffer (they share a type and
all operations).

I expect slices to be used heavily during packet construction. For
example, an RFCOMM implementation would request a buffer from the
L2CAP layer (which may in turn request a buffer from the HCI layer).
The L2CAP layer would reserve some space in the buffer for its header
and return a slice to the RFCOMM layer.
3 files changed