Bluetooth: Add bt_buf_pull_le16 helper

bt_buf_pull_le16 convert the initial 16 bits to little endian.

Change-Id: I6f6e9d63fc19b0579d9f445e15e975929fc63ba9
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This commit is contained in:
Luiz Augusto von Dentz 2015-05-12 17:30:52 +03:00 committed by Anas Nashif
commit d1b61254f3
2 changed files with 13 additions and 0 deletions

View file

@ -106,6 +106,9 @@ uint8_t *bt_buf_push(struct bt_buf *buf, size_t len);
/* Remove data from the beginning of the buffer */
uint8_t *bt_buf_pull(struct bt_buf *buf, size_t len);
/* Remove and convert 16 bits from the beginning of the buffer */
uint16_t bt_buf_pull_le16(struct bt_buf *buf);
/* Returns how much free space there is at the end of the buffer */
size_t bt_buf_tailroom(struct bt_buf *buf);

View file

@ -185,6 +185,16 @@ uint8_t *bt_buf_pull(struct bt_buf *buf, size_t len)
return buf->data += len;
}
uint16_t bt_buf_pull_le16(struct bt_buf *buf)
{
uint16_t value;
value = UNALIGNED_GET((uint16_t *)buf->data);
bt_buf_pull(buf, sizeof(value));
return sys_cpu_to_le16(value);
}
size_t bt_buf_headroom(struct bt_buf *buf)
{
return buf->data - buf->buf;