jekeyhui99 发表于 2018-3-29 15:21:39

Google Protocol Buffer 的使用和原理

<h2 id="major1" class="ibm-h2" style="padding-top: 12px; padding-bottom: 28px; border: 0px; vertical-align: baseline; font-size: 2.1875rem; line-height: 2.5rem; font-weight: normal; clear: left; color: rgb(63, 63, 63); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">简介</h2><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">什么是 Google Protocol Buffer? 假如您在网上搜索,应该会得到类似这样的文字介绍:</p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">Google Protocol Buffer( 简称 Protobuf) 是 Google 公司内部的混合语言数据标准,目前已经正在使用的有超过 48,162 种报文格式定义和超过 12,183 个 .proto 文件。他们用于 RPC 系统和持续数据存储系统。</p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">Protocol Buffers 是一种轻便高效的结构化数据存储格式,可以用于结构化数据串行化,或者说序列化。它很适合做数据存储或 RPC 数据交换格式。可用于通讯协议、数据存储等领域的语言无关、平台无关、可扩展的序列化结构数据格式。目前提供了 C++、Java、Python 三种语言的 API。</p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">或许您和我一样,在第一次看完这些介绍后还是不明白 Protobuf 究竟是什么,那么我想一个简单的例子应该比较有助于理解它。</p><h2 id="major2" class="ibm-h2" style="padding-top: 12px; padding-bottom: 28px; border: 0px; vertical-align: baseline; font-size: 2.1875rem; line-height: 2.5rem; font-weight: normal; clear: left; color: rgb(63, 63, 63); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">一个简单的例子</h2><h3 id="minor2.1" class="ibm-h3" style="padding-top: 24px; padding-bottom: 28px; border: 0px; vertical-align: baseline; font-size: 1.5625rem; line-height: 1.875rem; font-weight: normal; clear: left; color: rgb(63, 63, 63); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">安装 Google Protocol Buffer</h3><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">在网站&nbsp;<a href="http://code.google.com/p/protobuf/downloads/list" style="border: 0px; vertical-align: baseline; font-size: inherit; color: rgb(59, 108, 170); text-decoration-line: none; transition: color 0.3s;">http://code.google.com/p/protobuf/downloads/list</a>上可以下载 Protobuf 的源代码。然后解压编译安装便可以使用它了。</p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">安装步骤如下所示:</p><span class="dw-code-nohighlight" style="border: 0px; vertical-align: baseline; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;"><div class="ibm-syntax-container" style="border: 0px; vertical-align: baseline; font-size: 1rem;"><div style="border: 0px; vertical-align: baseline; font-size: 1rem;"><div id="highlighter_412174" class="syntaxhighlighterhtmlscript" style="border: 0px; vertical-align: baseline; font-size: 1rem; width: 940px; overflow-y: hidden; margin-bottom: 20px !important; position: relative !important; overflow-x: auto !important;"><table border="0" cellpadding="0" cellspacing="0" role="none" style="font-size: 0.875rem; line-height: 1.25rem; width: 940px; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; text-size-adjust: 110%; margin-bottom: 30px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><tbody style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><tr style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><td class="gutter" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border-width: 0px !important; border-style: initial !important; border-color: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: rgb(112, 112, 112) !important;"><div class="line number1 index0 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">1</div><div class="line number2 index1 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">2</div><div class="line number3 index2 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">3</div><div class="line number4 index3 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">4</div><div class="line number5 index4 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">5</div><div class="line number6 index5 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">6</div></td><td class="code" style="font-size: 0.875rem; line-height: 1.25rem; width: 907px; text-size-adjust: 110%; padding: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border-width: 0px !important; border-style: initial !important; border-color: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><div class="container" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: relative !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><div class="line number1 index0 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">tar -xzf protobuf-2.1.0.tar.gz </code></div><div class="line number2 index1 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">cd protobuf-2.1.0 </code></div><div class="line number3 index2 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">./configure --prefix=$INSTALL_DIR </code></div><div class="line number4 index3 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">make </code></div><div class="line number5 index4 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">make check </code></div><div class="line number6 index5 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">make install</code></div></div></td></tr></tbody></table></div></div></div></span><h3 id="minor2.2" class="ibm-h3" style="padding-top: 24px; padding-bottom: 28px; border: 0px; vertical-align: baseline; font-size: 1.5625rem; line-height: 1.875rem; font-weight: normal; clear: left; color: rgb(63, 63, 63); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">关于简单例子的描述</h3><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">我打算使用 Protobuf 和 C++ 开发一个十分简单的例子程序。</p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">该程序由两部分组成。第一部分被称为 Writer,第二部分叫做 Reader。</p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">Writer 负责将一些结构化的数据写入一个磁盘文件,Reader 则负责从该磁盘文件中读取结构化数据并打印到屏幕上。</p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">准备用于演示的结构化数据是 HelloWorld,它包含两个基本数据:</p><ul class="ibm-bullet-list" style="border: 0px; vertical-align: baseline; padding-bottom: 22px; list-style: none; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;"><li style="margin-left: 0px; padding-left: 28px; border: 0px; vertical-align: baseline; font-size: 1.0625rem;">ID,为一个整数类型的数据</li><li style="margin-left: 0px; padding-top: 7px; padding-left: 28px; border: 0px; vertical-align: baseline; font-size: 1.0625rem;">Str,这是一个字符串</li></ul><h3 id="minor2.3" class="ibm-h3" style="padding-top: 24px; padding-bottom: 28px; border: 0px; vertical-align: baseline; font-size: 1.5625rem; line-height: 1.875rem; font-weight: normal; clear: left; color: rgb(63, 63, 63); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">书写 .proto 文件</h3><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">首先我们需要编写一个 proto 文件,定义我们程序中需要处理的结构化数据,在 protobuf 的术语中,结构化数据被称为 Message。proto 文件非常类似 java 或者 C 语言的数据定义。代码清单 1 显示了例子应用中的 proto 文件内容。</p><h5 id="listing1" class="ibm-h5" style="padding-bottom: 15px; border: 0px; vertical-align: baseline; font-size: 1rem; line-height: 1.625rem; font-weight: normal; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">清单 1. proto 文件</h5><span class="dw-code-nohighlight" style="border: 0px; vertical-align: baseline; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;"><div class="ibm-syntax-container" style="border: 0px; vertical-align: baseline; font-size: 1rem;"><div style="border: 0px; vertical-align: baseline; font-size: 1rem;"><div id="highlighter_202934" class="syntaxhighlighterhtmlscript" style="border: 0px; vertical-align: baseline; font-size: 1rem; width: 940px; overflow-y: hidden; margin-bottom: 20px !important; position: relative !important; overflow-x: auto !important;"><table border="0" cellpadding="0" cellspacing="0" role="none" style="font-size: 0.875rem; line-height: 1.25rem; width: 940px; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; text-size-adjust: 110%; margin-bottom: 30px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><tbody style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><tr style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><td class="gutter" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border-width: 0px !important; border-style: initial !important; border-color: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: rgb(112, 112, 112) !important;"><div class="line number1 index0 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">1</div><div class="line number2 index1 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">2</div><div class="line number3 index2 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">3</div><div class="line number4 index3 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">4</div><div class="line number5 index4 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">5</div><div class="line number6 index5 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">6</div><div class="line number7 index6 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">7</div></td><td class="code" style="font-size: 0.875rem; line-height: 1.25rem; width: 907px; text-size-adjust: 110%; padding: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border-width: 0px !important; border-style: initial !important; border-color: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><div class="container" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: relative !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><div class="line number1 index0 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">package lm; </code></div><div class="line number2 index1 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">message helloworld </code></div><div class="line number3 index2 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">{ </code></div><div class="line number4 index3 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript spaces" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;">&nbsp;&nbsp;&nbsp;</code><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">required int32&nbsp;&nbsp;&nbsp;&nbsp; id = 1;&nbsp; // ID </code></div><div class="line number5 index4 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript spaces" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;">&nbsp;&nbsp;&nbsp;</code><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">required string&nbsp;&nbsp;&nbsp; str = 2;&nbsp; // str </code></div><div class="line number6 index5 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript spaces" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;">&nbsp;&nbsp;&nbsp;</code><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">optional int32&nbsp;&nbsp;&nbsp;&nbsp; opt = 3;&nbsp; //optional field </code></div><div class="line number7 index6 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">}</code></div></div></td></tr></tbody></table></div></div></div></span><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">一个比较好的习惯是认真对待 proto 文件的文件名。比如将命名规则定于如下:</p><span class="dw-code-nohighlight" style="border: 0px; vertical-align: baseline; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;"><div class="ibm-syntax-container" style="border: 0px; vertical-align: baseline; font-size: 1rem;"><div style="border: 0px; vertical-align: baseline; font-size: 1rem;"><div id="highlighter_861616" class="syntaxhighlighterhtmlscript" style="border: 0px; vertical-align: baseline; font-size: 1rem; width: 940px; overflow-y: hidden; margin-bottom: 20px !important; position: relative !important; overflow-x: auto !important;"><table border="0" cellpadding="0" cellspacing="0" role="none" style="font-size: 0.875rem; line-height: 1.25rem; width: 940px; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; text-size-adjust: 110%; margin-bottom: 30px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><tbody style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><tr style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><td class="gutter" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border-width: 0px !important; border-style: initial !important; border-color: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: rgb(112, 112, 112) !important;"><div class="line number1 index0 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">1</div></td><td class="code" style="font-size: 0.875rem; line-height: 1.25rem; width: 907px; text-size-adjust: 110%; padding: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border-width: 0px !important; border-style: initial !important; border-color: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><div class="container" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: relative !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><div class="line number1 index0 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">packageName.MessageName.proto</code></div></div></td></tr></tbody></table></div></div></div></span><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">在上例中,package 名字叫做 lm,定义了一个消息 helloworld,该消息有三个成员,类型为 int32 的 id,另一个为类型为 string 的成员 str。opt 是一个可选的成员,即消息中可以不包含该成员。</p><h3 id="minor2.4" class="ibm-h3" style="padding-top: 24px; padding-bottom: 28px; border: 0px; vertical-align: baseline; font-size: 1.5625rem; line-height: 1.875rem; font-weight: normal; clear: left; color: rgb(63, 63, 63); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">编译 .proto 文件</h3><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">写好 proto 文件之后就可以用 Protobuf 编译器将该文件编译成目标语言了。本例中我们将使用 C++。</p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">假设您的 proto 文件存放在 $SRC_DIR 下面,您也想把生成的文件放在同一个目录下,则可以使用如下命令:</p><span class="dw-code-nohighlight" style="border: 0px; vertical-align: baseline; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;"><div class="ibm-syntax-container" style="border: 0px; vertical-align: baseline; font-size: 1rem;"><div style="border: 0px; vertical-align: baseline; font-size: 1rem;"><div id="highlighter_960145" class="syntaxhighlighterhtmlscript" style="border: 0px; vertical-align: baseline; font-size: 1rem; width: 940px; overflow-y: hidden; margin-bottom: 20px !important; position: relative !important; overflow-x: auto !important;"><table border="0" cellpadding="0" cellspacing="0" role="none" style="font-size: 0.875rem; line-height: 1.25rem; width: 940px; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; text-size-adjust: 110%; margin-bottom: 30px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><tbody style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><tr style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><td class="gutter" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border-width: 0px !important; border-style: initial !important; border-color: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: rgb(112, 112, 112) !important;"><div class="line number1 index0 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">1</div></td><td class="code" style="font-size: 0.875rem; line-height: 1.25rem; width: 907px; text-size-adjust: 110%; padding: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border-width: 0px !important; border-style: initial !important; border-color: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><div class="container" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: relative !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><div class="line number1 index0 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">protoc -I=$SRC_DIR --cpp_out=$DST_DIR $SRC_DIR/addressbook.proto</code></div></div></td></tr></tbody></table></div></div></div></span><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">命令将生成两个文件:</p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">lm.helloworld.pb.h , 定义了 C++ 类的头文件</p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">lm.helloworld.pb.cc , C++ 类的实现文件</p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">在生成的头文件中,定义了一个 C++ 类 helloworld,后面的 Writer 和 Reader 将使用这个类来对消息进行操作。诸如对消息的成员进行赋值,将消息序列化等等都有相应的方法。</p><h3 id="minor2.5" class="ibm-h3" style="padding-top: 24px; padding-bottom: 28px; border: 0px; vertical-align: baseline; font-size: 1.5625rem; line-height: 1.875rem; font-weight: normal; clear: left; color: rgb(63, 63, 63); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">编写 writer 和 Reader</h3><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">如前所述,Writer 将把一个结构化数据写入磁盘,以便其他人来读取。假如我们不使用 Protobuf,其实也有许多的选择。一个可能的方法是将数据转换为字符串,然后将字符串写入磁盘。转换为字符串的方法可以使用 sprintf(),这非常简单。数字 123 可以变成字符串”123”。</p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">这样做似乎没有什么不妥,但是仔细考虑一下就会发现,这样的做法对写 Reader 的那个人的要求比较高,Reader 的作者必须了 Writer 的细节。比如”123”可以是单个数字 123,但也可以是三个数字 1,2 和 3,等等。这么说来,我们还必须让 Writer 定义一种分隔符一样的字符,以便 Reader 可以正确读取。但分隔符也许还会引起其他的什么问题。最后我们发现一个简单的 Helloworld 也需要写许多处理消息格式的代码。</p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">如果使用 Protobuf,那么这些细节就可以不需要应用程序来考虑了。</p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">使用 Protobuf,Writer 的工作很简单,需要处理的结构化数据由 .proto 文件描述,经过上一节中的编译过程后,该数据化结构对应了一个 C++ 的类,并定义在 lm.helloworld.pb.h 中。对于本例,类名为 lm::helloworld。</p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">Writer 需要 include 该头文件,然后便可以使用这个类了。</p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">现在,在 Writer 代码中,将要存入磁盘的结构化数据由一个 lm::helloworld 类的对象表示,它提供了一系列的 get/set 函数用来修改和读取结构化数据中的数据成员,或者叫 field。</p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">当我们需要将该结构化数据保存到磁盘上时,类 lm::helloworld 已经提供相应的方法来把一个复杂的数据变成一个字节序列,我们可以将这个字节序列写入磁盘。</p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">对于想要读取这个数据的程序来说,也只需要使用类 lm::helloworld 的相应反序列化方法来将这个字节序列重新转换会结构化数据。这同我们开始时那个“123”的想法类似,不过 Protobuf 想的远远比我们那个粗糙的字符串转换要全面,因此,我们不如放心将这类事情交给 Protobuf 吧。</p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">程序清单 2 演示了 Writer 的主要代码,您一定会觉得很简单吧?</p><h5 id="listing2" class="ibm-h5" style="padding-bottom: 15px; border: 0px; vertical-align: baseline; font-size: 1rem; line-height: 1.625rem; font-weight: normal; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">清单 2. Writer 的主要代码</h5><span class="dw-code-nohighlight" style="border: 0px; vertical-align: baseline; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;"><div class="ibm-syntax-container" style="border: 0px; vertical-align: baseline; font-size: 1rem;"><div style="border: 0px; vertical-align: baseline; font-size: 1rem;"><div id="highlighter_599134" class="syntaxhighlighterhtmlscript" style="border: 0px; vertical-align: baseline; font-size: 1rem; width: 940px; overflow-y: hidden; margin-bottom: 20px !important; position: relative !important; overflow-x: auto !important;"><table border="0" cellpadding="0" cellspacing="0" role="none" style="font-size: 0.875rem; line-height: 1.25rem; width: 940px; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; text-size-adjust: 110%; margin-bottom: 30px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><tbody style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><tr style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><td class="gutter" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border-width: 0px !important; border-style: initial !important; border-color: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: rgb(112, 112, 112) !important;"><div class="line number1 index0 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">1</div><div class="line number2 index1 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">2</div><div class="line number3 index2 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">3</div><div class="line number4 index3 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">4</div><div class="line number5 index4 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">5</div><div class="line number6 index5 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">6</div><div class="line number7 index6 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">7</div><div class="line number8 index7 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">8</div><div class="line number9 index8 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">9</div><div class="line number10 index9 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">10</div><div class="line number11 index10 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">11</div><div class="line number12 index11 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">12</div><div class="line number13 index12 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">13</div><div class="line number14 index13 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">14</div><div class="line number15 index14 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">15</div><div class="line number16 index15 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">16</div><div class="line number17 index16 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">17</div><div class="line number18 index17 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">18</div><div class="line number19 index18 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">19</div></td><td class="code" style="font-size: 0.875rem; line-height: 1.25rem; width: 899px; text-size-adjust: 110%; padding: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border-width: 0px !important; border-style: initial !important; border-color: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><div class="container" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: relative !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><div class="line number1 index0 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">#include "lm.helloworld.pb.h"</code></div><div class="line number2 index1 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">…</code></div><div class="line number3 index2 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">&nbsp;</div><div class="line number4 index3 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript spaces" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;">&nbsp;</code><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">int main(void) </code></div><div class="line number5 index4 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript spaces" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;">&nbsp;</code><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">{ </code></div><div class="line number6 index5 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript spaces" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;">&nbsp;&nbsp;</code>&nbsp;</div><div class="line number7 index6 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript spaces" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;">&nbsp;&nbsp;</code><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">lm::helloworld msg1; </code></div><div class="line number8 index7 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript spaces" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;">&nbsp;&nbsp;</code><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">msg1.set_id(101); </code></div><div class="line number9 index8 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript spaces" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;">&nbsp;&nbsp;</code><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">msg1.set_str(“hello”); </code></div><div class="line number10 index9 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript spaces" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;">&nbsp;&nbsp;&nbsp;&nbsp;</code>&nbsp;</div><div class="line number11 index10 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript spaces" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;">&nbsp;&nbsp;</code><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">// Write the new address book back to disk. </code></div><div class="line number12 index11 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript spaces" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;">&nbsp;&nbsp;</code><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">fstream output("./log", ios::out | ios::trunc | ios::binary); </code></div><div class="line number13 index12 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript spaces" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code>&nbsp;</div><div class="line number14 index13 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript spaces" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;">&nbsp;&nbsp;</code><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">if (!msg1.SerializeToOstream(&amp;output)) { </code></div><div class="line number15 index14 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript spaces" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">cerr &lt;&lt; "Failed to write msg." &lt;&lt; endl; </code></div><div class="line number16 index15 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript spaces" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">return -1; </code></div><div class="line number17 index16 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript spaces" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;">&nbsp;&nbsp;</code><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </code></div><div class="line number18 index17 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript spaces" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;">&nbsp;&nbsp;</code><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">return 0; </code></div><div class="line number19 index18 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript spaces" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;">&nbsp;</code><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">}</code></div></div></td></tr></tbody></table></div></div></div></span><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">Msg1 是一个 helloworld 类的对象,set_id() 用来设置 id 的值。SerializeToOstream 将对象序列化后写入一个 fstream 流。</p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">代码清单 3 列出了 reader 的主要代码。</p><h5 id="listing3" class="ibm-h5" style="padding-bottom: 15px; border: 0px; vertical-align: baseline; font-size: 1rem; line-height: 1.625rem; font-weight: normal; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">清单 3. Reader</h5><span class="dw-code-nohighlight" style="border: 0px; vertical-align: baseline; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;"><div class="ibm-syntax-container" style="border: 0px; vertical-align: baseline; font-size: 1rem;"><div style="border: 0px; vertical-align: baseline; font-size: 1rem;"><div id="highlighter_166263" class="syntaxhighlighterhtmlscript" style="border: 0px; vertical-align: baseline; font-size: 1rem; width: 940px; overflow-y: hidden; margin-bottom: 20px !important; position: relative !important; overflow-x: auto !important;"><table border="0" cellpadding="0" cellspacing="0" role="none" style="font-size: 0.875rem; line-height: 1.25rem; width: 940px; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; text-size-adjust: 110%; margin-bottom: 30px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><tbody style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><tr style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><td class="gutter" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border-width: 0px !important; border-style: initial !important; border-color: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: rgb(112, 112, 112) !important;"><div class="line number1 index0 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">1</div><div class="line number2 index1 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">2</div><div class="line number3 index2 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">3</div><div class="line number4 index3 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">4</div><div class="line number5 index4 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">5</div><div class="line number6 index5 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">6</div><div class="line number7 index6 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">7</div><div class="line number8 index7 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">8</div><div class="line number9 index8 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">9</div><div class="line number10 index9 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">10</div><div class="line number11 index10 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">11</div><div class="line number12 index11 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">12</div><div class="line number13 index12 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">13</div><div class="line number14 index13 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">14</div><div class="line number15 index14 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">15</div><div class="line number16 index15 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">16</div><div class="line number17 index16 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">17</div><div class="line number18 index17 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">18</div><div class="line number19 index18 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">19</div><div class="line number20 index19 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">20</div><div class="line number21 index20 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">21</div><div class="line number22 index21 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">22</div></td><td class="code" style="font-size: 0.875rem; line-height: 1.25rem; width: 899px; text-size-adjust: 110%; padding: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border-width: 0px !important; border-style: initial !important; border-color: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><div class="container" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: relative !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><div class="line number1 index0 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">#include "lm.helloworld.pb.h" </code></div><div class="line number2 index1 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">…</code></div><div class="line number3 index2 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript spaces" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;">&nbsp;</code><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">void ListMsg(const lm::helloworld &amp; msg) { </code></div><div class="line number4 index3 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript spaces" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;">&nbsp;&nbsp;</code><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">cout &lt;&lt; msg.id() &lt;&lt; endl; </code></div><div class="line number5 index4 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript spaces" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;">&nbsp;&nbsp;</code><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">cout &lt;&lt; msg.str() &lt;&lt; endl; </code></div><div class="line number6 index5 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript spaces" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;">&nbsp;</code><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">} </code></div><div class="line number7 index6 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript spaces" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;">&nbsp;</code>&nbsp;</div><div class="line number8 index7 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript spaces" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;">&nbsp;</code><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">int main(int argc, char* argv[]) { </code></div><div class="line number9 index8 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">&nbsp;</div><div class="line number10 index9 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript spaces" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;">&nbsp;&nbsp;</code><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">lm::helloworld msg1; </code></div><div class="line number11 index10 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript spaces" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;">&nbsp;</code>&nbsp;</div><div class="line number12 index11 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript spaces" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;">&nbsp;&nbsp;</code><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">{ </code></div><div class="line number13 index12 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript spaces" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">fstream input("./log", ios::in | ios::binary); </code></div><div class="line number14 index13 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript spaces" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">if (!msg1.ParseFromIstream(&amp;input)) { </code></div><div class="line number15 index14 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript spaces" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">cerr &lt;&lt; "Failed to parse address book." &lt;&lt; endl; </code></div><div class="line number16 index15 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript spaces" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">return -1; </code></div><div class="line number17 index16 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript spaces" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">} </code></div><div class="line number18 index17 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript spaces" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;">&nbsp;&nbsp;</code><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">} </code></div><div class="line number19 index18 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript spaces" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;">&nbsp;</code>&nbsp;</div><div class="line number20 index19 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript spaces" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;">&nbsp;&nbsp;</code><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">ListMsg(msg1); </code></div><div class="line number21 index20 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript spaces" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;">&nbsp;&nbsp;</code><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">… </code></div><div class="line number22 index21 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript spaces" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;">&nbsp;</code><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">}</code></div></div></td></tr></tbody></table></div></div></div></span><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">同样,Reader 声明类 helloworld 的对象 msg1,然后利用 ParseFromIstream 从一个 fstream 流中读取信息并反序列化。此后,ListMsg 中采用 get 方法读取消息的内部信息,并进行打印输出操作。</p><h3 id="minor2.6" class="ibm-h3" style="padding-top: 24px; padding-bottom: 28px; border: 0px; vertical-align: baseline; font-size: 1.5625rem; line-height: 1.875rem; font-weight: normal; clear: left; color: rgb(63, 63, 63); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">运行结果</h3><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">运行 Writer 和 Reader 的结果如下:</p><span class="dw-code-nohighlight" style="border: 0px; vertical-align: baseline; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;"><div class="ibm-syntax-container" style="border: 0px; vertical-align: baseline; font-size: 1rem;"><div style="border: 0px; vertical-align: baseline; font-size: 1rem;"><div id="highlighter_911956" class="syntaxhighlighterhtmlscript" style="border: 0px; vertical-align: baseline; font-size: 1rem; width: 940px; overflow-y: hidden; margin-bottom: 20px !important; position: relative !important; overflow-x: auto !important;"><table border="0" cellpadding="0" cellspacing="0" role="none" style="font-size: 0.875rem; line-height: 1.25rem; width: 940px; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; text-size-adjust: 110%; margin-bottom: 30px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><tbody style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><tr style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><td class="gutter" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border-width: 0px !important; border-style: initial !important; border-color: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: rgb(112, 112, 112) !important;"><div class="line number1 index0 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">1</div><div class="line number2 index1 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">2</div><div class="line number3 index2 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">3</div><div class="line number4 index3 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">4</div></td><td class="code" style="font-size: 0.875rem; line-height: 1.25rem; width: 907px; text-size-adjust: 110%; padding: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border-width: 0px !important; border-style: initial !important; border-color: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><div class="container" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: relative !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><div class="line number1 index0 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">&gt;writer </code></div><div class="line number2 index1 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">&gt;reader </code></div><div class="line number3 index2 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">101 </code></div><div class="line number4 index3 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">Hello</code></div></div></td></tr></tbody></table></div></div></div></span><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">Reader 读取文件 log 中的序列化信息并打印到屏幕上。本文中所有的例子代码都可以在附件中下载。您可以亲身体验一下。</p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">这个例子本身并无意义,但只要您稍加修改就可以将它变成更加有用的程序。比如将磁盘替换为网络 socket,那么就可以实现基于网络的数据交换任务。而存储和交换正是 Protobuf 最有效的应用领域。</p><h2 id="major3" class="ibm-h2" style="padding-top: 12px; padding-bottom: 28px; border: 0px; vertical-align: baseline; font-size: 2.1875rem; line-height: 2.5rem; font-weight: normal; clear: left; color: rgb(63, 63, 63); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">和其他类似技术的比较</h2><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">看完这个简单的例子之后,希望您已经能理解 Protobuf 能做什么了,那么您可能会说,世上还有很多其他的类似技术啊,比如 XML,JSON,Thrift 等等。和他们相比,Protobuf 有什么不同呢?</p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">简单说来 Protobuf 的主要优点就是:简单,快。</p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">这有测试为证,项目 thrift-protobuf-compare 比较了这些类似的技术,图 1 显示了该项目的一项测试结果,Total Time.</p><h5 id="fig1" class="ibm-h5" style="padding-bottom: 15px; border: 0px; vertical-align: baseline; font-size: 1rem; line-height: 1.625rem; font-weight: normal; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">图 1. 性能测试结果</h5><img src="https://www.ibm.com/developerworks/cn/linux/l-cn-gpb/image001.jpg" class="ibm-downsize" alt="图 1. 性能测试结果" height="246" width="414" style="border: 0px; vertical-align: baseline; max-width: 100%; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif; height: auto !important;"><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">Total Time 指一个对象操作的整个时间,包括创建对象,将对象序列化为内存中的字节序列,然后再反序列化的整个过程。从测试结果可以看到 Protobuf 的成绩很好,感兴趣的读者可以自行到网站&nbsp;<a href="http://code.google.com/p/thrift-protobuf-compare/wiki/Benchmarking" style="border: 0px; vertical-align: baseline; font-size: inherit; color: rgb(59, 108, 170); text-decoration-line: none; transition: color 0.3s;">http://code.google.com/p/thrift-protobuf-compare/wiki/Benchmarking</a>上了解更详细的测试结果。</p><h3 id="minor3.1" class="ibm-h3" style="padding-top: 24px; padding-bottom: 28px; border: 0px; vertical-align: baseline; font-size: 1.5625rem; line-height: 1.875rem; font-weight: normal; clear: left; color: rgb(63, 63, 63); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">Protobuf 的优点</h3><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">Protobuf 有如 XML,不过它更小、更快、也更简单。你可以定义自己的数据结构,然后使用代码生成器生成的代码来读写这个数据结构。你甚至可以在无需重新部署程序的情况下更新数据结构。只需使用 Protobuf 对数据结构进行一次描述,即可利用各种不同语言或从各种不同数据流中对你的结构化数据轻松读写。</p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">它有一个非常棒的特性,即“向后”兼容性好,人们不必破坏已部署的、依靠“老”数据格式的程序就可以对数据结构进行升级。这样您的程序就可以不必担心因为消息结构的改变而造成的大规模的代码重构或者迁移的问题。因为添加新的消息中的 field 并不会引起已经发布的程序的任何改变。</p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">Protobuf 语义更清晰,无需类似 XML 解析器的东西(因为 Protobuf 编译器会将 .proto 文件编译生成对应的数据访问类以对 Protobuf 数据进行序列化、反序列化操作)。</p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">使用 Protobuf 无需学习复杂的文档对象模型,Protobuf 的编程模式比较友好,简单易学,同时它拥有良好的文档和示例,对于喜欢简单事物的人们而言,Protobuf 比其他的技术更加有吸引力。</p><h3 id="minor3.2" class="ibm-h3" style="padding-top: 24px; padding-bottom: 28px; border: 0px; vertical-align: baseline; font-size: 1.5625rem; line-height: 1.875rem; font-weight: normal; clear: left; color: rgb(63, 63, 63); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">Protobuf 的不足</h3><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">Protbuf 与 XML 相比也有不足之处。它功能简单,无法用来表示复杂的概念。</p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">XML 已经成为多种行业标准的编写工具,Protobuf 只是 Google 公司内部使用的工具,在通用性上还差很多。</p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">由于文本并不适合用来描述数据结构,所以 Protobuf 也不适合用来对基于文本的标记文档(如 HTML)建模。另外,由于 XML 具有某种程度上的自解释性,它可以被人直接读取编辑,在这一点上 Protobuf 不行,它以二进制的方式存储,除非你有 .proto 定义,否则你没法直接读出 Protobuf 的任何内容【 2 】。</p><h2 id="major4" class="ibm-h2" style="padding-top: 12px; padding-bottom: 28px; border: 0px; vertical-align: baseline; font-size: 2.1875rem; line-height: 2.5rem; font-weight: normal; clear: left; color: rgb(63, 63, 63); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">高级应用话题</h2><h3 id="minor4.1" class="ibm-h3" style="padding-top: 24px; padding-bottom: 28px; border: 0px; vertical-align: baseline; font-size: 1.5625rem; line-height: 1.875rem; font-weight: normal; clear: left; color: rgb(63, 63, 63); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">更复杂的 Message</h3><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">到这里为止,我们只给出了一个简单的没有任何用处的例子。在实际应用中,人们往往需要定义更加复杂的 Message。我们用“复杂”这个词,不仅仅是指从个数上说有更多的 fields 或者更多类型的 fields,而是指更加复杂的数据结构:</p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;"><span style="border: 0px; vertical-align: baseline; font-size: inherit; font-weight: 600;">嵌套 Message</span></p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">嵌套是一个神奇的概念,一旦拥有嵌套能力,消息的表达能力就会非常强大。</p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">代码清单 4 给出一个嵌套 Message 的例子。</p><h5 id="listing4" class="ibm-h5" style="padding-bottom: 15px; border: 0px; vertical-align: baseline; font-size: 1rem; line-height: 1.625rem; font-weight: normal; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">清单 4. 嵌套 Message 的例子</h5><span class="dw-code-nohighlight" style="border: 0px; vertical-align: baseline; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;"><div class="ibm-syntax-container" style="border: 0px; vertical-align: baseline; font-size: 1rem;"><div style="border: 0px; vertical-align: baseline; font-size: 1rem;"><div id="highlighter_65367" class="syntaxhighlighterhtmlscript" style="border: 0px; vertical-align: baseline; font-size: 1rem; width: 940px; overflow-y: hidden; margin-bottom: 20px !important; position: relative !important; overflow-x: auto !important;"><table border="0" cellpadding="0" cellspacing="0" role="none" style="font-size: 0.875rem; line-height: 1.25rem; width: 940px; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; text-size-adjust: 110%; margin-bottom: 30px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><tbody style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><tr style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><td class="gutter" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border-width: 0px !important; border-style: initial !important; border-color: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: rgb(112, 112, 112) !important;"><div class="line number1 index0 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">1</div><div class="line number2 index1 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">2</div><div class="line number3 index2 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">3</div><div class="line number4 index3 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">4</div><div class="line number5 index4 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">5</div><div class="line number6 index5 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">6</div><div class="line number7 index6 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">7</div><div class="line number8 index7 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">8</div><div class="line number9 index8 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">9</div><div class="line number10 index9 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">10</div><div class="line number11 index10 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">11</div><div class="line number12 index11 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">12</div><div class="line number13 index12 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">13</div><div class="line number14 index13 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">14</div><div class="line number15 index14 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">15</div><div class="line number16 index15 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">16</div><div class="line number17 index16 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">17</div></td><td class="code" style="font-size: 0.875rem; line-height: 1.25rem; width: 899px; text-size-adjust: 110%; padding: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border-width: 0px !important; border-style: initial !important; border-color: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><div class="container" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: relative !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><div class="line number1 index0 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">message Person { </code></div><div class="line number2 index1 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript spaces" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;">&nbsp;</code><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">required string name = 1; </code></div><div class="line number3 index2 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript spaces" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;">&nbsp;</code><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">required int32 id = 2;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Unique ID number for this person. </code></div><div class="line number4 index3 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript spaces" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;">&nbsp;</code><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">optional string email = 3; </code></div><div class="line number5 index4 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">&nbsp;</div><div class="line number6 index5 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript spaces" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;">&nbsp;</code><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">enum PhoneType { </code></div><div class="line number7 index6 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript spaces" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;">&nbsp;&nbsp;&nbsp;</code><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">MOBILE = 0; </code></div><div class="line number8 index7 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript spaces" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;">&nbsp;&nbsp;&nbsp;</code><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">HOME = 1; </code></div><div class="line number9 index8 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript spaces" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;">&nbsp;&nbsp;&nbsp;</code><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">WORK = 2; </code></div><div class="line number10 index9 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript spaces" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;">&nbsp;</code><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">} </code></div><div class="line number11 index10 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">&nbsp;</div><div class="line number12 index11 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript spaces" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;">&nbsp;</code><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">message PhoneNumber { </code></div><div class="line number13 index12 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript spaces" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;">&nbsp;&nbsp;&nbsp;</code><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">required string number = 1; </code></div><div class="line number14 index13 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript spaces" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;">&nbsp;&nbsp;&nbsp;</code><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">optional PhoneType type = 2 ; </code></div><div class="line number15 index14 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript spaces" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;">&nbsp;</code><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">} </code></div><div class="line number16 index15 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript spaces" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;">&nbsp;</code><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">repeated PhoneNumber phone = 4; </code></div><div class="line number17 index16 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">}</code></div></div></td></tr></tbody></table></div></div></div></span><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">在 Message Person 中,定义了嵌套消息 PhoneNumber,并用来定义 Person 消息中的 phone 域。这使得人们可以定义更加复杂的数据结构。</p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;"><span style="border: 0px; vertical-align: baseline; font-size: inherit; font-weight: 600;">4.1.2 Import Message</span></p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">在一个 .proto 文件中,还可以用 Import 关键字引入在其他 .proto 文件中定义的消息,这可以称做 Import Message,或者 Dependency Message。</p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">比如下例:</p><h5 id="listing5" class="ibm-h5" style="padding-bottom: 15px; border: 0px; vertical-align: baseline; font-size: 1rem; line-height: 1.625rem; font-weight: normal; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">清单 5. 代码</h5><span class="dw-code-nohighlight" style="border: 0px; vertical-align: baseline; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;"><div class="ibm-syntax-container" style="border: 0px; vertical-align: baseline; font-size: 1rem;"><div style="border: 0px; vertical-align: baseline; font-size: 1rem;"><div id="highlighter_986575" class="syntaxhighlighterhtmlscript" style="border: 0px; vertical-align: baseline; font-size: 1rem; width: 940px; overflow-y: hidden; margin-bottom: 20px !important; position: relative !important; overflow-x: auto !important;"><table border="0" cellpadding="0" cellspacing="0" role="none" style="font-size: 0.875rem; line-height: 1.25rem; width: 940px; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; text-size-adjust: 110%; margin-bottom: 30px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><tbody style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><tr style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><td class="gutter" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border-width: 0px !important; border-style: initial !important; border-color: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: rgb(112, 112, 112) !important;"><div class="line number1 index0 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">1</div><div class="line number2 index1 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">2</div><div class="line number3 index2 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">3</div><div class="line number4 index3 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">4</div><div class="line number5 index4 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">5</div><div class="line number6 index5 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">6</div></td><td class="code" style="font-size: 0.875rem; line-height: 1.25rem; width: 907px; text-size-adjust: 110%; padding: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border-width: 0px !important; border-style: initial !important; border-color: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><div class="container" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: relative !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><div class="line number1 index0 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">import common.header; </code></div><div class="line number2 index1 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">&nbsp;</div><div class="line number3 index2 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">message youMsg{ </code></div><div class="line number4 index3 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript spaces" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;">&nbsp;</code><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">required common.info_header header = 1; </code></div><div class="line number5 index4 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript spaces" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;">&nbsp;</code><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">required string youPrivateData = 2; </code></div><div class="line number6 index5 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">}</code></div></div></td></tr></tbody></table></div></div></div></span><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;"><code style="border: 0px; vertical-align: baseline; font-size: 0.9375rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace;">其中 ,</code>common.info_header<code style="border: 0px; vertical-align: baseline; font-size: 0.9375rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace;">定义在</code>common.header<code style="border: 0px; vertical-align: baseline; font-size: 0.9375rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace;">包内。</code></p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">Import Message 的用处主要在于提供了方便的代码管理机制,类似 C 语言中的头文件。您可以将一些公用的 Message 定义在一个 package 中,然后在别的 .proto 文件中引入该 package,进而使用其中的消息定义。</p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">Google Protocol Buffer 可以很好地支持嵌套 Message 和引入 Message,从而让定义复杂的数据结构的工作变得非常轻松愉快。</p><h3 id="minor4.2" class="ibm-h3" style="padding-top: 24px; padding-bottom: 28px; border: 0px; vertical-align: baseline; font-size: 1.5625rem; line-height: 1.875rem; font-weight: normal; clear: left; color: rgb(63, 63, 63); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">动态编译</h3><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">一般情况下,使用 Protobuf 的人们都会先写好 .proto 文件,再用 Protobuf 编译器生成目标语言所需要的源代码文件。将这些生成的代码和应用程序一起编译。</p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">可是在某且情况下,人们无法预先知道 .proto 文件,他们需要动态处理一些未知的 .proto 文件。比如一个通用的消息转发中间件,它不可能预知需要处理怎样的消息。这需要动态编译 .proto 文件,并使用其中的 Message。</p><a id="OLE_LINK1" style="border: 0px; vertical-align: baseline; color: rgb(59, 108, 170); transition: color 0.3s; font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;"></a><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">Protobuf 提供了 google::protobuf::compiler 包来完成动态编译的功能。主要的类叫做 importer,定义在 importer.h 中。使用 Importer 非常简单,下图展示了与 Import 和其它几个重要的类的关系。</p><h5 id="fig2" class="ibm-h5" style="padding-bottom: 15px; border: 0px; vertical-align: baseline; font-size: 1rem; line-height: 1.625rem; font-weight: normal; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">图 2. Importer 类</h5><img src="https://www.ibm.com/developerworks/cn/linux/l-cn-gpb/image002.gif" class="ibm-downsize" alt="图 2. Importer 类" height="221" width="329" style="border: 0px; vertical-align: baseline; max-width: 100%; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif; height: auto !important;"><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">Import 类对象中包含三个主要的对象,分别为处理错误的 MultiFileErrorCollector 类,定义 .proto 文件源目录的 SourceTree 类。</p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">下面还是通过实例说明这些类的关系和使用吧。</p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">对于给定的 proto 文件,比如 lm.helloworld.proto,在程序中动态编译它只需要很少的一些代码。如代码清单 6 所示。</p><h5 id="listing6" class="ibm-h5" style="padding-bottom: 15px; border: 0px; vertical-align: baseline; font-size: 1rem; line-height: 1.625rem; font-weight: normal; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">清单 6. 代码</h5><span class="dw-code-nohighlight" style="border: 0px; vertical-align: baseline; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;"><div class="ibm-syntax-container" style="border: 0px; vertical-align: baseline; font-size: 1rem;"><div style="border: 0px; vertical-align: baseline; font-size: 1rem;"><div id="highlighter_671556" class="syntaxhighlighterhtmlscript" style="border: 0px; vertical-align: baseline; font-size: 1rem; width: 940px; overflow-y: hidden; margin-bottom: 20px !important; position: relative !important; overflow-x: auto !important;"><table border="0" cellpadding="0" cellspacing="0" role="none" style="font-size: 0.875rem; line-height: 1.25rem; width: 940px; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; text-size-adjust: 110%; margin-bottom: 30px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><tbody style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><tr style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><td class="gutter" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border-width: 0px !important; border-style: initial !important; border-color: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: rgb(112, 112, 112) !important;"><div class="line number1 index0 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">1</div><div class="line number2 index1 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">2</div><div class="line number3 index2 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">3</div><div class="line number4 index3 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">4</div><div class="line number5 index4 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">5</div><div class="line number6 index5 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">6</div><div class="line number7 index6 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">7</div></td><td class="code" style="font-size: 0.875rem; line-height: 1.25rem; width: 907px; text-size-adjust: 110%; padding: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border-width: 0px !important; border-style: initial !important; border-color: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><div class="container" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: relative !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><div class="line number1 index0 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">google::protobuf::compiler::MultiFileErrorCollector errorCollector;</code></div><div class="line number2 index1 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">google::protobuf::compiler::DiskSourceTree sourceTree; </code></div><div class="line number3 index2 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">&nbsp;</div><div class="line number4 index3 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">google::protobuf::compiler::Importer importer(&amp;sourceTree, &amp;errorCollector); </code></div><div class="line number5 index4 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">sourceTree.MapPath("", protosrc); </code></div><div class="line number6 index5 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">&nbsp;</div><div class="line number7 index6 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">importer.import(“lm.helloworld.proto”);</code></div></div></td></tr></tbody></table></div></div></div></span><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">首先构造一个 importer 对象。构造函数需要两个入口参数,一个是 source Tree 对象,该对象指定了存放 .proto 文件的源目录。第二个参数是一个 error collector 对象,该对象有一个 AddError 方法,用来处理解析 .proto 文件时遇到的语法错误。</p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">之后,需要动态编译一个 .proto 文件时,只需调用 importer 对象的 import 方法。非常简单。</p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">那么我们如何使用动态编译后的 Message 呢?我们需要首先了解几个其他的类</p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">Package google::protobuf::compiler 中提供了以下几个类,用来表示一个 .proto 文件中定义的 message,以及 Message 中的 field,如图所示。</p><h5 id="fig3" class="ibm-h5" style="padding-bottom: 15px; border: 0px; vertical-align: baseline; font-size: 1rem; line-height: 1.625rem; font-weight: normal; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">图 3. 各个 Compiler 类之间的关系</h5><img src="https://www.ibm.com/developerworks/cn/linux/l-cn-gpb/image003.jpg" class="ibm-downsize" alt="图 3. 各个 Compiler 类之间的关系" height="217" width="399" style="border: 0px; vertical-align: baseline; max-width: 100%; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif; height: auto !important;"><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">类 FileDescriptor 表示一个编译后的 .proto 文件;类 Descriptor 对应该文件中的一个 Message;类 FieldDescriptor 描述一个 Message 中的一个具体 Field。</p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">比如编译完 lm.helloworld.proto 之后,可以通过如下代码得到 lm.helloworld.id 的定义:</p><h5 id="listing7" class="ibm-h5" style="padding-bottom: 15px; border: 0px; vertical-align: baseline; font-size: 1rem; line-height: 1.625rem; font-weight: normal; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">清单 7. 得到 lm.helloworld.id 的定义的代码</h5><span class="dw-code-nohighlight" style="border: 0px; vertical-align: baseline; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;"><div class="ibm-syntax-container" style="border: 0px; vertical-align: baseline; font-size: 1rem;"><div style="border: 0px; vertical-align: baseline; font-size: 1rem;"><div id="highlighter_196604" class="syntaxhighlighterhtmlscript" style="border: 0px; vertical-align: baseline; font-size: 1rem; width: 940px; overflow-y: hidden; margin-bottom: 20px !important; position: relative !important; overflow-x: auto !important;"><table border="0" cellpadding="0" cellspacing="0" role="none" style="font-size: 0.875rem; line-height: 1.25rem; width: 940px; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; text-size-adjust: 110%; margin-bottom: 30px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><tbody style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><tr style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><td class="gutter" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border-width: 0px !important; border-style: initial !important; border-color: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: rgb(112, 112, 112) !important;"><div class="line number1 index0 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">1</div><div class="line number2 index1 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">2</div><div class="line number3 index2 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">3</div><div class="line number4 index3 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">4</div></td><td class="code" style="font-size: 0.875rem; line-height: 1.25rem; width: 907px; text-size-adjust: 110%; padding: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border-width: 0px !important; border-style: initial !important; border-color: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><div class="container" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: relative !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><div class="line number1 index0 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">const protobuf::Descriptor *desc = </code></div><div class="line number2 index1 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript spaces" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;">&nbsp;&nbsp;&nbsp;</code><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">importer_.pool()-&gt;FindMessageTypeByName(“lm.helloworld”); </code></div><div class="line number3 index2 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">const protobuf::FieldDescriptor* field = </code></div><div class="line number4 index3 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript spaces" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;">&nbsp;&nbsp;&nbsp;</code><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">desc-&gt;pool()-&gt;FindFileByName (“id”);</code></div></div></td></tr></tbody></table></div></div></div></span><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">通过 Descriptor,FieldDescriptor 的各种方法和属性,应用程序可以获得各种关于 Message 定义的信息。比如通过 field-&gt;name() 得到 field 的名字。这样,您就可以使用一个动态定义的消息了。</p><h3 id="minor4.3" class="ibm-h3" style="padding-top: 24px; padding-bottom: 28px; border: 0px; vertical-align: baseline; font-size: 1.5625rem; line-height: 1.875rem; font-weight: normal; clear: left; color: rgb(63, 63, 63); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">编写新的 proto 编译器</h3><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">随 Google Protocol Buffer 源代码一起发布的编译器 protoc 支持 3 种编程语言:C++,java 和 Python。但使用 Google Protocol Buffer 的 Compiler 包,您可以开发出支持其他语言的新的编译器。</p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">类 CommandLineInterface 封装了 protoc 编译器的前端,包括命令行参数的解析,proto 文件的编译等功能。您所需要做的是实现类 CodeGenerator 的派生类,实现诸如代码生成等后端工作:</p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">程序的大体框架如图所示:</p><h5 id="fig4" class="ibm-h5" style="padding-bottom: 15px; border: 0px; vertical-align: baseline; font-size: 1rem; line-height: 1.625rem; font-weight: normal; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">图 4. XML 编译器框图</h5><img src="https://www.ibm.com/developerworks/cn/linux/l-cn-gpb/image004.jpg" class="ibm-downsize" alt="图 4. XML 编译器框图" height="225" width="416" style="border: 0px; vertical-align: baseline; max-width: 100%; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif; height: auto !important;"><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">在 main() 函数内,生成 CommandLineInterface 的对象 cli,调用其 RegisterGenerator() 方法将新语言的后端代码生成器 yourG 对象注册给 cli 对象。然后调用 cli 的 Run() 方法即可。</p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">这样生成的编译器和 protoc 的使用方法相同,接受同样的命令行参数,cli 将对用户输入的 .proto 进行词法语法等分析工作,最终生成一个语法树。该树的结构如图所示。</p><h5 id="fig5" class="ibm-h5" style="padding-bottom: 15px; border: 0px; vertical-align: baseline; font-size: 1rem; line-height: 1.625rem; font-weight: normal; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">图 5. 语法树</h5><img src="https://www.ibm.com/developerworks/cn/linux/l-cn-gpb/image005.jpg" class="ibm-downsize" alt="图 5. 语法树" height="385" width="402" style="border: 0px; vertical-align: baseline; max-width: 100%; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif; height: auto !important;"><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">其根节点为一个 FileDescriptor 对象(请参考“动态编译”一节),并作为输入参数被传入 yourG 的 Generator() 方法。在这个方法内,您可以遍历语法树,然后生成对应的您所需要的代码。简单说来,要想实现一个新的 compiler,您只需要写一个 main 函数,和一个实现了方法 Generator() 的派生类即可。</p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">在本文的下载附件中,有一个参考例子,将 .proto 文件编译生成 XML 的 compiler,可以作为参考。</p><h2 id="major5" class="ibm-h2" style="padding-top: 12px; padding-bottom: 28px; border: 0px; vertical-align: baseline; font-size: 2.1875rem; line-height: 2.5rem; font-weight: normal; clear: left; color: rgb(63, 63, 63); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">Protobuf 的更多细节</h2><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">人们一直在强调,同 XML 相比, Protobuf 的主要优点在于性能高。它以高效的二进制方式存储,比 XML 小 3 到 10 倍,快 20 到 100 倍。</p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">对于这些 “小 3 到 10 倍”,“快 20 到 100 倍”的说法,严肃的程序员需要一个解释。因此在本文的最后,让我们稍微深入 Protobuf 的内部实现吧。</p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">有两项技术保证了采用 Protobuf 的程序能获得相对于 XML 极大的性能提高。</p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">第一点,我们可以考察 Protobuf 序列化后的信息内容。您可以看到 Protocol Buffer 信息的表示非常紧凑,这意味着消息的体积减少,自然需要更少的资源。比如网络上传输的字节数更少,需要的 IO 更少等,从而提高性能。</p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">第二点我们需要理解 Protobuf 封解包的大致过程,从而理解为什么会比 XML 快很多。</p><h3 id="minor5.1" class="ibm-h3" style="padding-top: 24px; padding-bottom: 28px; border: 0px; vertical-align: baseline; font-size: 1.5625rem; line-height: 1.875rem; font-weight: normal; clear: left; color: rgb(63, 63, 63); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">Google Protocol Buffer 的 Encoding</h3><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">Protobuf 序列化后所生成的二进制消息非常紧凑,这得益于 Protobuf 采用的非常巧妙的 Encoding 方法。</p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">考察消息结构之前,让我首先要介绍一个叫做 Varint 的术语。</p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">Varint 是一种紧凑的表示数字的方法。它用一个或多个字节来表示一个数字,值越小的数字使用越少的字节数。这能减少用来表示数字的字节数。</p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">比如对于 int32 类型的数字,一般需要 4 个 byte 来表示。但是采用 Varint,对于很小的 int32 类型的数字,则可以用 1 个 byte 来表示。当然凡事都有好的也有不好的一面,采用 Varint 表示法,大的数字则需要 5 个 byte 来表示。从统计的角度来说,一般不会所有的消息中的数字都是大数,因此大多数情况下,采用 Varint 后,可以用更少的字节数来表示数字信息。下面就详细介绍一下 Varint。</p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">Varint 中的每个 byte 的最高位 bit 有特殊的含义,如果该位为 1,表示后续的 byte 也是该数字的一部分,如果该位为 0,则结束。其他的 7 个 bit 都用来表示数字。因此小于 128 的数字都可以用一个 byte 表示。大于 128 的数字,比如 300,会用两个字节来表示:1010 1100 0000 0010</p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">下图演示了 Google Protocol Buffer 如何解析两个 bytes。注意到最终计算前将两个 byte 的位置相互交换过一次,这是因为 Google Protocol Buffer 字节序采用 little-endian 的方式。</p><h5 id="fig6" class="ibm-h5" style="padding-bottom: 15px; border: 0px; vertical-align: baseline; font-size: 1rem; line-height: 1.625rem; font-weight: normal; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">图 6. Varint 编码</h5><img src="https://www.ibm.com/developerworks/cn/linux/l-cn-gpb/image006.jpg" class="ibm-downsize" alt="图 6. Varint 编码" height="190" width="320" style="border: 0px; vertical-align: baseline; max-width: 100%; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif; height: auto !important;"><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">消息经过序列化后会成为一个二进制数据流,该流中的数据为一系列的 Key-Value 对。如下图所示:</p><h5 id="fig7" class="ibm-h5" style="padding-bottom: 15px; border: 0px; vertical-align: baseline; font-size: 1rem; line-height: 1.625rem; font-weight: normal; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">图 7. Message Buffer</h5><img src="https://www.ibm.com/developerworks/cn/linux/l-cn-gpb/image007.jpg" class="ibm-downsize" alt="图 7. Message Buffer" height="160" width="450" style="border: 0px; vertical-align: baseline; max-width: 100%; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif; height: auto !important;"><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">采用这种 Key-Pair 结构无需使用分隔符来分割不同的 Field。对于可选的 Field,如果消息中不存在该 field,那么在最终的 Message Buffer 中就没有该 field,这些特性都有助于节约消息本身的大小。</p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">以代码清单 1 中的消息为例。假设我们生成如下的一个消息 Test1:</p><span class="dw-code-nohighlight" style="border: 0px; vertical-align: baseline; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;"><div class="ibm-syntax-container" style="border: 0px; vertical-align: baseline; font-size: 1rem;"><div style="border: 0px; vertical-align: baseline; font-size: 1rem;"><div id="highlighter_919561" class="syntaxhighlighterhtmlscript" style="border: 0px; vertical-align: baseline; font-size: 1rem; width: 940px; overflow-y: hidden; margin-bottom: 20px !important; position: relative !important; overflow-x: auto !important;"><table border="0" cellpadding="0" cellspacing="0" role="none" style="font-size: 0.875rem; line-height: 1.25rem; width: 940px; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; text-size-adjust: 110%; margin-bottom: 30px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><tbody style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><tr style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><td class="gutter" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border-width: 0px !important; border-style: initial !important; border-color: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: rgb(112, 112, 112) !important;"><div class="line number1 index0 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">1</div><div class="line number2 index1 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">2</div></td><td class="code" style="font-size: 0.875rem; line-height: 1.25rem; width: 907px; text-size-adjust: 110%; padding: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border-width: 0px !important; border-style: initial !important; border-color: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><div class="container" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: relative !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><div class="line number1 index0 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">Test1.id = 10; </code></div><div class="line number2 index1 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">Test1.str = “hello”;</code></div></div></td></tr></tbody></table></div></div></div></span><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">则最终的 Message Buffer 中有两个 Key-Value 对,一个对应消息中的 id;另一个对应 str。</p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">Key 用来标识具体的 field,在解包的时候,Protocol Buffer 根据 Key 就可以知道相应的 Value 应该对应于消息中的哪一个 field。</p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">Key 的定义如下:</p><span class="dw-code-nohighlight" style="border: 0px; vertical-align: baseline; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;"><div class="ibm-syntax-container" style="border: 0px; vertical-align: baseline; font-size: 1rem;"><div style="border: 0px; vertical-align: baseline; font-size: 1rem;"><div id="highlighter_694987" class="syntaxhighlighterhtmlscript" style="border: 0px; vertical-align: baseline; font-size: 1rem; width: 940px; overflow-y: hidden; margin-bottom: 20px !important; position: relative !important; overflow-x: auto !important;"><table border="0" cellpadding="0" cellspacing="0" role="none" style="font-size: 0.875rem; line-height: 1.25rem; width: 940px; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; text-size-adjust: 110%; margin-bottom: 30px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><tbody style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><tr style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><td class="gutter" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border-width: 0px !important; border-style: initial !important; border-color: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: rgb(112, 112, 112) !important;"><div class="line number1 index0 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">1</div></td><td class="code" style="font-size: 0.875rem; line-height: 1.25rem; width: 907px; text-size-adjust: 110%; padding: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border-width: 0px !important; border-style: initial !important; border-color: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><div class="container" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: relative !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><div class="line number1 index0 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">(field_number &lt;&lt; 3) | wire_type</code></div></div></td></tr></tbody></table></div></div></div></span><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">可以看到 Key 由两部分组成。第一部分是 field_number,比如消息 lm.helloworld 中 field id 的 field_number 为 1。第二部分为 wire_type。表示 Value 的传输类型。</p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">Wire Type 可能的类型如下表所示:</p><h5 id="N101FF" class="ibm-h5" style="padding-bottom: 15px; border: 0px; vertical-align: baseline; font-size: 1rem; line-height: 1.625rem; font-weight: normal; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">表 1. Wire Type</h5><div id="DataTables_Table_0_wrapper" class="dataTables_wrapper no-footer" style="border: 0px; vertical-align: baseline; position: relative; clear: both; zoom: 1; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;"><table border="0" cellpadding="0" cellspacing="0" class="ibm-data-table display dataTable no-footer dtr-inline ibm-widget-processed" data-widget="datatable" id="DataTables_Table_0" role="grid" style="margin-right: auto; margin-left: auto; vertical-align: baseline; border-collapse: separate; font-size: inherit; width: 940px; clear: both; border-spacing: 0px; box-sizing: content-box; border-bottom: 1px solid rgb(221, 221, 221); margin-bottom: 30px !important;"><thead xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" style="vertical-align: baseline; font-size: inherit;"><tr role="row" style="vertical-align: baseline; font-size: inherit; border-bottom: 1px solid rgb(90, 90, 90); font-weight: 600;"><th class="ibm-background-neutral-white-30 sorting_disabled" rowspan="1" colspan="1" style="padding: 16px 20px; vertical-align: top; text-align: center; font-size: inherit; background-color: rgb(244, 244, 244); box-sizing: content-box; font-weight: bold; width: 75px; border-bottom: 1px solid rgb(255, 255, 255) !important;"><span style="border: 0px; vertical-align: baseline; font-size: inherit;">Type</span></th><th class="ibm-background-neutral-white-30 sorting_disabled" rowspan="1" colspan="1" style="padding: 16px 20px; vertical-align: top; text-align: center; font-size: inherit; background-color: rgb(244, 244, 244); box-sizing: content-box; font-weight: bold; width: 164px; border-bottom: 1px solid rgb(255, 255, 255) !important;"><span style="border: 0px; vertical-align: baseline; font-size: inherit;">Meaning</span></th><th class="ibm-background-neutral-white-30 sorting_disabled" rowspan="1" colspan="1" style="padding: 16px 20px; vertical-align: top; text-align: center; font-size: inherit; background-color: rgb(244, 244, 244); box-sizing: content-box; font-weight: bold; width: 581px; border-bottom: 1px solid rgb(255, 255, 255) !important;"><span style="border: 0px; vertical-align: baseline; font-size: inherit;">Used For</span></th></tr></thead><tbody xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" style="vertical-align: baseline; font-size: inherit;"><tr role="row" class="odd" style="vertical-align: baseline; font-size: inherit; background-color: inherit;"><td tabindex="0" style="padding: 16px 20px; vertical-align: top; font-size: inherit; box-sizing: content-box; border-top: 0px; background-color: inherit;">0</td><td style="padding: 16px 20px; vertical-align: top; font-size: inherit; box-sizing: content-box; border-top: 0px; background-color: inherit;">Varint</td><td style="padding: 16px 20px; vertical-align: top; font-size: inherit; box-sizing: content-box; border-top: 0px; background-color: inherit;">int32, int64, uint32, uint64, sint32, sint64, bool, enum</td></tr><tr role="row" class="even" style="vertical-align: baseline; font-size: inherit; border-top: 1px solid rgb(224, 224, 224);"><td tabindex="0" style="padding: 16px 20px; vertical-align: top; font-size: inherit; box-sizing: content-box; border-top-color: rgb(221, 221, 221); background-color: inherit;">1</td><td style="padding: 16px 20px; vertical-align: top; font-size: inherit; box-sizing: content-box; border-top-color: rgb(221, 221, 221); background-color: inherit;">64-bit</td><td style="padding: 16px 20px; vertical-align: top; font-size: inherit; box-sizing: content-box; border-top-color: rgb(221, 221, 221); background-color: inherit;">fixed64, sfixed64, double</td></tr><tr role="row" class="odd" style="vertical-align: baseline; font-size: inherit; border-top: 1px solid rgb(224, 224, 224); background-color: inherit;"><td tabindex="0" style="padding: 16px 20px; vertical-align: top; font-size: inherit; box-sizing: content-box; border-top-color: rgb(221, 221, 221); background-color: inherit;">2</td><td style="padding: 16px 20px; vertical-align: top; font-size: inherit; box-sizing: content-box; border-top-color: rgb(221, 221, 221); background-color: inherit;">Length-delimi</td><td style="padding: 16px 20px; vertical-align: top; font-size: inherit; box-sizing: content-box; border-top-color: rgb(221, 221, 221); background-color: inherit;">string, bytes, embedded messages, packed repeated fields</td></tr><tr role="row" class="even" style="vertical-align: baseline; font-size: inherit; border-top: 1px solid rgb(224, 224, 224);"><td tabindex="0" style="padding: 16px 20px; vertical-align: top; font-size: inherit; box-sizing: content-box; border-top-color: rgb(221, 221, 221); background-color: inherit;">3</td><td style="padding: 16px 20px; vertical-align: top; font-size: inherit; box-sizing: content-box; border-top-color: rgb(221, 221, 221); background-color: inherit;">Start group</td><td style="padding: 16px 20px; vertical-align: top; font-size: inherit; box-sizing: content-box; border-top-color: rgb(221, 221, 221); background-color: inherit;">Groups (deprecated)</td></tr><tr role="row" class="odd" style="vertical-align: baseline; font-size: inherit; border-top: 1px solid rgb(224, 224, 224); background-color: inherit;"><td tabindex="0" style="padding: 16px 20px; vertical-align: top; font-size: inherit; box-sizing: content-box; border-top-color: rgb(221, 221, 221); background-color: inherit;">4</td><td style="padding: 16px 20px; vertical-align: top; font-size: inherit; box-sizing: content-box; border-top-color: rgb(221, 221, 221); background-color: inherit;">End group</td><td style="padding: 16px 20px; vertical-align: top; font-size: inherit; box-sizing: content-box; border-top-color: rgb(221, 221, 221); background-color: inherit;">Groups (deprecated)</td></tr><tr role="row" class="even" style="vertical-align: baseline; font-size: inherit; border-top: 1px solid rgb(224, 224, 224);"><td tabindex="0" style="padding: 16px 20px; vertical-align: top; font-size: inherit; box-sizing: content-box; border-top-color: rgb(221, 221, 221); background-color: inherit;">5</td><td style="padding: 16px 20px; vertical-align: top; font-size: inherit; box-sizing: content-box; border-top-color: rgb(221, 221, 221); background-color: inherit;">32-bit</td><td style="padding: 16px 20px; vertical-align: top; font-size: inherit; box-sizing: content-box; border-top-color: rgb(221, 221, 221); background-color: inherit;">fixed32, sfixed32, float</td></tr></tbody></table></div><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">在我们的例子当中,field id 所采用的数据类型为 int32,因此对应的 wire type 为 0。细心的读者或许会看到在 Type 0 所能表示的数据类型中有 int32 和 sint32 这两个非常类似的数据类型。Google Protocol Buffer 区别它们的主要意图也是为了减少 encoding 后的字节数。</p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">在计算机内,一个负数一般会被表示为一个很大的整数,因为计算机定义负数的符号位为数字的最高位。如果采用 Varint 表示一个负数,那么一定需要 5 个 byte。为此 Google Protocol Buffer 定义了 sint32 这种类型,采用 zigzag 编码。</p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">Zigzag 编码用无符号数来表示有符号数字,正数和负数交错,这就是 zigzag 这个词的含义了。</p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">如图所示:</p><h5 id="fig8" class="ibm-h5" style="padding-bottom: 15px; border: 0px; vertical-align: baseline; font-size: 1rem; line-height: 1.625rem; font-weight: normal; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">图 8. ZigZag 编码</h5><img src="https://www.ibm.com/developerworks/cn/linux/l-cn-gpb/image008.jpg" class="ibm-downsize" alt="图 8. ZigZag 编码" height="220" width="366" style="border: 0px; vertical-align: baseline; max-width: 100%; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif; height: auto !important;"><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">使用 zigzag 编码,绝对值小的数字,无论正负都可以采用较少的 byte 来表示,充分利用了 Varint 这种技术。</p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">其他的数据类型,比如字符串等则采用类似数据库中的 varchar 的表示方法,即用一个 varint 表示长度,然后将其余部分紧跟在这个长度部分之后即可。</p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">通过以上对 protobuf Encoding 方法的介绍,想必您也已经发现 protobuf 消息的内容小,适于网络传输。假如您对那些有关技术细节的描述缺乏耐心和兴趣,那么下面这个简单而直观的比较应该能给您更加深刻的印象。</p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">对于代码清单 1 中的消息,用 Protobuf 序列化后的字节序列为:</p><span class="dw-code-nohighlight" style="border: 0px; vertical-align: baseline; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;"><div class="ibm-syntax-container" style="border: 0px; vertical-align: baseline; font-size: 1rem;"><div style="border: 0px; vertical-align: baseline; font-size: 1rem;"><div id="highlighter_580999" class="syntaxhighlighterhtmlscript" style="border: 0px; vertical-align: baseline; font-size: 1rem; width: 940px; overflow-y: hidden; margin-bottom: 20px !important; position: relative !important; overflow-x: auto !important;"><table border="0" cellpadding="0" cellspacing="0" role="none" style="font-size: 0.875rem; line-height: 1.25rem; width: 940px; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; text-size-adjust: 110%; margin-bottom: 30px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><tbody style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><tr style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><td class="gutter" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border-width: 0px !important; border-style: initial !important; border-color: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: rgb(112, 112, 112) !important;"><div class="line number1 index0 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">1</div></td><td class="code" style="font-size: 0.875rem; line-height: 1.25rem; width: 907px; text-size-adjust: 110%; padding: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border-width: 0px !important; border-style: initial !important; border-color: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><div class="container" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: relative !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><div class="line number1 index0 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">08 65 12 06 48 65 6C 6C 6F 77</code></div></div></td></tr></tbody></table></div></div></div></span><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">而如果用 XML,则类似这样:</p><span class="dw-code-nohighlight" style="border: 0px; vertical-align: baseline; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;"><div class="ibm-syntax-container" style="border: 0px; vertical-align: baseline; font-size: 1rem;"><div style="border: 0px; vertical-align: baseline; font-size: 1rem;"><div id="highlighter_928477" class="syntaxhighlighterhtmlscript" style="border: 0px; vertical-align: baseline; font-size: 1rem; width: 940px; overflow-y: hidden; margin-bottom: 20px !important; position: relative !important; overflow-x: auto !important;"><table border="0" cellpadding="0" cellspacing="0" role="none" style="font-size: 0.875rem; line-height: 1.25rem; width: 940px; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; text-size-adjust: 110%; margin-bottom: 30px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><tbody style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><tr style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><td class="gutter" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border-width: 0px !important; border-style: initial !important; border-color: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: rgb(112, 112, 112) !important;"><div class="line number1 index0 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">1</div><div class="line number2 index1 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">2</div><div class="line number3 index2 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">3</div><div class="line number4 index3 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">4</div><div class="line number5 index4 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">5</div><div class="line number6 index5 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">6</div><div class="line number7 index6 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">7</div><div class="line number8 index7 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">8</div><div class="line number9 index8 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 0.5em !important; padding-left: 1em !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(0, 118, 112) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">9</div></td><td class="code" style="font-size: 0.875rem; line-height: 1.25rem; width: 907px; text-size-adjust: 110%; padding: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; border-width: 0px !important; border-style: initial !important; border-color: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><div class="container" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: relative !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;"><div class="line number1 index0 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">31 30 31 3C 2F 69 64 3E 3C 6E 61 6D 65 3E 68 65 </code></div><div class="line number2 index1 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript spaces" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;">&nbsp;</code><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">6C 6C 6F 3C 2F 6E 61 6D 65 3E 3C 2F 68 65 6C 6C </code></div><div class="line number3 index2 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript spaces" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;">&nbsp;</code><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">6F 77 6F 72 6C 64 3E </code></div><div class="line number4 index3 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;">&nbsp;</div><div class="line number5 index4 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">一共 55 个字节,这些奇怪的数字需要稍微解释一下,其含义用 ASCII 表示如下:</code></div><div class="line number6 index5 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript spaces" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;">&nbsp;</code><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">&lt;</code><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">helloworld</code><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">&gt; </code></div><div class="line number7 index6 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript spaces" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">&lt;</code><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">id</code><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">&gt;101&lt;/</code><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">id</code><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">&gt; </code></div><div class="line number8 index7 alt1" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript spaces" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">&lt;</code><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">name</code><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">&gt;hello&lt;/</code><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">name</code><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">&gt; </code></div><div class="line number9 index8 alt2" style="font-size: 0.875rem; line-height: 1.25rem; text-size-adjust: 110%; padding-right: 1em !important; padding-left: 1em !important; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important;"><code class="htmlscript spaces" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;">&nbsp;</code><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">&lt;/</code><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">helloworld</code><code class="htmlscript plain" style="font-size: 0.875rem; font-family: ibm-plex-mono, Menlo, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera Sans Mono&quot;, Courier, monospace; line-height: 1.25rem; text-size-adjust: 110%; border: 0px !important; vertical-align: baseline !important; border-radius: 0px !important; background: none !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; color: black !important;">&gt;</code></div></div></td></tr></tbody></table></div></div></div></span><h3 id="minor5.2" class="ibm-h3" style="padding-top: 24px; padding-bottom: 28px; border: 0px; vertical-align: baseline; font-size: 1.5625rem; line-height: 1.875rem; font-weight: normal; clear: left; color: rgb(63, 63, 63); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">封解包的速度</h3><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">首先我们来了解一下 XML 的封解包过程。XML 需要从文件中读取出字符串,再转换为 XML 文档对象结构模型。之后,再从 XML 文档对象结构模型中读取指定节点的字符串,最后再将这个字符串转换成指定类型的变量。这个过程非常复杂,其中将 XML 文件转换为文档对象结构模型的过程通常需要完成词法文法分析等大量消耗 CPU 的复杂计算。</p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">反观 Protobuf,它只需要简单地将一个二进制序列,按照指定的格式读取到 C++ 对应的结构类型中就可以了。从上一节的描述可以看到消息的 decoding 过程也可以通过几个位移操作组成的表达式计算即可完成。速度非常快。</p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">为了说明这并不是我拍脑袋随意想出来的说法,下面让我们简单分析一下 Protobuf 解包的代码流程吧。</p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">以代码清单 3 中的 Reader 为例,该程序首先调用 msg1 的 ParseFromIstream 方法,这个方法解析从文件读入的二进制数据流,并将解析出来的数据赋予 helloworld 类的相应数据成员。</p><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">该过程可以用下图表示:</p><h5 id="fig9" class="ibm-h5" style="padding-bottom: 15px; border: 0px; vertical-align: baseline; font-size: 1rem; line-height: 1.625rem; font-weight: normal; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">图 9. 解包流程图</h5><img src="https://www.ibm.com/developerworks/cn/linux/l-cn-gpb/image009.jpg" class="ibm-downsize" alt="图 9. 解包流程图" height="286" width="415" style="border: 0px; vertical-align: baseline; max-width: 100%; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif; height: auto !important;"><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">整个解析过程需要 Protobuf 本身的框架代码和由 Protobuf 编译器生成的代码共同完成。Protobuf 提供了基类 Message 以及 Message_lite 作为通用的 Framework,,CodedInputStream 类,WireFormatLite 类等提供了对二进制数据的 decode 功能,从 5.1 节的分析来看,Protobuf 的解码可以通过几个简单的数学运算完成,无需复杂的词法语法分析,因此 ReadTag() 等方法都非常快。 在这个调用路径上的其他类和方法都非常简单,感兴趣的读者可以自行阅读。 相对于 XML 的解析过程,以上的流程图实在是非常简单吧?这也就是 Protobuf 效率高的第二个原因了。</p><h2 id="major6" class="ibm-h2" style="padding-top: 12px; padding-bottom: 28px; border: 0px; vertical-align: baseline; font-size: 2.1875rem; line-height: 2.5rem; font-weight: normal; clear: left; color: rgb(63, 63, 63); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">结束语</h2><p style="padding-bottom: 22px; border: 0px; vertical-align: baseline; font-size: 1.0625rem; line-height: 1.625rem; color: rgb(50, 50, 50); font-family: ibm-plex-sans, &quot;Helvetica Neue&quot;, Arial, sans-serif;">往往了解越多,人们就会越觉得自己无知。我惶恐地发现自己竟然写了一篇关于序列化的文章,文中必然有许多想当然而自以为是的东西,还希望各位能够去伪存真,更希望真的高手能不吝赐教,给我来信。谢谢。</p>
页: [1]
查看完整版本: Google Protocol Buffer 的使用和原理