---
title: llarp_buffer_t
summary: TODO: replace usage of these with std::span (via a backport until we move to C++20). 

---

# llarp_buffer_t



TODO: replace usage of these with std::span (via a backport until we move to C++20).  [More...](#detailed-description)


`#include <buffer.hpp>`

## Public Functions

|                | Name           |
| -------------- | -------------- |
| byte_t | **[operator[]](Classes/structllarp__buffer__t.md#function-operator[])**(size_t x) |
| | **[llarp_buffer_t](Classes/structllarp__buffer__t.md#function-llarp-buffer-t)**() =default |
| | **[llarp_buffer_t](Classes/structllarp__buffer__t.md#function-llarp-buffer-t)**(byte_t * b, byte_t * c, size_t s) |
| | **[llarp_buffer_t](Classes/structllarp__buffer__t.md#function-llarp-buffer-t)**(const [ManagedBuffer](Classes/structManagedBuffer.md) & ) =delete |
| | **[llarp_buffer_t](Classes/structllarp__buffer__t.md#function-llarp-buffer-t)**([ManagedBuffer](Classes/structManagedBuffer.md) && ) =delete |
| template <typename Byte ,typename  =std::enable_if_t<not std::is_const_v<Byte> && is_basic_byte<Byte>>\> <br>| **[llarp_buffer_t](Classes/structllarp__buffer__t.md#function-llarp-buffer-t)**(Byte * buf, size_t sz)<br>Construct referencing some 1-byte, trivially copyable (e.g.  |
| template <typename Byte ,typename  =std::enable_if_t<not std::is_const_v<Byte> && is_basic_byte<Byte>>\> <br>| **[llarp_buffer_t](Classes/structllarp__buffer__t.md#function-llarp-buffer-t)**(std::vector< Byte > & b)<br>initialize [llarp_buffer_t](Classes/structllarp__buffer__t.md) from vector or array of byte-like values  |
| template <typename Byte ,size_t N,typename  =std::enable_if_t<not std::is_const_v<Byte> && is_basic_byte<Byte>>\> <br>| **[llarp_buffer_t](Classes/structllarp__buffer__t.md#function-llarp-buffer-t)**(std::array< Byte, N > & b) |
| template <typename Byte ,typename  =std::enable_if_t<is_basic_byte<Byte>>\> <br>| **[llarp_buffer_t](Classes/structllarp__buffer__t.md#function-llarp-buffer-t)**(const Byte * buf, size_t sz) |
| template <typename Byte ,typename  =std::enable_if_t<is_basic_byte<Byte>>\> <br>| **[llarp_buffer_t](Classes/structllarp__buffer__t.md#function-llarp-buffer-t)**(const std::vector< Byte > & b) |
| template <typename Byte ,size_t N,typename  =std::enable_if_t<is_basic_byte<Byte>>\> <br>| **[llarp_buffer_t](Classes/structllarp__buffer__t.md#function-llarp-buffer-t)**(const std::array< Byte, N > & b) |
| template <typename T ,typename  =std::void_t<decltype(std::declval<T>().data() + std::declval<T>().size())>\> <br>| **[llarp_buffer_t](Classes/structllarp__buffer__t.md#function-llarp-buffer-t)**(T && t)<br>Explicitly construct a [llarp_buffer_t](Classes/structllarp__buffer__t.md) from anything with a `.data()` and a `.size()`. Cursed.  |
| byte_t * | **[begin](Classes/structllarp__buffer__t.md#function-begin)**() |
| const byte_t * | **[begin](Classes/structllarp__buffer__t.md#function-begin)**() const |
| byte_t * | **[end](Classes/structllarp__buffer__t.md#function-end)**() |
| const byte_t * | **[end](Classes/structllarp__buffer__t.md#function-end)**() const |
| size_t | **[size_left](Classes/structllarp__buffer__t.md#function-size-left)**() const |
| template <typename OutputIt \> <br>bool | **[read_into](Classes/structllarp__buffer__t.md#function-read-into)**(OutputIt begin, OutputIt end) |
| template <typename InputIt \> <br>bool | **[write](Classes/structllarp__buffer__t.md#function-write)**(InputIt begin, InputIt end) |
| bool | **[writef](Classes/structllarp__buffer__t.md#function-writef)**(const char * fmt, ... ) |
| bool bool | **[put_uint16](Classes/structllarp__buffer__t.md#function-put-uint16)**(uint16_t i) |
| bool | **[put_uint32](Classes/structllarp__buffer__t.md#function-put-uint32)**(uint32_t i) |
| bool | **[put_uint64](Classes/structllarp__buffer__t.md#function-put-uint64)**(uint64_t i) |
| bool | **[read_uint16](Classes/structllarp__buffer__t.md#function-read-uint16)**(uint16_t & i) |
| bool | **[read_uint32](Classes/structllarp__buffer__t.md#function-read-uint32)**(uint32_t & i) |
| bool | **[read_uint64](Classes/structllarp__buffer__t.md#function-read-uint64)**(uint64_t & i) |
| size_t | **[read_until](Classes/structllarp__buffer__t.md#function-read-until)**(char delim, byte_t * result, size_t resultlen) |
| std::vector< byte_t > | **[copy](Classes/structllarp__buffer__t.md#function-copy)**() const<br>make a copy of this buffer  |
| llarp::byte_view_t | **[view_all](Classes/structllarp__buffer__t.md#function-view-all)**() const<br>get a read-only view over the entire region  |
| llarp::byte_view_t | **[view_remaining](Classes/structllarp__buffer__t.md#function-view-remaining)**() const<br>get a read-only view over the remaining/unused region  |
| bool | **[startswith](Classes/structllarp__buffer__t.md#function-startswith)**(std::string_view prefix_str) const<br>Part of the curse.  |

## Public Attributes

|                | Name           |
| -------------- | -------------- |
| byte_t * | **[base](Classes/structllarp__buffer__t.md#variable-base)** <br>starting memory address  |
| byte_t * | **[cur](Classes/structllarp__buffer__t.md#variable-cur)** <br>memory address of stream position  |
| size_t | **[sz](Classes/structllarp__buffer__t.md#variable-sz)** <br>max size of buffer  |
| constexpr bool | **[is_basic_byte](Classes/structllarp__buffer__t.md#variable-is-basic-byte)**  |

## Friends

|                | Name           |
| -------------- | -------------- |
| struct | **[ManagedBuffer](Classes/structllarp__buffer__t.md#friend-managedbuffer)**  |

## Detailed Description

```cpp
struct llarp_buffer_t;
```

TODO: replace usage of these with std::span (via a backport until we move to C++20). 

That's a fairly big job, though, as [llarp_buffer_t](Classes/structllarp__buffer__t.md) is currently used a bit differently (i.e. maintains both start and current position, plus has some value reading/writing methods). 

## Public Functions Documentation

### function operator[]

```cpp
inline byte_t operator[](
    size_t x
)
```


### function llarp_buffer_t

```cpp
llarp_buffer_t() =default
```


### function llarp_buffer_t

```cpp
inline llarp_buffer_t(
    byte_t * b,
    byte_t * c,
    size_t s
)
```


### function llarp_buffer_t

```cpp
llarp_buffer_t(
    const ManagedBuffer & 
) =delete
```


### function llarp_buffer_t

```cpp
llarp_buffer_t(
    ManagedBuffer && 
) =delete
```


### function llarp_buffer_t

```cpp
template <typename Byte ,
typename  =std::enable_if_t<not std::is_const_v<Byte> && is_basic_byte<Byte>>>
inline llarp_buffer_t(
    Byte * buf,
    size_t sz
)
```

Construct referencing some 1-byte, trivially copyable (e.g. 

char, unsigned char, byte_t) pointer type and a buffer size. 


### function llarp_buffer_t

```cpp
template <typename Byte ,
typename  =std::enable_if_t<not std::is_const_v<Byte> && is_basic_byte<Byte>>>
inline llarp_buffer_t(
    std::vector< Byte > & b
)
```

initialize [llarp_buffer_t](Classes/structllarp__buffer__t.md) from vector or array of byte-like values 

### function llarp_buffer_t

```cpp
template <typename Byte ,
size_t N,
typename  =std::enable_if_t<not std::is_const_v<Byte> && is_basic_byte<Byte>>>
inline llarp_buffer_t(
    std::array< Byte, N > & b
)
```


### function llarp_buffer_t

```cpp
template <typename Byte ,
typename  =std::enable_if_t<is_basic_byte<Byte>>>
inline llarp_buffer_t(
    const Byte * buf,
    size_t sz
)
```


### function llarp_buffer_t

```cpp
template <typename Byte ,
typename  =std::enable_if_t<is_basic_byte<Byte>>>
inline llarp_buffer_t(
    const std::vector< Byte > & b
)
```


### function llarp_buffer_t

```cpp
template <typename Byte ,
size_t N,
typename  =std::enable_if_t<is_basic_byte<Byte>>>
inline llarp_buffer_t(
    const std::array< Byte, N > & b
)
```


### function llarp_buffer_t

```cpp
template <typename T ,
typename  =std::void_t<decltype(std::declval<T>().data() + std::declval<T>().size())>>
inline explicit llarp_buffer_t(
    T && t
)
```

Explicitly construct a [llarp_buffer_t](Classes/structllarp__buffer__t.md) from anything with a `.data()` and a `.size()`. Cursed. 

### function begin

```cpp
inline byte_t * begin()
```


### function begin

```cpp
inline const byte_t * begin() const
```


### function end

```cpp
inline byte_t * end()
```


### function end

```cpp
inline const byte_t * end() const
```


### function size_left

```cpp
inline size_t size_left() const
```


### function read_into

```cpp
template <typename OutputIt >
bool read_into(
    OutputIt begin,
    OutputIt end
)
```


### function write

```cpp
template <typename InputIt >
bool write(
    InputIt begin,
    InputIt end
)
```


### function writef

```cpp
bool writef(
    const char * fmt,
    ... 
)
```


### function put_uint16

```cpp
bool bool put_uint16(
    uint16_t i
)
```


### function put_uint32

```cpp
bool put_uint32(
    uint32_t i
)
```


### function put_uint64

```cpp
bool put_uint64(
    uint64_t i
)
```


### function read_uint16

```cpp
bool read_uint16(
    uint16_t & i
)
```


### function read_uint32

```cpp
bool read_uint32(
    uint32_t & i
)
```


### function read_uint64

```cpp
bool read_uint64(
    uint64_t & i
)
```


### function read_until

```cpp
size_t read_until(
    char delim,
    byte_t * result,
    size_t resultlen
)
```


### function copy

```cpp
std::vector< byte_t > copy() const
```

make a copy of this buffer 

### function view_all

```cpp
inline llarp::byte_view_t view_all() const
```

get a read-only view over the entire region 

### function view_remaining

```cpp
inline llarp::byte_view_t view_remaining() const
```

get a read-only view over the remaining/unused region 

### function startswith

```cpp
inline bool startswith(
    std::string_view prefix_str
) const
```

Part of the curse. 

Returns true if the remaining buffer space starts with the given string view. 


## Public Attributes Documentation

### variable base

```cpp
byte_t * base {nullptr};
```

starting memory address 

### variable cur

```cpp
byte_t * cur {nullptr};
```

memory address of stream position 

### variable sz

```cpp
size_t sz {0};
```

max size of buffer 

### variable is_basic_byte

```cpp
static constexpr bool is_basic_byte = sizeof(Byte) == 1 and std::is_trivially_copyable_v<Byte>;
```


## Friends

### friend ManagedBuffer

```cpp
friend struct ManagedBuffer(
    ManagedBuffer 
);
```


-------------------------------

Updated on 2025-01-26 at 05:10:09 +0000