# litert::BufferRef


`#include <litert_buffer_ref.h>`

An immutable and non-owning view of a buffer.

## Summary

<br />

Details Template Parameters `ByteT` The byte type of the buffer.

### Inheritance

Direct Known Subclasses:[litert::MutableBufferRef\< ByteT \>](https://developers.google.com/edge/api/litert/c/classlitert/1-1-mutable-buffer-ref)

| ### Constructors and Destructors ||
|---|---|
| `https://developers.google.com/edge/api/litert/c/classlitert/1-1-buffer-ref#classlitert_1_1_buffer_ref_1aa453b259b5ae9b9b3e93dd9674fea737()` Constructs a null buffer. ||
| `https://developers.google.com/edge/api/litert/c/classlitert/1-1-buffer-ref#classlitert_1_1_buffer_ref_1ade716db6f38ebc73d095e4cc881341df(const ByteT *data, size_t end_offset, size_t start_offset)` Constructs from an already allocated buffer. ||
| `https://developers.google.com/edge/api/litert/c/classlitert/1-1-buffer-ref#classlitert_1_1_buffer_ref_1ab2bc9e633b5f7f98a63e938a669f68c5(const void *data, size_t end_offset, size_t start_offset)` ||
| `https://developers.google.com/edge/api/litert/c/classlitert/1-1-buffer-ref#classlitert_1_1_buffer_ref_1a82b684dc2048c3841349e0c983c914bc(absl::Span< const ByteT > data)` ||
| `https://developers.google.com/edge/api/litert/c/classlitert/1-1-buffer-ref#classlitert_1_1_buffer_ref_1ad284e1c2e8e5dd57c335d9da6f083218(const https://developers.google.com/edge/api/litert/c/classlitert/1-1-buffer-ref#classlitert_1_1_buffer_ref & other)` ||
| `https://developers.google.com/edge/api/litert/c/classlitert/1-1-buffer-ref#classlitert_1_1_buffer_ref_1aa2680689264761c0588eab50f54a8a2e()` ||

| ### Public types ||
|---|---|
| `https://developers.google.com/edge/api/litert/c/classlitert/1-1-buffer-ref#classlitert_1_1_buffer_ref_1afa49502a41def89b6e31ad1bd1e8f07c` | using `std::tuple< const ByteT *const, const size_t, const size_t >` |

| ### Protected attributes ||
|---|---|
| `https://developers.google.com/edge/api/litert/c/classlitert/1-1-buffer-ref#classlitert_1_1_buffer_ref_1ae0bfd707189b52057cc81698749912ef = nullptr` | `ByteT *` The original pointer to the memory. |
| `https://developers.google.com/edge/api/litert/c/classlitert/1-1-buffer-ref#classlitert_1_1_buffer_ref_1ab798f06127b5c9a9e08e8bc036af550a` | `size_t` The end offset of the actual data, relative to `data_`. |
| `https://developers.google.com/edge/api/litert/c/classlitert/1-1-buffer-ref#classlitert_1_1_buffer_ref_1af1decf22fcb62facd3b3b8ba9fbc48d5` | `size_t` The start offset of the actual data, relative to `data_`. |

| ### Public functions ||
|---|---|
| `https://developers.google.com/edge/api/litert/c/classlitert/1-1-buffer-ref#classlitert_1_1_buffer_ref_1a6ebdc9f313b10730059409dc5dd73cf8() const ` | `const ByteT *` Returns a pointer to the start of the actual data. |
| `https://developers.google.com/edge/api/litert/c/classlitert/1-1-buffer-ref#classlitert_1_1_buffer_ref_1a568bb5e9093d81699c55dd8edd8bd606(std::ostream & out) const ` | `void` Prints information about this buffer. |
| `https://developers.google.com/edge/api/litert/c/classlitert/1-1-buffer-ref#classlitert_1_1_buffer_ref_1ab2a2e82f583282d91176ab340edfd06d() const ` | `TupleT` Returns the buffer details as a tuple. |
| `https://developers.google.com/edge/api/litert/c/classlitert/1-1-buffer-ref#classlitert_1_1_buffer_ref_1a0e6a9ce4c4401744b8f28ce2038281f0() const ` | `size_t` Returns the size of the actual data. |
| `https://developers.google.com/edge/api/litert/c/classlitert/1-1-buffer-ref#classlitert_1_1_buffer_ref_1a8bae5796141379bd9c3013d94c91f28b() const ` | `absl::Span< const ByteT >` Returns a const span of the actual data. |
| `https://developers.google.com/edge/api/litert/c/classlitert/1-1-buffer-ref#classlitert_1_1_buffer_ref_1ab98c339ad51cc78873f233bd5ad3cade() const ` | `const char *` Returns a pointer to the start of the actual data as a signed char. |
| `https://developers.google.com/edge/api/litert/c/classlitert/1-1-buffer-ref#classlitert_1_1_buffer_ref_1a187bb9fc36caca5a2beed051715991ba() const ` | `absl::string_view` Returns a string view of the actual data. |
| `https://developers.google.com/edge/api/litert/c/classlitert/1-1-buffer-ref#classlitert_1_1_buffer_ref_1a548f6bbe59109e36506363357d813fa1() const ` | `std::vector< ByteT >` Copies the buffer data to a vector. |
| `https://developers.google.com/edge/api/litert/c/classlitert/1-1-buffer-ref#classlitert_1_1_buffer_ref_1afcc4e29333a993803e3d944bdd454e47(std::ostream & out) const ` | `void` Writes the string data to a stream. |
| `https://developers.google.com/edge/api/litert/c/classlitert/1-1-buffer-ref#classlitert_1_1_buffer_ref_1aec38ae5324690728bb0c5abd49a6a64b(const https://developers.google.com/edge/api/litert/c/classlitert/1-1-buffer-ref#classlitert_1_1_buffer_ref & other)=default` | `https://developers.google.com/edge/api/litert/c/classlitert/1-1-buffer-ref#classlitert_1_1_buffer_ref &` |

| ### Protected functions ||
|---|---|
| `https://developers.google.com/edge/api/litert/c/classlitert/1-1-buffer-ref#classlitert_1_1_buffer_ref_1ab502e6e5cbd4f11dca0ba4e611e3a4d3() const ` | `virtual absl::string_view` Returns the debug name of the class. |

## Public types

### TupleT

```
std::tuple< const ByteT *const, const size_t, const size_t > TupleT
```

## Protected attributes

### data_

```
ByteT * data_ = nullptr
```
The original pointer to the memory.

### end_offset_

```
size_t end_offset_
```
The end offset of the actual data, relative to `data_`.

### start_offset_

```
size_t start_offset_
```
The start offset of the actual data, relative to `data_`.

## Public functions

### BufferRef

```
 BufferRef()
```
Constructs a null buffer.

### BufferRef

```
 BufferRef(
  const ByteT *data,
  size_t end_offset,
  size_t start_offset
)
```
Constructs from an already allocated buffer.

The view will only expose `data[offset, offset + size]`.
Details Parameters `data` A pointer to the start of the buffer. `end_offset` The end offset of the buffer view. `start_offset` The start offset of the buffer view.

### BufferRef

```
 BufferRef(
  const void *data,
  size_t end_offset,
  size_t start_offset
)
```

### BufferRef

```
 BufferRef(
  absl::Span< const ByteT > data
)
```

### BufferRef

```
 BufferRef(
  const BufferRef & other
)=default
```

### Data

```
const ByteT * Data() const 
```
Returns a pointer to the start of the actual data.

### Dump

```
void Dump(
  std::ostream & out
) const 
```
Prints information about this buffer.

### Get

```
TupleT Get() const 
```
Returns the buffer details as a tuple.

### Size

```
size_t Size() const 
```
Returns the size of the actual data.

### Span

```
absl::Span< const ByteT > Span() const 
```
Returns a const span of the actual data.

### StrData

```
const char * StrData() const 
```
Returns a pointer to the start of the actual data as a signed char.


> [!NOTE]
> **Note:** The returned pointer might not be null-terminated.

<br />

### StrView

```
absl::string_view StrView() const 
```
Returns a string view of the actual data.


> [!NOTE]
> **Note:** Ensures the view is null-terminated.

<br />

### ToVec

```
std::vector< ByteT > ToVec() const 
```
Copies the buffer data to a vector.

### WriteStr

```
void WriteStr(
  std::ostream & out
) const 
```
Writes the string data to a stream.

### operator=

```
BufferRef & operator=(
  const BufferRef & other
)=default
```

### \~BufferRef

```
virtual  ~BufferRef()=default
```

## Protected functions

### TypeName

```
virtual absl::string_view TypeName() const 
```
Returns the debug name of the class.