CODE 项目整体迁移至码云平台(https://gitee.com)公告
冬瓜猫 / protobuf_tools C++

因为工作需要分析protobuf的数据,google了一下,我个人没有找到合适的,就参考google protobuf文档,写了一个分析工具。这个项目用的是C++Builder XE10.2, win64实现。

c++builder protobuf
拷贝地址

项目最近一次提交:4 个月 前 982bc8506

4_zdhsoft 冬瓜猫 Merge branch 'master' of code.csdn.net:zdhsoft/protobuf_tools 2017-08-19 21:29:23
文件 130行 3.8 KB
   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "mainFrm.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TfrmMain *frmMain;
//---------------------------------------------------------------------------
__fastcall TfrmMain::TfrmMain(TComponent* Owner)
: TForm(Owner)
{
}

void BuildTree(TTreeView * pView, TTreeNode * pNode, std::vector<zdh::ProtoItem> & SubList) {
//auto & SubList = m_Item.SubList;
for(auto iter = SubList.begin(); iter != SubList.end(); ++iter) {
TTreeNode * pItem = pView->Items->AddChild(pNode, iter->ToString());
pItem->ImageIndex = (*iter).m_WireType;
pItem->SelectedIndex = (*iter).m_WireType;
pItem->Data = (void *)iter->m_ID;

}
}

//---------------------------------------------------------------------------
void __fastcall TfrmMain::ToolButton1Click(TObject *Sender)
{
//
if(OpenDialog1->Execute()) {
UTF8String s(OpenDialog1->FileName);
//zdh::XUtils::LoadFile(s.c_str(), m_Buff);
zdh::XUtils::LoadFile(s.c_str(), m_Buff);
zdh::ProtoReader r;
zdh::ProtoReader::m_ID = 0;
m_Item.Reset();
r.Read(m_Buff, m_Item);
TreeView1->Items->Clear();
TTreeNode * pRoot = TreeView1->Items->Add(nullptr, "Root");
BuildTree(TreeView1, pRoot, m_Item.SubList);
}
// UTF8String s = "D:\\tmp\\db\\m\\0000012606376909670322508";
// zdh::XUtils::LoadFile(s.c_str(), m_Buff);
// zdh::ProtoReader r;
// zdh::ProtoReader::m_ID = 0;
// m_Item.Reset();
// r.Read(m_Buff, m_Item);
// TreeView1->Items->Clear();
// TTreeNode * pRoot = TreeView1->Items->Add(nullptr, "Root");
// BuildTree(TreeView1, pRoot, m_Item.SubList);
// auto & SubList = m_Item.SubList;
// for(auto iter = SubList.begin(); iter != SubList.end(); ++iter) {
// TTreeNode * pItem = TreeView1->Items->AddChild(pRoot, iter->ToString());
// pItem->ImageIndex = (*iter).m_WireType;
// pItem->SelectedIndex = (*iter).m_WireType;
// pItem->Data = (void *)iter->m_ID;
//
// }
//ShowMessage("hello");
}
//---------------------------------------------------------------------------

void __fastcall TfrmMain::PopupMenu1Popup(TObject *Sender)
{
for(int i = 0; i < ActionList1->ActionCount; i++) {
ActionList1->Actions[i]->Visible = false;
}
//ActionList1->ActionCount
TTreeNode * p = TreeView1->Selected;
if(p == nullptr) return;
p->Selected = true;
int nID = (int)p->Data;
auto * pFindItem = m_Item.GetItemByID(nID);
if(pFindItem == nullptr) return;
std::set<int> s;
zdh::GetWireTypeItemTypeSet(pFindItem->m_WireType, s);
for(int i = 0; i < ActionList1->ActionCount; i++) {
auto * pAction = ActionList1->Actions[i];
auto itfind = s.find(pAction->Tag);
if(itfind != s.end()) {
pAction->Visible = true;
}
}
}
//---------------------------------------------------------------------------

// void __fastcall TfrmMain::ActionSetInt32Execute(TObject *Sender)
//{
// //
// auto * pAction = dynamic_cast<TContainedAction *>(Sender);
// if(pAction != nullptr) {
// Memo1->Lines->Add(IntToStr(pAction->Tag));
// }
// else {
// Memo1->Lines->Add("nullptr");
// }
//
//}
////


void __fastcall TfrmMain::ActionSetInt32Execute(TObject *Sender)
{
auto * pAction = dynamic_cast<TContainedAction *>(Sender);
if(pAction != nullptr) {
//Memo1->Lines->Add(IntToStr(pAction->Tag));
TTreeNode * p = TreeView1->Selected;
if(p == nullptr) return;
int nID = (int)p->Data;
auto * pFindItem = m_Item.GetItemByID(nID);
if(pFindItem == nullptr) return;
pFindItem->m_EIT = pAction->Tag;
if(pAction->Tag == zdh::EIT_DATA) {
pFindItem->DecodeSubList();
for(int i = 0; i < p->Count; i++) {
p->Item[i]->Delete();
}
BuildTree(TreeView1, p, pFindItem->SubList);
}
p->Text = pFindItem->ToString();
}
else {
//Memo1->Lines->Add("nullptr");
}
}
//---------------------------------------------------------------------------