Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
MemoryStream Struct Reference

Represents an in-memory input byte stream. More...

#include <memorystream.h>

Collaboration diagram for MemoryStream:

Public Types

typedef char Ch
 

Public Member Functions

 MemoryStream (const Ch *src, size_t size)
 
Ch Peek () const
 
Ch Take ()
 
size_t Tell () const
 
ChPutBegin ()
 
void Put (Ch)
 
void Flush ()
 
size_t PutEnd (Ch *)
 
const ChPeek4 () const
 

Public Attributes

const Chsrc_
 Current read position.
 
const Chbegin_
 Original head of the string.
 
const Chend_
 End of stream.
 
size_t size_
 Size of the stream.
 

Detailed Description

This class is mainly for being wrapped by EncodedInputStream or AutoUTFInputStream.

It is similar to FileReadBuffer but the source is an in-memory buffer instead of a file.

Differences between MemoryStream and StringStream:

  1. StringStream has encoding but MemoryStream is a byte stream.
  2. MemoryStream needs size of the source buffer and the buffer don't need to be null terminated. StringStream assume null-terminated string as source.
  3. MemoryStream supports Peek4() for encoding detection. StringStream is specified with an encoding so it should not have Peek4().
    Note
    implements Stream concept

Definition at line 40 of file memorystream.h.

Member Typedef Documentation

◆ Ch

Definition at line 41 of file memorystream.h.

Constructor & Destructor Documentation

◆ MemoryStream()

MemoryStream::MemoryStream ( const Ch * src,
size_t size )
inline

Definition at line 43 of file memorystream.h.

43: src_(src), begin_(src), end_(src + size), size_(size) {}
const Ch * end_
End of stream.
const Ch * src_
Current read position.
const Ch * begin_
Original head of the string.
size_t size_
Size of the stream.

Member Function Documentation

◆ Flush()

void MemoryStream::Flush ( )
inline

Definition at line 51 of file memorystream.h.

51{ RAPIDJSON_ASSERT(false); }
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition rapidjson.h:406

◆ Peek()

Ch MemoryStream::Peek ( ) const
inline

Definition at line 45 of file memorystream.h.

45{ return RAPIDJSON_UNLIKELY(src_ == end_) ? '\0' : *src_; }
#define RAPIDJSON_UNLIKELY(x)
Compiler branching hint for expression with low probability to be true.
Definition rapidjson.h:476

◆ Peek4()

const Ch * MemoryStream::Peek4 ( ) const
inline

Definition at line 55 of file memorystream.h.

55 {
56 return Tell() + 4 <= size_ ? src_ : 0;
57 }
size_t Tell() const
Here is the call graph for this function:

◆ Put()

void MemoryStream::Put ( Ch )
inline

Definition at line 50 of file memorystream.h.

50{ RAPIDJSON_ASSERT(false); }

◆ PutBegin()

Ch * MemoryStream::PutBegin ( )
inline

Definition at line 49 of file memorystream.h.

49{ RAPIDJSON_ASSERT(false); return 0; }

◆ PutEnd()

size_t MemoryStream::PutEnd ( Ch * )
inline

Definition at line 52 of file memorystream.h.

52{ RAPIDJSON_ASSERT(false); return 0; }

◆ Take()

Ch MemoryStream::Take ( )
inline

Definition at line 46 of file memorystream.h.

46{ return RAPIDJSON_UNLIKELY(src_ == end_) ? '\0' : *src_++; }

◆ Tell()

size_t MemoryStream::Tell ( ) const
inline

Definition at line 47 of file memorystream.h.

47{ return static_cast<size_t>(src_ - begin_); }
Here is the caller graph for this function:

Member Data Documentation

◆ begin_

const Ch* MemoryStream::begin_

Definition at line 60 of file memorystream.h.

◆ end_

const Ch* MemoryStream::end_

Definition at line 61 of file memorystream.h.

◆ size_

size_t MemoryStream::size_

Definition at line 62 of file memorystream.h.

◆ src_

const Ch* MemoryStream::src_

Definition at line 59 of file memorystream.h.


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