ICU 70.1 70.1

Public Member Functions
icu::ByteSink Class Referenceabstract

A ByteSink can be filled with bytes. More...

`#include <bytestream.h>`

Inheritance diagram for icu::ByteSink:

## Public Member Functions
| ByteSink ()
| Default constructor. More...
virtual | ~ByteSink ()
| Virtual destructor. More...
virtual void | Append (const char *bytes, int32_t n)=0
| Append "bytes[0,n-1]" to this. More...
void | AppendU8 (const char *bytes, int32_t n)
| Appends n bytes to this. More...
void | AppendU8 (const char8_t *bytes, int32_t n)
| Appends n bytes to this. More...
virtual char * | GetAppendBuffer (int32_t min_capacity, int32_t desired_capacity_hint, char *scratch, int32_t scratch_capacity, int32_t *result_capacity)
| Returns a writable buffer for appending and writes the buffer's capacity to *result_capacity. More...
virtual void | Flush ()
| Flush internal buffers. More...

## Detailed Description

A ByteSink can be filled with bytes.

Stable:
  ICU 4.2

Definition at line 53 of file bytestream.h.

## Constructor & Destructor Documentation

## ◆ ByteSink()

icu::ByteSink::ByteSink | ( |  | ) |
| inline

Default constructor.

Stable:
  ICU 4.2

Definition at line 59 of file bytestream.h.

## ◆ ~ByteSink()

virtual icu::ByteSink::~ByteSink | ( |  | ) |
| virtual

Virtual destructor.

Stable:
  ICU 4.2

## Member Function Documentation

## ◆ Append()

virtual void icu::ByteSink::Append | ( | const char * | bytes,
|  | int32_t | n
| ) |  |
| pure virtual

Append "bytes[0,n-1]" to this.

Parameters

  bytes | the pointer to the bytes
  n | the number of bytes; must be non-negative

Stable:
  ICU 4.2

Implemented in icu::CheckedArrayByteSink, and icu::StringByteSink< StringClass >.

## ◆ AppendU8() [1/2]

void icu::ByteSink::AppendU8 | ( | const char * | bytes,
|  | int32_t | n
| ) |  |
| inline

Appends n bytes to this.

Same as Append(). Call AppendU8() with u8"string literals" which are const char * in C++11 but const char8_t * in C++20. If the compiler does support char8_t as a distinct type, then an AppendU8() overload for that is defined and will be chosen.

Parameters

  bytes | the pointer to the bytes
  n | the number of bytes; must be non-negative

Stable:
  ICU 67

Definition at line 85 of file bytestream.h.

## ◆ AppendU8() [2/2]

void icu::ByteSink::AppendU8 | ( | const char8_t * | bytes,
|  | int32_t | n
| ) |  |
| inline

Appends n bytes to this.

Same as Append() but for a const char8_t * pointer. Call AppendU8() with u8"string literals" which are const char * in C++11 but const char8_t * in C++20. If the compiler does support char8_t as a distinct type, then this AppendU8() overload for that is defined and will be chosen.

Parameters

  bytes | the pointer to the bytes
  n | the number of bytes; must be non-negative

Stable:
  ICU 67

Definition at line 101 of file bytestream.h.

## ◆ Flush()

virtual void icu::ByteSink::Flush | ( |  | ) |
| virtual

Flush internal buffers.

Some byte sinks use internal buffers or provide buffering and require calling Flush() at the end of the stream. The ByteSink should be ready for further Append() calls after Flush(). The default implementation of Flush() does nothing.

Stable:
  ICU 4.2

## ◆ GetAppendBuffer()

virtual char * icu::ByteSink::GetAppendBuffer | ( | int32_t | min_capacity,
|  | int32_t | desired_capacity_hint,
|  | char * | scratch,
|  | int32_t | scratch_capacity,
|  | int32_t * | result_capacity
| ) |  |
| virtual

Returns a writable buffer for appending and writes the buffer's capacity to *result_capacity.

Guarantees *result_capacity>=min_capacity. May return a pointer to the caller-owned scratch buffer which must have scratch_capacity>=min_capacity. The returned buffer is only valid until the next operation on this ByteSink.

After writing at most *result_capacity bytes, call Append() with the pointer returned from this function and the number of bytes written. Many Append() implementations will avoid copying bytes if this function returned an internal buffer.

Partial usage example: int32_t capacity; char* buffer = sink->GetAppendBuffer(..., &capacity); ... Write n bytes into buffer, with n <= capacity. sink->Append(buffer, n); In many implementations, that call to Append will avoid copying bytes.

If the ByteSink allocates or reallocates an internal buffer, it should use the desired_capacity_hint if appropriate. If a caller cannot provide a reasonable guess at the desired capacity, it should pass desired_capacity_hint=0.

If a non-scratch buffer is returned, the caller may only pass a prefix to it to Append(). That is, it is not correct to pass an interior pointer to Append().

The default implementation always returns the scratch buffer.

Parameters

  min_capacity | required minimum capacity of the returned buffer; must be non-negative
  desired_capacity_hint | desired capacity of the returned buffer; must be non-negative
  scratch | default caller-owned buffer
  scratch_capacity | capacity of the scratch buffer
  result_capacity | pointer to an integer which will be set to the capacity of the returned buffer

Returns
  a buffer with *result_capacity>=min_capacity

Stable:
  ICU 4.2

Reimplemented in icu::CheckedArrayByteSink.

The documentation for this class was generated from the following file:

- bytestream.h