ibstream_view Class¶
Provides the functionality of Binary Reader.
Syntax¶
namespace yasio {
using ibstream_view = basic_ibstream_view<endian::network_convert_tag>;
using fast_ibstream_view = basic_ibstream_view<endian::host_convert_tag>;
}
Members¶
Public Constructors¶
Name | Description |
---|---|
ibstream_view::ibstream_view | Constructs a ibstream_view object. |
Public Methods¶
Name | Description |
---|---|
ibstream_view::reset | Reset input data, weak reference. |
ibstream_view::read | Function template, read number value. |
ibstream_view:read_ix | Function template,read 7bit Encoded Int/Int64. |
ibstream_view:read_v | Read blob data with 7bit Encoded Int/Int64 lenght field. |
ibstream_view:read_byte | Read 1 byte. |
ibstream_view:read_bytes | Read blob data without length field. |
ibstream_view::empty | Check is stream empty. |
ibstream_view::data | Retrieves stream data pointer. |
ibstream_view::length | Retrieves size of stream. |
ibstream_view::seek | Moves the read position in a stream. |
Remarks¶
This class is inspired from C++17 std::string_view, it never copy any buffer during initialize and read.
Requirements¶
Header: ibstream.hpp
ibstream_view::ibstream_view¶
Constructs a ibstream_view
object.
ibstream_view();
ibstream_view(const void* data, size_t size);
ibstream_view(const obstream* obs);
Parameters¶
data
The pointer to first byte of buffer.
size
The size of data.
obs
The obstream object.
Example¶
TODO:
ibstream_view::reset¶
Resets ibstream_view
input buffer view.
void ibstream_view::reset(const void* data, size_t size);
Parameters¶
data
The pointer to first byte of buffer.
size
The size of data.
ibstream_view::read¶
Read number value from stream with byte order convertion.
template<typename _Nty>
_Nty ibstream_view::read();
Return Value¶
Returns the value to be read.
Remarks¶
The type _Nty of value could be any (1~8bytes) integral or float types.
Example¶
TODO:
ibstream_view::read_ix¶
Read 7Bit Encoded Int compressed value.
template<typename _Intty>
_Intty ibstream_view::read_ix();
Return Value¶
Returns the value to be read.
Remarks¶
The type _Intty of value must be one of follows
- int32_t
- int64_t
This function behavior is compatible with dotnet
Example¶
TODO:
ibstream_view::read_v¶
Read blob data with 7Bit Encoded Int length field.
cxx17::string_view read_v();
Return Value¶
Returns the blob view to be read
Remarks¶
This function will read length field with 7Bit Encoded first, then call read_bytes to read the value.
Example¶
TODO:
ibstream_view::read_byte¶
Read 1 byte from stream.
uint8_t read_byte();
Return Value¶
Returns the value to be read.
Remarks¶
This function is identical to ibstream_view::read
Example¶
TODO:
ibstream_view::read_bytes¶
Read byte array from stream.
cxx17::string_view read_bytes();
Return Value¶
The blob view to be read.
Example¶
TODO:
ibstream_view::empty¶
Tests whether the ibstream_view is empty.
bool empty() const;
Return Value¶
true
if the ibstream_view empty; false
if it has at least one byte.
Remarks¶
The member function is equivalent to length == 0.
Example¶
TODO:
ibstream_view::data¶
Retrieves stream data pointer.
const char* data() const;
Return Value¶
A pointer to the first byte in the stream.
Example¶
TODO:
ibstream_view::length¶
Returns the number of bytes in the stream.
size_t length() const;
Return Value¶
The current length of the stream.
Example¶
TODO:
ibstream_view::seek¶
Moves the read position in a stream.
ptrdiff_t seek(ptrdiff_t offset, int whence);
Parameters¶
offset\ An offset to move the read pointer relative to whence.
whence\
One of the SEEK_SET
,SEEK_CUR
,SEEK_END
enumerations.
Return Value¶
The current read poistion of the stream after seek.
Example¶
TODO:
ibstream Class¶
Provides the functionality of Binary Reader with buffer storage.
Syntax¶
namespace yasio {
using ibstream = basic_ibstream<endian::network_convert_tag>;
using fast_ibstream = basic_ibstream<endian::host_convert_tag>;
}
Members¶
Public Constructors¶
Name | Description |
---|---|
ibstream::ibstream | Constructs a ibstream object. |
Public Methods¶
Name | Description |
---|---|
ibstream::load | Load stream from file. |
Inheritance Hierarchy¶
ibstream
ibstream::ibstream¶
Constructs a ibstream
object.
ibstream(std::vector<char> blob);
ibstream(const obstream* obs);
Parameters¶
blob
The input binary buffer.
obs
The obstream object.
Example¶
TODO:
ibstream::load¶
Load the stream data from file.
bool load(const char* filename) const;
Return Value¶
true
succed, false
fail.
Example¶
See: obstream::save