⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bencode.h

📁 linux系统下bt的客户端实现。 采用的是c++
💻 H
字号:
#ifndef BENCODE_H
#define BENCODE_H
#include <map>
#include <string>
#include <iostream>
#include <vector>
#include <inttypes.h>
//using namespace std;

const char END_DELIMITER = 'e';
const char BEN_LIST = 'l';
const char BEN_DICT = 'd';
enum BencodeType { bencode_obj, bencode_int, bencode_str, bencode_list,
  bencode_dict,
};


class Bencode {
public:BencodeType m_enumType;
  Bencode(BencodeType type = bencode_obj) {
    m_enumType = type;
  } 
  virtual size_t Decode(char *pch, size_t len) = 0;
  virtual uint64_t Encode(char* pch, size_t len) = 0;
  virtual void printout() = 0;
};

class BencodeInt:public Bencode {
public:int m_nValue;
   BencodeInt():Bencode(bencode_int) {
  };
  size_t Decode(char *pch, size_t len);
  uint64_t Encode(char* pch, size_t len);
  void FreeCode();
  void printout();
  ~BencodeInt();
};

class BencodeString:public Bencode {
public:std::string m_strValue;
  BencodeString():Bencode(bencode_str) {
  };
  size_t Decode(char *pch, size_t len);
  uint64_t Encode(char *pch, size_t len);
  void printout();
  ~BencodeString();
};

class BencodeList:public Bencode {
public:std::vector < Bencode * >m_list;
  BencodeList():Bencode(bencode_list) {
  };
  size_t Decode(char *pch, size_t len);
  uint64_t Encode(char *pch, size_t len);
  void printout();
  ~BencodeList();
};

class BencodeDict:public Bencode {
public:std::map < std::string, Bencode * >m_map;
  BencodeDict():Bencode(bencode_dict) {
  };
  size_t Decode(char *pch, size_t len);
  uint64_t Encode(char *pch, size_t len);
  Bencode *Search(std::string& keylist);
  void printout();
  ~BencodeDict();
};


BencodeDict* create_dictionary(const char* path);
Bencode* query_dict(Bencode*, std::string&);
bool search_dictionary(Bencode* pcode,std::string& keylist, char** buf, int* pint);
void delete_dictionary(Bencode* pcode);

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -