BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bslx::ByteOutStream Class Reference

#include <bslx_byteoutstream.h>

Public Member Functions

 ByteOutStream (int versionSelector, bslma::Allocator *basicAllocator=0)
 
 ByteOutStream (int versionSelector, bsl::size_t initialCapacity, bslma::Allocator *basicAllocator=0)
 
 ~ByteOutStream ()
 Destroy this object.
 
void invalidate ()
 
ByteOutStreamputLength (int length)
 
ByteOutStreamputVersion (int version)
 
void reserveCapacity (bsl::size_t newCapacity)
 
void reset ()
 
ByteOutStreamputInt64 (bsls::Types::Int64 value)
 
ByteOutStreamputUint64 (bsls::Types::Uint64 value)
 
ByteOutStreamputInt56 (bsls::Types::Int64 value)
 
ByteOutStreamputUint56 (bsls::Types::Uint64 value)
 
ByteOutStreamputInt48 (bsls::Types::Int64 value)
 
ByteOutStreamputUint48 (bsls::Types::Uint64 value)
 
ByteOutStreamputInt40 (bsls::Types::Int64 value)
 
ByteOutStreamputUint40 (bsls::Types::Uint64 value)
 
ByteOutStreamputInt32 (int value)
 
ByteOutStreamputUint32 (unsigned int value)
 
ByteOutStreamputInt24 (int value)
 
ByteOutStreamputUint24 (unsigned int value)
 
ByteOutStreamputInt16 (int value)
 
ByteOutStreamputUint16 (unsigned int value)
 
ByteOutStreamputInt8 (int value)
 
ByteOutStreamputUint8 (unsigned int value)
 
ByteOutStreamputFloat64 (double value)
 
ByteOutStreamputFloat32 (float value)
 
ByteOutStreamputString (const bsl::string &value)
 
ByteOutStreamputArrayInt64 (const bsls::Types::Int64 *values, int numValues)
 
ByteOutStreamputArrayUint64 (const bsls::Types::Uint64 *values, int numValues)
 
ByteOutStreamputArrayInt56 (const bsls::Types::Int64 *values, int numValues)
 
ByteOutStreamputArrayUint56 (const bsls::Types::Uint64 *values, int numValues)
 
ByteOutStreamputArrayInt48 (const bsls::Types::Int64 *values, int numValues)
 
ByteOutStreamputArrayUint48 (const bsls::Types::Uint64 *values, int numValues)
 
ByteOutStreamputArrayInt40 (const bsls::Types::Int64 *values, int numValues)
 
ByteOutStreamputArrayUint40 (const bsls::Types::Uint64 *values, int numValues)
 
ByteOutStreamputArrayInt32 (const int *values, int numValues)
 
ByteOutStreamputArrayUint32 (const unsigned int *values, int numValues)
 
ByteOutStreamputArrayInt24 (const int *values, int numValues)
 
ByteOutStreamputArrayUint24 (const unsigned int *values, int numValues)
 
ByteOutStreamputArrayInt16 (const short *values, int numValues)
 
ByteOutStreamputArrayUint16 (const unsigned short *values, int numValues)
 
ByteOutStreamputArrayInt8 (const char *values, int numValues)
 
ByteOutStreamputArrayInt8 (const signed char *values, int numValues)
 
ByteOutStreamputArrayUint8 (const char *values, int numValues)
 
ByteOutStreamputArrayUint8 (const unsigned char *values, int numValues)
 
ByteOutStreamputArrayFloat64 (const double *values, int numValues)
 
ByteOutStreamputArrayFloat32 (const float *values, int numValues)
 
 operator const void * () const
 
int bdexVersionSelector () const
 
const char * data () const
 
bool isValid () const
 
bsl::size_t length () const
 Return the number of bytes in this stream.
 

Friends

bsl::ostream & operator<< (bsl::ostream &, const ByteOutStream &)
 

Detailed Description

