TSDuck v3.38-3696
MPEG Transport Stream Toolkit
Loading...
Searching...
No Matches
ts::PSIBuffer Class Reference

A specialized subclass of ts::Buffer for PSI serialization. More...

#include <tsPSIBuffer.h>

Inheritance diagram for ts::PSIBuffer:
Collaboration diagram for ts::PSIBuffer:

Public Member Functions

 PSIBuffer (DuckContext &duck, const Section &section)
 Constructor over the payload of a read-only section which must remain unmodified as long as the PSIBuffer object is used and not reset.
 
 PSIBuffer (DuckContext &duck, const void *data, size_t size)
 Constructor using a read-only external memory area which must remain valid as long as the PSIBuffer object is used and not reset.
 
 PSIBuffer (DuckContext &duck, size_t size=DEFAULT_SIZE)
 Default constructor.
 
 PSIBuffer (DuckContext &duck, void *data, size_t size, bool read_only=false)
 Constructor using an external memory area which must remain valid as long as the PSIBuffer object is used and not reset.
 
bool backBits (size_t bits)
 Skip read bits backward.
 
bool backBytes (size_t bytes)
 Skip read bytes backward.
 
bool canRead () const
 Check if we can still read from the buffer.
 
bool canReadBits (size_t bits) const
 Check if we can read at least the specified number of bits from the buffer.
 
bool canReadBytes (size_t bytes) const
 Check if we can read at least the specified number of bytes from the buffer.
 
bool canWrite () const
 Check if we can still write in the buffer.
 
bool canWriteBits (size_t bits) const
 Check if we can write at least the specified number of bits in the buffer.
 
bool canWriteBytes (size_t bytes) const
 Check if we can write at least the specified number of bytes in the buffer.
 
size_t capacity () const
 Get the maximum buffer size in bytes.
 
void clearError ()
 Clear all error states.
 
void clearReadError ()
 Clear the read error state.
 
void clearUserError ()
 Clear the user-generated error state.
 
void clearWriteError ()
 Clear the write error state.
 
const uint8_t * currentReadAddress () const
 Get starting address of current read data (ignoring bit offset inside first byte to read).
 
size_t currentReadBitOffset () const
 Get current read bit offset from the beginning of the buffer.
 
size_t currentReadByteOffset () const
 Get current read byte index (ignoring bit offset inside bytes).
 
size_t currentWriteBitOffset () const
 Get current write bit offset from the beginning of the buffer.
 
size_t currentWriteByteOffset () const
 Get current write byte index (ignoring bit offset inside bytes).
 
const uint8_t * data () const
 Get the current base address of the buffer.
 
bool dropState (size_t level=NPOS)
 Drop the last saved state of the read/write streams from the stack of saved states.
 
DuckContextduck () const
 Get a reference to the associated TSDuck execution context.
 
bool endOfRead () const
 Check end of read stream.
 
bool endOfWrite () const
 Check end of write stream.
 
bool error () const
 Check if there was any kind of error.
 
bool externalMemory () const
 Check if the buffer is linked to some external memory area.
 
template<typename INT , typename std::enable_if< std::is_integral< INT >::value >::type * = nullptr>
bool getBCD (INT &value, size_t bcd_count)
 Read the next 4*n bits as a Binary Coded Decimal (BCD) value and advance the read pointer.
 
template<typename INT , typename std::enable_if< std::is_integral< INT >::value >::type * = nullptr>
INT getBCD (size_t bcd_count)
 Read the next 4*n bits as a Binary Coded Decimal (BCD) value and advance the read pointer.
 
uint8_t getBit ()
 Read the next bit and advance the read pointer.
 
template<class Rep , class Period >
void getBits (cn::duration< Rep, Period > &value, size_t bits)
 Read the next n bits as a std::chrono::duration value and advance the read pointer.
 
template<typename INT , typename std::enable_if< std::is_integral< INT >::value >::type * = nullptr>
void getBits (INT &value, size_t bits)
 Read the next n bits as an integer value and advance the read pointer.
 
template<typename INT , typename std::enable_if< std::is_integral< INT >::value &&std::is_unsigned< INT >::value >::type * = nullptr>
INT getBits (size_t bits)
 Read the next n bits as an integer value and advance the read pointer.
 
template<typename INT , typename std::enable_if< std::is_integral< INT >::value >::type * = nullptr>
void getBits (std::optional< INT > &value, size_t bits)
 Read the next n bits as an integer value and advance the read pointer.
 
bool getBool ()
 Read the next bit as a boolean and advance the read pointer.
 
void getBytes (ByteBlock &bb, size_t bytes=NPOS)
 Get bulk bytes from the buffer.
 
ByteBlock getBytes (size_t bytes=NPOS)
 Get bulk bytes from the buffer.
 
size_t getBytes (uint8_t *buffer, size_t bytes)
 Get bulk bytes from the buffer.
 
size_t getBytesAppend (ByteBlock &bb, size_t bytes=NPOS)
 Get bulk bytes from the buffer.
 
Time getDateMJD ()
 Get the date part of a Modified Julian Date (MJD), the time part is ignored, 2 bytes.
 
bool getDescriptorList (DescriptorList &descs, size_t length=NPOS)
 Get (deserialize) a descriptor list.
 
bool getDescriptorListWithLength (DescriptorList &descs, size_t length_bits=12)
 Get (deserialize) a descriptor list with a 2-byte length field before the descriptor list.
 
ieee_float32_t getFloat32 ()
 Read the next 32 bits as an IEEE float value and advance the read pointer.
 
ieee_float64_t getFloat64 ()
 Read the next 64 bits as an IEEE float value and advance the read pointer.
 
Time getFullMJD ()
 Get a full Modified Julian Date (MJD), date and time, 5 bytes.
 
int16_t getInt16 ()
 Read the next 16 bits as a signed integer value and advance the read pointer.
 
int32_t getInt24 ()
 Read the next 24 bits as a signed integer value and advance the read pointer.
 
int32_t getInt32 ()
 Read the next 32 bits as a signed integer value and advance the read pointer.
 
int64_t getInt40 ()
 Read the next 40 bits as a signed integer value and advance the read pointer.
 
int64_t getInt48 ()
 Read the next 48 bits as a signed integer value and advance the read pointer.
 
int64_t getInt64 ()
 Read the next 64 bits as a signed integer value and advance the read pointer.
 
int8_t getInt8 ()
 Read the next 8 bits as a signed integer value and advance the read pointer.
 
UString getLanguageCode ()
 Read the next 24 bits as a 3-character language or country code and advance the read pointer.
 
bool getLanguageCode (UString &str)
 Read the next 24 bits as a 3-character language or country code and advance the read pointer.
 
template<class Rep , class Period >
void getMinutesBCD (cn::duration< Rep, Period > &duration)
 Get (deserialize) a duration in minutes as 4 BCD digits (HHMM), 2 bytes.
 
Time getMJD (size_t mjd_size)
 Get a Modified Julian Date (MJD), 2 to 5 bytes.
 
bool getMultipleString (ATSCMultipleString &mss, size_t mss_size=NPOS, bool ignore_empty=false)
 Get (deserialize) an ATSC multiple_string_structure() as defined in ATSC A/65.
 
bool getMultipleStringWithLength (ATSCMultipleString &mss, size_t length_bytes=1)
 Get (deserialize) an ATSC multiple_string_structure() as defined in ATSC A/65, with a leading byte length.
 
PID getPID ()
 Deserialize a 13-bit PID value.
 
template<class Rep , class Period >
void getSecondsBCD (cn::duration< Rep, Period > &duration)
 Get (deserialize) a duration in seconds as 6 BCD digits (HHMMSS), 3 bytes.
 
UString getString (size_t size=NPOS, const Charset *charset=nullptr)
 Get a string using the default input character set.
 
bool getString (UString &str, size_t size=NPOS, const Charset *charset=nullptr)
 Get a string using the default input character set.
 
UString getStringWithByteLength (const Charset *charset=nullptr)
 Get a string (preceded by its one-byte length) using the default input character set.
 
bool getStringWithByteLength (UString &str, const Charset *charset=nullptr)
 Get a string (preceded by its one-byte length) using the default input character set.
 
uint16_t getUInt16 ()
 Read the next 16 bits as an unsigned integer value and advance the read pointer.
 
uint32_t getUInt24 ()
 Read the next 24 bits as an unsigned integer value and advance the read pointer.
 
uint32_t getUInt32 ()
 Read the next 32 bits as an unsigned integer value and advance the read pointer.
 
uint64_t getUInt40 ()
 Read the next 40 bits as an unsigned integer value and advance the read pointer.
 
uint64_t getUInt48 ()
 Read the next 48 bits as an unsigned integer value and advance the read pointer.
 
uint64_t getUInt64 ()
 Read the next 64 bits as an unsigned integer value and advance the read pointer.
 
uint8_t getUInt8 ()
 Read the next 8 bits as an unsigned integer value and advance the read pointer.
 
size_t getUnalignedLength (size_t length_bits)
 Get a 2-byte integer length field, typically a length before a descriptor list.
 
UString getUTF16 (size_t bytes=NPOS)
 Get a UTF-16 string.
 
bool getUTF16 (UString &result, size_t bytes=NPOS)
 Get a UTF-16 string.
 
UString getUTF16WithLength (size_t length_bits=8)
 Get a UTF-16 string (preceded by its length).
 
bool getUTF16WithLength (UString &result, size_t length_bits=8)
 Get a UTF-16 string (preceded by its length).
 
UString getUTF8 (size_t bytes=NPOS)
 Get a UTF-8 string.
 
bool getUTF8 (UString &result, size_t bytes=NPOS)
 Get a UTF-8 string.
 
UString getUTF8WithLength (size_t length_bits=8)
 Get a UTF-8 string (preceded by its length).
 
bool getUTF8WithLength (UString &result, size_t length_bits=8)
 Get a UTF-8 string (preceded by its length).
 
uint64_t getVluimsbf5 ()
 Get (deserialize) an integer value in "vluimsbf5" format.
 
bool internalMemory () const
 Check if the buffer uses some internal private memory buffer.
 
bool isBigEndian () const
 Check if read/write operations of integers use big endian representation.
 
bool isLittleEndian () const
 Check if read/write operations of integers use little endian representation.
 
bool isNativeEndian () const
 Check if read/write operations of integers use the native endian representation.
 
bool isValid () const
 Check if the buffer is valid and contains some memory.
 
bool popState (size_t level=NPOS)
 Pop the current state of the read/write streams from the stack of saved states and perform appropriate actions.
 
size_t pushedLevels () const
 Get the current number of pushed states of the read/write streams.
 
size_t pushReadSize (size_t size)
 Temporary reduce the readable size of the buffer.
 
size_t pushReadSizeFromLength (size_t length_bits)
 Temporary reduce the readable size of the buffer using a length field from the stream.
 
size_t pushState ()
 Push the current state of the read/write streams on a stack of saved states.
 
size_t pushWriteSequenceWithLeadingLength (size_t length_bits)
 Start a write sequence with a leading length field.
 
size_t pushWriteSize (size_t size)
 Temporary reduce the writable size of the buffer.
 
template<typename INT , typename std::enable_if< std::is_integral< INT >::value >::type * = nullptr>
bool putBCD (INT value, size_t bcd_count)
 Put the next 4*n bits as a Binary Coded Decimal (BCD) value and advance the write pointer.
 
bool putBit (uint8_t bit)
 Write the next bit and advance the write pointer.
 
template<class Rep , class Period >
bool putBits (cn::duration< Rep, Period > value, size_t bits)
 Put the next n bits from a std::chrono::duration value and advance the write pointer.
 
template<typename INT , typename std::enable_if< std::is_integral< INT >::value >::type * = nullptr>
bool putBits (INT value, size_t bits)
 Put the next n bits from an integer value and advance the write pointer.
 
size_t putBytes (const ByteBlock &bb, size_t start=0, size_t count=NPOS)
 Put bulk bytes in the buffer.
 
size_t putBytes (const uint8_t *buffer, size_t bytes)
 Put bytes in the buffer.
 
bool putDateMJD (const Time &time)
 Put (serialize) the date part of a Modified Julian Date (MJD), the time part is ignored, 2 bytes.
 
bool putDescriptorList (const DescriptorList &descs, size_t start=0, size_t count=NPOS)
 Put (serialize) a complete descriptor list.
 
bool putDescriptorListWithLength (const DescriptorList &descs, size_t start=0, size_t count=NPOS, size_t length_bits=12)
 Put (serialize) a complete descriptor list with a 2-byte length field before the descriptor list.
 
bool putFixedUTF16 (const UString &str, size_t size, uint16_t pad=0, size_t start=0, size_t count=NPOS)
 Put a string using UTF-16 format with a fixed binary size (truncate or pad).
 
bool putFixedUTF8 (const UString &str, size_t size, uint8_t pad=0, size_t start=0, size_t count=NPOS)
 Put a string using UTF-8 format with a fixed binary size (truncate or pad).
 
bool putFloat32 (ieee_float32_t f)
 Write a 32-bit IEEE float value and advance the write pointer.
 
bool putFloat64 (ieee_float64_t f)
 Write a 64-bit IEEE float value and advance the write pointer.
 
bool putFullMJD (const Time &time)
 Put (serialize) a full Modified Julian Date (MJD), date and time, 5 bytes.
 
bool putInt16 (int16_t i)
 Write a 16-bit signed integer value and advance the write pointer.
 
bool putInt24 (int32_t i)
 Write a 24-bit signed integer value and advance the write pointer.
 
bool putInt32 (int32_t i)
 Write a 32-bit signed integer value and advance the write pointer.
 
bool putInt40 (int64_t i)
 Write a 40-bit signed integer value and advance the write pointer.
 
bool putInt48 (int64_t i)
 Write a 48-bit signed integer value and advance the write pointer.
 
bool putInt64 (int64_t i)
 Write a 64-bit signed integer value and advance the write pointer.
 
bool putInt8 (int8_t i)
 Write an 8-bit signed integer value and advance the write pointer.
 
bool putLanguageCode (const UString &str, bool allow_empty=false)
 Serialize a 3-byte language or country code and advance the write pointer.
 
template<class Rep , class Period >
bool putMinutesBCD (const cn::duration< Rep, Period > &duration)
 Put (serialize) a duration in minutes as 4 BCD digits (HHMM), 2 bytes.
 
bool putMJD (const Time &time, size_t mjd_size)
 Put (serialize) a Modified Julian Date (MJD), 2 to 5 bytes.
 
bool putMultipleString (const ATSCMultipleString &mss, size_t max_size=NPOS, bool ignore_empty=false)
 Put (serialize) an ATSC multiple_string_structure() as defined in ATSC A/65.
 
bool putMultipleStringWithLength (const ATSCMultipleString &mss, size_t length_bytes=1)
 Put (serialize) an ATSC multiple_string_structure() as defined in ATSC A/65, with a leading byte length.
 
size_t putPartialDescriptorList (const DescriptorList &descs, size_t start=0, size_t count=NPOS)
 Put (serialize) as many descriptors as possible from a descriptor list.
 
size_t putPartialDescriptorListWithLength (const DescriptorList &descs, size_t start=0, size_t count=NPOS, size_t length_bits=12)
 Put (serialize) as many descriptors as possible from a descriptor list with a 2-byte length field before the descriptor list.
 
size_t putPartialString (const UString &str, size_t start=0, size_t count=NPOS, const Charset *charset=nullptr)
 Put a partial string using the preferred output character set.
 
size_t putPartialStringWithByteLength (const UString &str, size_t start=0, size_t count=NPOS, const Charset *charset=nullptr)
 Put a partial string (preceded by its one-byte length) using the preferred output character set.
 
size_t putPartialUTF16 (const UString &str, size_t start=0, size_t count=NPOS)
 Put a partial string using UTF-8 format.
 
size_t putPartialUTF16WithLength (const UString &str, size_t start=0, size_t count=NPOS, size_t length_bits=8)
 Put a partial string (preceded by its length) using UTF-16 format.
 
size_t putPartialUTF8 (const UString &str, size_t start=0, size_t count=NPOS)
 Put a partial string using UTF-8 format.
 
size_t putPartialUTF8WithLength (const UString &str, size_t start=0, size_t count=NPOS, size_t length_bits=8)
 Put a partial string (preceded by its length) using UTF-8 format.
 
bool putPID (PID pid)
 Serialize a 13-bit PID value.
 
bool putReserved (size_t bits)
 Serialize the number of reserved '1' bits.
 
bool putReservedZero (size_t bits)
 Serialize the number of reserved '0' bits.
 
template<class Rep , class Period >
bool putSecondsBCD (const cn::duration< Rep, Period > &duration)
 Put (serialize) a duration in seconds as 6 BCD digits (HHMMSS), 3 bytes.
 
bool putString (const UString &str, size_t start=0, size_t count=NPOS, const Charset *charset=nullptr)
 Put a string using the preferred output character set.
 
bool putStringWithByteLength (const UString &str, size_t start=0, size_t count=NPOS, const Charset *charset=nullptr)
 Put a string (preceded by its one-byte length) using the preferred output character set.
 
bool putUInt16 (uint16_t i)
 Write a 16-bit unsigned integer value and advance the write pointer.
 
bool putUInt24 (uint32_t i)
 Write a 24-bit unsigned integer value and advance the write pointer.
 
bool putUInt32 (uint32_t i)
 Write a 32-bit unsigned integer value and advance the write pointer.
 
bool putUInt40 (uint64_t i)
 Write a 40-bit unsigned integer value and advance the write pointer.
 
bool putUInt48 (uint64_t i)
 Write a 48-bit unsigned integer value and advance the write pointer.
 
bool putUInt64 (uint64_t i)
 Write a 64-bit unsigned integer value and advance the write pointer.
 
bool putUInt8 (uint8_t i)
 Write an 8-bit unsigned integer value and advance the write pointer.
 
bool putUTF16 (const UString &str, size_t start=0, size_t count=NPOS)
 Put a string using UTF-16 format.
 
bool putUTF16WithLength (const UString &str, size_t start=0, size_t count=NPOS, size_t length_bits=8)
 Put a string (preceded by its length) using UTF-16 format.
 
bool putUTF8 (const UString &str, size_t start=0, size_t count=NPOS)
 Put a string using UTF-8 format.
 
bool putUTF8WithLength (const UString &str, size_t start=0, size_t count=NPOS, size_t length_bits=8)
 Put a string (preceded by its length) using UTF-8 format.
 
bool putVluimsbf5 (uint64_t value)
 Put (serialize) an integer value in "vluimsbf5" format.
 
bool readError () const
 Check if there was a read error.
 
bool readIsByteAligned () const
 Check if the current read bit pointer is on a byte boundary.
 
bool readOnly () const
 Check if the buffer is read-only.
 
bool readRealignByte ()
 Align the read pointer to the next byte boundary if not already aligned.
 
bool readSeek (size_t byte, size_t bit=0)
 Reset reading at the specified offset in the buffer.
 
size_t remainingReadBits () const
 Get number of remaining bits to read.
 
size_t remainingReadBytes () const
 Get number of remaining bytes to read (ignoring bit offset inside bytes).
 
size_t remainingWriteBits () const
 Get number of remaining bits to write.
 
size_t remainingWriteBytes () const
 Get number of remaining bytes to write (ignoring bit offset inside bytes).
 
bool reservedBitsError () const
 Check if there were "reserved bits errors".
 
UString reservedBitsErrorString (size_t base_offset=0, const UString &margin=UString())
 Return a string describing the "reserved bits errors".
 
void reset (const void *data, size_t size)
 Reset the buffer using a read-only external memory area which must remain valid as long as the Buffer object is used and not reset.
 
void reset (size_t size)
 Reset the buffer, remove link to any external memory, reallocate an internal buffer if necessary.
 
void reset (void *data, size_t size, bool read_only=false)
 Reset the buffer using an external memory area which must remain valid as long as the Buffer object is used and not reset.
 
bool resize (size_t size, bool reallocate)
 Change the usable size of the buffer.
 
void setBigEndian ()
 Specify that read/write operations of integers should use big endian representation.
 
void setLittleEndian ()
 Specify that read/write operations of integers should use little endian representation.
 
void setNativeEndian ()
 Specify that read/write operations of integers should use the native endian representation.
 
void setUserError ()
 Set the user-generated error state.
 
size_t size () const
 Get the current buffer size in bytes.
 
bool skipBits (size_t bits)
 Skip read bits forward.
 
bool skipBytes (size_t bytes)
 Skip read bytes forward (ignoring bit offset inside bytes).
 
bool skipReservedBits (size_t bits, int expected=1)
 Skip read reserved bits forward.
 
size_t swapState ()
 Swap the current state of the read/write streams with the one on top of the stack of saved states.
 
void switchEndian ()
 Switch the endianness of read/write operations of integers.
 
UString tryGetASCII (size_t bytes=NPOS)
 Try to get an ASCII string.
 
bool tryGetASCII (UString &result, size_t bytes=NPOS)
 Try to get an ASCII string.
 
bool userError () const
 Check if there was a user-generated error.
 
bool writeError () const
 Check if there was a write error.
 
bool writeIsByteAligned () const
 Check if the current write bit pointer is on a byte boundary.
 
bool writeRealignByte (int stuffing=0)
 Align the write pointer to the next byte boundary if not already aligned.
 
bool writeSeek (size_t byte, size_t bit, uint8_t stuffing)
 Reset writing at the specified offset in the buffer and trash forward memory.
 
bool writeSeek (size_t byte, size_t bit=0)
 Reset writing at the specified offset in the buffer.
 

Static Public Member Functions

static UString ReservedBitsErrorString (std::vector< size_t > &errors, size_t base_offset=0, const UString &margin=UString())
 This static method returns a string describing "reserved bits errors".
 

Static Public Attributes

static constexpr size_t DEFAULT_SIZE = 1024
 Default internal size in bytes of a buffer.
 
static constexpr size_t MINIMUM_SIZE = 16
 Minimal internal allocation size (capacity) in bytes of an internal private buffer.
 

Protected Member Functions

uint8_t * currentWriteAddress () const
 Get starting address of current write area (ignoring bit offset inside first byte to read).
 
void setReadError ()
 Set the read error state (reserved to subclasses).
 
void setWriteError ()
 Set the write error state (reserved to subclasses).
 

Detailed Description

A specialized subclass of ts::Buffer for PSI serialization.

Constructor & Destructor Documentation

◆ PSIBuffer() [1/4]

ts::PSIBuffer::PSIBuffer ( DuckContext duck,
size_t  size = DEFAULT_SIZE 
)
explicit

Default constructor.

The read and write index are at the beginning of the buffer. So, initially, there is nothing to read and the entire buffer to write.

Parameters
[in,out]duckReference to TSDuck execution context.
[in]sizeInitial internal size in bytes of the buffer.

◆ PSIBuffer() [2/4]

ts::PSIBuffer::PSIBuffer ( DuckContext duck,
void *  data,
size_t  size,
bool  read_only = false 
)

Constructor using an external memory area which must remain valid as long as the PSIBuffer object is used and not reset.

When read_only is true, the read index is at the beginning of the buffer and the write index is at the end of the buffer. When read_only is false, the read and write index are both at the beginning of the buffer.

Parameters
[in,out]duckReference to TSDuck execution context.
[in]dataAddress of data area to use as memory buffer.
[in]sizeSize in bytes of the data area.
[in]read_onlyThe buffer is read-only.

◆ PSIBuffer() [3/4]

ts::PSIBuffer::PSIBuffer ( DuckContext duck,
const void *  data,
size_t  size 
)

Constructor using a read-only external memory area which must remain valid as long as the PSIBuffer object is used and not reset.

The read index is at the beginning of the buffer and the write index is at the end of the buffer.

Parameters
[in,out]duckReference to TSDuck execution context.
[in]dataAddress of data area to use as memory buffer.
[in]sizeSize in bytes of the data area.

◆ PSIBuffer() [4/4]

ts::PSIBuffer::PSIBuffer ( DuckContext duck,
const Section section 
)

Constructor over the payload of a read-only section which must remain unmodified as long as the PSIBuffer object is used and not reset.

The read index is at the beginning of the section payload and the write index is at the end of the section payload.

Parameters
[in,out]duckReference to TSDuck execution context.
[in]sectionSection the payload of which is analysed by this PSIBuffer.

Member Function Documentation

◆ duck()

DuckContext & ts::PSIBuffer::duck ( ) const
inline

Get a reference to the associated TSDuck execution context.

Returns
A reference to the associated TSDuck execution context.

◆ getPID()

PID ts::PSIBuffer::getPID ( )

Deserialize a 13-bit PID value.

If the current read pointer is byte-aligned, 3 bits are skipped first. If the current read bit pointer is 3, the PID value is directly read. For all other read pointers, a read error is generated.

Returns
The decoded 13-bit PID value.

◆ putPID()

bool ts::PSIBuffer::putPID ( PID  pid)

Serialize a 13-bit PID value.

If the current write pointer is byte-aligned, 3 '1' bits are written first. If the current write bit pointer is 3, the PID value is directly written. For all other write pointers, a write error is generated.

Parameters
[in]pid13-bit PID value to write.
Returns
True on success, false if there is not enough space to write (and set write error flag).

◆ putLanguageCode()

bool ts::PSIBuffer::putLanguageCode ( const UString str,
bool  allow_empty = false 
)

Serialize a 3-byte language or country code and advance the write pointer.

Parameters
[in]strString to serialize. Generate a buffer error if not 3 characters long.
[in]allow_emptyIf true, an empty string is allowed and serialized as zeroes.
Returns
True on success, false if there is not enough space to write (and set write error flag).

◆ getLanguageCode() [1/2]

bool ts::PSIBuffer::getLanguageCode ( UString str)

Read the next 24 bits as a 3-character language or country code and advance the read pointer.

Set the read error flag if there are not enough bits to read or if the current read pointer is not at a byte boundary. Non-ASCII characters are ignored.

Parameters
[out]strReturned decoded string.
Returns
True on success, false on error (truncated, unsupported format, etc.)

◆ getLanguageCode() [2/2]

UString ts::PSIBuffer::getLanguageCode ( )

Read the next 24 bits as a 3-character language or country code and advance the read pointer.

Set the read error flag if there are not enough bits to read or if the current read pointer is not at a byte boundary. Non-ASCII characters are ignored.

Returns
The language or country code string.

◆ putString()

bool ts::PSIBuffer::putString ( const UString str,
size_t  start = 0,
size_t  count = NPOS,
const Charset charset = nullptr 
)
inline

Put a string using the preferred output character set.

Generate a write error when the buffer is full before writing the complete string.

Parameters
[in]strThe UTF-16 string to encode.
[in]startStarting offset to convert in this UTF-16 string.
[in]countMaximum number of characters to convert.
[in]charsetAn optional specific character set to use instead of the default one.
Returns
True on success, false if there is not enough space to write (and set write error flag).

◆ putPartialString()

size_t ts::PSIBuffer::putPartialString ( const UString str,
size_t  start = 0,
size_t  count = NPOS,
const Charset charset = nullptr 
)
inline

Put a partial string using the preferred output character set.

Stop either when this string is serialized or when the buffer is full, whichever comes first. Do not generate a write error when the buffer is full.

Parameters
[in]strThe UTF-16 string to encode.
[in]startStarting offset to convert in this UTF-16 string.
[in]countMaximum number of characters to convert.
[in]charsetAn optional specific character set to use instead of the default one.
Returns
The number of serialized characters (which is usually not the same as the number of written bytes).

◆ putStringWithByteLength()

bool ts::PSIBuffer::putStringWithByteLength ( const UString str,
size_t  start = 0,
size_t  count = NPOS,
const Charset charset = nullptr 
)
inline

Put a string (preceded by its one-byte length) using the preferred output character set.

Generate a write error when the buffer is full before writing the complete string.

Parameters
[in]strThe UTF-16 string to encode.
[in]startStarting offset to convert in this UTF-16 string.
[in]countMaximum number of characters to convert.
[in]charsetAn optional specific character set to use instead of the default one.
Returns
True on success, false if there is not enough space to write (and set write error flag).

◆ putPartialStringWithByteLength()

size_t ts::PSIBuffer::putPartialStringWithByteLength ( const UString str,
size_t  start = 0,
size_t  count = NPOS,
const Charset charset = nullptr 
)
inline

Put a partial string (preceded by its one-byte length) using the preferred output character set.

Stop either when this string is serialized or when the buffer is full, whichever comes first. Do not generate a write error when the buffer is full.

Parameters
[in]strThe UTF-16 string to encode.
[in]startStarting offset to convert in this UTF-16 string.
[in]countMaximum number of characters to convert.
[in]charsetAn optional specific character set to use instead of the default one.
Returns
The number of serialized characters (which is usually not the same as the number of written bytes).

◆ getString() [1/2]

bool ts::PSIBuffer::getString ( UString str,
size_t  size = NPOS,
const Charset charset = nullptr 
)

Get a string using the default input character set.

Parameters
[out]strReturned decoded string.
[in]sizeSize in bytes of the encoded string. If specified as NPOS (the default), read up to the end of the buffer. If different from NPOS, the exact number of bytes must be available or a read error is generated.
[in]charsetAn optional specific character set to use instead of the default one.
Returns
True on success, false on error (truncated, unsupported format, etc.)

◆ getString() [2/2]

UString ts::PSIBuffer::getString ( size_t  size = NPOS,
const Charset charset = nullptr 
)

Get a string using the default input character set.

Parameters
[in]sizeSize in bytes of the encoded string. If specified as NPOS (the default), read up to the end of the buffer. If different from NPOS, the exact number of bytes must be available or a read error is generated.
[in]charsetAn optional specific character set to use instead of the default one.
Returns
The decoded string.

◆ getStringWithByteLength() [1/2]

bool ts::PSIBuffer::getStringWithByteLength ( UString str,
const Charset charset = nullptr 
)

Get a string (preceded by its one-byte length) using the default input character set.

The specified number of bytes must be available or a read error is generated.

Parameters
[out]strReturned decoded string.
[in]charsetAn optional specific character set to use instead of the default one.
Returns
True on success, false on error (truncated, unsupported format, etc.)

◆ getStringWithByteLength() [2/2]

UString ts::PSIBuffer::getStringWithByteLength ( const Charset charset = nullptr)

Get a string (preceded by its one-byte length) using the default input character set.

The specified number of bytes must be available or a read error is generated.

Parameters
[in]charsetAn optional specific character set to use instead of the default one.
Returns
The decoded string.

◆ putFullMJD()

bool ts::PSIBuffer::putFullMJD ( const Time time)
inline

Put (serialize) a full Modified Julian Date (MJD), date and time, 5 bytes.

Generate a write error when the buffer is not large enough or when the write pointer is not byte-aligned.

Parameters
[in]timeThe date and time to serialize.
Returns
True on success, false if there is not enough space to write (and set write error flag).

◆ putDateMJD()

bool ts::PSIBuffer::putDateMJD ( const Time time)
inline

Put (serialize) the date part of a Modified Julian Date (MJD), the time part is ignored, 2 bytes.

Generate a write error when the buffer is not large enough or when the write pointer is not byte-aligned.

Parameters
[in]timeThe date to serialize.
Returns
True on success, false if there is not enough space to write (and set write error flag).

◆ putMJD()

bool ts::PSIBuffer::putMJD ( const Time time,
size_t  mjd_size 
)

Put (serialize) a Modified Julian Date (MJD), 2 to 5 bytes.

Generate a write error when the buffer is not large enough or when the write pointer is not byte-aligned.

Parameters
[in]timeThe date and time to serialize.
[in]mjd_sizeSize in bytes of the MJD area, 2 to 5 bytes.
Returns
True on success, false if there is not enough space to write (and set write error flag).

◆ getFullMJD()

Time ts::PSIBuffer::getFullMJD ( )
inline

Get a full Modified Julian Date (MJD), date and time, 5 bytes.

Generate a read error when there is not enough bytes or when the write pointer is not byte-aligned.

Returns
The deserialize date and time (Epoch on error).

◆ getDateMJD()

Time ts::PSIBuffer::getDateMJD ( )
inline

Get the date part of a Modified Julian Date (MJD), the time part is ignored, 2 bytes.

Generate a read error when there is not enough bytes or when the write pointer is not byte-aligned.

Returns
The deserialize date and time (Epoch on error).

◆ getMJD()

Time ts::PSIBuffer::getMJD ( size_t  mjd_size)

Get a Modified Julian Date (MJD), 2 to 5 bytes.

Generate a read error when there is not enough bytes or when the write pointer is not byte-aligned.

Parameters
[in]mjd_sizeSize in bytes of the MJD area, 2 to 5 bytes.
Returns
The deserialize date and time (Epoch on error).

◆ putMinutesBCD()

template<class Rep , class Period >
bool ts::PSIBuffer::putMinutesBCD ( const cn::duration< Rep, Period > &  duration)

Put (serialize) a duration in minutes as 4 BCD digits (HHMM), 2 bytes.

Generate a write error when the buffer is not large enough.

Parameters
[in]durationA duration in any std::chrono::duration type.
Returns
True on success, false if there is not enough space to write (and set write error flag).

◆ putSecondsBCD()

template<class Rep , class Period >
bool ts::PSIBuffer::putSecondsBCD ( const cn::duration< Rep, Period > &  duration)

Put (serialize) a duration in seconds as 6 BCD digits (HHMMSS), 3 bytes.

Generate a write error when the buffer is not large enough.

Parameters
[in]durationA duration in any std::chrono::duration type.
Returns
True on success, false if there is not enough space to write (and set write error flag).

◆ getMinutesBCD()

template<class Rep , class Period >
void ts::PSIBuffer::getMinutesBCD ( cn::duration< Rep, Period > &  duration)

Get (deserialize) a duration in minutes as 4 BCD digits (HHMM), 2 bytes.

Generate a read error when there is not enough bytes.

Parameters
[out]durationReturned duration, converted in any std::chrono::duration type.

◆ getSecondsBCD()

template<class Rep , class Period >
void ts::PSIBuffer::getSecondsBCD ( cn::duration< Rep, Period > &  duration)

Get (deserialize) a duration in seconds as 6 BCD digits (HHMMSS), 3 bytes.

Generate a read error when there is not enough bytes.

Parameters
[out]durationReturned duration, converted in any std::chrono::duration type.

◆ getVluimsbf5()

uint64_t ts::PSIBuffer::getVluimsbf5 ( )

Get (deserialize) an integer value in "vluimsbf5" format.

This weird format is defined in ISO/IEC 23005-6 as follow:

"vluimsbf5: Variable length unsigned integer most significant bit first representation consisting of two parts. The first part defines the number n of 4-bit fields used for the value representation, encoded by a sequence of n-1 "1" bits, followed by a "0" bit signaling its end. The second part contains the value of the integer encoded using the number of bit fields specified in the first part."

Very similar to the following (for connoisseurs only):

"And Saint Attila raised the hand grenade up on high, saying, 'O Lord, bless this thy hand grenade, that with it thou mayst blow thine enemies to tiny bits, in thy mercy.' And the Lord did grin. And the people did feast upon the lambs, and sloths, and carp, and anchovies, and orangutans, and breakfast cereals, and fruit bats, and large chulapas. And the Lord spake, saying, 'First shalt thou take out the Holy Pin. Then shalt thou count to three, no more, no less. Three shall be the number thou shalt count, and the number of the counting shall be three. Four shalt thou not count, neither count thou two, excepting that thou then proceed to three. Five is right out. Once the number three, being the third number, be reached, then lobbest thou thy Holy Hand Grenade of Antioch towards thy foe, who, being naughty in My sight, shall snuff it.'"

Generate a read error when there is not enough bytes.

Returns
The decoded integer value as a 64-bit integer.

◆ putVluimsbf5()

bool ts::PSIBuffer::putVluimsbf5 ( uint64_t  value)

Put (serialize) an integer value in "vluimsbf5" format.

Generate a write error when the buffer is not large enough.

Parameters
[in]valueAn integer to serialize.
Returns
True on success, false if there is not enough space to write (and set write error flag).
See also
getVluimsbf5()

◆ putDescriptorList()

bool ts::PSIBuffer::putDescriptorList ( const DescriptorList descs,
size_t  start = 0,
size_t  count = NPOS 
)

Put (serialize) a complete descriptor list.

Generate a write error when the buffer is not large enough to write all descriptors or when the write pointer is not byte-aligned.

Parameters
[in]descsThe descriptor list to serialize into the buffer.
[in]startStarting index in the descriptor list.
[in]countMaximum number of descriptors to serialize.
Returns
True on success, false if there is not enough space to write (and set write error flag).

◆ putPartialDescriptorList()

size_t ts::PSIBuffer::putPartialDescriptorList ( const DescriptorList descs,
size_t  start = 0,
size_t  count = NPOS 
)

Put (serialize) as many descriptors as possible from a descriptor list.

Generate a write error when the write pointer is not byte-aligned.

Parameters
[in]descsThe descriptor list to serialize into the buffer.
[in]startStarting index in the descriptor list.
[in]countMaximum number of descriptors to serialize.
Returns
The index of the first descriptor that could not be serialized (or descs.size() if all descriptors were serialized). In the first case, the returned index can be used as start parameter to serialized the rest of the list (in another section for instance).

◆ putDescriptorListWithLength()

bool ts::PSIBuffer::putDescriptorListWithLength ( const DescriptorList descs,
size_t  start = 0,
size_t  count = NPOS,
size_t  length_bits = 12 
)

Put (serialize) a complete descriptor list with a 2-byte length field before the descriptor list.

Generate a write error when the buffer is not large enough to write all descriptors or when the write pointer is not byte-aligned.

The 2-byte length field uses only its N least significant bits (length_bits) for the length of the descriptor list. If the current write pointer is byte-aligned, 16-N '1' bits are written first. If the current write bit pointer is 16-N, the length is directly written after that bit. For all other write pointers, a write error is generated.

Parameters
[in]descsThe descriptor list to serialize into the buffer.
[in]startStarting index in the descriptor list.
[in]countMaximum number of descriptors to serialize.
[in]length_bitsNumber of meaningful bits in the length field.
Returns
True on success, false if there is not enough space to write (and set write error flag).

◆ putPartialDescriptorListWithLength()

size_t ts::PSIBuffer::putPartialDescriptorListWithLength ( const DescriptorList descs,
size_t  start = 0,
size_t  count = NPOS,
size_t  length_bits = 12 
)

Put (serialize) as many descriptors as possible from a descriptor list with a 2-byte length field before the descriptor list.

The 2-byte length field uses only its N least significant bits (length_bits) for the length of the descriptor list. If the current write pointer is byte-aligned, 16-N '1' bits are written first. If the current write bit pointer is 16-N, the length is directly written after that bit. For all other write pointers, a write error is generated.

Parameters
[in]descsThe descriptor list to serialize into the buffer.
[in]startStarting index in the descriptor list.
[in]countMaximum number of descriptors to serialize.
[in]length_bitsNumber of meaningful bits in the length field.
Returns
The index of the first descriptor that could not be serialized (or descs.size() if all descriptors were serialized). In the first case, the returned index can be used as start parameter to serialized the rest of the list (in another section for instance).

◆ getDescriptorList()

bool ts::PSIBuffer::getDescriptorList ( DescriptorList descs,
size_t  length = NPOS 
)

Get (deserialize) a descriptor list.

Parameters
[in,out]descsThe descriptor list into which the deserialized descriptors are appended.
[in]lengthNumber of bytes to read. If NPOS is specified (the default), read the rest of the buffer.
Returns
True on success, false on error (truncated, misaligned, etc.)

◆ getDescriptorListWithLength()

bool ts::PSIBuffer::getDescriptorListWithLength ( DescriptorList descs,
size_t  length_bits = 12 
)

Get (deserialize) a descriptor list with a 2-byte length field before the descriptor list.

The 2-byte length field uses only its N least significant bits (length_bits) for the length of the descriptor list. If the current read pointer is byte-aligned, 16-N bits are skipped first. If the current read bit pointer is 16-N, the length is directly read after that bit. For all other read pointers, a read error is generated.

Parameters
[in,out]descsThe descriptor list into which the deserialized descriptors are appended.
[in]length_bitsNumber of meaningful bits in the length field.
Returns
True on success, false on error (truncated, misaligned, etc.)

◆ getUnalignedLength()

size_t ts::PSIBuffer::getUnalignedLength ( size_t  length_bits)

Get a 2-byte integer length field, typically a length before a descriptor list.

The 2-byte integer field uses only its N least significant bits (length_bits). If the current read pointer is byte-aligned, 16-N bits are skipped first. If the current read bit pointer is 16-N, the length is directly read after that bit. For all other read pointers, a read error is generated.

Parameters
[in]length_bitsNumber of meaningful bits in the integer field.
Returns
The integer value. Return zero on error. The returned value cannot be larger than the remaining number of bytes to read.

◆ getMultipleString()

bool ts::PSIBuffer::getMultipleString ( ATSCMultipleString mss,
size_t  mss_size = NPOS,
bool  ignore_empty = false 
)

Get (deserialize) an ATSC multiple_string_structure() as defined in ATSC A/65.

Parameters
[out]mssThe deserialized multiple_string_structure.
[in]mss_sizeOptional size of the multiple_string_structure to deserialize. If different from NPOS (the default), do not read more than mss_size bytes and move the read pointer after mss_size bytes, even if the multiple_string_structure is shorter.
[in]ignore_emptyIf true and there is nothing left to read, then this is a valid empty multiple_string_structure.
Returns
True on success, false on error (truncated, misaligned, etc.)

◆ getMultipleStringWithLength()

bool ts::PSIBuffer::getMultipleStringWithLength ( ATSCMultipleString mss,
size_t  length_bytes = 1 
)

Get (deserialize) an ATSC multiple_string_structure() as defined in ATSC A/65, with a leading byte length.

Parameters
[out]mssThe deserialized multiple_string_structure.
[in]length_bytesSize in bytes of the leading length field (1 byte by default).
Returns
True on success, false on error (truncated, misaligned, etc.)

◆ putMultipleString()

bool ts::PSIBuffer::putMultipleString ( const ATSCMultipleString mss,
size_t  max_size = NPOS,
bool  ignore_empty = false 
)

Put (serialize) an ATSC multiple_string_structure() as defined in ATSC A/65.

Parameters
[in]mssThe multiple_string_structure to serialize.
[in]max_sizeMax size to serialize, possibly lower than the buffer size.
[in]ignore_emptyIf true and the multiple_string_structure is empty, do nothing.
Returns
True on success, false on error (truncated, misaligned, etc.)

◆ putMultipleStringWithLength()

bool ts::PSIBuffer::putMultipleStringWithLength ( const ATSCMultipleString mss,
size_t  length_bytes = 1 
)

Put (serialize) an ATSC multiple_string_structure() as defined in ATSC A/65, with a leading byte length.

Parameters
[in]mssThe multiple_string_structure to serialize.
[in]length_bytesSize in bytes of the leading length field (1 byte by default).
Returns
True on success, false on error (truncated, misaligned, etc.)

◆ isValid()

bool ts::Buffer::isValid ( ) const
inherited

Check if the buffer is valid and contains some memory.

Returns
True if the buffer is valid and contains some memory.

◆ readOnly()

bool ts::Buffer::readOnly ( ) const
inlineinherited

Check if the buffer is read-only.

Returns
True if the buffer is read-only.

◆ internalMemory()

bool ts::Buffer::internalMemory ( ) const
inlineinherited

Check if the buffer uses some internal private memory buffer.

Returns
True if the buffer uses some internal private memory buffer.

◆ externalMemory()

bool ts::Buffer::externalMemory ( ) const
inlineinherited

Check if the buffer is linked to some external memory area.

Returns
True if the buffer is linked to some external memory area.

◆ capacity()

size_t ts::Buffer::capacity ( ) const
inlineinherited

Get the maximum buffer size in bytes.

Returns
The maximum buffer size in bytes.

◆ size()

size_t ts::Buffer::size ( ) const
inlineinherited

Get the current buffer size in bytes.

Returns
The current buffer size in bytes.

◆ data()

const uint8_t * ts::Buffer::data ( ) const
inlineinherited

Get the current base address of the buffer.

Returns
A constant pointer the base of the buffer.

◆ setBigEndian()

void ts::Buffer::setBigEndian ( )
inlineinherited

Specify that read/write operations of integers should use big endian representation.

The endianness of the buffer is not changed by the various reset() operations.

◆ setLittleEndian()

void ts::Buffer::setLittleEndian ( )
inlineinherited

Specify that read/write operations of integers should use little endian representation.

The endianness of the buffer is not changed by the various reset() operations.

◆ setNativeEndian()

void ts::Buffer::setNativeEndian ( )
inlineinherited

Specify that read/write operations of integers should use the native endian representation.

The endianness of the buffer is not changed by the various reset() operations.

◆ switchEndian()

void ts::Buffer::switchEndian ( )
inlineinherited

Switch the endianness of read/write operations of integers.

The endianness of the buffer is not changed by the various reset() operations.

◆ isBigEndian()

bool ts::Buffer::isBigEndian ( ) const
inlineinherited

Check if read/write operations of integers use big endian representation.

Returns
True if big endian is used, false if little endian.

◆ isLittleEndian()

bool ts::Buffer::isLittleEndian ( ) const
inlineinherited

Check if read/write operations of integers use little endian representation.

Returns
True if little endian is used, false if big endian.

◆ isNativeEndian()

bool ts::Buffer::isNativeEndian ( ) const
inlineinherited

Check if read/write operations of integers use the native endian representation.

Returns
True if the native endian is used, false otherwise.

◆ reset() [1/3]

void ts::Buffer::reset ( size_t  size)
inherited

Reset the buffer, remove link to any external memory, reallocate an internal buffer if necessary.

The read and write index are at the beginning of the buffer. So, initially, there is nothing to read and the entire buffer to write.

Parameters
[in]sizeInternal size in bytes of the buffer. If an internal buffer already exists and is larger than the requested size, it is not shrunk.

◆ reset() [2/3]

void ts::Buffer::reset ( void *  data,
size_t  size,
bool  read_only = false 
)
inherited

Reset the buffer using an external memory area which must remain valid as long as the Buffer object is used and not reset.

When read_only is true, the read index is at the beginning of the buffer and the write index is at the end of the buffer. When read_only is false, the read and write index are both at the beginning of the buffer.

Parameters
[in]dataAddress of data area to use as memory buffer.
[in]sizeSize in bytes of the data area.
[in]read_onlyThe buffer is read-only.

◆ reset() [3/3]

void ts::Buffer::reset ( const void *  data,
size_t  size 
)
inherited

Reset the buffer using a read-only external memory area which must remain valid as long as the Buffer object is used and not reset.

The read index is at the beginning of the buffer and the write index is at the end of the buffer.

Parameters
[in]dataAddress of data area to use as memory buffer.
[in]sizeSize in bytes of the data area.

◆ readError()

bool ts::Buffer::readError ( ) const
inlineinherited

Check if there was a read error.

Returns
True if there was a read error.

◆ writeError()

bool ts::Buffer::writeError ( ) const
inlineinherited

Check if there was a write error.

Returns
True if there was a write error.

◆ userError()

bool ts::Buffer::userError ( ) const
inlineinherited

Check if there was a user-generated error.

Returns
True if there was a user-generated error.
See also
setUserError()

◆ error()

bool ts::Buffer::error ( ) const
inlineinherited

Check if there was any kind of error.

Returns
True if there was any kind of error.

◆ setUserError()

void ts::Buffer::setUserError ( )
inlineinherited

Set the user-generated error state.

This can be used to indicate an application error such as invalid data format for instance.

◆ readSeek()

bool ts::Buffer::readSeek ( size_t  byte,
size_t  bit = 0 
)
inherited

Reset reading at the specified offset in the buffer.

Seeking past the write pointer moves the read pointer to the write pointer and generates a read error.

Parameters
[in]byteIndex of next byte to read.
[in]bitOffset of next bit to read in this byte.
Returns
True on success, false on error.

◆ writeSeek() [1/2]

bool ts::Buffer::writeSeek ( size_t  byte,
size_t  bit = 0 
)
inherited

Reset writing at the specified offset in the buffer.

Seeking backward beyon the read pointer moves the write pointer to the read pointer and generates a write error. Seeking forward past the end of buffer moves the write pointer to the end of the buffer and generates a write error.

Parameters
[in]byteIndex of next byte to write.
[in]bitOffset of next bit to write in this byte.
Returns
True on success, false on error.

◆ writeSeek() [2/2]

bool ts::Buffer::writeSeek ( size_t  byte,
size_t  bit,
uint8_t  stuffing 
)
inherited

Reset writing at the specified offset in the buffer and trash forward memory.

Seeking backward beyon the read pointer moves the write pointer to the read pointer and generates a write error. Seeking forward past the end of buffer moves the write pointer to the end of the buffer and generates a write error.

Parameters
[in]byteIndex of next byte to write.
[in]bitOffset of next bit to write in this byte.
[in]stuffingWhen seeking forward, byte value to write in skipped bytes.
Returns
True on success, false on error.

◆ readIsByteAligned()

bool ts::Buffer::readIsByteAligned ( ) const
inlineinherited

Check if the current read bit pointer is on a byte boundary.

Returns
True if the next bit to read is at the beginning of a byte.

◆ writeIsByteAligned()

bool ts::Buffer::writeIsByteAligned ( ) const
inlineinherited

Check if the current write bit pointer is on a byte boundary.

Returns
True if the next bit to write is at the beginning of a byte.

◆ readRealignByte()

bool ts::Buffer::readRealignByte ( )
inherited

Align the read pointer to the next byte boundary if not already aligned.

Skip any bit in a partially read byte.

Returns
True on success, false if would got beyond write pointer (and set read error flag).

◆ writeRealignByte()

bool ts::Buffer::writeRealignByte ( int  stuffing = 0)
inherited

Align the write pointer to the next byte boundary if not already aligned.

Fill bits in a partially written byte with a know value.

Parameters
[in]stuffingBit value (must be 0 or 1) to write in skipped bits.
Returns
Always true.

◆ skipBytes()

bool ts::Buffer::skipBytes ( size_t  bytes)
inherited

Skip read bytes forward (ignoring bit offset inside bytes).

Parameters
[in]bytesNumber of bytes to skip.
Returns
True on success, false if would got beyond write pointer (and set read error flag).

◆ skipBits()

bool ts::Buffer::skipBits ( size_t  bits)
inherited

Skip read bits forward.

Parameters
[in]bitsNumber of bits to skip.
Returns
True on success, false if would got beyond write pointer (and set read error flag).

◆ skipReservedBits()

bool ts::Buffer::skipReservedBits ( size_t  bits,
int  expected = 1 
)
inherited

Skip read reserved bits forward.

Parameters
[in]bitsNumber of reserved bits to skip.
[in]expectedExpected value of each reserved bit. Must be 0 or 1, default is 1. For each reserved bit which does not have the expected value, a "reserved bit error" is logged.
Returns
True on success, false if would got beyond write pointer (and set read error flag).
See also
reservedBitsError()

◆ reservedBitsError()

bool ts::Buffer::reservedBitsError ( ) const
inlineinherited

Check if there were "reserved bits errors".

Returns
True if there were "reserved bits errors".
See also
skipReservedBits()

◆ reservedBitsErrorString()

UString ts::Buffer::reservedBitsErrorString ( size_t  base_offset = 0,
const UString margin = UString() 
)
inlineinherited

Return a string describing the "reserved bits errors".

Parameters
[in]base_offsetArtificial base offset in bytes which is used to describe the placement of each bit error. When the Buffer instance describes the payload of a structure, specify the structure header size as base_offset in order to display each bit error relatively to the complete structure.
[in]marginPrepend that string to each line.
Returns
A string describing the "reserved bits errors". This is a mul
See also
skipReservedBits()

◆ ReservedBitsErrorString()

static UString ts::Buffer::ReservedBitsErrorString ( std::vector< size_t > &  errors,
size_t  base_offset = 0,
const UString margin = UString() 
)
staticinherited

This static method returns a string describing "reserved bits errors".

Parameters
[in,out]errorsA vector of error description. Each value is made of byte offset || bit offset (3 bits) || expected bit value (1 bit). The vector is sorted first.
[in]base_offsetArtificial base offset in bytes which is used to describe the placement of each bit error. When the Buffer instance describes the payload of a structure, specify the structure header size as base_offset in order to display each bit error relatively to the complete structure.
[in]marginPrepend that string to each line.
Returns
A string describing the "reserved bits errors". This is a mul
See also
skipReservedBits()

◆ backBytes()

bool ts::Buffer::backBytes ( size_t  bytes)
inherited

Skip read bytes backward.

Parameters
[in]bytesNumber of bytes to skip back.
Returns
True on success, false if would got beyond start of buffer (and set read error flag).

◆ backBits()

bool ts::Buffer::backBits ( size_t  bits)
inherited

Skip read bits backward.

Parameters
[in]bitsNumber of bits to skip back.
Returns
True on success, false if would got beyond start of buffer (and set read error flag).

◆ currentReadAddress()

const uint8_t * ts::Buffer::currentReadAddress ( ) const
inlineinherited

Get starting address of current read data (ignoring bit offset inside first byte to read).

Returns
The starting address of current read data.

◆ currentReadByteOffset()

size_t ts::Buffer::currentReadByteOffset ( ) const
inlineinherited

Get current read byte index (ignoring bit offset inside bytes).

Returns
The offset of the byte to read from the beginning of the buffer.

◆ currentReadBitOffset()

size_t ts::Buffer::currentReadBitOffset ( ) const
inlineinherited

Get current read bit offset from the beginning of the buffer.

Returns
The offset of the current bit to read from the beginning of the buffer.

◆ currentWriteByteOffset()

size_t ts::Buffer::currentWriteByteOffset ( ) const
inlineinherited

Get current write byte index (ignoring bit offset inside bytes).

Returns
The offset of the next byte to write from the beginning of the buffer.

◆ currentWriteBitOffset()

size_t ts::Buffer::currentWriteBitOffset ( ) const
inlineinherited

Get current write bit offset from the beginning of the buffer.

Returns
The offset of the next bit to write from the beginning of the buffer.

◆ remainingReadBytes()

size_t ts::Buffer::remainingReadBytes ( ) const
inherited

Get number of remaining bytes to read (ignoring bit offset inside bytes).

Returns
The number of remaining bytes to read.

◆ remainingReadBits()

size_t ts::Buffer::remainingReadBits ( ) const
inherited

Get number of remaining bits to read.

Returns
The number of remaining bits to read.

◆ remainingWriteBytes()

size_t ts::Buffer::remainingWriteBytes ( ) const
inherited

Get number of remaining bytes to write (ignoring bit offset inside bytes).

Returns
The number of remaining bytes to write.

◆ remainingWriteBits()

size_t ts::Buffer::remainingWriteBits ( ) const
inherited

Get number of remaining bits to write.

Returns
The number of remaining bits to write.

◆ endOfRead()

bool ts::Buffer::endOfRead ( ) const
inlineinherited

Check end of read stream.

Returns
True if the end of read stream is reached.

◆ endOfWrite()

bool ts::Buffer::endOfWrite ( ) const
inlineinherited

Check end of write stream.

Returns
True if the end of write stream is reached.

◆ canRead()

bool ts::Buffer::canRead ( ) const
inlineinherited

Check if we can still read from the buffer.

Returns
True if we can still read from the buffer.

◆ canReadBytes()

bool ts::Buffer::canReadBytes ( size_t  bytes) const
inlineinherited

Check if we can read at least the specified number of bytes from the buffer.

Parameters
[in]bytesNumber of bytes.
Returns
True if we can read at least bytes.

◆ canReadBits()

bool ts::Buffer::canReadBits ( size_t  bits) const
inlineinherited

Check if we can read at least the specified number of bits from the buffer.

Parameters
[in]bitsNumber of bits.
Returns
True if we can read at least bits.

◆ canWrite()

bool ts::Buffer::canWrite ( ) const
inlineinherited

Check if we can still write in the buffer.

Returns
True if we can still write in the buffer.

◆ canWriteBytes()

bool ts::Buffer::canWriteBytes ( size_t  bytes) const
inlineinherited

Check if we can write at least the specified number of bytes in the buffer.

Parameters
[in]bytesNumber of bytes.
Returns
True if we can write at least bytes.

◆ canWriteBits()

bool ts::Buffer::canWriteBits ( size_t  bits) const
inlineinherited

Check if we can write at least the specified number of bits in the buffer.

Parameters
[in]bitsNumber of bits.
Returns
True if we can write at least bits.

◆ pushState()

size_t ts::Buffer::pushState ( )
inherited

Push the current state of the read/write streams on a stack of saved states.

There is an internal stack of read/write states. It is possible to save the current state of the buffer, try to do some operations and then either restore (pop) the previous state if the attempted operations failed or drop the saved state and continue with the new state.

Returns
The level of pushed state (0 for the first push, then 1, etc.) The returned level can be used by popState() and dropState().
See also
popState()

◆ pushReadSize()

size_t ts::Buffer::pushReadSize ( size_t  size)
inherited

Temporary reduce the readable size of the buffer.

The previous state is pushed to the internal stack of state and can be restored later. Saving the readable size temporarily changes the write pointer and sets the buffer as read only. When the state is restored using popState(), the previous readable size (write pointer) and read-only indicator are restored. The read pointer is set to the end of previous readable size.

Parameters
[in]sizeNew readable size in bytes of the buffer. In some cases, the final granted size can be different. The final value is bounded by the current read and write pointers.
Returns
The level of pushed state (0 for the first push, then 1, etc.) Return NPOS on error.
See also
popState()

◆ pushReadSizeFromLength()

size_t ts::Buffer::pushReadSizeFromLength ( size_t  length_bits)
inherited

Temporary reduce the readable size of the buffer using a length field from the stream.

An integer value is read from the stream (given the value size in bits). The read pointer must then be byte-aligned. Finally, pushReadSize() is called so that the remaining number of bytes to read is the length value that was just read.

Parameters
[in]length_bitsSize in bits of the length field to read.
Returns
The level of pushed state (0 for the first push, then 1, etc.) Return NPOS on error.
See also
pushReadSize()

◆ pushWriteSize()

size_t ts::Buffer::pushWriteSize ( size_t  size)
inherited

Temporary reduce the writable size of the buffer.

The previous state is pushed to the internal stack of state and can be restored later. Saving the writable size temporarily changes the end of buffer. When the state is restored using popState(), the previous end of buffer is restored. The read and write pointers are not restored (everything that was read or written in the meantime remain valid).

Parameters
[in]sizeNew writable size in bytes of the buffer. In some cases, the final granted size can be different. The final value is bounded by the current write pointer and end of buffer.
Returns
The level of pushed state (0 for the first push, then 1, etc.) Return NPOS on error.
See also
popState()

◆ pushWriteSequenceWithLeadingLength()

size_t ts::Buffer::pushWriteSequenceWithLeadingLength ( size_t  length_bits)
inherited

Start a write sequence with a leading length field.

The current state is pushed and the specified number of bits are skipped in the write field. The write stream must then be byte-aligned or an error is generated. Writing data can be continued by the application. When popState() is called, the size in bytes starting after the length field is then written in the length field.

Parameters
[in]length_bitsSize in bits of the length field to write. Must be in the range 1 to 64.
Returns
The level of pushed state (0 for the first push, then 1, etc.) Return NPOS on error.
See also
popState()

◆ swapState()

size_t ts::Buffer::swapState ( )
inherited

Swap the current state of the read/write streams with the one on top of the stack of saved states.

The previous state must have been fully saved using pushState() only, not any other push method such as pushReadSize() or pushWriteSize(). Otherwise, the buffer is set in read and write error state.

As a result, the previously saved state is restored and the current state (just before restoring the saved state) is pushed. If there was no saved state, the current state is unchanged but still saved. So it is always safe to assume that the current state was saved.

Returns
The level of pushed state (0 for the first push, then 1, etc.) Return NPOS on error.

◆ popState()

bool ts::Buffer::popState ( size_t  level = NPOS)
inherited

Pop the current state of the read/write streams from the stack of saved states and perform appropriate actions.

The new state depends on which method was used to push the previous state.

Parameters
[in]levelSaved level to restore. The default is NPOS, meaning the last saved state. Another inner level can be specified, in which case all outer levels are also popped.
Returns
True on success. False if there is no saved state or level does not exist.
See also
pushState()
pushReadSize()
pushWriteSize()

◆ dropState()

bool ts::Buffer::dropState ( size_t  level = NPOS)
inherited

Drop the last saved state of the read/write streams from the stack of saved states.

Parameters
[in]levelSaved level to drop. The default is NPOS, meaning the last saved state. Another inner level can be specified, in which case the specified level and all outer levels are dropped.
Returns
True on success. False if there is no saved state or level does not exist.
See also
pushReadWriteState()

◆ pushedLevels()

size_t ts::Buffer::pushedLevels ( ) const
inlineinherited

Get the current number of pushed states of the read/write streams.

Returns
The current number of pushed states of the read/write streams.

◆ resize()

bool ts::Buffer::resize ( size_t  size,
bool  reallocate 
)
inherited

Change the usable size of the buffer.

Parameters
[in]sizeNew usable size in bytes of the buffer. In some cases, the final granted size can be different:
  • If size is lower than the current write pointer, the new usable size is set to the current write pointer.
  • If size is greater than the current capacity() and the buffer is an external memory or reallocate is false, the new usable size is set to the current capacity().
[in]reallocateIf true and the buffer is internally allocated, then reallocate the internal buffer to the final accepted size.
Returns
True in case of success. False if the requested size could not be granted. When the result is false, call size() to get the new actual buffer size.
See also
size()
capacity()

◆ getBit()

uint8_t ts::Buffer::getBit ( )
inherited

Read the next bit and advance the read pointer.

Returns
The value of the next bit.

◆ getBool()

bool ts::Buffer::getBool ( )
inlineinherited

Read the next bit as a boolean and advance the read pointer.

Returns
The value of the next bit.

◆ putBit()

bool ts::Buffer::putBit ( uint8_t  bit)
inherited

Write the next bit and advance the write pointer.

Parameters
[in]bitThe bit value (0 or 1).
Returns
True on success, false on error (read only or no more space to write).

◆ getBits() [1/4]

template<typename INT , typename std::enable_if< std::is_integral< INT >::value &&std::is_unsigned< INT >::value >::type * >
INT ts::Buffer::getBits ( size_t  bits)
inherited

Read the next n bits as an integer value and advance the read pointer.

Template Parameters
INTAn integer type for the result.
Parameters
[in]bitsNumber of bits to read.
Returns
The value of the next bits.

◆ getBits() [2/4]

template<typename INT , typename std::enable_if< std::is_integral< INT >::value >::type * = nullptr>
void ts::Buffer::getBits ( INT value,
size_t  bits 
)
inlineinherited

Read the next n bits as an integer value and advance the read pointer.

Template Parameters
INTAn integer type for the result.
Parameters
[out]valueThe value of the next bits.
[in]bitsNumber of bits to read.

◆ getBits() [3/4]

template<typename INT , typename std::enable_if< std::is_integral< INT >::value >::type * >
void ts::Buffer::getBits ( std::optional< INT > &  value,
size_t  bits 
)
inherited

Read the next n bits as an integer value and advance the read pointer.

Template Parameters
INTAn integer type for the result.
Parameters
[out]valueThe value of the next bits as a std::optional instance. If no integer can be read, the std::optional is unset.
[in]bitsNumber of bits to read.

◆ getBits() [4/4]

template<class Rep , class Period >
void ts::Buffer::getBits ( cn::duration< Rep, Period > &  value,
size_t  bits 
)
inherited

Read the next n bits as a std::chrono::duration value and advance the read pointer.

Parameters
[out]valueThe value of the next bits.
[in]bitsNumber of bits to read.

◆ putBits() [1/2]

template<typename INT , typename std::enable_if< std::is_integral< INT >::value >::type * >
bool ts::Buffer::putBits ( INT  value,
size_t  bits 
)
inherited

Put the next n bits from an integer value and advance the write pointer.

Template Parameters
INTAn integer type.
Parameters
[in]valueInteger value to write.
[in]bitsNumber of bits to write.
Returns
True on success, false on error (read only or no more space to write).

◆ putBits() [2/2]

template<class Rep , class Period >
bool ts::Buffer::putBits ( cn::duration< Rep, Period >  value,
size_t  bits 
)
inlineinherited

Put the next n bits from a std::chrono::duration value and advance the write pointer.

Parameters
[in]valueInteger value to write.
[in]bitsNumber of bits to write.
Returns
True on success, false on error (read only or no more space to write).

◆ putReserved()

bool ts::Buffer::putReserved ( size_t  bits)
inherited

Serialize the number of reserved '1' bits.

Parameters
[in]bitsNumber of reserved '1' bits to write.
Returns
True on success, false on error (read only or no more space to write).

◆ putReservedZero()

bool ts::Buffer::putReservedZero ( size_t  bits)
inlineinherited

Serialize the number of reserved '0' bits.

Parameters
[in]bitsNumber of reserved '0' bits to write.
Returns
True on success, false on error (read only or no more space to write).

◆ getBytes() [1/3]

size_t ts::Buffer::getBytes ( uint8_t *  buffer,
size_t  bytes 
)
inherited

Get bulk bytes from the buffer.

The bit aligment is ignored, reading starts at the current read byte pointer, even if a few bits were already read from that byte.

Parameters
[out]bufferAddress of the buffer receiving the read bytes.
[in]bytesNumber of bytes to read.
Returns
Actual number of returned bytes. If the requested number of bytes is not available, return as much as possible and set the read error.

◆ getBytes() [2/3]

ByteBlock ts::Buffer::getBytes ( size_t  bytes = NPOS)
inherited

Get bulk bytes from the buffer.

The bit aligment is ignored, reading starts at the current read byte pointer, even if a few bits were already read from that byte.

Parameters
[in]bytesNumber of bytes to read. If specified as NPOS, return all remaining bytes.
Returns
Read data as a byte block. If the requested number of bytes is not available, return as much as possible and set the read error.

◆ getBytes() [3/3]

void ts::Buffer::getBytes ( ByteBlock bb,
size_t  bytes = NPOS 
)
inherited

Get bulk bytes from the buffer.

The bit aligment is ignored, reading starts at the current read byte pointer, even if a few bits were already read from that byte.

Parameters
[out]bbByte block receiving the read bytes.
[in]bytesNumber of bytes to read. If specified as NPOS, return all remaining bytes.

◆ getBytesAppend()

size_t ts::Buffer::getBytesAppend ( ByteBlock bb,
size_t  bytes = NPOS 
)
inherited

Get bulk bytes from the buffer.

The bit aligment is ignored, reading starts at the current read byte pointer, even if a few bits were already read from that byte.

Parameters
[in,out]bbByte block receiving the read bytes. The read data are appended to bb.
[in]bytesNumber of bytes to read. If specified as NPOS, return all remaining bytes.
Returns
Actual number of appended bytes. If the requested number of bytes is not available, return as much as possible and set the read error.

◆ putBytes() [1/2]

size_t ts::Buffer::putBytes ( const uint8_t *  buffer,
size_t  bytes 
)
inherited

Put bytes in the buffer.

Parameters
[in]bufferAddress of the data to write.
[in]bytesNumber of bytes to write.
Returns
Actual number of written bytes. If the requested number of bytes is not available, write as much as possible and set the write error.

◆ putBytes() [2/2]

size_t ts::Buffer::putBytes ( const ByteBlock bb,
size_t  start = 0,
size_t  count = NPOS 
)
inherited

Put bulk bytes in the buffer.

The bit aligment is ignored, writing starts at the current write byte pointer, even if a few bits were already written in that byte.

Parameters
[in]bbByte block containing the data to write.
[in]startStart in index in bb.
[in]countNumber of bytes to write.
Returns
Actual number of written bytes. If the requested number of bytes is not available, write as much as possible and set the write error.

