chromium之pickle
pickle谷歌翻译成泡菜
醉了,看一下头文件的说明
// This class provides facilities for basic binary value packing and unpacking.
献丑一下翻译一下:此类提供基本的二进制打包、解包的功能。
看一下头文件提供的函数
class Pickle {
public:
virtual ~Pickle();
// Initialize a Pickle object using the default header size.
Pickle();
// Initialize a Pickle object with the specified header size in bytes, which
// must be greater-than-or-equal-to sizeof(Pickle::Header). The header size
// will be rounded up to ensure that the header size is 32bit-aligned.
explicit Pickle(int header_size);
// Initializes a Pickle from a const block of data. The data is not copied;
// instead the data is merely referenced by this Pickle. Only const methods
// should be used on the Pickle when initialized this way. The header
// padding size is deduced from the data length.
Pickle(const char* data, int data_len);
// Initializes a Pickle as a deep copy of another Pickle.
Pickle(const Pickle& other);
// Performs a deep copy.
Pickle& operator=(const Pickle& other);
// Returns the size of the Pickle's data.
int size() const { return static_cast<int>(header_size_ +
header_->payload_size); }
// Returns the data for this Pickle.
const void* data() const { return header_; }
// Methods for reading the payload of the Pickle. To read from the start of
// the Pickle, initialize *iter to NULL. If successful, these methods return
// true. Otherwise, false is returned to indicate that the result could not
// be extracted.
bool ReadBool(void** iter, bool* result) const;
bool ReadInt(void** iter, int* result) const;
bool ReadLong(void** iter, long* result) const;
bool ReadSize(void** iter, size_t* result) const;
bool ReadUInt32(void** iter, uint32* result) const;
bool ReadInt64(void** iter, int64* result) const;
bool ReadIntPtr(void** iter, intptr_t* result) const;
bool ReadString(void** iter, std::string* result) const;
bool ReadWString(void** iter, std::wstring* result) const;
bool ReadString16(void** iter, string16* result) const;
bool ReadData(void** iter, const char** data, int* length) const;
bool ReadBytes(void** iter, const char** data, int length) const;
// Safer version of ReadInt() checks for the result not being negative.
// Use it for reading the object sizes.
bool ReadLength(void** iter, int* result) const;
// Methods for adding to the payload of the Pickle. These values are
// appended to the end of the Pickle's payload. When reading values from a
// Pickle, it is important to read them in the order in which they were added
// to the Pickle.
bool WriteBool(bool value) {
return WriteInt(value ? : );
}
bool WriteInt(int value) {
return WriteBytes(&value, sizeof(value));
}
bool WriteLong(long value) {
return WriteBytes(&value, sizeof(value));
}
bool WriteSize(size_t value) {
return WriteBytes(&value, sizeof(value));
}
bool WriteUInt32(uint32 value) {
return WriteBytes(&value, sizeof(value));
}
bool WriteInt64(int64 value) {
return WriteBytes(&value, sizeof(value));
}
bool WriteIntPtr(intptr_t value) {
return WriteBytes(&value, sizeof(value));
}
bool WriteString(const std::string& value);
bool WriteWString(const std::wstring& value);
bool WriteString16(const string16& value);
bool WriteData(const char* data, int length);
bool WriteBytes(const void* data, int data_len);
// .....
};
再瞄一下测试用例,这样这个类是干嘛的,就心里有数了
const int testint = ;
const std::string teststr("Hello world"); // note non-aligned string length
const std::wstring testwstr(L"Hello, world");
const char testdata[] = "AAA\0BBB\0";
const int testdatalen = arraysize(testdata) - ;
const bool testbool1 = false;
const bool testbool2 = true; // checks that the result
void VerifyResult(const Pickle& pickle) {
void* iter = NULL; int outint;
EXPECT_TRUE(pickle.ReadInt(&iter, &outint));
EXPECT_EQ(testint, outint); std::string outstr;
EXPECT_TRUE(pickle.ReadString(&iter, &outstr));
EXPECT_EQ(teststr, outstr); std::wstring outwstr;
EXPECT_TRUE(pickle.ReadWString(&iter, &outwstr));
EXPECT_EQ(testwstr, outwstr); bool outbool;
EXPECT_TRUE(pickle.ReadBool(&iter, &outbool));
EXPECT_EQ(testbool1, outbool);
EXPECT_TRUE(pickle.ReadBool(&iter, &outbool));
EXPECT_EQ(testbool2, outbool); const char* outdata;
int outdatalen;
EXPECT_TRUE(pickle.ReadData(&iter, &outdata, &outdatalen));
EXPECT_EQ(testdatalen, outdatalen);
EXPECT_EQ(memcmp(testdata, outdata, outdatalen), ); EXPECT_TRUE(pickle.ReadData(&iter, &outdata, &outdatalen));
EXPECT_EQ(testdatalen, outdatalen);
EXPECT_EQ(memcmp(testdata, outdata, outdatalen), ); // reads past the end should fail
EXPECT_FALSE(pickle.ReadInt(&iter, &outint));
} } // namespace TEST(PickleTest, EncodeDecode) {
Pickle pickle; EXPECT_TRUE(pickle.WriteInt(testint));
EXPECT_TRUE(pickle.WriteString(teststr));
EXPECT_TRUE(pickle.WriteWString(testwstr));
EXPECT_TRUE(pickle.WriteBool(testbool1));
EXPECT_TRUE(pickle.WriteBool(testbool2));
EXPECT_TRUE(pickle.WriteData(testdata, testdatalen)); // Over allocate BeginWriteData so we can test TrimWriteData.
char* dest = pickle.BeginWriteData(testdatalen + );
EXPECT_TRUE(dest);
memcpy(dest, testdata, testdatalen); pickle.TrimWriteData(testdatalen); VerifyResult(pickle); // test copy constructor
Pickle pickle2(pickle);
VerifyResult(pickle2); // test operator=
Pickle pickle3;
pickle3 = pickle;
VerifyResult(pickle3);
}
chromium之pickle的更多相关文章
- chromium之histogram.h
histogram不知道是干啥的 // Histogram is an object that aggregates statistics, and can summarize them in // ...
- [原创]chromium源码阅读-进程间通信IPC.消息的接收与应答
chromium源码阅读-进程间通信IPC.消息的接收与应答 chromium源码阅读-进程间通信IPC.消息的接收与应答 介绍 chromium进程间通信在win32下是通过命名管道的方式实现的 ...
- QT5利用chromium内核与HTML页面交互
在QT5.4之前,做QT开发浏览器只能选择QWebkit,但是有过使用的都会发现,这个webkit不是出奇的慢,简直是慢的令人发指,Release模式下还行,debug下你就无语了,但是webkit毕 ...
- 运行nltk示例 Resource u'tokenizers punkt english.pickle' not found解决
nltk安装完毕后,编写如下示例程序并运行,报Resource u'tokenizers/punkt/english.pickle' not found错误 import nltk sentence ...
- python常用模块(模块和包的解释,time模块,sys模块,random模块,os模块,json和pickle序列化模块)
1.1模块 什么是模块: 在计算机程序的开发过程中,随着程序代码越写越多,在一个文件里代码就会越来越长,越来越不容易维护. 为了编写可维护的代码,我们把很多函数分组,分别放到不同的文件里,这样,每个文 ...
- python模块(json和pickle模块)
json和pickle模块,两个都是用于序列化的模块 • json模块,用于字符串与python数据类型之间的转换 • pickle模块,用于python特有类型与python数据类型之间的转换 两个 ...
- python3的pickle导致乱码
资料: http://www.cnblogs.com/pzxbc/archive/2012/03/18/2404715.html http://bbs.chinaunix.net/thread-419 ...
- Google之Chromium浏览器源码学习——base公共通用库(一)
Google的优秀C++开源项目繁多,其中的Chromium浏览器项目可以说是很具有代表性的,此外还包括其第三开发开源库或是自己的优秀开源库,可以根据需要抽取自己感兴趣的部分.在研究.学习该项目前的时 ...
- 如何在windows上编译Chromium (CEF3) 并加入MP3支持(二)
时隔一年,再次编译cef3,独一无二的目的仍为加入mp3支持.新版本的编译环境和注意事项都已经发生了变化,于是再记录一下. 一.编译版本 cef版本号格式为X.YYYY.A.gHHHHHHH X为主版 ...
随机推荐
- print控制台输出带颜色文字方法
在python开发的过程中,经常会遇到需要打印各种信息.海量的信息堆砌在控制台中,就会导致信息都混在一起,降低了重要信息的可读性.这时候,如果能给重要的信息加上字体颜色,那么就会更加方便用户阅读了. ...
- 原生js实现雪花飘落效果
雪花飘落的效果实现步骤:1.使用setInterval定时器每800毫秒创建一个雪花:2.把每一个雪花作为参数传进动态下落的方法中即可. <style> *{padding: 0;marg ...
- Stage1--Python的特点和安装
说在前面: Stage1-Stage4简单介绍一下Python语法,Stage5开始用python实现一些实际应用,语法的东西到处可以查看到,学习一门程序语言的最终目的是应用,而不是学习语法,语法本事 ...
- ASP.NET MVC Tips
1. _ViewStart.cshtml会在调用每个页面的时候执行,我们可以在页面内设置Layout页面,也可以在这个页面写一些逻辑来根据不同的情况引用不同的Layout页面,详情请参考此处:
- Bootstrap table分页问题汇总
首先非常感谢作者针对bootstrap table分页问题进行详细的整理,并分享给了大家,希望通过这篇文章可以帮助大家解决Bootstrap table分页的各种问题,谢谢大家的阅读. 问题1 :服务 ...
- pthread 的几个结构体
http://blog.csdn.net/yangzhongxuan/article/details/7397139 /* Copyright (C) 2002,2003,2004,2005,2006 ...
- 线程pthread_cleanup_push的简单例程.
http://www.cnblogs.com/hnrainll/archive/2011/04/20/2022149.html #include<stdlib.h> #include< ...
- poj 2356 抽屉原理
基本原理: n+1个鸽子放到n个笼子里,至少有一个笼子里有两只及其以上的鸽子.若有n个笼子,kn+1个鸽子,至少有一个笼子里面有k+1个鸽子: 题意:给定N个数,挑出一些数,他们和和是n的整数倍: 分 ...
- SpringBoot使用PageHelper进行分页
因为SpringBoot就是为了实现没有配置文件,因此之前手动在Mybatis中配置的PageHelper现在需要重新配置,而且配置方式与之前的SSM框架中还是有点点区别. 首先需要在pom文件 ...
- bzoj 2434 [Noi2011]阿狸的打字机——AC自动机
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2434 dfs AC自动机,走过的点权值+1,回溯的时候权值-1:走到询问的 y 串的节点,看 ...