This class provides output methods to externalize values, and C-style arrays of values, of the fundamental integral and floating-point types, as well as bsl::string values. In particular, each put method of this class is guaranteed to write stream data that can be read by the corresponding get method of bslx::ByteInStream. See the bslx package-level documentation for the definition of the BDEX OutStream protocol.

See bslx_byteoutstream

Constructor & Destructor Documentation

◆ ByteOutStream() [1/2]

bslx::ByteOutStream::ByteOutStream ( int  versionSelector,
bslma::Allocator basicAllocator = 0 
)
inlineexplicit

Create an empty output byte stream that will use the specified (compile-time-defined) versionSelector as needed (see {Versioning}). Optionally specify a basicAllocator used to supply memory. If basicAllocator is 0, the currently installed default allocator is used. Note that the versionSelector is expected to be formatted as "YYYYMMDD", a date representation.

◆ ByteOutStream() [2/2]

bslx::ByteOutStream::ByteOutStream ( int  versionSelector,
bsl::size_t  initialCapacity,
bslma::Allocator basicAllocator = 0 
)
inline

Create an empty output byte stream having an initial buffer capacity of at least the specified initialCapacity (in bytes) and that will use the specified (compile-time-defined) versionSelector as needed (see {Versioning}). Optionally specify a basicAllocator used to supply memory. If basicAllocator is 0, the currently installed default allocator is used. Note that the versionSelector is expected to be formatted as "YYYYMMDD", a date representation.

◆ ~ByteOutStream()

bslx::ByteOutStream::~ByteOutStream ( )
inline

Member Function Documentation

◆ bdexVersionSelector()

int bslx::ByteOutStream::bdexVersionSelector ( ) const
inline

Return the versionSelector to be used with operator<< for BDEX streaming as per the bslx package-level documentation.

◆ data()

const char * bslx::ByteOutStream::data ( ) const
inline

Return the address of the contiguous, non-modifiable internal memory buffer of this stream. The address will remain valid as long as this stream is not destroyed or modified. The behavior of accessing elements outside the range [ data() .. data() + (length() - 1) ] is undefined.

◆ invalidate()

void bslx::ByteOutStream::invalidate ( )
inline

Put this output stream in an invalid state. This function has no effect if this stream is already invalid.

◆ isValid()

bool bslx::ByteOutStream::isValid ( ) const
inline

Return true if this stream is valid, and false otherwise. An invalid stream is a stream for which an output operation was detected to have failed or invalidate was called.

◆ length()

bsl::size_t bslx::ByteOutStream::length ( ) const
inline

◆ operator const void *()

bslx::ByteOutStream::operator const void * ( ) const
inline

Return a non-zero value if this stream is valid, and 0 otherwise. An invalid stream is a stream for which an output operation was detected to have failed or invalidate was called.

◆ putArrayFloat32()

ByteOutStream & bslx::ByteOutStream::putArrayFloat32 ( const float *  values,
int  numValues 
)
inline

Write to this stream the consecutive four-byte IEEE single-precision floating-point numbers (in network byte order) comprised of the most-significant four bytes of each of the specified numValues leading entries in the specified values (in host byte order), and return a reference to this stream. If this stream is initially invalid, this operation has no effect. The behavior is undefined unless 0 <= numValues and values has sufficient contents. Note that for non-conforming platforms, this operation may be lossy.

◆ putArrayFloat64()

ByteOutStream & bslx::ByteOutStream::putArrayFloat64 ( const double *  values,
int  numValues 
)
inline

Write to this stream the consecutive eight-byte IEEE double-precision floating-point numbers (in network byte order) comprised of the most-significant eight bytes of each of the specified numValues leading entries in the specified values (in host byte order), and return a reference to this stream. If this stream is initially invalid, this operation has no effect. The behavior is undefined unless 0 <= numValues and values has sufficient contents. Note that for non-conforming platforms, this operation may be lossy.

◆ putArrayInt16()

ByteOutStream & bslx::ByteOutStream::putArrayInt16 ( const short *  values,
int  numValues 
)
inline

Write to this stream the consecutive two-byte, two's complement integers (in network byte order) comprised of the least-significant two bytes of each of the specified numValues leading entries in the specified values (in host byte order), and return a reference to this stream. If this stream is initially invalid, this operation has no effect. The behavior is undefined unless 0 <= numValues and values has sufficient contents.

◆ putArrayInt24()

ByteOutStream & bslx::ByteOutStream::putArrayInt24 ( const int *  values,
int  numValues 
)
inline

Write to this stream the consecutive three-byte, two's complement integers (in network byte order) comprised of the least-significant three bytes of each of the specified numValues leading entries in the specified values (in host byte order), and return a reference to this stream. If this stream is initially invalid, this operation has no effect. The behavior is undefined unless 0 <= numValues and values has sufficient contents.

◆ putArrayInt32()

ByteOutStream & bslx::ByteOutStream::putArrayInt32 ( const int *  values,
int  numValues 
)
inline

Write to this stream the consecutive four-byte, two's complement integers (in network byte order) comprised of the least-significant four bytes of each of the specified numValues leading entries in the specified values (in host byte order), and return a reference to this stream. If this stream is initially invalid, this operation has no effect. The behavior is undefined unless 0 <= numValues and values has sufficient contents.

◆ putArrayInt40()

ByteOutStream & bslx::ByteOutStream::putArrayInt40 ( const bsls::Types::Int64 values,
int  numValues 
)
inline

Write to this stream the consecutive five-byte, two's complement integers (in network byte order) comprised of the least-significant five bytes of each of the specified numValues leading entries in the specified values (in host byte order), and return a reference to this stream. If this stream is initially invalid, this operation has no effect. The behavior is undefined unless 0 <= numValues and values has sufficient contents.

◆ putArrayInt48()

ByteOutStream & bslx::ByteOutStream::putArrayInt48 ( const bsls::Types::Int64 values,
int  numValues 
)
inline

Write to this stream the consecutive six-byte, two's complement integers (in network byte order) comprised of the least-significant six bytes of each of the specified numValues leading entries in the specified values (in host byte order), and return a reference to this stream. If this stream is initially invalid, this operation has no effect. The behavior is undefined unless 0 <= numValues and values has sufficient contents.

◆ putArrayInt56()

ByteOutStream & bslx::ByteOutStream::putArrayInt56 ( const bsls::Types::Int64 values,
int  numValues 
)
inline

Write to this stream the consecutive seven-byte, two's complement integers (in network byte order) comprised of the least-significant seven bytes of each of the specified numValues leading entries in the specified values (in host byte order), and return a reference to this stream. If this stream is initially invalid, this operation has no effect. The behavior is undefined unless 0 <= numValues and values has sufficient contents.

◆ putArrayInt64()

ByteOutStream & bslx::ByteOutStream::putArrayInt64 ( const bsls::Types::Int64 values,
int  numValues 
)
inline

Write to this stream the consecutive eight-byte, two's complement integers (in network byte order) comprised of the least-significant eight bytes of each of the specified numValues leading entries in the specified values (in host byte order), and return a reference to this stream. If this stream is initially invalid, this operation has no effect. The behavior is undefined unless 0 <= numValues and values has sufficient contents.

◆ putArrayInt8() [1/2]

ByteOutStream & bslx::ByteOutStream::putArrayInt8 ( const char *  values,
int  numValues 
)
inline

Write to this stream the consecutive one-byte, two's complement integers comprised of the least-significant one byte of each of the specified numValues leading entries in the specified values, and return a reference to this stream. If this stream is initially invalid, this operation has no effect. The behavior is undefined unless 0 <= numValues and values has sufficient contents.

◆ putArrayInt8() [2/2]

ByteOutStream & bslx::ByteOutStream::putArrayInt8 ( const signed char *  values,
int  numValues 
)
inline

◆ putArrayUint16()