◆ getUInt8()

uint8_t ts::Buffer::getUInt8 ( )
inlineinherited

Read the next 8 bits as an unsigned integer value and advance the read pointer.

Set the read error flag if there are not enough bits to read.

Returns
The decoded integer value.

◆ getUInt16()

uint16_t ts::Buffer::getUInt16 ( )
inlineinherited

Read the next 16 bits as an unsigned integer value and advance the read pointer.

Set the read error flag if there are not enough bits to read.

Returns
The decoded integer value, according to the current endianness of the buffer.

◆ getUInt24()

uint32_t ts::Buffer::getUInt24 ( )
inlineinherited

Read the next 24 bits as an unsigned integer value and advance the read pointer.

Set the read error flag if there are not enough bits to read.

Returns
The decoded integer value, according to the current endianness of the buffer.

◆ getUInt32()

uint32_t ts::Buffer::getUInt32 ( )
inlineinherited

Read the next 32 bits as an unsigned integer value and advance the read pointer.

Set the read error flag if there are not enough bits to read.

Returns
The decoded integer value, according to the current endianness of the buffer.

◆ getUInt40()

uint64_t ts::Buffer::getUInt40 ( )
inlineinherited

Read the next 40 bits as an unsigned integer value and advance the read pointer.

Set the read error flag if there are not enough bits to read.

Returns
The decoded integer value, according to the current endianness of the buffer.

◆ getUInt48()

uint64_t ts::Buffer::getUInt48 ( )
inlineinherited

Read the next 48 bits as an unsigned integer value and advance the read pointer.

Set the read error flag if there are not enough bits to read.

Returns
The decoded integer value, according to the current endianness of the buffer.

◆ getUInt64()

uint64_t ts::Buffer::getUInt64 ( )
inlineinherited

Read the next 64 bits as an unsigned integer value and advance the read pointer.

Set the read error flag if there are not enough bits to read.

Returns
The decoded integer value, according to the current endianness of the buffer.

◆ getInt8()

int8_t ts::Buffer::getInt8 ( )
inlineinherited

Read the next 8 bits as a signed integer value and advance the read pointer.

Set the read error flag if there are not enough bits to read.

Returns
The decoded integer value.

◆ getInt16()

int16_t ts::Buffer::getInt16 ( )
inlineinherited

Read the next 16 bits as a signed integer value and advance the read pointer.

Set the read error flag if there are not enough bits to read.

Returns
The decoded integer value, according to the current endianness of the buffer.

◆ getInt24()

int32_t ts::Buffer::getInt24 ( )
inlineinherited

Read the next 24 bits as a signed integer value and advance the read pointer.

Set the read error flag if there are not enough bits to read.

Returns
The decoded integer value, according to the current endianness of the buffer.

◆ getInt32()

int32_t ts::Buffer::getInt32 ( )
inlineinherited

Read the next 32 bits as a signed integer value and advance the read pointer.

Set the read error flag if there are not enough bits to read.

Returns
The decoded integer value, according to the current endianness of the buffer.

◆ getInt40()

int64_t ts::Buffer::getInt40 ( )
inlineinherited

Read the next 40 bits as a signed integer value and advance the read pointer.

Set the read error flag if there are not enough bits to read.

Returns
The decoded integer value, according to the current endianness of the buffer.

◆ getInt48()

int64_t ts::Buffer::getInt48 ( )
inlineinherited

Read the next 48 bits as a signed integer value and advance the read pointer.

Set the read error flag if there are not enough bits to read.

Returns
The decoded integer value, according to the current endianness of the buffer.

◆ getInt64()

int64_t ts::Buffer::getInt64 ( )
inlineinherited

Read the next 64 bits as a signed integer value and advance the read pointer.

Set the read error flag if there are not enough bits to read.

Returns
The decoded integer value, according to the current endianness of the buffer.

◆ getFloat32()

ieee_float32_t ts::Buffer::getFloat32 ( )
inlineinherited

Read the next 32 bits as an IEEE float value and advance the read pointer.

Set the read error flag if there are not enough bits to read.

Returns
The decoded IEEE float value, according to the current endianness of the buffer.

◆ getFloat64()

ieee_float64_t ts::Buffer::getFloat64 ( )
inlineinherited

Read the next 64 bits as an IEEE float value and advance the read pointer.

Set the read error flag if there are not enough bits to read.

Returns
The decoded IEEE float value, according to the current endianness of the buffer.

◆ putUInt8()

bool ts::Buffer::putUInt8 ( uint8_t  i)
inlineinherited

Write an 8-bit unsigned integer value and advance the write pointer.

Parameters
[in]i8-bit unsigned integer value to write.
Returns
True on success, false if there is not enough space to write (and set write error flag).

◆ putUInt16()

bool ts::Buffer::putUInt16 ( uint16_t  i)
inlineinherited

Write a 16-bit unsigned integer value and advance the write pointer.

Parameters
[in]i16-bit unsigned integer value to write.
Returns
True on success, false if there is not enough space to write (and set write error flag).

◆ putUInt24()

bool ts::Buffer::putUInt24 ( uint32_t  i)
inlineinherited

Write a 24-bit unsigned integer value and advance the write pointer.

Parameters
[in]i24-bit unsigned integer value to write.
Returns
True on success, false if there is not enough space to write (and set write error flag).

◆ putUInt32()

bool ts::Buffer::putUInt32 ( uint32_t  i)
inlineinherited

Write a 32-bit unsigned integer value and advance the write pointer.

Parameters
[in]i32-bit unsigned integer value to write.
Returns
True on success, false if there is not enough space to write (and set write error flag).

◆ putUInt40()

bool ts::Buffer::putUInt40 ( uint64_t  i)
inlineinherited

Write a 40-bit unsigned integer value and advance the write pointer.

Parameters
[in]i40-bit unsigned integer value to write.
Returns
True on success, false if there is not enough space to write (and set write error flag).

◆ putUInt48()

bool ts::Buffer::putUInt48 ( uint64_t  i)
inlineinherited

Write a 48-bit unsigned integer value and advance the write pointer.

Parameters
[in]i48-bit unsigned integer value to write.
Returns
True on success, false if there is not enough space to write (and set write error flag).

◆ putUInt64()

bool ts::Buffer::putUInt64 ( uint64_t  i)
inlineinherited

Write a 64-bit unsigned integer value and advance the write pointer.

Parameters
[in]i64-bit unsigned integer value to write.
Returns
True on success, false if there is not enough space to write (and set write error flag).

◆ putInt8()

bool ts::Buffer::putInt8 ( int8_t  i)
inlineinherited

Write an 8-bit signed integer value and advance the write pointer.

Parameters
[in]i8-bit signed integer value to write.
Returns
True on success, false if there is not enough space to write (and set write error flag).

◆ putInt16()

bool ts::Buffer::putInt16 ( int16_t  i)
inlineinherited

Write a 16-bit signed integer value and advance the write pointer.

Parameters
[in]i16-bit signed integer value to write.
Returns
True on success, false if there is not enough space to write (and set write error flag).

◆ putInt24()

bool ts::Buffer::putInt24 ( int32_t  i)
inlineinherited

Write a 24-bit signed integer value and advance the write pointer.

Parameters
[in]i24-bit signed integer value to write.
Returns
True on success, false if there is not enough space to write (and set write error flag).

◆ putInt32()

bool ts::Buffer::putInt32 ( int32_t  i)
inlineinherited

Write a 32-bit signed integer value and advance the write pointer.

Parameters
[in]i32-bit signed integer value to write.
Returns
True on success, false if there is not enough space to write (and set write error flag).

◆ putInt40()

bool ts::Buffer::putInt40 ( int64_t  i)
inlineinherited

Write a 40-bit signed integer value and advance the write pointer.

Parameters
[in]i40-bit signed integer value to write.
Returns
True on success, false if there is not enough space to write (and set write error flag).

◆ putInt48()

bool ts::Buffer::putInt48 ( int64_t  i)
inlineinherited

Write a 48-bit signed integer value and advance the write pointer.

Parameters
[in]i48-bit signed integer value to write.
Returns
True on success, false if there is not enough space to write (and set write error flag).

◆ putInt64()

bool ts::Buffer::putInt64 ( int64_t  i)
inlineinherited

Write a 64-bit signed integer value and advance the write pointer.

Parameters
[in]i64-bit signed integer value to write.
Returns
True on success, false if there is not enough space to write (and set write error flag).

◆ putFloat32()

bool ts::Buffer::putFloat32 ( ieee_float32_t  f)
inlineinherited

Write a 32-bit IEEE float value and advance the write pointer.

Parameters
[in]f32-bit IEEE float value to write.
Returns
True on success, false if there is not enough space to write (and set write error flag).

◆ putFloat64()

bool ts::Buffer::putFloat64 ( ieee_float64_t  f)
inlineinherited

Write a 64-bit IEEE float value and advance the write pointer.

Parameters
[in]f32-bit IEEE float value to write.
Returns
True on success, false if there is not enough space to write (and set write error flag).

◆ getBCD() [1/2]

template<typename INT , typename std::enable_if< std::is_integral< INT >::value >::type * >
INT ts::Buffer::getBCD ( size_t  bcd_count)
inherited

Read the next 4*n bits as a Binary Coded Decimal (BCD) value and advance the read pointer.

If an invalid BCD digit is found, the read error state of the buffer is set after reading all BCD digits.

Template Parameters
INTAn integer type.
Parameters
[in]bcd_countNumber of BCD digits (bcd_count * 4 bits).
Returns
The decoded BCD value or zero in case of error.

◆ getBCD() [2/2]

template<typename INT , typename std::enable_if< std::is_integral< INT >::value >::type * >
bool ts::Buffer::getBCD ( INT value,
size_t  bcd_count 
)
inherited

Read the next 4*n bits as a Binary Coded Decimal (BCD) value and advance the read pointer.

If an invalid BCD digit is found, the read error state of the buffer is set after reading all BCD digits.

Template Parameters
INTAn integer type.
Parameters
[out]valueThe decoded BCD value or zero in case of error.
[in]bcd_countNumber of BCD digits (bcd_count * 4 bits).
Returns
True on success, false on error.

◆ putBCD()

template<typename INT , typename std::enable_if< std::is_integral< INT >::value >::type * >
bool ts::Buffer::putBCD ( INT  value,
size_t  bcd_count 
)
inherited

Put the next 4*n bits as a Binary Coded Decimal (BCD) value and advance the write pointer.

Template Parameters
INTAn integer type.
Parameters
[in]valueInteger value to write.
[in]bcd_countNumber of BCD digits (bcd_count * 4 bits).
Returns
True on success, false on error (read only or no more space to write).

◆ tryGetASCII() [1/2]

bool ts::Buffer::tryGetASCII ( UString result,
size_t  bytes = NPOS 
)
inherited

Try to get an ASCII string.

The read-pointer must be byte-aligned. If all bytes are valid ASCII characters (optionally zero-padded), the corresponding string is returned and the read pointer is moved. If the corresponding area is not a valid ASCII string (optionally zero-padded), do not move the read pointer and return an empty string.

Parameters
[out]resultReturned ASCII string. If the binary area is zero-padded, the trailing zeroes are not included in the string. This means that result can be shorter than bytes.
[in]bytesSize in bytes of the string. If specified as NPOS (the default), read up to the end of the buffer. If different from NPOS, the exact number of bytes must be available or a read error is generated.
Returns
True on success, false on error. Also return false when the binary area is not a valid ASCII string (optionally zero-padded), but do not generate a read error (it was just a try).

