nim-libp2p/enhance-logs-for-nwaku-over.../libp2p/varint.html

734 lines
52 KiB
HTML

<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!-- This file is generated by Nim. -->
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Favicon -->
<link rel="shortcut icon" href="data:image/x-icon;base64,AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AAAAAAUAAAAF////AP///wD///8A////AP///wD///8A////AP///wD///8A////AAAAAAIAAABbAAAAlQAAAKIAAACbAAAAmwAAAKIAAACVAAAAWwAAAAL///8A////AP///wD///8A////AAAAABQAAADAAAAAYwAAAA3///8A////AP///wD///8AAAAADQAAAGMAAADAAAAAFP///wD///8A////AP///wAAAACdAAAAOv///wD///8A////AP///wD///8A////AP///wD///8AAAAAOgAAAJ3///8A////AP///wAAAAAnAAAAcP///wAAAAAoAAAASv///wD///8A////AP///wAAAABKAAAAKP///wAAAABwAAAAJ////wD///8AAAAAgQAAABwAAACIAAAAkAAAAJMAAACtAAAAFQAAABUAAACtAAAAkwAAAJAAAACIAAAAHAAAAIH///8A////AAAAAKQAAACrAAAAaP///wD///8AAAAARQAAANIAAADSAAAARf///wD///8AAAAAaAAAAKsAAACk////AAAAADMAAACcAAAAnQAAABj///8A////AP///wAAAAAYAAAAGP///wD///8A////AAAAABgAAACdAAAAnAAAADMAAAB1AAAAwwAAAP8AAADpAAAAsQAAAE4AAAAb////AP///wAAAAAbAAAATgAAALEAAADpAAAA/wAAAMMAAAB1AAAAtwAAAOkAAAD/AAAA/wAAAP8AAADvAAAA3gAAAN4AAADeAAAA3gAAAO8AAAD/AAAA/wAAAP8AAADpAAAAtwAAAGUAAAA/AAAA3wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAADfAAAAPwAAAGX///8A////AAAAAEgAAADtAAAAvwAAAL0AAADGAAAA7wAAAO8AAADGAAAAvQAAAL8AAADtAAAASP///wD///8A////AP///wD///8AAAAAO////wD///8A////AAAAAIcAAACH////AP///wD///8AAAAAO////wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A//8AAP//AAD4HwAA7/cAAN/7AAD//wAAoYUAAJ55AACf+QAAh+EAAAAAAADAAwAA4AcAAP5/AAD//wAA//8AAA=="/>
<link rel="icon" type="image/png" sizes="32x32" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAA3XAAAN1wFCKJt4AAAAB3RJTUUH4QQQEwksSS9ZWwAAAk1JREFUWMPtll2ITVEUx39nn/O7Y5qR8f05wtCUUr6ZIS++8pEnkZInPImneaCQ5METNdOkeFBKUhMPRIkHKfEuUZSUlGlKPN2TrgfncpvmnntnmlEyq1Z7t89/rf9a6+y99oZxGZf/XeIq61EdtgKXgdXA0xrYAvBjOIF1AI9zvjcC74BSpndrJPkBWDScTF8Aa4E3wDlgHbASaANmVqlcCnwHvgDvgVfAJ+AikAAvgfVZwLnSVZHZaOuKoQi3ZOMi4NkYkpe1p4J7A8BpYAD49hfIy/oqG0+hLomiKP2L5L+1ubn5115S+3OAn4EnwBlgMzCjyt6ZAnQCJ4A7wOs88iRJHvw50HoujuPBoCKwHWiosy8MdfZnAdcHk8dxXFJ3VQbQlCTJvRBCGdRbD4M6uc5glpY3eAihpN5S5w12diSEcCCEcKUO4ljdr15T76ur1FDDLIQQ3qv71EdDOe3Kxj3leRXyk+pxdWnFWod6Wt2bY3de3aSuUHcPBVimHs7mK9WrmeOF6lR1o9qnzskh2ar2qm1qizpfXaPeVGdlmGN5pb09qMxz1Xb1kLqgzn1RyH7JUXW52lr5e/Kqi9qpto7V1atuUzfnARrV7jEib1T76gG2qxdGmXyiekkt1GswPTtek0aBfJp6YySGBfWg2tPQ0FAYgf1stUfdmdcjarbYJEniKIq6gY/Aw+zWHAC+p2labGpqiorFYgGYCEzN7oQdQClN07O1/EfDyGgC0ALMBdYAi4FyK+4H3gLPsxfR1zRNi+NP7nH5J+QntnXe5B5mpfQAAAAASUVORK5CYII=">
<!-- Google fonts -->
<link href='https://fonts.googleapis.com/css?family=Lato:400,600,900' rel='stylesheet' type='text/css'/>
<link href='https://fonts.googleapis.com/css?family=Source+Code+Pro:400,500,600' rel='stylesheet' type='text/css'/>
<!-- CSS -->
<title>libp2p/varint</title>
<link rel="stylesheet" type="text/css" href="../nimdoc.out.css">
<script type="text/javascript" src="../dochack.js"></script>
<script type="text/javascript">
function main() {
var pragmaDots = document.getElementsByClassName("pragmadots");
for (var i = 0; i < pragmaDots.length; i++) {
pragmaDots[i].onclick = function(event) {
// Hide tease
event.target.parentNode.style.display = "none";
// Show actual
event.target.parentNode.nextElementSibling.style.display = "inline";
}
}
function switchTheme(e) {
if (e.target.checked) {
document.documentElement.setAttribute('data-theme', 'dark');
localStorage.setItem('theme', 'dark');
} else {
document.documentElement.setAttribute('data-theme', 'light');
localStorage.setItem('theme', 'light');
}
}
const toggleSwitch = document.querySelector('.theme-switch input[type="checkbox"]');
if (toggleSwitch !== null) {
toggleSwitch.addEventListener('change', switchTheme, false);
}
var currentTheme = localStorage.getItem('theme');
if (!currentTheme && window.matchMedia('(prefers-color-scheme: dark)').matches) {
currentTheme = 'dark';
}
if (currentTheme) {
document.documentElement.setAttribute('data-theme', currentTheme);
if (currentTheme === 'dark' && toggleSwitch !== null) {
toggleSwitch.checked = true;
}
}
}
window.addEventListener('DOMContentLoaded', main);
</script>
</head>
<body>
<div class="document" id="documentId">
<div class="container">
<h1 class="title">libp2p/varint</h1>
<div class="row">
<div class="three columns">
<div class="theme-switch-wrapper">
<label class="theme-switch" for="checkbox">
<input type="checkbox" id="checkbox" />
<div class="slider round"></div>
</label>
&nbsp;&nbsp;&nbsp; <em>Dark Mode</em>
</div>
<div id="global-links">
<ul class="simple">
<li>
<a href="../theindex.html">Index</a>
</li>
</ul>
</div>
<div id="searchInputDiv">
Search: <input type="text" id="searchInput"
onkeyup="search()" />
</div>
<div>
Group by:
<select onchange="groupBy(this.value)">
<option value="section">Section</option>
<option value="type">Type</option>
</select>
</div>
<script type="text/javascript">
function main2() {
// Create the slider
var firstSlider = document.getElementsByClassName("theme-switch-wrapper")[0];
var newSlider = document.createRange().createContextualFragment(`
<div class="theme-switch-wrapper">
<label class="theme-switch" for="internalcheckbox">
<input type="checkbox" id="internalcheckbox">
<div class="slider round"></div>
</label>
&nbsp;&nbsp;&nbsp; <em>Internal</em>
</div>
`);
var sliderInst = firstSlider.after(newSlider);
// Restore slider state from storage
var currentMode = localStorage.getItem('privateMode');
if (currentMode == "private") {
document.getElementById("internalcheckbox").checked = true;
} else {
hidePrivateProcs();
}
document.getElementById("internalcheckbox").onclick = togglePrivateProcs;
}
function hidePrivateProcs() {
var toHide = document.getElementsByClassName("tohide");
for (var i = 0; i < toHide.length; i++) {
var pragmas = toHide[i].querySelectorAll("span.Identifier");
var public = false;
for (var z = 0; z < pragmas.length; z++) {
if (pragmas[z].innerText == "public") {
public = true;
break;
}
}
if (public == false) {
toHide[i].style.display = "none";
toHide[i].classList.add("hidden");
links = document.querySelectorAll("a[href='#" + encodeURIComponent(toHide[i].id) + "']");
for (var y = 0; y < links.length; y++) {
links[y].parentNode.style.display = "none";
links[y].parentNode.classList.add("hidden");
}
}
}
// TOC
var nestedSections = document.getElementsByClassName("nested-toc-section");
for (var i = 0; i < nestedSections.length; i++) {
if (nestedSections[i].querySelectorAll("li:not(.hidden)").length == 0) {
nestedSections[i].style.display = "none";
nestedSections[i].classList.add("hidden");
}
}
var sections = document.getElementsByClassName("simple-toc-section");
for (var i = 0; i < sections.length; i++) {
if (sections[i].querySelectorAll(".nested-toc-section:not(.hidden)").length == 0) {
sections[i].parentNode.style.display = "none";
sections[i].parentNode.classList.add("hidden");
}
}
// Sections
var sections = document.getElementsByClassName("section");
for (var i = 0; i < sections.length; i++) {
if (sections[i].querySelectorAll(".item > div").length == 0) continue;
if (sections[i].querySelectorAll(".item > div:not(.hidden)").length == 0) {
sections[i].style.display = "none";
sections[i].classList.add("hidden");
}
}
}
function showPrivateProcs() {
var toHide = Array.from(document.getElementsByClassName("hidden"));
for (var i = 0; i < toHide.length; i++) {
toHide[i].style.display = "";
toHide[i].classList.remove("hidden");
}
}
function togglePrivateProcs() {
if (document.getElementById("internalcheckbox").checked) {
localStorage.setItem('privateMode', 'private');
showPrivateProcs();
} else {
localStorage.setItem('privateMode', 'public');
hidePrivateProcs();
}
}
window.addEventListener("DOMContentLoaded", main2);
</script>
<ul class="simple simple-toc" id="toc-list">
<li>
<a class="reference reference-toplevel" href="#7" id="57">Types</a>
<ul class="simple simple-toc-section">
<li><a class="reference" href="#hint"
title="hint = distinct int">hint</a></li>
<li><a class="reference" href="#hint32"
title="hint32 = distinct int32">hint32</a></li>
<li><a class="reference" href="#hint64"
title="hint64 = distinct int64">hint64</a></li>
<li><a class="reference" href="#LP"
title="LP = object">LP</a></li>
<li><a class="reference" href="#LPSomeUVarint"
title="LPSomeUVarint = uint | uint64 | uint32 | uint16 | uint8">LPSomeUVarint</a></li>
<li><a class="reference" href="#LPSomeVarint"
title="LPSomeVarint = LPSomeUVarint">LPSomeVarint</a></li>
<li><a class="reference" href="#PB"
title="PB = object">PB</a></li>
<li><a class="reference" href="#PBSomeSVarint"
title="PBSomeSVarint = hint | hint64 | hint32">PBSomeSVarint</a></li>
<li><a class="reference" href="#PBSomeUVarint"
title="PBSomeUVarint = uint | uint64 | uint32">PBSomeUVarint</a></li>
<li><a class="reference" href="#PBSomeVarint"
title="PBSomeVarint = PBSomeUVarint | PBSomeSVarint | PBZigVarint">PBSomeVarint</a></li>
<li><a class="reference" href="#PBZigVarint"
title="PBZigVarint = zint | zint64 | zint32">PBZigVarint</a></li>
<li><a class="reference" href="#SomeUVarint"
title="SomeUVarint = PBSomeUVarint | LPSomeUVarint">SomeUVarint</a></li>
<li><a class="reference" href="#SomeVarint"
title="SomeVarint = PBSomeVarint | LPSomeVarint">SomeVarint</a></li>
<li><a class="reference" href="#VarintError"
title="VarintError {.pure.} = enum
Error, Overflow, Incomplete, Overlong, Overrun">VarintError</a></li>
<li><a class="reference" href="#VarintResult"
title="VarintResult[T] = Result[T, VarintError]">VarintResult</a></li>
<li><a class="reference" href="#zint"
title="zint = distinct int">zint</a></li>
<li><a class="reference" href="#zint32"
title="zint32 = distinct int32">zint32</a></li>
<li><a class="reference" href="#zint64"
title="zint64 = distinct int64">zint64</a></li>
</ul>
</li>
<li>
<a class="reference reference-toplevel" href="#12" id="62">Procs</a>
<ul class="simple simple-toc-section">
<ul class="simple nested-toc-section">encodeVarint
<li><a class="reference" href="#encodeVarint%2Ctypedesc%5BLP%5D%2CLPSomeVarint"
title="encodeVarint(vtype: typedesc[LP]; value: LPSomeVarint): VarintResult[seq[byte]]">encodeVarint(vtype: typedesc[LP]; value: LPSomeVarint): VarintResult[seq[byte]]</a></li>
<li><a class="reference" href="#encodeVarint%2Ctypedesc%5BPB%5D%2CPBSomeVarint"
title="encodeVarint(vtype: typedesc[PB]; value: PBSomeVarint): VarintResult[seq[byte]]">encodeVarint(vtype: typedesc[PB]; value: PBSomeVarint): VarintResult[seq[byte]]</a></li>
</ul>
<ul class="simple nested-toc-section">getSVarint
<li><a class="reference" href="#getSVarint%2CopenArray%5Bbyte%5D%2Cint%2C"
title="getSVarint(pbytes: openArray[byte]; outsize: var int;
outval: var (PBZigVarint | PBSomeSVarint)): VarintResult[void]">getSVarint(pbytes: openArray[byte]; outsize: var int;
outval: var (PBZigVarint | PBSomeSVarint)): VarintResult[void]</a></li>
</ul>
<ul class="simple nested-toc-section">getUVarint
<li><a class="reference" href="#getUVarint%2Ctypedesc%5BT%5D%2CopenArray%5Bbyte%5D%2Cint%2CSomeUVarint"
title="getUVarint[T: PB | LP](vtype: typedesc[T]; pbytes: openArray[byte];
outlen: var int; outval: var SomeUVarint): VarintResult[
void]">getUVarint[T: PB | LP](vtype: typedesc[T]; pbytes: openArray[byte];
outlen: var int; outval: var SomeUVarint): VarintResult[
void]</a></li>
</ul>
<ul class="simple nested-toc-section">getVarint
<li><a class="reference" href="#getVarint%2Ctypedesc%5BT%5D%2CopenArray%5Bbyte%5D%2Cint%2CSomeVarint"
title="getVarint[T: PB | LP](vtype: typedesc[T]; pbytes: openArray[byte];
nbytes: var int; value: var SomeVarint): VarintResult[void]">getVarint[T: PB | LP](vtype: typedesc[T]; pbytes: openArray[byte];
nbytes: var int; value: var SomeVarint): VarintResult[void]</a></li>
</ul>
<ul class="simple nested-toc-section">putSVarint
<li><a class="reference" href="#putSVarint%2CopenArray%5Bbyte%5D%2Cint%2C"
title="putSVarint(pbytes: var openArray[byte]; outsize: var int;
outval: (PBZigVarint | PBSomeSVarint)): VarintResult[void]">putSVarint(pbytes: var openArray[byte]; outsize: var int;
outval: (PBZigVarint | PBSomeSVarint)): VarintResult[void]</a></li>
</ul>
<ul class="simple nested-toc-section">putUVarint
<li><a class="reference" href="#putUVarint%2Ctypedesc%5BT%5D%2CopenArray%5Bbyte%5D%2Cint%2CSomeUVarint"
title="putUVarint[T: PB | LP](vtype: typedesc[T]; pbytes: var openArray[byte];
outlen: var int; outval: SomeUVarint): VarintResult[void]">putUVarint[T: PB | LP](vtype: typedesc[T]; pbytes: var openArray[byte];
outlen: var int; outval: SomeUVarint): VarintResult[void]</a></li>
</ul>
<ul class="simple nested-toc-section">putVarint
<li><a class="reference" href="#putVarint%2Ctypedesc%5BT%5D%2CopenArray%5Bbyte%5D%2Cint%2CSomeVarint"
title="putVarint[T: PB | LP](vtype: typedesc[T]; pbytes: var openArray[byte];
nbytes: var int; value: SomeVarint): VarintResult[void]">putVarint[T: PB | LP](vtype: typedesc[T]; pbytes: var openArray[byte];
nbytes: var int; value: SomeVarint): VarintResult[void]</a></li>
</ul>
<ul class="simple nested-toc-section">vsizeof
<li><a class="reference" href="#vsizeof%2CSomeVarint"
title="vsizeof(x: SomeVarint): int">vsizeof(x: SomeVarint): int</a></li>
</ul>
</ul>
</li>
<li>
<a class="reference reference-toplevel" href="#18" id="68">Templates</a>
<ul class="simple simple-toc-section">
<ul class="simple nested-toc-section">toBytes
<li><a class="reference" href="#toBytes.t%2Ctypedesc%5BPB%5D%2CPBSomeVarint"
title="toBytes(vtype: typedesc[PB]; value: PBSomeVarint): auto">toBytes(vtype: typedesc[PB]; value: PBSomeVarint): auto</a></li>
</ul>
</ul>
</li>
</ul>
</div>
&nbsp;&nbsp;<a
href="https://github.com/status-im/nim-libp2p/tree/enhance-logs-for-nwaku-over-0.30.1-extra-logs/libp2p/varint.nim#L1"
class="link-seesrc" target="_blank">Source</a>
&nbsp;&nbsp;<a href="https://github.com/status-im/nim-libp2p/edit/devel/libp2p/varint.nim#L1" class="link-seesrc" target="_blank" >Edit</a>
<div class="nine columns" id="content">
<div id="tocRoot"></div>
<p class="module-desc">This module implements Variable Integer <tt class="docutils literal"><span class="pre"><span class="Identifier">VARINT</span></span></tt>. This module supports two variants of variable integer<ul class="simple"><li>Google ProtoBuf varint, which is able to encode full uint64 number and maximum size of encoded value is 10 octets (bytes). <a class="reference external" href="https://developers.google.com/protocol-buffers/docs/encoding#varints">https://developers.google.com/protocol-buffers/docs/encoding#varints</a></li>
<li>LibP2P varint, which is able to encode only 63bits of uint64 number and maximum size of encoded value is 9 octets (bytes). <a class="reference external" href="https://github.com/multiformats/unsigned-varint">https://github.com/multiformats/unsigned-varint</a></li>
</ul>
</p>
<div class="section" id="7">
<h1><a class="toc-backref" href="#7">Types</a></h1>
<dl class="item">
<div id="hint" class="tohide">
<dt><pre><a href="varint.html#hint"><span class="Identifier">hint</span></a> <span class="Other">=</span> <span class="Keyword">distinct</span> <span class="Identifier">int</span></pre></dt>
<dd>
Signed integer types which will be encoded using simple cast.
&nbsp;&nbsp;<a
href="https://github.com/status-im/nim-libp2p/tree/enhance-logs-for-nwaku-over-0.30.1-extra-logs/libp2p/varint.nim#L44"
class="link-seesrc" target="_blank">Source</a>
&nbsp;&nbsp;<a href="https://github.com/status-im/nim-libp2p/edit/devel/libp2p/varint.nim#L44" class="link-seesrc" target="_blank" >Edit</a>
</dd>
</div>
<div id="hint32" class="tohide">
<dt><pre><a href="varint.html#hint32"><span class="Identifier">hint32</span></a> <span class="Other">=</span> <span class="Keyword">distinct</span> <span class="Identifier">int32</span></pre></dt>
<dd>
&nbsp;&nbsp;<a
href="https://github.com/status-im/nim-libp2p/tree/enhance-logs-for-nwaku-over-0.30.1-extra-logs/libp2p/varint.nim#L42"
class="link-seesrc" target="_blank">Source</a>
&nbsp;&nbsp;<a href="https://github.com/status-im/nim-libp2p/edit/devel/libp2p/varint.nim#L42" class="link-seesrc" target="_blank" >Edit</a>
</dd>
</div>
<div id="hint64" class="tohide">
<dt><pre><a href="varint.html#hint64"><span class="Identifier">hint64</span></a> <span class="Other">=</span> <span class="Keyword">distinct</span> <span class="Identifier">int64</span></pre></dt>
<dd>
&nbsp;&nbsp;<a
href="https://github.com/status-im/nim-libp2p/tree/enhance-logs-for-nwaku-over-0.30.1-extra-logs/libp2p/varint.nim#L43"
class="link-seesrc" target="_blank">Source</a>
&nbsp;&nbsp;<a href="https://github.com/status-im/nim-libp2p/edit/devel/libp2p/varint.nim#L43" class="link-seesrc" target="_blank" >Edit</a>
</dd>
</div>
<div id="LP" class="tohide">
<dt><pre><a href="varint.html#LP"><span class="Identifier">LP</span></a> <span class="Other">=</span> <span class="Keyword">object</span></pre></dt>
<dd>
Use this type to specify LibP2P varint encoding
&nbsp;&nbsp;<a
href="https://github.com/status-im/nim-libp2p/tree/enhance-logs-for-nwaku-over-0.30.1-extra-logs/libp2p/varint.nim#L35"
class="link-seesrc" target="_blank">Source</a>
&nbsp;&nbsp;<a href="https://github.com/status-im/nim-libp2p/edit/devel/libp2p/varint.nim#L35" class="link-seesrc" target="_blank" >Edit</a>
</dd>
</div>
<div id="LPSomeUVarint" class="tohide">
<dt><pre><a href="varint.html#LPSomeUVarint"><span class="Identifier">LPSomeUVarint</span></a> <span class="Other">=</span> <span class="Identifier">uint</span> <span class="Operator">|</span> <span class="Identifier">uint64</span> <span class="Operator">|</span> <span class="Identifier">uint32</span> <span class="Operator">|</span> <span class="Identifier">uint16</span> <span class="Operator">|</span> <span class="Identifier">uint8</span></pre></dt>
<dd>
&nbsp;&nbsp;<a
href="https://github.com/status-im/nim-libp2p/tree/enhance-logs-for-nwaku-over-0.30.1-extra-logs/libp2p/varint.nim#L50"
class="link-seesrc" target="_blank">Source</a>
&nbsp;&nbsp;<a href="https://github.com/status-im/nim-libp2p/edit/devel/libp2p/varint.nim#L50" class="link-seesrc" target="_blank" >Edit</a>
</dd>
</div>
<div id="LPSomeVarint" class="tohide">
<dt><pre><a href="varint.html#LPSomeVarint"><span class="Identifier">LPSomeVarint</span></a> <span class="Other">=</span> <a href="varint.html#LPSomeUVarint"><span class="Identifier">LPSomeUVarint</span></a></pre></dt>
<dd>
&nbsp;&nbsp;<a
href="https://github.com/status-im/nim-libp2p/tree/enhance-logs-for-nwaku-over-0.30.1-extra-logs/libp2p/varint.nim#L51"
class="link-seesrc" target="_blank">Source</a>
&nbsp;&nbsp;<a href="https://github.com/status-im/nim-libp2p/edit/devel/libp2p/varint.nim#L51" class="link-seesrc" target="_blank" >Edit</a>
</dd>
</div>
<div id="PB" class="tohide">
<dt><pre><a href="varint.html#PB"><span class="Identifier">PB</span></a> <span class="Other">=</span> <span class="Keyword">object</span></pre></dt>
<dd>
Use this type to specify Google ProtoBuf's varint encoding
&nbsp;&nbsp;<a
href="https://github.com/status-im/nim-libp2p/tree/enhance-logs-for-nwaku-over-0.30.1-extra-logs/libp2p/varint.nim#L34"
class="link-seesrc" target="_blank">Source</a>
&nbsp;&nbsp;<a href="https://github.com/status-im/nim-libp2p/edit/devel/libp2p/varint.nim#L34" class="link-seesrc" target="_blank" >Edit</a>
</dd>
</div>
<div id="PBSomeSVarint" class="tohide">
<dt><pre><a href="varint.html#PBSomeSVarint"><span class="Identifier">PBSomeSVarint</span></a> <span class="Other">=</span> <a href="varint.html#hint"><span class="Identifier">hint</span></a> <span class="Operator">|</span> <a href="varint.html#hint64"><span class="Identifier">hint64</span></a> <span class="Operator">|</span> <a href="varint.html#hint32"><span class="Identifier">hint32</span></a></pre></dt>
<dd>
&nbsp;&nbsp;<a
href="https://github.com/status-im/nim-libp2p/tree/enhance-logs-for-nwaku-over-0.30.1-extra-logs/libp2p/varint.nim#L47"
class="link-seesrc" target="_blank">Source</a>
&nbsp;&nbsp;<a href="https://github.com/status-im/nim-libp2p/edit/devel/libp2p/varint.nim#L47" class="link-seesrc" target="_blank" >Edit</a>
</dd>
</div>
<div id="PBSomeUVarint" class="tohide">
<dt><pre><a href="varint.html#PBSomeUVarint"><span class="Identifier">PBSomeUVarint</span></a> <span class="Other">=</span> <span class="Identifier">uint</span> <span class="Operator">|</span> <span class="Identifier">uint64</span> <span class="Operator">|</span> <span class="Identifier">uint32</span></pre></dt>
<dd>
&nbsp;&nbsp;<a
href="https://github.com/status-im/nim-libp2p/tree/enhance-logs-for-nwaku-over-0.30.1-extra-logs/libp2p/varint.nim#L46"
class="link-seesrc" target="_blank">Source</a>
&nbsp;&nbsp;<a href="https://github.com/status-im/nim-libp2p/edit/devel/libp2p/varint.nim#L46" class="link-seesrc" target="_blank" >Edit</a>
</dd>
</div>
<div id="PBSomeVarint" class="tohide">
<dt><pre><a href="varint.html#PBSomeVarint"><span class="Identifier">PBSomeVarint</span></a> <span class="Other">=</span> <a href="varint.html#PBSomeUVarint"><span class="Identifier">PBSomeUVarint</span></a> <span class="Operator">|</span> <a href="varint.html#PBSomeSVarint"><span class="Identifier">PBSomeSVarint</span></a> <span class="Operator">|</span> <a href="varint.html#PBZigVarint"><span class="Identifier">PBZigVarint</span></a></pre></dt>
<dd>
&nbsp;&nbsp;<a
href="https://github.com/status-im/nim-libp2p/tree/enhance-logs-for-nwaku-over-0.30.1-extra-logs/libp2p/varint.nim#L49"
class="link-seesrc" target="_blank">Source</a>
&nbsp;&nbsp;<a href="https://github.com/status-im/nim-libp2p/edit/devel/libp2p/varint.nim#L49" class="link-seesrc" target="_blank" >Edit</a>
</dd>
</div>
<div id="PBZigVarint" class="tohide">
<dt><pre><a href="varint.html#PBZigVarint"><span class="Identifier">PBZigVarint</span></a> <span class="Other">=</span> <a href="varint.html#zint"><span class="Identifier">zint</span></a> <span class="Operator">|</span> <a href="varint.html#zint64"><span class="Identifier">zint64</span></a> <span class="Operator">|</span> <a href="varint.html#zint32"><span class="Identifier">zint32</span></a></pre></dt>
<dd>
&nbsp;&nbsp;<a
href="https://github.com/status-im/nim-libp2p/tree/enhance-logs-for-nwaku-over-0.30.1-extra-logs/libp2p/varint.nim#L48"
class="link-seesrc" target="_blank">Source</a>
&nbsp;&nbsp;<a href="https://github.com/status-im/nim-libp2p/edit/devel/libp2p/varint.nim#L48" class="link-seesrc" target="_blank" >Edit</a>
</dd>
</div>
<div id="SomeUVarint" class="tohide">
<dt><pre><a href="varint.html#SomeUVarint"><span class="Identifier">SomeUVarint</span></a> <span class="Other">=</span> <a href="varint.html#PBSomeUVarint"><span class="Identifier">PBSomeUVarint</span></a> <span class="Operator">|</span> <a href="varint.html#LPSomeUVarint"><span class="Identifier">LPSomeUVarint</span></a></pre></dt>
<dd>
&nbsp;&nbsp;<a
href="https://github.com/status-im/nim-libp2p/tree/enhance-logs-for-nwaku-over-0.30.1-extra-logs/libp2p/varint.nim#L53"
class="link-seesrc" target="_blank">Source</a>
&nbsp;&nbsp;<a href="https://github.com/status-im/nim-libp2p/edit/devel/libp2p/varint.nim#L53" class="link-seesrc" target="_blank" >Edit</a>
</dd>
</div>
<div id="SomeVarint" class="tohide">
<dt><pre><a href="varint.html#SomeVarint"><span class="Identifier">SomeVarint</span></a> <span class="Other">=</span> <a href="varint.html#PBSomeVarint"><span class="Identifier">PBSomeVarint</span></a> <span class="Operator">|</span> <a href="varint.html#LPSomeVarint"><span class="Identifier">LPSomeVarint</span></a></pre></dt>
<dd>
&nbsp;&nbsp;<a
href="https://github.com/status-im/nim-libp2p/tree/enhance-logs-for-nwaku-over-0.30.1-extra-logs/libp2p/varint.nim#L52"
class="link-seesrc" target="_blank">Source</a>
&nbsp;&nbsp;<a href="https://github.com/status-im/nim-libp2p/edit/devel/libp2p/varint.nim#L52" class="link-seesrc" target="_blank" >Edit</a>
</dd>
</div>
<div id="VarintError" class="tohide">
<dt><pre><a href="varint.html#VarintError"><span class="Identifier">VarintError</span></a> {.<span class="Identifier">pure</span>.} <span class="Other">=</span> <span class="Keyword">enum</span>
<span class="Identifier">Error</span><span class="Other">,</span> <span class="Identifier">Overflow</span><span class="Other">,</span> <span class="Identifier">Incomplete</span><span class="Other">,</span> <span class="Identifier">Overlong</span><span class="Other">,</span> <span class="Identifier">Overrun</span></pre></dt>
<dd>
&nbsp;&nbsp;<a
href="https://github.com/status-im/nim-libp2p/tree/enhance-logs-for-nwaku-over-0.30.1-extra-logs/libp2p/varint.nim#L25"
class="link-seesrc" target="_blank">Source</a>
&nbsp;&nbsp;<a href="https://github.com/status-im/nim-libp2p/edit/devel/libp2p/varint.nim#L25" class="link-seesrc" target="_blank" >Edit</a>
</dd>
</div>
<div id="VarintResult" class="tohide">
<dt><pre><a href="varint.html#VarintResult"><span class="Identifier">VarintResult</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span> <span class="Other">=</span> <span class="Identifier">Result</span><span class="Other">[</span><span class="Identifier">T</span><span class="Other">,</span> <a href="varint.html#VarintError"><span class="Identifier">VarintError</span></a><span class="Other">]</span></pre></dt>
<dd>
&nbsp;&nbsp;<a
href="https://github.com/status-im/nim-libp2p/tree/enhance-logs-for-nwaku-over-0.30.1-extra-logs/libp2p/varint.nim#L32"
class="link-seesrc" target="_blank">Source</a>
&nbsp;&nbsp;<a href="https://github.com/status-im/nim-libp2p/edit/devel/libp2p/varint.nim#L32" class="link-seesrc" target="_blank" >Edit</a>
</dd>
</div>
<div id="zint" class="tohide">
<dt><pre><a href="varint.html#zint"><span class="Identifier">zint</span></a> <span class="Other">=</span> <span class="Keyword">distinct</span> <span class="Identifier">int</span></pre></dt>
<dd>
Signed integer types which will be encoded using zigzag encoding.
&nbsp;&nbsp;<a
href="https://github.com/status-im/nim-libp2p/tree/enhance-logs-for-nwaku-over-0.30.1-extra-logs/libp2p/varint.nim#L39"
class="link-seesrc" target="_blank">Source</a>
&nbsp;&nbsp;<a href="https://github.com/status-im/nim-libp2p/edit/devel/libp2p/varint.nim#L39" class="link-seesrc" target="_blank" >Edit</a>
</dd>
</div>
<div id="zint32" class="tohide">
<dt><pre><a href="varint.html#zint32"><span class="Identifier">zint32</span></a> <span class="Other">=</span> <span class="Keyword">distinct</span> <span class="Identifier">int32</span></pre></dt>
<dd>
&nbsp;&nbsp;<a
href="https://github.com/status-im/nim-libp2p/tree/enhance-logs-for-nwaku-over-0.30.1-extra-logs/libp2p/varint.nim#L37"
class="link-seesrc" target="_blank">Source</a>
&nbsp;&nbsp;<a href="https://github.com/status-im/nim-libp2p/edit/devel/libp2p/varint.nim#L37" class="link-seesrc" target="_blank" >Edit</a>
</dd>
</div>
<div id="zint64" class="tohide">
<dt><pre><a href="varint.html#zint64"><span class="Identifier">zint64</span></a> <span class="Other">=</span> <span class="Keyword">distinct</span> <span class="Identifier">int64</span></pre></dt>
<dd>
&nbsp;&nbsp;<a
href="https://github.com/status-im/nim-libp2p/tree/enhance-logs-for-nwaku-over-0.30.1-extra-logs/libp2p/varint.nim#L38"
class="link-seesrc" target="_blank">Source</a>
&nbsp;&nbsp;<a href="https://github.com/status-im/nim-libp2p/edit/devel/libp2p/varint.nim#L38" class="link-seesrc" target="_blank" >Edit</a>
</dd>
</div>
</dl></div>
<div class="section" id="12">
<h1><a class="toc-backref" href="#12">Procs</a></h1>
<dl class="item">
<div id="encodeVarint,typedesc[LP],LPSomeVarint" class="tohide">
<dt><pre><span class="Keyword">proc</span> <a href="#encodeVarint%2Ctypedesc%5BLP%5D%2CLPSomeVarint"><span class="Identifier">encodeVarint</span></a><span class="Other">(</span><span class="Identifier">vtype</span><span class="Other">:</span> <span class="Identifier">typedesc</span><span class="Other">[</span><a href="varint.html#LP"><span class="Identifier">LP</span></a><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">value</span><span class="Other">:</span> <a href="varint.html#LPSomeVarint"><span class="Identifier">LPSomeVarint</span></a><span class="Other">)</span><span class="Other">:</span> <a href="varint.html#VarintResult"><span class="Identifier">VarintResult</span></a><span class="Other">[</span>
<span class="Identifier">seq</span><span class="Other">[</span><span class="Identifier">byte</span><span class="Other">]</span><span class="Other">]</span> {.<span class="Identifier">inline</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
Encode integer to LibP2P <tt class="docutils literal"><span class="pre"><span class="Identifier">unsigned</span> <span class="Identifier">varint</span></span></tt> and returns sequence of bytes as buffer.
&nbsp;&nbsp;<a
href="https://github.com/status-im/nim-libp2p/tree/enhance-logs-for-nwaku-over-0.30.1-extra-logs/libp2p/varint.nim#L304"
class="link-seesrc" target="_blank">Source</a>
&nbsp;&nbsp;<a href="https://github.com/status-im/nim-libp2p/edit/devel/libp2p/varint.nim#L304" class="link-seesrc" target="_blank" >Edit</a>
</dd>
</div>
<div id="encodeVarint,typedesc[PB],PBSomeVarint" class="tohide">
<dt><pre><span class="Keyword">proc</span> <a href="#encodeVarint%2Ctypedesc%5BPB%5D%2CPBSomeVarint"><span class="Identifier">encodeVarint</span></a><span class="Other">(</span><span class="Identifier">vtype</span><span class="Other">:</span> <span class="Identifier">typedesc</span><span class="Other">[</span><a href="varint.html#PB"><span class="Identifier">PB</span></a><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">value</span><span class="Other">:</span> <a href="varint.html#PBSomeVarint"><span class="Identifier">PBSomeVarint</span></a><span class="Other">)</span><span class="Other">:</span> <a href="varint.html#VarintResult"><span class="Identifier">VarintResult</span></a><span class="Other">[</span>
<span class="Identifier">seq</span><span class="Other">[</span><span class="Identifier">byte</span><span class="Other">]</span><span class="Other">]</span> {.<span class="Identifier">inline</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
Encode integer to Google ProtoBuf's <tt class="docutils literal"><span class="pre"><span class="Identifier">signed</span><span class="Operator">/</span><span class="Identifier">unsigned</span> <span class="Identifier">varint</span></span></tt> and returns sequence of bytes as buffer.
&nbsp;&nbsp;<a
href="https://github.com/status-im/nim-libp2p/tree/enhance-logs-for-nwaku-over-0.30.1-extra-logs/libp2p/varint.nim#L283"
class="link-seesrc" target="_blank">Source</a>
&nbsp;&nbsp;<a href="https://github.com/status-im/nim-libp2p/edit/devel/libp2p/varint.nim#L283" class="link-seesrc" target="_blank" >Edit</a>
</dd>
</div>
<div id="getSVarint,openArray[byte],int," class="tohide">
<dt><pre><span class="Keyword">proc</span> <a href="#getSVarint%2CopenArray%5Bbyte%5D%2Cint%2C"><span class="Identifier">getSVarint</span></a><span class="Other">(</span><span class="Identifier">pbytes</span><span class="Other">:</span> <span class="Identifier">openArray</span><span class="Other">[</span><span class="Identifier">byte</span><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">outsize</span><span class="Other">:</span> <span class="Keyword">var</span> <span class="Identifier">int</span><span class="Other">;</span>
<span class="Identifier">outval</span><span class="Other">:</span> <span class="Keyword">var</span> <span class="Other">(</span><a href="varint.html#PBZigVarint"><span class="Identifier">PBZigVarint</span></a> <span class="Operator">|</span> <a href="varint.html#PBSomeSVarint"><span class="Identifier">PBSomeSVarint</span></a><span class="Other">)</span><span class="Other">)</span><span class="Other">:</span> <a href="varint.html#VarintResult"><span class="Identifier">VarintResult</span></a><span class="Other">[</span><span class="Identifier">void</span><span class="Other">]</span> {.
<span class="Identifier">inline</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
<p>Decode signed integer (<tt class="docutils literal"><span class="pre">int32</span></tt> or <tt class="docutils literal"><span class="pre">int64</span></tt>) from buffer <tt class="docutils literal"><span class="pre">pbytes</span></tt> and store it to <tt class="docutils literal"><span class="pre">outval</span></tt>.</p>
<p>On success <tt class="docutils literal"><span class="pre">outlen</span></tt> will be set to number of bytes processed while decoding signed varint.</p>
<p>If array <tt class="docutils literal"><span class="pre">pbytes</span></tt> is empty, <tt class="docutils literal"><span class="pre">Incomplete</span></tt> error will be returned.</p>
<p>If there not enough bytes available in array <tt class="docutils literal"><span class="pre">pbytes</span></tt> to decode <tt class="docutils literal"><span class="pre"><span class="Identifier">signed</span> <span class="Identifier">varint</span></span></tt>, <tt class="docutils literal"><span class="pre">Incomplete</span></tt> error will be returned.</p>
<p>If encoded value can produce integer overflow, <tt class="docutils literal"><span class="pre">Overflow</span></tt> error will be returned.</p>
<p>Note, when decoding 10th byte of 64bit integer only 1 bit from byte will be decoded, all other bits will be ignored. When decoding 5th byte of 32bit integer only 4 bits from byte will be decoded, all other bits will be ignored.</p>
&nbsp;&nbsp;<a
href="https://github.com/status-im/nim-libp2p/tree/enhance-logs-for-nwaku-over-0.30.1-extra-logs/libp2p/varint.nim#L188"
class="link-seesrc" target="_blank">Source</a>
&nbsp;&nbsp;<a href="https://github.com/status-im/nim-libp2p/edit/devel/libp2p/varint.nim#L188" class="link-seesrc" target="_blank" >Edit</a>
</dd>
</div>
<div id="getUVarint,typedesc[T],openArray[byte],int,SomeUVarint" class="tohide">
<dt><pre><span class="Keyword">proc</span> <a href="#getUVarint%2Ctypedesc%5BT%5D%2CopenArray%5Bbyte%5D%2Cint%2CSomeUVarint"><span class="Identifier">getUVarint</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">:</span> <a href="varint.html#PB"><span class="Identifier">PB</span></a> <span class="Operator">|</span> <a href="varint.html#LP"><span class="Identifier">LP</span></a><span class="Other">]</span><span class="Other">(</span><span class="Identifier">vtype</span><span class="Other">:</span> <span class="Identifier">typedesc</span><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">pbytes</span><span class="Other">:</span> <span class="Identifier">openArray</span><span class="Other">[</span><span class="Identifier">byte</span><span class="Other">]</span><span class="Other">;</span>
<span class="Identifier">outlen</span><span class="Other">:</span> <span class="Keyword">var</span> <span class="Identifier">int</span><span class="Other">;</span> <span class="Identifier">outval</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="varint.html#SomeUVarint"><span class="Identifier">SomeUVarint</span></a><span class="Other">)</span><span class="Other">:</span> <a href="varint.html#VarintResult"><span class="Identifier">VarintResult</span></a><span class="Other">[</span>
<span class="Identifier">void</span><span class="Other">]</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
<p>Decode <tt class="docutils literal"><span class="pre"><span class="Identifier">unsigned</span> <span class="Identifier">varint</span></span></tt> from buffer <tt class="docutils literal"><span class="pre">pbytes</span></tt> and store it to <tt class="docutils literal"><span class="pre">outval</span></tt>. On success <tt class="docutils literal"><span class="pre">outlen</span></tt> will be set to number of bytes processed while decoding <tt class="docutils literal"><span class="pre"><span class="Identifier">unsigned</span> <span class="Identifier">varint</span></span></tt>.</p>
<p>If array <tt class="docutils literal"><span class="pre">pbytes</span></tt> is empty, <tt class="docutils literal"><span class="pre">Incomplete</span></tt> error will be returned.</p>
<p>If there not enough bytes available in array <tt class="docutils literal"><span class="pre">pbytes</span></tt> to decode <tt class="docutils literal"><span class="pre"><span class="Identifier">unsigned</span> <span class="Identifier">varint</span></span></tt>, <tt class="docutils literal"><span class="pre">Incomplete</span></tt> error will be returned.</p>
<p>If encoded value can produce integer overflow, <tt class="docutils literal"><span class="pre">Overflow</span></tt> error will be returned.</p>
<p>Google ProtoBuf When decoding 10th byte of Google Protobuf's 64bit integer only 1 bit from byte will be decoded, all other bits will be ignored. When decoding 5th byte of 32bit integer only 4 bits from byte will be decoded, all other bits will be ignored.</p>
<p>LibP2P When decoding 5th byte of 32bit integer only 4 bits from byte will be decoded, all other bits will be ignored.</p>
&nbsp;&nbsp;<a
href="https://github.com/status-im/nim-libp2p/tree/enhance-logs-for-nwaku-over-0.30.1-extra-logs/libp2p/varint.nim#L106"
class="link-seesrc" target="_blank">Source</a>
&nbsp;&nbsp;<a href="https://github.com/status-im/nim-libp2p/edit/devel/libp2p/varint.nim#L106" class="link-seesrc" target="_blank" >Edit</a>
</dd>
</div>
<div id="getVarint,typedesc[T],openArray[byte],int,SomeVarint" class="tohide">
<dt><pre><span class="Keyword">proc</span> <a href="#getVarint%2Ctypedesc%5BT%5D%2CopenArray%5Bbyte%5D%2Cint%2CSomeVarint"><span class="Identifier">getVarint</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">:</span> <a href="varint.html#PB"><span class="Identifier">PB</span></a> <span class="Operator">|</span> <a href="varint.html#LP"><span class="Identifier">LP</span></a><span class="Other">]</span><span class="Other">(</span><span class="Identifier">vtype</span><span class="Other">:</span> <span class="Identifier">typedesc</span><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">pbytes</span><span class="Other">:</span> <span class="Identifier">openArray</span><span class="Other">[</span><span class="Identifier">byte</span><span class="Other">]</span><span class="Other">;</span>
<span class="Identifier">nbytes</span><span class="Other">:</span> <span class="Keyword">var</span> <span class="Identifier">int</span><span class="Other">;</span> <span class="Identifier">value</span><span class="Other">:</span> <span class="Keyword">var</span> <a href="varint.html#SomeVarint"><span class="Identifier">SomeVarint</span></a><span class="Other">)</span><span class="Other">:</span> <a href="varint.html#VarintResult"><span class="Identifier">VarintResult</span></a><span class="Other">[</span>
<span class="Identifier">void</span><span class="Other">]</span> {.<span class="Identifier">inline</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
&nbsp;&nbsp;<a
href="https://github.com/status-im/nim-libp2p/tree/enhance-logs-for-nwaku-over-0.30.1-extra-logs/libp2p/varint.nim#L260"
class="link-seesrc" target="_blank">Source</a>
&nbsp;&nbsp;<a href="https://github.com/status-im/nim-libp2p/edit/devel/libp2p/varint.nim#L260" class="link-seesrc" target="_blank" >Edit</a>
</dd>
</div>
<div id="putSVarint,openArray[byte],int," class="tohide">
<dt><pre><span class="Keyword">proc</span> <a href="#putSVarint%2CopenArray%5Bbyte%5D%2Cint%2C"><span class="Identifier">putSVarint</span></a><span class="Other">(</span><span class="Identifier">pbytes</span><span class="Other">:</span> <span class="Keyword">var</span> <span class="Identifier">openArray</span><span class="Other">[</span><span class="Identifier">byte</span><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">outsize</span><span class="Other">:</span> <span class="Keyword">var</span> <span class="Identifier">int</span><span class="Other">;</span>
<span class="Identifier">outval</span><span class="Other">:</span> <span class="Other">(</span><a href="varint.html#PBZigVarint"><span class="Identifier">PBZigVarint</span></a> <span class="Operator">|</span> <a href="varint.html#PBSomeSVarint"><span class="Identifier">PBSomeSVarint</span></a><span class="Other">)</span><span class="Other">)</span><span class="Other">:</span> <a href="varint.html#VarintResult"><span class="Identifier">VarintResult</span></a><span class="Other">[</span><span class="Identifier">void</span><span class="Other">]</span> {.
<span class="Identifier">inline</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
<p>Encode signed integer <tt class="docutils literal"><span class="pre">outval</span></tt> using ProtoBuffer's zigzag encoding (<tt class="docutils literal"><span class="pre">sint32</span></tt> or <tt class="docutils literal"><span class="pre">sint64</span></tt>) and store it to array <tt class="docutils literal"><span class="pre">pbytes</span></tt>.</p>
<p>On success <tt class="docutils literal"><span class="pre">outlen</span></tt> will hold number of bytes (octets) used to encode unsigned integer <tt class="docutils literal"><span class="pre">v</span></tt>.</p>
<p>If there not enough bytes available in buffer <tt class="docutils literal"><span class="pre">pbytes</span></tt>, <tt class="docutils literal"><span class="pre">Incomplete</span></tt> error will be returned and <tt class="docutils literal"><span class="pre">outlen</span></tt> will be set to number of bytes required.</p>
<p>Maximum encoded length of 64bit integer is 10 octets. Maximum encoded length of 32bit integer is 5 octets.</p>
&nbsp;&nbsp;<a
href="https://github.com/status-im/nim-libp2p/tree/enhance-logs-for-nwaku-over-0.30.1-extra-logs/libp2p/varint.nim#L219"
class="link-seesrc" target="_blank">Source</a>
&nbsp;&nbsp;<a href="https://github.com/status-im/nim-libp2p/edit/devel/libp2p/varint.nim#L219" class="link-seesrc" target="_blank" >Edit</a>
</dd>
</div>
<div id="putUVarint,typedesc[T],openArray[byte],int,SomeUVarint" class="tohide">
<dt><pre><span class="Keyword">proc</span> <a href="#putUVarint%2Ctypedesc%5BT%5D%2CopenArray%5Bbyte%5D%2Cint%2CSomeUVarint"><span class="Identifier">putUVarint</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">:</span> <a href="varint.html#PB"><span class="Identifier">PB</span></a> <span class="Operator">|</span> <a href="varint.html#LP"><span class="Identifier">LP</span></a><span class="Other">]</span><span class="Other">(</span><span class="Identifier">vtype</span><span class="Other">:</span> <span class="Identifier">typedesc</span><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">pbytes</span><span class="Other">:</span> <span class="Keyword">var</span> <span class="Identifier">openArray</span><span class="Other">[</span><span class="Identifier">byte</span><span class="Other">]</span><span class="Other">;</span>
<span class="Identifier">outlen</span><span class="Other">:</span> <span class="Keyword">var</span> <span class="Identifier">int</span><span class="Other">;</span> <span class="Identifier">outval</span><span class="Other">:</span> <a href="varint.html#SomeUVarint"><span class="Identifier">SomeUVarint</span></a><span class="Other">)</span><span class="Other">:</span> <a href="varint.html#VarintResult"><span class="Identifier">VarintResult</span></a><span class="Other">[</span>
<span class="Identifier">void</span><span class="Other">]</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
<p>Encode <tt class="docutils literal"><span class="pre"><span class="Identifier">unsigned</span> <span class="Identifier">varint</span></span></tt> <tt class="docutils literal"><span class="pre">outval</span></tt> and store it to array <tt class="docutils literal"><span class="pre">pbytes</span></tt>.</p>
<p>On success <tt class="docutils literal"><span class="pre">outlen</span></tt> will hold number of bytes (octets) used to encode unsigned integer <tt class="docutils literal"><span class="pre">v</span></tt>.</p>
<p>If there not enough bytes available in buffer <tt class="docutils literal"><span class="pre">pbytes</span></tt>, <tt class="docutils literal"><span class="pre">Incomplete</span></tt> error will be returned and <tt class="docutils literal"><span class="pre">outlen</span></tt> will be set to number of bytes required.</p>
<p>Google ProtoBuf Maximum encoded length of 64bit integer is 10 octets. Maximum encoded length of 32bit integer is 5 octets.</p>
<p>LibP2P Maximum encoded length of 63bit integer is 9 octets. Maximum encoded length of 32bit integer is 5 octets.</p>
&nbsp;&nbsp;<a
href="https://github.com/status-im/nim-libp2p/tree/enhance-logs-for-nwaku-over-0.30.1-extra-logs/libp2p/varint.nim#L154"
class="link-seesrc" target="_blank">Source</a>
&nbsp;&nbsp;<a href="https://github.com/status-im/nim-libp2p/edit/devel/libp2p/varint.nim#L154" class="link-seesrc" target="_blank" >Edit</a>
</dd>
</div>
<div id="putVarint,typedesc[T],openArray[byte],int,SomeVarint" class="tohide">
<dt><pre><span class="Keyword">proc</span> <a href="#putVarint%2Ctypedesc%5BT%5D%2CopenArray%5Bbyte%5D%2Cint%2CSomeVarint"><span class="Identifier">putVarint</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">:</span> <a href="varint.html#PB"><span class="Identifier">PB</span></a> <span class="Operator">|</span> <a href="varint.html#LP"><span class="Identifier">LP</span></a><span class="Other">]</span><span class="Other">(</span><span class="Identifier">vtype</span><span class="Other">:</span> <span class="Identifier">typedesc</span><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">pbytes</span><span class="Other">:</span> <span class="Keyword">var</span> <span class="Identifier">openArray</span><span class="Other">[</span><span class="Identifier">byte</span><span class="Other">]</span><span class="Other">;</span>
<span class="Identifier">nbytes</span><span class="Other">:</span> <span class="Keyword">var</span> <span class="Identifier">int</span><span class="Other">;</span> <span class="Identifier">value</span><span class="Other">:</span> <a href="varint.html#SomeVarint"><span class="Identifier">SomeVarint</span></a><span class="Other">)</span><span class="Other">:</span> <a href="varint.html#VarintResult"><span class="Identifier">VarintResult</span></a><span class="Other">[</span>
<span class="Identifier">void</span><span class="Other">]</span> {.<span class="Identifier">inline</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
&nbsp;&nbsp;<a
href="https://github.com/status-im/nim-libp2p/tree/enhance-logs-for-nwaku-over-0.30.1-extra-logs/libp2p/varint.nim#L240"
class="link-seesrc" target="_blank">Source</a>
&nbsp;&nbsp;<a href="https://github.com/status-im/nim-libp2p/edit/devel/libp2p/varint.nim#L240" class="link-seesrc" target="_blank" >Edit</a>
</dd>
</div>
<div id="vsizeof,SomeVarint" class="tohide">
<dt><pre><span class="Keyword">proc</span> <a href="#vsizeof%2CSomeVarint"><span class="Identifier">vsizeof</span></a><span class="Other">(</span><span class="Identifier">x</span><span class="Other">:</span> <a href="varint.html#SomeVarint"><span class="Identifier">SomeVarint</span></a><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">int</span> {.<span class="Identifier">inline</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
<dd>
Returns number of bytes required to encode integer <tt class="docutils literal"><span class="pre">x</span></tt> as varint.
&nbsp;&nbsp;<a
href="https://github.com/status-im/nim-libp2p/tree/enhance-logs-for-nwaku-over-0.30.1-extra-logs/libp2p/varint.nim#L102"
class="link-seesrc" target="_blank">Source</a>
&nbsp;&nbsp;<a href="https://github.com/status-im/nim-libp2p/edit/devel/libp2p/varint.nim#L102" class="link-seesrc" target="_blank" >Edit</a>
</dd>
</div>
</dl></div>
<div class="section" id="18">
<h1><a class="toc-backref" href="#18">Templates</a></h1>
<dl class="item">
<div id="toBytes.t,typedesc[PB],PBSomeVarint" class="tohide">
<dt><pre><span class="Keyword">template</span> <a href="#toBytes.t%2Ctypedesc%5BPB%5D%2CPBSomeVarint"><span class="Identifier">toBytes</span></a><span class="Other">(</span><span class="Identifier">vtype</span><span class="Other">:</span> <span class="Identifier">typedesc</span><span class="Other">[</span><a href="varint.html#PB"><span class="Identifier">PB</span></a><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">value</span><span class="Other">:</span> <a href="varint.html#PBSomeVarint"><span class="Identifier">PBSomeVarint</span></a><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">auto</span></pre></dt>
<dd>
&nbsp;&nbsp;<a
href="https://github.com/status-im/nim-libp2p/tree/enhance-logs-for-nwaku-over-0.30.1-extra-logs/libp2p/varint.nim#L280"
class="link-seesrc" target="_blank">Source</a>
&nbsp;&nbsp;<a href="https://github.com/status-im/nim-libp2p/edit/devel/libp2p/varint.nim#L280" class="link-seesrc" target="_blank" >Edit</a>
</dd>
</div>
</dl></div>
</div>
</div>
<div class="row">
<div class="twelve-columns footer">
<span class="nim-sprite"></span>
<br/>
<small style="color: var(--hint);">Made with Nim. Generated: 2024-07-29 15:57:41 UTC</small>
</div>
</div>
</div>
</div>
</body>
</html>