Skip to content

Instantly share code, notes, and snippets.

@aschrijver
Created July 22, 2017 06:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aschrijver/0a2fb12347362ced80c6c5443fa8f40e to your computer and use it in GitHub Desktop.
Save aschrijver/0a2fb12347362ced80c6c5443fa8f40e to your computer and use it in GitHub Desktop.
Example of incorrect output running protoc-gen-doc with custom html mustache template
<!DOCTYPE html>
<html>
<head>
<title>Protocol Documentation</title>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Ubuntu:400,700,400italic"/>
<style>
body {
width: 60em;
margin: 1em auto;
color: #222;
font-family: "Ubuntu", sans-serif;
padding-bottom: 4em;
}
h1 {
font-weight: normal;
border-bottom: 1px solid #aaa;
padding-bottom: 0.5ex;
}
h2 {
border-bottom: 1px solid #aaa;
padding-bottom: 0.5ex;
margin: 1.5em 0;
}
h3 {
font-weight: normal;
border-bottom: 1px solid #aaa;
padding-bottom: 0.5ex;
}
a {
text-decoration: none;
color: #567e25;
}
table {
width: 100%;
font-size: 80%;
border-collapse: collapse;
}
thead {
font-weight: 700;
background-color: #dcdcdc;
}
tbody tr:nth-child(even) {
background-color: #fbfbfb;
}
td {
border: 1px solid #ccc;
padding: 0.5ex 2ex;
}
td p {
text-indent: 1em;
margin: 0;
}
td p:nth-child(1) {
text-indent: 0; /* No indent on first p in td */
}
/* Table of fields */
.field-table td:nth-child(1) { /* Field */
width: 10em;
}
.field-table td:nth-child(2) { /* Type */
width: 10em;
}
.field-table td:nth-child(3) { /* Label */
width: 6em;
}
.field-table td:nth-child(4) { /* Description */
width: auto;
}
/* Table of extensions */
.extension-table td:nth-child(1) { /* Extension */
width: 10em;
}
.extension-table td:nth-child(2) { /* Type */
width: 10em;
}
.extension-table td:nth-child(3) { /* Base */
width: 10em;
}
.extension-table td:nth-child(4) { /* Number */
width: 5em;
}
.extension-table td:nth-child(5) { /* Description */
width: auto;
}
/* Table of enum values. */
.enum-table td:nth-child(1) { /* Name */
width: 10em;
}
.enum-table td:nth-child(2) { /* Number */
width: 10em;
}
.enum-table td:nth-child(3) { /* Description */
width: auto;
}
/* Table of scalar value types. */
.scalar-value-types-table tr {
height: 3em;
}
/* Table of contents. */
#toc-container ul {
list-style-type: none;
padding-left: 1em;
line-height: 180%;
margin: 0;
}
#toc > li > a {
font-weight: bold;
}
/* File heading div */
.file-heading {
width: 100%;
display: table;
border-bottom: 1px solid #aaa;
margin: 4em 0 1.5em 0;
}
.file-heading h2 {
border: none;
display: table-cell;
}
.file-heading a {
text-align: right;
display: table-cell;
}
/* The 'M', 'E' and 'X' badges in the ToC */
.badge {
width: 1.6em;
height: 1.6em;
display: inline-block;
line-height: 1.6em;
text-align: center;
font-weight: bold;
font-size: 60%;
color: #89ba48;
background-color: #dff0c8;
margin: 0.5ex 1em 0.5ex -1em;
border: 1px solid #fbfbfb;
border-radius: 1ex;
}
</style>
<!-- User custom CSS -->
<link rel="stylesheet" type="text/css" href="stylesheet.css"/>
</head>
<body>
<h1 id="title">Hypercore Protocol</h1>
<h2>Overview</h2>
<div id="toc-container">
<ul id="toc">
<li>
<a href="#HypercoreSpecV1_html.proto">HypercoreSpecV1_html.proto</a>
<ul>
<li>
<a href="#Cancel">
<span class="badge">M</span>
Cancel
</a>
</li>
<li>
<a href="#Data">
<span class="badge">M</span>
Data
</a>
</li>
<li>
<a href="#Data.Node">
<span class="badge">M</span>
Data.Node
</a>
</li>
<li>
<a href="#Feed">
<span class="badge">M</span>
Feed
</a>
</li>
<li>
<a href="#Handshake">
<span class="badge">M</span>
Handshake
</a>
</li>
<li>
<a href="#Have">
<span class="badge">M</span>
Have
</a>
</li>
<li>
<a href="#Info">
<span class="badge">M</span>
Info
</a>
</li>
<li>
<a href="#Request">
<span class="badge">M</span>
Request
</a>
</li>
<li>
<a href="#Unhave">
<span class="badge">M</span>
Unhave
</a>
</li>
<li>
<a href="#Unwant">
<span class="badge">M</span>
Unwant
</a>
</li>
<li>
<a href="#Want">
<span class="badge">M</span>
Want
</a>
</li>
</ul>
</li>
<li><a href="#scalar-value-types">Scalar Value Types</a></li>
</ul>
</div>
<div class="file-heading">
<h2 id="HypercoreSpecV1_html.proto">HypercoreSpecV1_html.proto</h2><a href="#title">Top</a>
</div>
<p>The SLEEP format is designed to allow for sparse replication, meaning you
can efficiently download only the metadata and data required to resolve a
single byte region of a single file, which makes Dat suitable for a wide
variety of streaming, real time and large dataset use cases.</p><p>To take advantage of this, Dat includes a network protocol. It is message
based and stateless, making it possible to implement on a variety of network
transport protocols including UDP and TCP.</p><p>Both metadata and content registers in SLEEP share the exact same
replication protocol.<br>
Individual messages are encoded using Protocol Buffers and there are ten
message types in total.</p><p>Over the wire messages are packed in the following lightweight
container format:</p><p><pre>
&lt;varint - length of rest of message&gt;
&lt;varint - header&gt;
&lt;message&gt;
</pre></p><p>The header value is a single varint that has two pieces of information,
the integer type that declares a 4-bit message type (used below), and a
channel identifier, 0 for metadata and 1 for content.</p><p>To generate this varint, you bitshift the 4-bit type integer onto the end of
the channel identifier, e.g. channel &lt;&ltl 4 | &lt;4-bit-type&gt;.</p>
<h3 id="Cancel">Cancel</h3>
<p></p>
<h3 id="Data">Data</h3>
<p></p>
<h3 id="Data.Node">Data.Node</h3>
<p></p>
<h3 id="Feed">Feed</h3>
<p>Type 0, should be the first message sent on a channel.</p>
<h3 id="Handshake">Handshake</h3>
<p></p>
<h3 id="Have">Have</h3>
<p></p>
<h3 id="Info">Info</h3>
<p>Type 2. Message indicating state changes. Used to indicate whether you are
uploading and/or downloading.</p><p>Initial state for uploading / downloading is true.
If both ends are not downloading and not live it is safe to consider
the stream ended.</p>
<h3 id="Request">Request</h3>
<p></p>
<h3 id="Unhave">Unhave</h3>
<p></p>
<h3 id="Unwant">Unwant</h3>
<p></p>
<h3 id="Want">Want</h3>
<p></p>
<h2 id="scalar-value-types">Scalar Value Types</h2>
<table class="scalar-value-types-table">
<thead>
<tr><td>.proto Type</td><td>Notes</td><td>C++ Type</td><td>Java Type</td><td>Python Type</td></tr>
</thead>
<tbody>
<tr id="double">
<td>double</td>
<td></td>
<td>double</td>
<td>double</td>
<td>float</td>
</tr>
<tr id="float">
<td>float</td>
<td></td>
<td>float</td>
<td>float</td>
<td>float</td>
</tr>
<tr id="int32">
<td>int32</td>
<td>Uses variable-length encoding. Inefficient for encoding negative numbers – if your field is likely to have negative values, use sint32 instead.</td>
<td>int32</td>
<td>int</td>
<td>int</td>
</tr>
<tr id="int64">
<td>int64</td>
<td>Uses variable-length encoding. Inefficient for encoding negative numbers – if your field is likely to have negative values, use sint64 instead.</td>
<td>int64</td>
<td>long</td>
<td>int/long</td>
</tr>
<tr id="uint32">
<td>uint32</td>
<td>Uses variable-length encoding.</td>
<td>uint32</td>
<td>int</td>
<td>int/long</td>
</tr>
<tr id="uint64">
<td>uint64</td>
<td>Uses variable-length encoding.</td>
<td>uint64</td>
<td>long</td>
<td>int/long</td>
</tr>
<tr id="sint32">
<td>sint32</td>
<td>Uses variable-length encoding. Signed int value. These more efficiently encode negative numbers than regular int32s.</td>
<td>int32</td>
<td>int</td>
<td>int</td>
</tr>
<tr id="sint64">
<td>sint64</td>
<td>Uses variable-length encoding. Signed int value. These more efficiently encode negative numbers than regular int64s.</td>
<td>int64</td>
<td>long</td>
<td>int/long</td>
</tr>
<tr id="fixed32">
<td>fixed32</td>
<td>Always four bytes. More efficient than uint32 if values are often greater than 2^28.</td>
<td>uint32</td>
<td>int</td>
<td>int</td>
</tr>
<tr id="fixed64">
<td>fixed64</td>
<td>Always eight bytes. More efficient than uint64 if values are often greater than 2^56.</td>
<td>uint64</td>
<td>long</td>
<td>int/long</td>
</tr>
<tr id="sfixed32">
<td>sfixed32</td>
<td>Always four bytes.</td>
<td>int32</td>
<td>int</td>
<td>int</td>
</tr>
<tr id="sfixed64">
<td>sfixed64</td>
<td>Always eight bytes.</td>
<td>int64</td>
<td>long</td>
<td>int/long</td>
</tr>
<tr id="bool">
<td>bool</td>
<td></td>
<td>bool</td>
<td>boolean</td>
<td>boolean</td>
</tr>
<tr id="string">
<td>string</td>
<td>A string must always contain UTF-8 encoded or 7-bit ASCII text.</td>
<td>string</td>
<td>String</td>
<td>str/unicode</td>
</tr>
<tr id="bytes">
<td>bytes</td>
<td>May contain any arbitrary sequence of bytes.</td>
<td>string</td>
<td>ByteString</td>
<td>str</td>
</tr>
</tbody>
</table>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment