BDE 4.14.0 Production release
|
Provide a basic input stream buffer using a client buffer.
This component provides a mechanism, bdlsb::FixedMemInput
, that implements the input portion of the bsl::basic_streambuf
protocol using a client-supplied memory buffer. Method names necessarily correspond to the protocol-specified method names. Clients supply the character buffer at stream buffer construction, and can later reinitialize the stream buffer with a different character buffer by calling the pubsetbuf
method. This component provides none of the output-related functionality of bsl::basic_streambuf
nor does it use locales in any way. The only difference between this component and bdlsb::FixedMemInStreamBuf
is that the class bdlsb::FixedMemInput
does not derive from a bsl::streambuf
, and is generally more efficient (at initialization and due to the lack of virtual functions). It is especially designed for streaming a very small amount of information from a fixed-length buffer using a bslx_genericinstream .
This section illustrates intended use of this component.
The bdlsb::FixedMemInput
class is intended to be used as a template parameter to the bslx::GenericInStream
class. Such specialization provides user with performance efficient way to unexternalize BDEX encoded data from an existing character buffer.
See the bslx_genericinstream component usage example for a more practical example of using bslx
streams.
This example demonstrates instantiating a template, bslx::GenericInStream
, on a bdlsb::FixedMemInput
object and using the bslx::GenericInStream
object to stream in some data.
First, create bslx::ByteOutStream
outStream
and externalize some user data to it. Note that this code only prepares the character buffer that is used to illustrate the purpose of the bdlsb::FixedMemInput
class.
Next, create a bdlsb::FixedMemInput
stream buffer initialized with the buffer from the bslx::ByteOutStream
object outStream
:
Then, create the bslx::GenericInStream
stream parameterized with bdlsb::FixedMemInput
:
Now, use resulting inStream
to unexternalize user data:
Finally, verify that the data from the supplied buffer was unexternalized correctly: