Quick Links:

bal | bbl | bdl | bsl

Namespaces

Component bdlsb_fixedmeminput
[Package bdlsb]

Provide a basic input stream buffer using a client buffer. More...

Namespaces

namespace  bdlsb

Detailed Description

Outline
Purpose:
Provide a basic input stream buffer using a client buffer.
Classes:
bdlsb::FixedMemInput basic input stream buffer using client memory
See also:
Component bdlsb_fixedmeminstreambuf
Description:
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.
Usage:
This section illustrates intended use of this component.
Example 1: Basic Use of bdlsb::FixedMemInput:
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.
  bslx::ByteOutStream outStream(20131127);

  unsigned int MAGIC = 0x1812;

  outStream.putUint32(MAGIC);
  outStream.putInt32(83);
  outStream.putString(bsl::string("test"));
  assert(outStream.isValid());
Next, create a bdlsb::FixedMemInput stream buffer initialized with the buffer from the bslx::ByteOutStream object outStream:
  bdlsb::FixedMemInput streamBuffer(outStream.data(), outStream.length());
Then, create the bslx::GenericInStream stream parameterized with bdlsb::FixedMemInput: Now, use resulting inStream to unexternalize user data:
  unsigned int  magic;
  int           key;
  bsl::string   value;

  inStream.getUint32(magic);
  inStream.getInt32(key);
  inStream.getString(value);
  assert(inStream.isValid());
Finally, verify that the data from the supplied buffer was unexternalized correctly:
  assert(MAGIC  == magic);
  assert(83     == key);
  assert("test" == value);