<commit_before>
//g++ -g test.cpp proto.cpp addressbook.pb.cc -lprotobuf -lz -std=gnu++11 -o proto -Wl,-rpath,/usr/local/lib -I/usr/local/include/
//g++ -rdynamic -std=gnu++11 -fPIC -g test.cpp proto.cpp addressbook.pb.cc -I/usr/local/include/ -Wl,-rpath,/usr/local/lib -Wl,-Bdynamic -lz -Wl,-Bstatic -lprotobuf -Wl,-Bdynamic -o proto
//g++ -rdynamic -std=gnu++11 -fPIC -O3 test.cpp proto.cpp addressbook.pb.cc -I/usr/local/include/ -Wl,-rpath,/usr/local/lib -Wl,-Bdynamic -lz -Wl,-Bstatic -lprotobuf -Wl,-Bdynamic -o proto

#include "addressbook.pb.h"
#include "proto.h"
#include <iostream>
using namespace std;

//以下部分为测试代码
void addPerson(protocol::AddressBook &address_book)
{
	protocol::Person* person = address_book.add_people();
	assert(person);
	static int32_t id = 100;	
	person->set_id(id++);
	*person->mutable_name() = "huang马克黄";
	person->set_email("<EMAIL>");
	//
	protocol::Person::PhoneNumber* phone_number = person->add_phones();
    phone_number->set_number("18912345678");
	phone_number->set_type(protocol::Person::MOBILE);

	phone_number = person->add_phones();
    phone_number->set_number("075512345678");
	phone_number->set_type(protocol::Person::WORK);	
}

void print_(const protocol::AddressBook *book)
{
	for(int i = 0;i < book->people_size();++i)
	{
		const protocol::Person &person = book->people(i);
		std::cout<<"id:"<<person.id()<<endl;
		std::cout<<"e-mail:"<<person.email()<<endl;
		std::cout<<"name:"<<person.name()<<endl;
		for(int k = 0;k< person.phones_size();++k)
		{
			const protocol::Person_PhoneNumber &number = person.phones(k);
			std::cout<<"number:"<<number.number()<<endl;
			std::cout<<"number type:"<<number.type()<<endl;
		}
	}
}

int main(int argc,char * argv[])
{
	GOOGLE_PROTOBUF_VERIFY_VERSION;
	
	protocol::AddressBook address_book;

	for(int i = 0;i< 5;++i)
	{
		addPerson(address_book);
		//addPerson(address_book);
	}
	//std::string protobuf = "";
	//assert(address_book.SerializeToString(&protobuf));

	CProtobufPacket packet;
	packet.set_proto_checksum_algorithm(true);
	packet.set_proto_format(true);
	packet.set_proto_zip(true);
	std::string buf = packet.encode(address_book);

	//std::cout<<"buf"<<buf<<endl;
	buf.append("附加测试,判定只解析需要的数据");
	protocol::AddressBook *book = dynamic_cast<protocol::AddressBook*>(packet.decode(buf));  
	print_(book);

	CJsonPacket jsonpacket;
	buf = jsonpacket.encode(*book);
	std::cout<<buf.size()<<endl;
	std::cout<<buf<<endl;
	
	book = dynamic_cast<protocol::AddressBook*>(jsonpacket.decode(buf));
	//print_(book);	
	delete book;	

	// Optional:  Delete all global objects allocated by libprotobuf.
  	google::protobuf::ShutdownProtobufLibrary();

	return 0;
}<commit_msg>释放C++资源<commit_after>
//g++ -g test.cpp proto.cpp addressbook.pb.cc -lprotobuf -lz -std=gnu++11 -o proto -Wl,-rpath,/usr/local/lib -I/usr/local/include/
//g++ -rdynamic -std=gnu++11 -fPIC -g test.cpp proto.cpp addressbook.pb.cc -I/usr/local/include/ -Wl,-rpath,/usr/local/lib -Wl,-Bdynamic -lz -Wl,-Bstatic -lprotobuf -Wl,-Bdynamic -o proto
//g++ -rdynamic -std=gnu++11 -fPIC -O3 test.cpp proto.cpp addressbook.pb.cc -I/usr/local/include/ -Wl,-rpath,/usr/local/lib -Wl,-Bdynamic -lz -Wl,-Bstatic -lprotobuf -Wl,-Bdynamic -o proto

#include "addressbook.pb.h"
#include "proto.h"
#include <iostream>
using namespace std;

//以下部分为测试代码
void addPerson(protocol::AddressBook &address_book)
{
	protocol::Person* person = address_book.add_people();
	assert(person);
	static int32_t id = 100;	
	person->set_id(id++);
	*person->mutable_name() = "huang马克黄";
	person->set_email("<EMAIL>");
	//
	protocol::Person::PhoneNumber* phone_number = person->add_phones();
    phone_number->set_number("18912345678");
	phone_number->set_type(protocol::Person::MOBILE);

	phone_number = person->add_phones();
    phone_number->set_number("075512345678");
	phone_number->set_type(protocol::Person::WORK);	
}

void print_(const protocol::AddressBook *book)
{
	for(int i = 0;i < book->people_size();++i)
	{
		const protocol::Person &person = book->people(i);
		std::cout<<"id:"<<person.id()<<endl;
		std::cout<<"e-mail:"<<person.email()<<endl;
		std::cout<<"name:"<<person.name()<<endl;
		for(int k = 0;k< person.phones_size();++k)
		{
			const protocol::Person_PhoneNumber &number = person.phones(k);
			std::cout<<"number:"<<number.number()<<endl;
			std::cout<<"number type:"<<number.type()<<endl;
		}
	}
}

int main(int argc,char * argv[])
{
	GOOGLE_PROTOBUF_VERIFY_VERSION;
	
	protocol::AddressBook address_book;

	for(int i = 0;i< 5;++i)
	{
		addPerson(address_book);
		//addPerson(address_book);
	}
	//std::string protobuf = "";
	//assert(address_book.SerializeToString(&protobuf));

	CProtobufPacket packet;
	packet.set_proto_checksum_algorithm(true);
	packet.set_proto_format(true);
	packet.set_proto_zip(true);
	std::string buf = packet.encode(address_book);

	//std::cout<<"buf"<<buf<<endl;
	buf.append("附加测试,判定只解析需要的数据");
	protocol::AddressBook *book = dynamic_cast<protocol::AddressBook*>(packet.decode(buf));  
	print_(book);

	CJsonPacket jsonpacket;
	buf = jsonpacket.encode(*book);
        delete book;
	std::cout<<buf.size()<<endl;
	std::cout<<buf<<endl;
	
	book = dynamic_cast<protocol::AddressBook*>(jsonpacket.decode(buf));
	//print_(book);	
	delete book;	

	// Optional:  Delete all global objects allocated by libprotobuf.
  	google::protobuf::ShutdownProtobufLibrary();

	return 0;
}
{'fraction_non_alphanumeric': 0.18982607069384702, 'fraction_numerical': 0.014961660744342622, 'mean_word_length': 5.31404958677686, 'pattern_counts': {'":': 0, '<': 105, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3119465', 'n_tokens_mistral': 2101, 'n_tokens_neox': 2016, 'n_words': 320}