Samchon Framework for CPP  1.0.0
samchon::ByteArray Class Reference

Binary data class. More...

#include <ByteArray.hpp>

Public Member Functions

 ByteArray ()
 Default Constructor. More...
 
 ByteArray (const ByteArray &)
 Copy Constructor. More...
 
 ByteArray (ByteArray &&)
 Move Constructor. More...
 
auto getPosition () const -> size_t
 Get position. More...
 
void setPosition (size_t)
 Set poisition. More...
 
template<typename T >
auto read () const -> T
 Read data. More...
 
template<typename T >
auto readReversely () const -> T
 Read a reversed data. More...
 
template<typename T >
void write (const T &val)
 Write a data. More...
 
template<typename T >
void writeReversely (const T &val)
 Write a data. More...
 
auto compress () const -> ByteArray
 Compress the binary data
. More...
 
auto decompress () const -> ByteArray
 Decompress the binary data. More...
 

Static Public Member Functions

template<typename T >
static auto reverse (const T &val) -> T
 Reverse byte ordering. More...
 

Private Attributes

size_t position
 Current position of the ByteArray.
. More...
 

Detailed Description

Binary data class.

ByteArray is the standard class for handling binary data in Samchon Framework.

ByteArray provides methods for reading and writing binary data.

In addition, zlib compression and decompression are supported.

Note

ByteArray is a class only for advanced developer who can access data on byte level as the reason of:

  • Handling File Data
  • Custom protocol for network I/O
  • Optimizing the size of data for performance

If you're not trying to use ByteArray as the reason of what I've mentioned but only for representing entity data, I recomment you to use Entity instead.

See also
samchon::library
Author
Jeongho Nam http://samchon.org

Definition at line 30 of file ByteArray.hpp.

Constructor & Destructor Documentation

ByteArray::ByteArray ( )

Default Constructor.

Definition at line 9 of file ByteArray.cpp.

References position.

ByteArray::ByteArray ( const ByteArray byteArray)

Copy Constructor.

Definition at line 14 of file ByteArray.cpp.

References position.

ByteArray::ByteArray ( ByteArray &&  byteArray)

Move Constructor.

Definition at line 19 of file ByteArray.cpp.

References position.

Member Function Documentation

auto ByteArray::getPosition ( ) const -> size_t

Get position.

Get a position represents starting point of bytes to read

Definition at line 46 of file ByteArray.cpp.

References position.

Referenced by samchon::protocol::IWebClientBase::listen(), and samchon::protocol::IClient::listen().

Here is the caller graph for this function:

void ByteArray::setPosition ( size_t  val)

Set poisition.

Set a position represents starting point of bytes to read

Definition at line 50 of file ByteArray.cpp.

References position.

Referenced by samchon::protocol::IClient::listen().

Here is the caller graph for this function:

template<typename T >
static auto samchon::ByteArray::reverse ( const T &  val) -> T
inlinestatic

Reverse byte ordering.

Creates a copy of data which of byte ordering is reversed.

  • BIG_ENDIAN to SMALL_ENDIAN li SMALL_ENDIAN to BIG_ENDIAN

Definition at line 96 of file ByteArray.hpp.

template<typename T >
auto samchon::ByteArray::read ( ) const -> T
inline

Read data.

Reads a data(_Ty) from (starting) position of the ByteArray and adds the position following the size.

Template Parameters
_TyA type of data to be returned
Exceptions
exceptionout of range
Returns
Read data from the byte stream

Definition at line 121 of file ByteArray.hpp.

Referenced by samchon::protocol::IWebClientBase::listen(), samchon::protocol::IClient::listen(), and samchon::protocol::IWebServer::open().

Here is the caller graph for this function:

template<typename T >
auto samchon::ByteArray::readReversely ( ) const -> T
inline

Read a reversed data.

Reads data(_Ty) from (starting) position of the ByteArray, which byte ordering is reversed, from the ByteArray and adds the position following the size.

  • BIG_ENDIAN to SMALL_ENDIAN li SMALL_ENDIAN to BIG_ENDIAN
Template Parameters
_TyA type of data to be returned
Exceptions
exceptionout of range
Returns
Read data from the byte stream

Definition at line 152 of file ByteArray.hpp.

Referenced by samchon::protocol::IWebClientBase::listen().

Here is the caller graph for this function:

template<typename T >
void samchon::ByteArray::write ( const T &  val)
inline

Write a data.

Writes a data(_Ty) to tail of the ByteArray

Template Parameters
_TyA type of data to write
Parameters
valSomething to write on ByteArray

Definition at line 168 of file ByteArray.hpp.

Referenced by samchon::protocol::IWebClientBase::listen(), and samchon::protocol::IWebClientBase::sendData().

Here is the caller graph for this function:

template<typename T >
void samchon::ByteArray::writeReversely ( const T &  val)
inline

Write a data.

Writes a data(_Ty), which byte order is reversed, to tail of the ByteArray

  • BIG_ENDIAN to SMALL_ENDIAN li SMALL_ENDIAN to BIG_ENDIAN
Template Parameters
_TyA type of data to write
Parameters
valSomething to write on ByteArray

Definition at line 193 of file ByteArray.hpp.

Referenced by samchon::protocol::IWebServer::open(), samchon::protocol::IWebClientBase::sendData(), and samchon::protocol::service::Client::sendData().

Here is the caller graph for this function:

auto ByteArray::compress ( ) const -> ByteArray

Compress the binary data
.

Generates a binary data compressed from the ByteArray.

The binary data will be compressed by zlib library.

Returns
ByteArray which is compressed

Definition at line 63 of file ByteArray.cpp.

auto ByteArray::decompress ( ) const -> ByteArray

Decompress the binary data.

Generates a decompressed binary data form the ByteArray.

The binary data will be decompressed by zlib library.

Returns
ByteArray that is decompressed

Definition at line 67 of file ByteArray.cpp.

Member Data Documentation

size_t samchon::ByteArray::position
private

Current position of the ByteArray.
.

If you call read, starting pointer will be the position

  • (_Ty ptr = (_Ty)data() + position)

Definition at line 43 of file ByteArray.hpp.

Referenced by ByteArray(), getPosition(), and setPosition().


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