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 &obj)
 Copy Constructor. More...
 
 ByteArray (ByteArray &&obj)
 Move Constructor. More...
 
auto get_position () const -> size_t
 Get position. More...
 
void set_position (size_t val)
 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 29 of file ByteArray.hpp.

Constructor & Destructor Documentation

samchon::ByteArray::ByteArray ( )
inline

Default Constructor.

Definition at line 53 of file ByteArray.hpp.

samchon::ByteArray::ByteArray ( const ByteArray obj)
inline

Copy Constructor.

Definition at line 61 of file ByteArray.hpp.

samchon::ByteArray::ByteArray ( ByteArray &&  obj)
inline

Move Constructor.

Definition at line 69 of file ByteArray.hpp.

References position.

Member Function Documentation

auto samchon::ByteArray::get_position ( ) const -> size_t
inline

Get position.

Get a position represents starting point of bytes to read

Definition at line 98 of file ByteArray.hpp.

References position.

void samchon::ByteArray::set_position ( size_t  val)
inline

Set poisition.

Set a position represents starting point of bytes to read

Definition at line 108 of file ByteArray.hpp.

References position.

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
  • SMALL_ENDIAN to BIG_ENDIAN

Definition at line 125 of file ByteArray.hpp.

Referenced by readReversely(), and writeReversely().

Here is the caller graph for this function:

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 150 of file ByteArray.hpp.

References position.

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 181 of file ByteArray.hpp.

References reverse().

Here is the call 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 197 of file ByteArray.hpp.

Referenced by samchon::protocol::WebCommunicator::sendData(), and writeReversely().

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 222 of file ByteArray.hpp.

References reverse(), and write().

Referenced by samchon::protocol::WebCommunicator::sendData(), and samchon::protocol::Communicator::sendData().

Here is the call graph for this function:

Here is the caller graph for this function:

auto samchon::ByteArray::compress ( ) const -> ByteArray
inline

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 239 of file ByteArray.hpp.

auto samchon::ByteArray::decompress ( ) const -> ByteArray
inline

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 253 of file ByteArray.hpp.

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 42 of file ByteArray.hpp.

Referenced by ByteArray(), get_position(), read(), and set_position().


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