ByteOutStream & bslx::ByteOutStream::putArrayUint16 ( const unsigned short *  values,
int  numValues 
)
inline

Write to this stream the consecutive two-byte, two's complement unsigned integers (in network byte order) comprised of the least-significant two bytes of each of the specified numValues leading entries in the specified values (in host byte order), and return a reference to this stream. If this stream is initially invalid, this operation has no effect. The behavior is undefined unless 0 <= numValues and values has sufficient contents.

◆ putArrayUint24()

ByteOutStream & bslx::ByteOutStream::putArrayUint24 ( const unsigned int *  values,
int  numValues 
)
inline

Write to this stream the consecutive three-byte, two's complement unsigned integers (in network byte order) comprised of the least-significant three bytes of each of the specified numValues leading entries in the specified values (in host byte order), and return a reference to this stream. If this stream is initially invalid, this operation has no effect. The behavior is undefined unless 0 <= numValues and values has sufficient contents.

◆ putArrayUint32()

ByteOutStream & bslx::ByteOutStream::putArrayUint32 ( const unsigned int *  values,
int  numValues 
)
inline

Write to this stream the consecutive four-byte, two's complement unsigned integers (in network byte order) comprised of the least-significant four bytes of each of the specified numValues leading entries in the specified values (in host byte order), and return a reference to this stream. If this stream is initially invalid, this operation has no effect. The behavior is undefined unless 0 <= numValues and values has sufficient contents.

◆ putArrayUint40()

ByteOutStream & bslx::ByteOutStream::putArrayUint40 ( const bsls::Types::Uint64 values,
int  numValues 
)
inline

Write to this stream the consecutive five-byte, two's complement unsigned integers (in network byte order) comprised of the least-significant five bytes of each of the specified numValues leading entries in the specified values (in host byte order), and return a reference to this stream. If this stream is initially invalid, this operation has no effect. The behavior is undefined unless 0 <= numValues and values has sufficient contents.

◆ putArrayUint48()

ByteOutStream & bslx::ByteOutStream::putArrayUint48 ( const bsls::Types::Uint64 values,
int  numValues 
)
inline

Write to this stream the consecutive six-byte, two's complement unsigned integers (in network byte order) comprised of the least-significant six bytes of each of the specified numValues leading entries in the specified values (in host byte order), and return a reference to this stream. If this stream is initially invalid, this operation has no effect. The behavior is undefined unless 0 <= numValues and values has sufficient contents.

◆ putArrayUint56()

ByteOutStream & bslx::ByteOutStream::putArrayUint56 ( const bsls::Types::Uint64 values,
int  numValues 
)
inline

Write to this stream the consecutive seven-byte, two's complement unsigned integers (in network byte order) comprised of the least-significant seven bytes of each of the specified numValues leading entries in the specified values (in host byte order), and return a reference to this stream. If this stream is initially invalid, this operation has no effect. The behavior is undefined unless 0 <= numValues and values has sufficient contents.

◆ putArrayUint64()

ByteOutStream & bslx::ByteOutStream::putArrayUint64 ( const bsls::Types::Uint64 values,
int  numValues 
)
inline

Write to this stream the consecutive eight-byte, two's complement unsigned integers (in network byte order) comprised of the least-significant eight bytes of each of the specified numValues leading entries in the specified values (in host byte order), and return a reference to this stream. If this stream is initially invalid, this operation has no effect. The behavior is undefined unless 0 <= numValues and values has sufficient contents.

◆ putArrayUint8() [1/2]

ByteOutStream & bslx::ByteOutStream::putArrayUint8 ( const char *  values,
int  numValues 
)
inline

Write to this stream the consecutive one-byte, two's complement unsigned integers comprised of the least-significant one byte of each of the specified numValues leading entries in the specified values, and return a reference to this stream. If this stream is initially invalid, this operation has no effect. The behavior is undefined unless 0 <= numValues and values has sufficient contents.

◆ putArrayUint8() [2/2]

ByteOutStream & bslx::ByteOutStream::putArrayUint8 ( const unsigned char *  values,
int  numValues 
)
inline

◆ putFloat32()

ByteOutStream & bslx::ByteOutStream::putFloat32 ( float  value)
inline

Write to this stream the four-byte IEEE single-precision floating-point number (in network byte order) comprised of the most-significant four bytes of the specified value (in host byte order), and return a reference to this stream. If this stream is initially invalid, this operation has no effect. Note that for non-conforming platforms, this operation may be lossy.

◆ putFloat64()

ByteOutStream & bslx::ByteOutStream::putFloat64 ( double  value)
inline

Write to this stream the eight-byte IEEE double-precision floating-point number (in network byte order) comprised of the most-significant eight bytes of the specified value (in host byte order), and return a reference to this stream. If this stream is initially invalid, this operation has no effect. Note that for non-conforming platforms, this operation may be lossy.

◆ putInt16()

ByteOutStream & bslx::ByteOutStream::putInt16 ( int  value)
inline

Write to this stream the two-byte, two's complement integer (in network byte order) comprised of the least-significant two bytes of the specified value (in host byte order), and return a reference to this stream. If this stream is initially invalid, this operation has no effect.

◆ putInt24()

ByteOutStream & bslx::ByteOutStream::putInt24 ( int  value)
inline

Write to this stream the three-byte, two's complement integer (in network byte order) comprised of the least-significant three bytes of the specified value (in host byte order), and return a reference to this stream. If this stream is initially invalid, this operation has no effect.

◆ putInt32()

ByteOutStream & bslx::ByteOutStream::putInt32 ( int  value)
inline

Write to this stream the four-byte, two's complement integer (in network byte order) comprised of the least-significant four bytes of the specified value (in host byte order), and return a reference to this stream. If this stream is initially invalid, this operation has no effect.

◆ putInt40()

ByteOutStream & bslx::ByteOutStream::putInt40 ( bsls::Types::Int64  value)
inline

Write to this stream the five-byte, two's complement integer (in network byte order) comprised of the least-significant five bytes of the specified value (in host byte order), and return a reference to this stream. If this stream is initially invalid, this operation has no effect.

◆ putInt48()

ByteOutStream & bslx::ByteOutStream::putInt48 ( bsls::Types::Int64  value)
inline

Write to this stream the six-byte, two's complement integer (in network byte order) comprised of the least-significant six bytes of the specified value (in host byte order), and return a reference to this stream. If this stream is initially invalid, this operation has no effect.

◆ putInt56()

ByteOutStream & bslx::ByteOutStream::putInt56 ( bsls::Types::Int64  value)
inline

Write to this stream the seven-byte, two's complement integer (in network byte order) comprised of the least-significant seven bytes of the specified value (in host byte order), and return a reference to this stream. If this stream is initially invalid, this operation has no effect.

◆ putInt64()

ByteOutStream & bslx::ByteOutStream::putInt64 ( bsls::Types::Int64  value)
inline

Write to this stream the eight-byte, two's complement integer (in network byte order) comprised of the least-significant eight bytes of the specified value (in host byte order), and return a reference to this stream. If this stream is initially invalid, this operation has no effect.

◆ putInt8()

ByteOutStream & bslx::ByteOutStream::putInt8 ( int  value)
inline

Write to this stream the one-byte, two's complement integer comprised of the least-significant one byte of the specified value, and return a reference to this stream. If this stream is initially invalid, this operation has no effect.

◆ putLength()

ByteOutStream & bslx::ByteOutStream::putLength ( int  length)
inline

If the specified length is less than 128, write to this stream the one-byte integer comprised of the least-significant one byte of the length; otherwise, write to this stream the four-byte, two's complement integer (in network byte order) comprised of the least-significant four bytes of the length (in host byte order) with the most-significant bit set. Return a reference to this stream. If this stream is initially invalid, this operation has no effect. The behavior is undefined unless 0 <= length.

◆ putString()

ByteOutStream & bslx::ByteOutStream::putString ( const bsl::string value)

Write to this stream the length of the specified value (see putLength) and an array of one-byte, two's complement unsigned integers comprised of the least-significant one byte of each character in the value, and return a reference to this stream. If this stream is initially invalid, this operation has no effect.

◆ putUint16()

ByteOutStream & bslx::ByteOutStream::putUint16 ( unsigned int  value)
inline

Write to this stream the two-byte, two's complement unsigned integer (in network byte order) comprised of the least-significant two bytes of the specified value (in host byte order), and return a reference to this stream. If this stream is initially invalid, this operation has no effect.

◆ putUint24()

ByteOutStream & bslx::ByteOutStream::putUint24 ( unsigned int  value)
inline

Write to this stream the three-byte, two's complement unsigned integer (in network byte order) comprised of the least-significant three bytes of the specified value (in host byte order), and return a reference to this stream. If this stream is initially invalid, this operation has no effect.

◆ putUint32()

ByteOutStream & bslx::ByteOutStream::putUint32 ( unsigned int  value)
inline

Write to this stream the four-byte, two's complement unsigned integer (in network byte order) comprised of the least-significant four bytes of the specified value (in host byte order), and return a reference to this stream. If this stream is initially invalid, this operation has no effect.

◆ putUint40()

ByteOutStream & bslx::ByteOutStream::putUint40 ( bsls::Types::Uint64  value)
inline

Write to this stream the five-byte, two's complement unsigned integer (in network byte order) comprised of the least-significant five bytes of the specified value (in host byte order), and return a reference to this stream. If this stream is initially invalid, this operation has no effect.

◆ putUint48()

ByteOutStream & bslx::ByteOutStream::putUint48 ( bsls::Types::Uint64  value)
inline

Write to this stream the six-byte, two's complement unsigned integer (in network byte order) comprised of the least-significant six bytes of the specified value (in host byte order), and return a reference to this stream. If this stream is initially invalid, this operation has no effect.

◆ putUint56()

ByteOutStream & bslx::ByteOutStream::putUint56 ( bsls::Types::Uint64  value)
inline

Write to this stream the seven-byte, two's complement unsigned integer (in network byte order) comprised of the least-significant seven bytes of the specified value (in host byte order), and return a reference to this stream. If this stream is initially invalid, this operation has no effect.

◆ putUint64()

ByteOutStream & bslx::ByteOutStream::putUint64 ( bsls::Types::Uint64  value)
inline

Write to this stream the eight-byte, two's complement unsigned integer (in network byte order) comprised of the least-significant eight bytes of the specified value (in host byte order), and return a reference to this stream. If this stream is initially invalid, this operation has no effect.

◆ putUint8()

ByteOutStream & bslx::ByteOutStream::putUint8 ( unsigned int  value)
inline

Write to this stream the one-byte, two's complement unsigned integer comprised of the least-significant one byte of the specified value, and return a reference to this stream. If this stream is initially invalid, this operation has no effect.

◆ putVersion()

ByteOutStream & bslx::ByteOutStream::putVersion ( int  version)
inline

Write to this stream the one-byte, two's complement unsigned integer comprised of the least-significant one byte of the specified version, and return a reference to this stream. If this stream is initially invalid, this operation has no effect.

◆ reserveCapacity()

void bslx::ByteOutStream::reserveCapacity ( bsl::size_t  newCapacity)
inline

Set the internal buffer size of this stream to be at least the specified newCapacity (in bytes).

◆ reset()

void bslx::ByteOutStream::reset ( )
inline

Remove all content in this stream and validate this stream if it is currently invalid.

Friends And Related Symbol Documentation

◆ operator<<

bsl::ostream & operator<< ( bsl::ostream &  ,
const ByteOutStream  
)
friend

Write the specified object to the specified output stream in some reasonable (multi-line) format, and return a reference to stream.


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