◆ tryGetASCII() [2/2]

UString ts::Buffer::tryGetASCII ( size_t  bytes = NPOS)
inherited

Try to get an ASCII string.

The read-pointer must be byte-aligned. If all bytes are valid ASCII characters (optionally zero-padded), the corresponding string is returned and the read pointer is moved. If the corresponding area is not a valid ASCII string (optionally zero-padded), do not move the read pointer and return an empty string.

Parameters
[in]bytesSize in bytes of the string. If specified as NPOS (the default), read up to the end of the buffer. If different from NPOS, the exact number of bytes must be available or a read error is generated.
Returns
The ASCII string. If the binary area is zero-padded, the trailing zeroes are not included in the string. This means that result can be shorter than bytes. Return an empty string when the entire binary area is not a valid ASCII string (optionally zero-padded), but do not generate a read error (it was just a try).

◆ getUTF8() [1/2]

bool ts::Buffer::getUTF8 ( UString result,
size_t  bytes = NPOS 
)
inlineinherited

Get a UTF-8 string.

The read-pointer must be byte-aligned.

Parameters
[out]resultReturned decoded string.
[in]bytesSize in bytes of the encoded UTF-8 string. If specified as NPOS (the default), read up to the end of the buffer. If different from NPOS, the exact number of bytes must be available or a read error is generated.
Returns
True on success, false on error.

◆ getUTF8() [2/2]

UString ts::Buffer::getUTF8 ( size_t  bytes = NPOS)
inlineinherited

Get a UTF-8 string.

The read-pointer must be byte-aligned.

Parameters
[in]bytesSize in bytes of the encoded UTF-8 string. If specified as NPOS (the default), read up to the end of the buffer. If different from NPOS, the exact number of bytes must be available or a read error is generated.
Returns
The decoded string.

◆ getUTF8WithLength() [1/2]

bool ts::Buffer::getUTF8WithLength ( UString result,
size_t  length_bits = 8 
)
inlineinherited

Get a UTF-8 string (preceded by its length).

The read-pointer must be byte-aligned after reading the length-field. The specified number of bytes must be available or a read error is generated.

Parameters
[out]resultReturned decoded string.
[in]length_bitsSize in bits in the length field.
Returns
True on success, false on error (truncated, unsupported format, etc.)

◆ getUTF8WithLength() [2/2]

UString ts::Buffer::getUTF8WithLength ( size_t  length_bits = 8)
inlineinherited

Get a UTF-8 string (preceded by its length).

The read-pointer must be byte-aligned after reading the length-field. The specified number of bytes must be available or a read error is generated.

Parameters
[in]length_bitsSize in bits in the length field.
Returns
The decoded string.

◆ getUTF16() [1/2]

bool ts::Buffer::getUTF16 ( UString result,
size_t  bytes = NPOS 
)
inlineinherited

Get a UTF-16 string.

The read-pointer must be byte-aligned.

Parameters
[out]resultReturned decoded string.
[in]bytesSize in bytes of the encoded UTF-16 string. If specified as NPOS (the default), read up to the end of the buffer. If different from NPOS, the exact number of bytes must be available or a read error is generated. If bytes is an odd value, the last byte is skipped and ignored.
Returns
True on success, false on error.

◆ getUTF16() [2/2]

UString ts::Buffer::getUTF16 ( size_t  bytes = NPOS)
inlineinherited

Get a UTF-16 string.

The read-pointer must be byte-aligned.

Parameters
[in]bytesSize in bytes of the encoded UTF-16 string. If specified as NPOS (the default), read up to the end of the buffer. If different from NPOS, the exact number of bytes must be available or a read error is generated. If bytes is an odd value, the last byte is skipped and ignored.
Returns
The decoded string.

◆ getUTF16WithLength() [1/2]

bool ts::Buffer::getUTF16WithLength ( UString result,
size_t  length_bits = 8 
)
inlineinherited

Get a UTF-16 string (preceded by its length).

The read-pointer must be byte-aligned after reading the length-field. The specified number of bytes must be available or a read error is generated. If the extracted length is an odd value, the last byte is skipped and ignored.

Parameters
[out]resultReturned decoded string.
[in]length_bitsSize in bits in the length field.
Returns
True on success, false on error (truncated, unsupported format, etc.)

◆ getUTF16WithLength() [2/2]

UString ts::Buffer::getUTF16WithLength ( size_t  length_bits = 8)
inlineinherited

Get a UTF-16 string (preceded by its length).

The read-pointer must be byte-aligned after reading the length-field. The specified number of bytes must be available or a read error is generated. If the extracted length is an odd value, the last byte is skipped and ignored.

Parameters
[in]length_bitsSize in bits in the length field.
Returns
The decoded string.

◆ putUTF8()

bool ts::Buffer::putUTF8 ( const UString str,
size_t  start = 0,
size_t  count = NPOS 
)
inlineinherited

Put a string using UTF-8 format.

The write-pointer must be byte-aligned. Generate a write error when the buffer is full before writing the complete string.

Parameters
[in]strThe UTF-16 string to encode.
[in]startStarting offset to convert in this UTF-16 string.
[in]countMaximum number of characters to convert.
Returns
True on success, false if there is not enough space to write (and set write error flag).

◆ putFixedUTF8()

bool ts::Buffer::putFixedUTF8 ( const UString str,
size_t  size,
uint8_t  pad = 0,
size_t  start = 0,
size_t  count = NPOS 
)
inlineinherited

Put a string using UTF-8 format with a fixed binary size (truncate or pad).

The write-pointer must be byte-aligned. Generate a write error when the buffer is full before writing the complete string.

Parameters
[in]strThe UTF-16 string to encode.
[in]sizeFixed size in bytes to fill. If str cannot be fully serialized, it is truncated.
[in]padIt str does not fill size bytes, pad the remaining bytes with this value.
[in]startStarting offset to convert in this UTF-16 string.
[in]countMaximum number of characters to convert.
Returns
True on success, false if there is not enough space to write (and set write error flag).

◆ putPartialUTF8()

size_t ts::Buffer::putPartialUTF8 ( const UString str,
size_t  start = 0,
size_t  count = NPOS 
)
inlineinherited

Put a partial string using UTF-8 format.

The write-pointer must be byte-aligned. Stop either when this string is serialized or when the buffer is full, whichever comes first. Do not generate a write error when the buffer is full.

Parameters
[in]strThe UTF-16 string to encode.
[in]startStarting offset to convert in this UTF-16 string.
[in]countMaximum number of characters to convert.
Returns
The number of serialized characters (which is usually not the same as the number of written bytes).

◆ putUTF8WithLength()

bool ts::Buffer::putUTF8WithLength ( const UString str,
size_t  start = 0,
size_t  count = NPOS,
size_t  length_bits = 8 
)
inlineinherited

Put a string (preceded by its length) using UTF-8 format.

The write-pointer must be byte-aligned after writing the length-field. Generate a write error when the buffer is full before writing the complete string.

Parameters
[in]strThe UTF-16 string to encode.
[in]startStarting offset to convert in this UTF-16 string.
[in]countMaximum number of characters to convert.
[in]length_bitsSize in bits in the length field.
Returns
True on success, false if there is not enough space to write (and set write error flag).

◆ putPartialUTF8WithLength()

size_t ts::Buffer::putPartialUTF8WithLength ( const UString str,
size_t  start = 0,
size_t  count = NPOS,
size_t  length_bits = 8 
)
inlineinherited

Put a partial string (preceded by its length) using UTF-8 format.

The write-pointer must be byte-aligned after writing the length-field. Do not generate a write error when the buffer is full.

Parameters
[in]strThe UTF-16 string to encode.
[in]startStarting offset to convert in this UTF-16 string.
[in]countMaximum number of characters to convert.
[in]length_bitsSize in bits in the length field.
Returns
The number of serialized characters (which is usually not the same as the number of written bytes).

◆ putUTF16()

bool ts::Buffer::putUTF16 ( const UString str,
size_t  start = 0,
size_t  count = NPOS 
)
inlineinherited

Put a string using UTF-16 format.

The write-pointer must be byte-aligned. Generate a write error when the buffer is full before writing the complete string.

Parameters
[in]strThe UTF-16 string to encode.
[in]startStarting offset to convert in this UTF-16 string.
[in]countMaximum number of characters to convert.
Returns
True on success, false if there is not enough space to write (and set write error flag).

◆ putFixedUTF16()

bool ts::Buffer::putFixedUTF16 ( const UString str,
size_t  size,
uint16_t  pad = 0,
size_t  start = 0,
size_t  count = NPOS 
)
inlineinherited

Put a string using UTF-16 format with a fixed binary size (truncate or pad).

The write-pointer must be byte-aligned. Generate a write error when the buffer is full before writing the complete string.

Parameters
[in]strThe UTF-16 string to encode.
[in]sizeFixed size in bytes to fill. If str cannot be fully serialized, it is truncated.
[in]padIt str does not fill size bytes, serialize the remaining UTF-16 characters with this value. If size has an odd value, the last byte is padded with the least significant byte of pad.
[in]startStarting offset to convert in this UTF-16 string.
[in]countMaximum number of characters to convert.
Returns
True on success, false if there is not enough space to write (and set write error flag).

◆ putPartialUTF16()

size_t ts::Buffer::putPartialUTF16 ( const UString str,
size_t  start = 0,
size_t  count = NPOS 
)
inlineinherited

Put a partial string using UTF-8 format.

The write-pointer must be byte-aligned. Stop either when this string is serialized or when the buffer is full, whichever comes first. Do not generate a write error when the buffer is full.

Parameters
[in]strThe UTF-16 string to encode.
[in]startStarting offset to convert in this UTF-16 string.
[in]countMaximum number of characters to convert.
Returns
The number of serialized characters (which is usually not the same as the number of written bytes).

◆ putUTF16WithLength()

bool ts::Buffer::putUTF16WithLength ( const UString str,
size_t  start = 0,
size_t  count = NPOS,
size_t  length_bits = 8 
)
inlineinherited

Put a string (preceded by its length) using UTF-16 format.

The write-pointer must be byte-aligned after writing the length-field. Generate a write error when the buffer is full before writing the complete string.

Parameters
[in]strThe UTF-16 string to encode.
[in]startStarting offset to convert in this UTF-16 string.
[in]countMaximum number of characters to convert.
[in]length_bitsSize in bits in the length field.
Returns
True on success, false if there is not enough space to write (and set write error flag).

◆ putPartialUTF16WithLength()

size_t ts::Buffer::putPartialUTF16WithLength ( const UString str,
size_t  start = 0,
size_t  count = NPOS,
size_t  length_bits = 8 
)
inlineinherited

Put a partial string (preceded by its length) using UTF-16 format.

The write-pointer must be byte-aligned after writing the length-field. Do not generate a write error when the buffer is full.

Parameters
[in]strThe UTF-16 string to encode.
[in]startStarting offset to convert in this UTF-16 string.
[in]countMaximum number of characters to convert.
[in]length_bitsSize in bits in the length field.
Returns
The number of serialized characters (which is usually not the same as the number of written bytes).

◆ currentWriteAddress()

uint8_t * ts::Buffer::currentWriteAddress ( ) const
inlineprotectedinherited

Get starting address of current write area (ignoring bit offset inside first byte to read).

This operation is reserved to subclasses. Applications can only get a read-only pointer to the current read area (see currentReadAddress()).

Returns
The starting address of current write area.

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