LinuxC/C++编程基础(36) Poco::BinaryReader的实现

本文介绍了Linyanwen的BinaryReader类,该类用于从输入流中以二进制形式读取基本类型和std::vector。它提供了类似于istream的接口,并支持从大端到小端的自动转换。类定义包括读取不同数据类型的方法,并提供了一个检查是否仍可读取的good()函数。
摘要由CSDN通过智能技术生成

一.BinaryReader.h的定义如下:

#ifndef LINYANWENBINARYREADER_H_
#define LINYANWENBINARYREADER_H_

#include "Poco/TextConverter.h"
#include "Poco/Foundation.h"
#include <vector>
#include <istream>

namespace Linyanwen {
class TextEncoding;
class BinaryReader
 /// This class reads basic types (and std::vectors thereof)
 /// in binary form into an input stream.
 /// It provides an extractor-based interface similar to istream.
 /// The reader also supports automatic conversion from big-endian
 /// (network byte order) to little-endian and vice-versa.
 /// Use a BinaryWriter to create a stream suitable for a BinaryReader.
{
public:
 enum StreamByteOrder
 {
  NATIVE_BYTE_ORDER        = 1,  /// the host's native byte-order
  BIG_ENDIAN_BYTE_ORDER    = 2,  /// big-endian (network) byte-order
  NETWORK_BYTE_ORDER       = 2,  /// big-endian (network) byte-order
  LITTLE_ENDIAN_BYTE_ORDER = 3,  /// little-endian byte-order
  UNSPECIFIED_BYTE_ORDER   = 4   /// unknown, byte-order will be determined by reading the byte-order mark
 };
 BinaryReader(Poco::UInt8* _buffer,Poco::UInt32 _size);
 ~BinaryReader();
 BinaryReader& operator >>(bool& value);
 BinaryReader& operator >>(char& value);
 BinaryReader& operator >>(unsigned char& value);
 BinaryReader& operator >>(signed char& value);
 BinaryReader& operator >>(short& value);
 BinaryReader& operator >>(unsigned short& value);
 BinaryReader& operator >>(int& value);
 BinaryReader& operator >>(unsigned int& value);
 BinaryReader& operator >>(long& value);
 BinaryReader& operator >>(unsigned long& value);
 BinaryReader& operator >>(float& value);
 BinaryReader& operator >>(double& value);
 BinaryReader& operator >> (std::string& value);
 /****************************************/
 void   read7BitEncoded(Poco::UInt32&a

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值