Language Guide中文翻译(Google Protocol Buffers中文教程)

Google Protocol Buffers中文教程 注:这些是本人的翻译,可能不准确,可能有错误,但是基本上可以理解,希望能对大家有所帮助!(转载请注明出处:本文来自learnhard的优快云博客:http://blog.youkuaiyun.com/learnhard/)请参看如下几个链接:Style Guide中文翻译(Google Protocol Buffers中文教程)Language Guide中文翻译(Google Protocol Buffers中文教程)Style Guide中文翻译(Google Protocol Buffers中文教程) 阅读详情

NULL

完整文章,请查看:http://www.codelast.com/?p=299

 


Language Guide

 

注:这是本人的翻译,可能不准确,可能有错误,但是基本上可以理解,希望能对大家有所帮助!(转载请注明出处:本文来自learnhard的博客:http://www.codelast.com/ & http://blog.youkuaiyun.com/learnhard/)


·         Defining A Message Type

·         Scalar Value Types

·         Optional And Default Values

·         Enumerations

·         Using Other Message Types

·         Nested Types

·         Updating A Message Type

·         Extensions

·         Packages

·         Defining Services

·         Options

·         Generating Your Classes

This guide describes how to use the protocol buffer language to structure your protocol buffer data, including .proto file syntax and how to generate data access classes from your .proto files.

This is a reference guide – for a step by step example that uses many of the features described in this document, see the tutorial for your chosen language.

 

语言指南

l  定义一个消息(message)类型

l  标量值类型

l  可选的(optional)字段以及默认值

l  枚举

l  使用其他消息类型

l  嵌套类型

l  更新一个消息类型

l  扩展

l  包(package)

l  定义服务(service)

l  选项(option)

l  生成访问类

本指南描述了怎样使用protocol buffer语言来构造你的protocol buffer数据,包括.proto文件语法以及怎样生成.proto文件的数据访问类。

本文是一个参考指南——如果要查看如何使用本文中描述的多个特性的循序渐进的例子,请在tutorial中查找你需要的语言的教程。

 

Defining A Message Type 定义一个消息类型

First let's look at a very simple example. Let's say you want to define a search request message format, where each search request has a query string, the particular page of results you are interested in, and a number of results per page. Here's the .proto file you use to define the message type.

首先看一个非常简单的例子。假设你想定义一个“搜索请求”(search request)的消息格式,每一个搜索请求含有一个查询字符串、你感兴趣的查询结果所在的页数,以及每一页多少条查询结果。那么下面这个就是用来定义消息类型的.proto文件了:

message SearchRequest {

  required string query = 1;

  optional int32 page_number = 2;

  optional int32 result_per_page = 3;

}

The SearchRequest message definition specifies three fields (name/value pairs), one for each piece of data that you want to include in this type of message. Each field has a name and a type.

SearchRequest消息类型指定了3个字段(名/值 对),你想在消息中承载的数据分别对应于每一个字段。每个字段都有一个名字(name)和一个类型(type)。

Specifying Field Types 指定字段类型

In the above example, all the fields are scalar types: two integers (page_number and result_per_page) and a string (query). H owever, you can also specify composite types for your fields, including enumerations and other message types.

在上面的例子中,所有字段都是标量类型(scalar types):两个整型(page_number和result_per_page),一个string(query)。然而,你也可以为字段指定合成的类型,包括枚举(enumerations)以及其他消息类型。

Assigning Tags 分配标识号

As you can see, each field in the message definition has a unique numbered tag. These tags are used to identify your fields in the message binary format , and should not be changed once your message type is in use. Note that tags with values in the range 1 through 15 take one byte to encode. Tags in the range 16 through 2047 take two bytes. So you should reserve the tags 1 through 15 for very frequently occurring message elements. Remember to leave some room for frequently occurring elements that might be added in the future.

The smallest tag number you can specify is 1, and the largest is 229 - 1, or 536,870,911. You also cannot use the numbers 19000 though 19999 (FieldDescriptor::kFirstReservedNumber through FieldDescriptor::kLastReservedNumber), as they are reserved for the Protocol Buffers implementation - the protocol buffer compiler will complain if you use one of these reserved numbers in your .proto.

如你所见,在消息定义中,每一个字段都有一个独一无二的标识号(unique numbered tag)。这些标识号是用来在消息二进制格式(message binary format)中识别你的字段的。注意:[1,15]之内的标识号在编码的时候会占用一个字节。[16,2047]之内的标识号则占用2个字节。所以你应该为那些频繁出现的消息元素保留[1,15]之内的标识号。切记:要为将来有可能添加的、频繁出现的标识号预留一些标识号。

Specifying Field Rules 指定字段规则

You specify that message fields are one of the following:

·         required: a well-formed message must have exactly one of this field.

·         optional: a well-formed message can have zero or one of this field (but not more than one).

·         repeated: this field can be repeated any number of times (including zero) in a well-formed message. The order of the repeated values will be preserved.

你所指定的消息字段必须是如下之一:

l  required:一个格式良好的消息一定要含有1个这种字段。

l  optional:一个格式良好的消息可以有0个或1个这种字段(但不超过1个)。

l  repeated:在一个格式良好的消息中,这种字段可以重复任意多次(包括0次)。重复的值的顺序会被保留。

(译者注:这一段内容我不太理解,因为Google提供的.proto示例文件似乎并没有按这个说法来编写...)

 


 

 

 

 

For historical reasons, repeated fields of basic numeric types aren't encoded as efficiently as they could be. New code should use the special option [packed=true] to get a more efficient encoding. For example:

由于历史原因,基本数值类型的repeated的字段并没有被尽可能地高效编码。在新的代码(译者注:这里是指.proto文件的内容)中,用户应该使用特殊选项[packed=true]来保证更高效的编码。例如:

repeated int32 samples = 4 [packed=true];

Required Is Forever You should be very careful about marking fields as required. If at some point you wish to stop writing or sending a required field, it will be problematic to change the field to an optional field – old readers will consider messages without this field to be incomplete and may reject or drop them unintentionally. You should consider writing application-specific custom validation routines for your buffers instead. Some engineers at Google have come to the conclusion that using required does more harm than good; they prefer to use onlyoptional and repeated. However, this view is not universal.

required是永久性的:在把一个字段标识为required的时候,你应该特别小心。如果在某些情况下你不想写入或者发送一个required的字段,那么将该字段更改为optional可能会遇到问题——旧版本的读者(译者注:即读取、解析消息的一方)会认为不含该字段的消息(message)是不完整的,从而有可能会拒绝解析。在这种情况下,你应该考虑编写特别针对于应用程序的、自定义的消息校验函数。Google的一些工程师得出了一个结论:使用required弊多于利;他们更愿意使用optional和repeated而不是required。当然,这个观点并不具有普遍性。

 

Adding More Message Types 添加更多消息类型

Multiple message types can be defined in a single .proto file. This is useful if you are defining multiple related messages – so, for example, if you wanted to define the reply message format that corresponds to your SearchResponse message type, you could add it to the same .proto:

在一个.proto文件中可以定义多个消息类型。在定义多个相关的消息的时候,这一点特别有用——例如,如果你想定义与你的SearchResponse消息类型对应的回复消息格式的话,你可以将它添加到相同的.proto文件中:

message SearchRequest {

  required string query = 1;

  optional int32 page_number = 2;

  optional int32 result_per_page = 3;

}

 

message SearchResponse {

 ...

}

Adding Comments 添加注释

To add comments to your .proto files, use C/C++-style // syntax.

向.proto文件添加注释,可以使用C/C++风格的双斜杠(//) 语法格式。

message SearchRequest {

  required string query = 1;

  optional int32 page_number = 2;// Which page number do we want?

  optional int32 result_per_page = 3;// Number of results to return per page.

}

What's Generated From Your .proto? 从你的.proto文件生成了什么?

When you run the protocol buffer compiler on a .proto, the compiler generates the code in your chosen language you'll need to work with the message types you've described in the file, including getting and setting field values, serializing your messages to an output stream, and parsing your messages from an input stream.

当你对.proto文件运行protocol buffer编译器(protocol buffer compiler)的时候,编译器生成你所选择的语言的代码,这些代码可以操作你在.proto文件中定义的消息类型,包括获取、设置字段值,将你的消息序列化到一个输出流中,以及从一个输入流中解析你的消息。

(本文来自learnhard的优快云博客:http://blog.youkuaiyun.com/learnhard/)

 

For C++, the compiler generates a .h and .cc file from each .proto, with a class for each message type described in your file.

For Java, the compiler generates a .java file with a class for each message type, as well as a special Builder classes for creating message class instances.

对C++来说,编译器为每一个.proto文件生成了一个.h文件和一个.cc文件,.proto文件中的每一个消息有一个对应的类。

对Java来说,编译器为每一个消息类型生成了一个.java文件,以及一个特殊的Builder类(这个类是用来创建消息类接口的)。

 

Python is a little different – the Python compiler generates a module with a static descriptor of each message type in your .proto, which is then used with a metaclass to create the necessary Python data access class at runtime.

You can find out more about using the APIs for each language by following the tutorial for your chosen language. For even more API details, see the relevant API reference.

对Python来说,有点不一样——Python编译器为.proto文件中的每个消息类型生成一个模型,其含有一个静态描述符(static descriptor,译者注:没用过Python,不清楚这样翻译正确与否),该模型与一个元类(metaclass)在运行时(runtime)被用来创建必需的Python数据访问类。

你可以从每种语言的教程中找到更多使用使用API的方法。如欲查看更详细的API信息,请阅相关的文章API reference。

 

Scalar Value Types 标量数值类型

A scalar message field can have one of the following types – the table shows the type specified in the .proto file, and the corresponding type in the automatically generated class:

一个标量消息字段可以含有一个如下的类型——该表格展示了定义于.proto文件中的类型,以及与之对应的、在自动生成的访问类中定义的类型:

.proto Type

Notes

C++ Type

Java Type

double

 

double

double

float

 

float

float

int32

Uses variable-length encoding. Inefficient for encoding negative numbers – if your field is likely to have negative values, use sint32 instead.

使用可变长编码方式。编码负数时不够高效——如果你的字段可能含有负数,那么请使用sint32。

int32

int

int64

Uses variable-length encoding. Inefficient for encoding negative numbers – if your field is likely to have negative values, use sint64 instead.

使用可变长编码方式。编码负数时不够高效——如果你的字段可能含有负数,那么请使用sint64。

int64

long

uint32

Uses variable-length encoding.

使用可变长编码方式。

uint32

int[1]

uint64

Uses variable-length encoding.

使用可变长编码方式。

uint64

long[1]

sint32

Uses variable-length encoding. Signed int value. These more efficiently encode negative numbers than regular int32s.

使用可变长编码方式。有符号的整型值。编码时比通常的int32高效。

int32

int

sint64

Uses variable-length encoding. Signed int value. These more efficiently encode negative numbers than regular int64s.

使用可变长编码方式。有符号的整型值。编码时比通常的int64高效。

int64

long

fixed32

Always four bytes. More efficient than uint32 if values are often greater than 228.

总是4个字节。如果数值总是比总是比228大的话,这个类型会比uint32高效。

uint32

int[1]

fixed64

Always eight bytes. More efficient than uint64 if values are often greater than 256.

总是8个字节。如果数值总是比总是比256大的话,这个类型会比uint64高效。

uint64

long[1]

sfixed32

Always four bytes.

总是4个字节。

int32

int

sfixed64

Always eight bytes.

总是8个字节。

int64

long

bool

 

bool

boolean

string

A string must always contain UTF-8 encoded or 7-bit ASCII text.

一个字符串必须是UTF-8编码或者7-bit ASCII编码的文本。

string

String

bytes

May contain any arbitrary sequence of bytes.

可能包含任意顺序的字节数据。

string

ByteString

You can find out more about how these types are encoded when you serialize your message in Protocol Buffer Encoding.

[1] In Java, unsigned 32-bit and 64-bit integers are represented using their signed counterparts, with the top bit simply being stored in the sign bit.

你可以在文章Protocol Buffer Encoding中,找到更多“序列化消息时各种类型如何编码”的信息。

[1]在Java中,无符号32位和64位整型以它们对应的有符号类型来表示。

Optional Fields And Default Values Optional的字段和默认值

As mentioned above, elements in a message description can be labeled optional. A well-formed message may or may not contain an optional element. When a message is parsed, if it does not contain an optional element, the corresponding field in the parsed object is set to the default value for that field. The default value can be specified as part of the message description. For example, let's say you want to provide a default value of 10 for a SearchRequest's result_per_page value.

如上所述,消息描述中的一个元素可以被标记为“可选的”(optional)。一个格式良好的消息可以包含一个optional的元素,也可以不包含。当解析一个消息的时候,如果它不包含optional的元素,那么解析出来的对象中的对应字段就被置为默认值。默认值可以在消息描述文件中指定。例如,要为SearchRequest消息的result_per_page字段指定默认值10,可以这样做:

optional int32 result_per_page = 3 [default = 10];

If the default value is not specified for an optional element, a type-specific default value is used instead: for strings, the default value is the empty string. For bools, the default value is false. For numeric types, the default value is zero. For enums, the default value is the first value listed in the enum's type definition.

如果没有为optional的元素指定默认值,那么就会使用与特定类型相关的默认值:对string来说,默认值是空字符串。对bool来说,默认值是false。对数值类型来说,默认值是0。对枚举来说,默认值是枚举类型定义中的第一个值。

(本文来自learnhard的优快云博客:http://blog.youkuaiyun.com/learnhard/)

 

Enumerations 枚举

When you're defining a message type, you might want one of its fields to only have one of a pre-defined list of values. For example, let's say you want to add a corpus field for each SearchRequest, where the corpus can be UNIVERSAL, WEB, IMAGES, LOCAL, NEWS, PRODUCTS or VIDEO. You can do this very simply by adding an enum to your message definition - a field with an enum type can only have one of a specified set of constants as its value (if you try to provide a different value, the parser will treat it like an unknown field). In the following example we've added an enum called Corpuswith all the possible values, and a field of type Corpus:

当你定义一个消息类型的时候,你可能想为一个字段指定某“预定义值序列”(pre-defined list of values)中的一个值。例如,假设你想为每一个SearchRequest消息添加一个corpus字段,而corpus的值可能是UNIVERSAL,WEB,IMAGES,LOCAL,NEWS,PRODUCTS或VIDEO中的一个。你可以很容易地实现这一点:通过向你的消息定义中添加一个枚举(enum)就可以了。一个enum类型的字段只能用指定的常量集(specified set of constants)中的一个值作为其值(如果你尝试指定不同的值,解析器就会把它当作一个未知的字段来对待)。在下面的例子中,我们已经添加了一个叫做Corpus的枚举(enum)——它含有所有可能的值——以及一个类型为Corpus的字段:

 

 

 

 


 

完整文章,请查看:http://www.codelast.com/?p=299

protocol buffers 官网中文教程 google protocol buffers 官网中文教程 立即下载

相关推荐

【AI方案集】个人记忆库型AI智能体终身伴侣方案.docx

这套AI技术方案不走“先堆概念再硬套场景”的老路,而是以业务痛点为锚点,把机器视觉识别、预测性分析、大模型知识赋能等能力拆解成轻量化可落地的功能模块,直接嵌入生产运营的关键环节,既能快速落地见效,又能通过持续的数据迭代逐步放大价值,帮企业在不盲目新增硬件投入的前提下,稳步完成智能化升级,实实在在把AI变成能降本、提效、控风险的生产工具。

Techniques 中文翻译(Google Protocol Buffers中文教程)

Techniques 技巧注:这是本人的翻译,可能不准确,可能有错误,但是基本上可以理解,希望能对大家有所帮助!(转载请注明出处:本文来自learnhard的优快云博客:http://blog.youkuaiyun.com/learnhard/)·         Streaming Multiple Messages·         Large Data Sets·         Union Types·         Self-describing MessagesThis page describes s

编码无悔 2868

Mac用户福音:三步搞定PyMol开源版,告别许可证弹窗(附Homebrew/MacPorts安装指南)

本文为Mac用户提供三步安装PyMol开源版的详细指南,帮助科研人员告别许可证弹窗烦恼。通过Homebrew或MacPorts包管理器安装开源核心,并与商业版图形界面整合,实现无干扰的分子可视化研究体验。特别适合MacOS用户快速部署PyMol进行结构生物学分析。

weixin_28743405的博客 196

Protocol Buffers(Protobuf) 官方文档--Protobuf语言指南

约定:为方便书写,ProtocolBuffers在下文中将已Protobuf代替。 本指南将向您描述如何使用protobuf定义i结构化Protobuf数据,包括.proto文件语法和如何使用.proto文件生成数据存取类。 作为一个参考指南,本文档将以示例的形式一步步向您介绍Protobuf的特点。您可以参考您所选择的语言的示例。tutorial  --------------------

等灯等灯等灯! 1万+

机器学习入门指南:Jupyter Notebook实战

对于机器学习工程师而言,他们更擅长的是算法、模型、数据探索的工作,而对于工程化的能力则并不是其擅长的工作。Jupyter Notebook生成PMML文件1​​​​​​​。Jupyter Notebook生成PMML文件2​​​​​​​。PySpark Notebook建模 -折线图​​​​​​​。TensorFlowNotebook建模​​​​​​​。R Notebook建模 - 散点图​​​​​​​。PySpark Notebook建模​​​​​​​。R Notebook获取训练数据集​​​​​​​。

datacreating的博客 1976

安鸾渗透测试平台-CTF系列-bash

工具Xshell 公网VPS接收反弹shell Xshell新手的下载及安装教程(超详细)_新手程序员攀爬之路的博客-优快云博客_xshell使用教程 Xshell连接后 #!/bin/bash cat ${0} while : do echo "$" read input output=`$input` 显示了一个文件,不过咋做呢?这里可能考察的是linux的语法 方法 输入bash 获得shell cat ${0} while : do .

AAAAAAAAAAAA66的博客 2689

【Google Protocol Buffer】Language Guide中文翻译

Language Guide 语言指南<br />注:这是本人的翻译,可能不准确,可能有错误,但是基本上可以理解,希望能对大家有所帮助!(转载请注明出处:本文来自learnhard的博客:http://www.codelast.com/ & http://blog.youkuaiyun.com/learnhard/)<br /><br /><br />·         Defining A Message Type<br />·         Scalar Value Types<br />·         Op

秋水之城 2300

PCB工艺-SI9000-模型选择

本文介绍了PCB设计中常用的阻抗计算模型,主要包括外层、内层和嵌入式三类共12种计算模型,涵盖单端/差分、共面等不同场景。针对阻抗计算中的关键参数,文章提供了经验值参考:表层走线厚度0.035mm(1.4mil),内层0.0152mm(0.6mil);并列出常见PP材料的介电常数(3.8-4.5)和成品厚度(3-7.5mil)。作者建议90%的设计问题可通过上述模型解决,层叠参数建议咨询PCB厂家获取。

weixin_50120208的博客 1385

rsync错误:@ERROR: auth failed on module XXX 的原因之一

在Linux下使用rsync,将远程目录下的文件同步到本地目录时,可能会出现以下错误: @ERROR: auth failed on module XXX 其中,XXX 表示你的远程rsync服务模块名称。 出现这种情况,先检查你的用户名和密码是否正确,如果都正确,有一个可能是原因是:远程rsync服务器的帐户密码文件的权限必须为600,例如,你在rsyncd.conf中设

编码无悔 5万+

C51红外接收与发射控制及原理编码与解码

基于38khz的NEC协议红外发射简易电路图NEC协议产生红外光数据编码 0 1结合程序红外接收接收电路解码过程解码代码 红外发射 通过通过红外二极管发射红外光,三极管的状态来控制。 红外模块一般都是三个引脚,vcc,gnd,dat,通过控制dat口的来控制发射红外光。 简易电路图 将数据口连接到单片机的引脚为上,控制io口的电平状态,来控制三极管的导通状态,从而发射红外光。 NEC协议 NEC协议特点:8位地址和8位命令为提高可靠性,地址和命令都传输2次,脉冲间隔调制38kHz载波频率。 包含引导码,

yangfeng20的博客 1万+

AI医疗影像诊断工具2025 完整教程

本教程所述工具均为辅助诊断设备,不可替代执业医师判断。部署使用需遵守当地医疗器械管理法规。推荐开源框架组合:代码太多打包上传网盘了 自行下载。2025年的AI医疗影像诊断工具将以。

m0_60084632的博客 2029

shell中初始化数组并遍历数组

<br />假设有数组名为ARR,则初始化的一种方法是:<br /> <br />ARR=(2 4 6 8)<br /> <br />其中,括号里的各项使用空格来分隔。<br /> <br />遍历数组的方法为:<br /> <br />for NUM in ${ARR[*]}<br />do<br />echo $NUM<br />done<br /> <br />其中,每一次循环过程中,数组里的当前元素均被保存到NUM变量中,使用即可。<br /> 

编码无悔 4万+

SAP DRC 是什么?一文读懂 SAP Document and Reporting Compliance 的定位、架构与落地案例

把视线拉长,会发现SAP DRC的价值并不仅是用来交差的工具。它更像是企业在全球化经营中建设的一套公共底座:既能以最低的重复成本去应对各国不断演进的监管要求,也能为财务数字化与供应链协同提供可信数据回路。依托本地与云的分层职责、与的生态联动、以及按国家不断更新的任务目录,企业可以将合规变成一种标准化、工程化、可持续运营的能力。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 1655

用GDB调试Segmentation Fault错误

        调试Linux程序的时候,出现Segmentation Fault是最郁闷的事情了,程序代码量很大的时候,可能花很多时间都找不到出错原因。       这里介绍一种对你调试Segmentation Fault很有帮助的方法,可能能迅速帮助你找到出错的代码行。       这种方法需要用到Linux提供的core dump机制:当程序中出现内存操作错误时,会发生崩溃并产生

编码无悔 4万+

手把手教你学Simulink——基于Simulink的多轮PMSM同步驱动交叉耦合控制

摘要:本文针对多轮PMSM同步驱动系统的负载不均、参数差异等问题,提出基于Simulink的交叉耦合控制解决方案。通过实时补偿轮间同步误差,实现同步误差<1%、转矩脉动<5%的性能提升。文章详细介绍了系统架构、核心算法(包括PMSM数学模型和偏差耦合控制算法)、Simulink建模步骤及参数设置,并通过仿真验证了稳态和动态性能。同时提供了工程调试建议和完整代码实现,为多轮驱动系统开发提供实用参考。该方案计算量小,可移植性强,适用于电动汽车、AGV等应用场景。

MHD0815的博客 141

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

valgrind提示的错误:Conditional jump or move depends on uninitialised value(s)

用valgrind对代码进行内存检测的时候,如果提示“Conditional jump or move depends on uninitialised value(s)”,有可能是某些变量未初始化造成的。例如我遇到的两处这样的提示,一处是由于 struct tm 结构体未初始化,另一处是由于 char tmp[512]未初始化造成的。要初始化,只需memset即可,这样做之后,valgrin

编码无悔 3万+

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

关于Linux中的SIGABRT信号

转自网络: SIGABRT是中止一个程序,它可以被捕捉,但不能被阻塞。处理函数返回后,所有打开的文件描述符将会被关闭,流也会被flush。程序会结束,有可能的话还会core dump。 当程序调用abort(3)时,该进程会向自己发送SIGABRT信号。所以,SIGABRT一般用于信号中一些关键的处理,assert失败时也会使用它。你不应该去捕捉SIGSEGV和SIGABRT信号,如果收到

编码无悔 3万+

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

std::find,std::find_if对类进行查找

STL的find,find_if函数提供了一种对数组、STL容器进行查找的方法。使用该函数,需 #include 我们查找一个list中的数据,通常用find(),例如:using namespace std;int main(){list lst;lst.push_back(10);lst.push_back(20);lst.push_back(30);list::iterator it = find(lst.begin(), lst.end(), 10);// 查找list中是否有元素“10”if (i

编码无悔 3万+

curl的超时时间设置

使用curl时,有两个超时时间:一个是连接超时时间,另一个是最大允许时间。连接超时时间用 --connect-timeout 参数来指定,最大允许时间用 -m 参数来指定。例如:curl --connect-timeout 10 -m 20 "http://XXXXXXX"连接超时的话,出错提示形如:curl: (28) connect() timed out!最大允许时间超时的话,出错提示形如:curl: (28) Operation timed out after 2000 milliseconds w

编码无悔 2万+

免费/开源的视频监控软件

在中文网站里找一个免费的视频监控软件还真不容易,随便一搜出来都是收费的,而且功能还不咋滴。转到国外网站,别说是免费的,开源的软件功能都杠杠地。 (1)ZoneMinder : the top Linux video camera security and surveillance solution。网址:http://www.zoneminder.com/ (2)SecureC

编码无悔 1万+

一些发送Email的C/C++库/软件

spnetkit(无文档,有示例程序): http://code.google.com/p/spnetkit/msmtp:http://msmtp.sourceforge.net/index.htmlLibESMTP:http://www.stafford.uklinux.net/libesmtp/index.htmlPOCO:http://pocoproject.org/index.html

编码无悔 1万+

shell读取文件的指定行字符串

<br />命令:<br /> <br />sed -n Np 文件名<br /> <br />其中,“N”必须替换成一个数字,例如,你要取文件1.txt的第7行,命令为: sed -n 7p 1.txt<br /> <br />输出结果即为指定行内容。

编码无悔 1万+

浮点数/float/double 是否需要考虑网络字节序的问题

在网络上传输数据时,对整数,我们使用转换为网络字节序的方法,来保证跨平台传输数据时不会出现字节顺序问题导致的解析错误,但是对浮点数,是否也需要这样做?在socket编程中,只有针对整型的字节顺序转换函数,例如htonl(),htons()等,浮点数怎么办?这里先转载一段网上摘取的文章:_______________________________________________________________________________问:为什么在网络编程中,即需要考虑字节序的问题时。对于double、

编码无悔 1万+

用shell获取目录/文件夹/文件的时间戳

<br />命令:<br /> <br />date +%s -r 目录名/文件名<br /> <br /> <br />输出内容形如:<br /> <br />1276225332

编码无悔 1万+

查看SELinux的状态,关闭SELinux

查看SELinux当前的状态,使用命令:getenforce例如,输出:Disabled 关闭SELinux,可修改 /etc/selinux/config 文件,将其中的 SELINUX=enforcing 改为 SELINUX=disabled然后重启即可。 

编码无悔 1万+

emacs解除read-only的buffer锁定

如果你用emacs打开一个文件,却编辑不了它(提示该buffer是read-only的),那么用Ctrl-x,Ctrl-q就可以解除锁定。

编码无悔 9793
上一篇: Protocol Buffer Basics: C++中文翻译(Google Protocol Buffers中文教程)
下一篇: Style Guide中文翻译(Google Protocol Buffers中文教程)
codelast.com
博客等级 码龄21年 92粉丝 97原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值