#include <haproxy/ncbuf2-t.h>
#include <haproxy/ncbuf_common-t.h>
+static inline int ncb2_is_null(const struct ncbuf2 *buf)
+{
+ return buf->size == 0;
+}
+
struct ncbuf2 ncb2_make(char *area, ncb2_sz_t size, ncb2_sz_t head);
static inline char *ncb2_orig(const struct ncbuf2 *buf)
return buf->area + buf->size;
}
+static inline ncb2_sz_t ncb2_size(const struct ncbuf2 *buf)
+{
+ if (ncb2_is_null(buf))
+ return 0;
+
+ return buf->size;
+}
+
+ncb2_sz_t ncb2_data(const struct ncbuf2 *buf, ncb2_sz_t offset);
+
enum ncb_ret ncb2_add(struct ncbuf2 *buf, ncb2_sz_t off,
const char *data, ncb2_sz_t len, enum ncb_add_mode mode);
ncb2_sz_t ncb2_data(const struct ncbuf2 *buf, ncb2_sz_t off)
{
- /* TODO */
- return 0;
+ struct itbmap it = itbmap_get(buf, off);
+ unsigned char value;
+ ncb2_sz_t count = 0;
+
+ while (itbmap_is_full(&it)) {
+ count += it.bitcount;
+ it = itbmap_next(buf, &it);
+ }
+
+ if (it.b) {
+ value = *it.b & it.mask;
+ while (it.mask && !(it.mask & 0x80)) {
+ it.mask <<= 1;
+ value <<= 1;
+ }
+
+ while (it.mask && (it.mask & 0x80) && (value & 0x80)) {
+ it.mask <<= 1;
+ value <<= 1;
+ ++count;
+ }
+ }
+
+ return count;
}
enum ncb_ret ncb2_add(struct ncbuf2 *buf, ncb2_sz_t off,