ICU 72.1 72.1
Public Member Functions
icu::CheckedArrayByteSink Class Reference

Implementation of ByteSink that writes to a flat byte array, with bounds-checking: This sink will not write more than capacity bytes to outbuf. More...

#include <bytestream.h>

Inheritance diagram for icu::CheckedArrayByteSink:
icu::ByteSink icu::UMemory

Public Member Functions

 CheckedArrayByteSink (char *outbuf, int32_t capacity)
 Constructs a ByteSink that will write to outbuf[0..capacity-1]. More...
 
virtual ~CheckedArrayByteSink ()
 Destructor. More...
 
virtual CheckedArrayByteSinkReset ()
 Returns the sink to its original state, without modifying the buffer. More...
 
virtual void Append (const char *bytes, int32_t n) override
 Append "bytes[0,n-1]" 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) override
 Returns a writable buffer for appending and writes the buffer's capacity to *result_capacity. More...
 
int32_t NumberOfBytesWritten () const
 Returns the number of bytes actually written to the sink. More...
 
UBool Overflowed () const
 Returns true if any bytes were discarded, i.e., if there was an attempt to write more than 'capacity' bytes. More...
 
int32_t NumberOfBytesAppended () const
 Returns the number of bytes appended to the sink. More...
 
- Public Member Functions inherited from icu::ByteSink
 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

Implementation of ByteSink that writes to a flat byte array, with bounds-checking: This sink will not write more than capacity bytes to outbuf.

If more than capacity bytes are Append()ed, then excess bytes are ignored, and Overflowed() will return true. Overflow does not cause a runtime error.

Stable:
ICU 4.2

Definition at line 180 of file bytestream.h.

Constructor & Destructor Documentation

◆ CheckedArrayByteSink()

icu::CheckedArrayByteSink::CheckedArrayByteSink ( char *  outbuf,
int32_t  capacity 
)

Constructs a ByteSink that will write to outbuf[0..capacity-1].

Parameters
outbufbuffer to write to
capacitysize of the buffer
Stable:
ICU 4.2

◆ ~CheckedArrayByteSink()

virtual icu::CheckedArrayByteSink::~CheckedArrayByteSink ( )
virtual

Destructor.

Stable:
ICU 4.2

Member Function Documentation

◆ Append()

virtual void icu::CheckedArrayByteSink::Append ( const char *  bytes,
int32_t  n 
)
overridevirtual

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

Parameters
bytesthe pointer to the bytes
nthe number of bytes; must be non-negative
Stable:
ICU 4.2

Implements icu::ByteSink.

◆ GetAppendBuffer()

virtual char * icu::CheckedArrayByteSink::GetAppendBuffer ( int32_t  min_capacity,
int32_t  desired_capacity_hint,
char *  scratch,
int32_t  scratch_capacity,
int32_t *  result_capacity 
)
overridevirtual

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

For details see the base class documentation.

Parameters
min_capacityrequired minimum capacity of the returned buffer; must be non-negative
desired_capacity_hintdesired capacity of the returned buffer; must be non-negative
scratchdefault caller-owned buffer
scratch_capacitycapacity of the scratch buffer
result_capacitypointer 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 from icu::ByteSink.

◆ NumberOfBytesAppended()

int32_t icu::CheckedArrayByteSink::NumberOfBytesAppended ( ) const
inline

Returns the number of bytes appended to the sink.

If Overflowed() then NumberOfBytesAppended()>NumberOfBytesWritten() else they return the same number.

Returns
number of bytes written to the buffer
Stable:
ICU 4.6

Definition at line 248 of file bytestream.h.

◆ NumberOfBytesWritten()

int32_t icu::CheckedArrayByteSink::NumberOfBytesWritten ( ) const
inline

Returns the number of bytes actually written to the sink.

Returns
number of bytes written to the buffer
Stable:
ICU 4.2

Definition at line 233 of file bytestream.h.

◆ Overflowed()

UBool icu::CheckedArrayByteSink::Overflowed ( ) const
inline

Returns true if any bytes were discarded, i.e., if there was an attempt to write more than 'capacity' bytes.

Returns
true if more than 'capacity' bytes were Append()ed
Stable:
ICU 4.2

Definition at line 240 of file bytestream.h.

◆ Reset()

virtual CheckedArrayByteSink & icu::CheckedArrayByteSink::Reset ( )
virtual

Returns the sink to its original state, without modifying the buffer.

Useful for reusing both the buffer and the sink for multiple streams. Resets the state to NumberOfBytesWritten()=NumberOfBytesAppended()=0 and Overflowed()=false.

Returns
*this
Stable:
ICU 4.6

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