This commit is contained in:
Sergey Lyubka 2022-06-08 11:30:54 +01:00
parent 94ea973fb5
commit ee65342545
5 changed files with 386 additions and 4 deletions

View File

@ -3192,12 +3192,18 @@ Return value: new `io` length
Usage example:
```c
struct mg_iobuf io;
mg_iobuf_init(&io, 0); // Empty buffer
mg_iobuf_add(&io, 0, "hi", 2, 512); // io->len is 2, io->size is 512
struct mg_iobuf io; // Declare buffer
mg_iobuf_init(&io, 0); // Initialise buffer to have 0 allocated bytes
```
<img src="images/mg_iobuf_add.png" alt="Function mg_iobuf_add()" />
<img src="images/mg_iobuf_add1.svg" alt="Function mg_iobuf_init()" />
```c
mg_iobuf_add(&io, 0, "hello", 5, 512); // Add "hello" at offset 0
```
<img src="images/mg_iobuf_add2.svg" alt="Function mg_iobuf_add()" />
### mg\_iobuf\_del()

View File

@ -0,0 +1,97 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 25.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 493.8 205.5" style="enable-background:new 0 0 493.8 205.5;" xml:space="preserve">
<style type="text/css">
.st0{fill:#576174;}
.st1{fill:#FFFFFF;}
.st2{font-family:'Courier'; font-weight: bold; }
.st3{font-size:16.7604px;}
.st4{fill:#00983A;}
.st5{fill:none;stroke:#45CFFF;stroke-width:2.7934;stroke-linecap:round;stroke-linejoin:round;}
.st6{fill:#45CFFF;}
.st7{fill:none;stroke:#A000FF;stroke-width:2.7934;stroke-linecap:round;stroke-linejoin:round;}
.st8{fill:#A000FF;}
.st9{fill:none;stroke:#FFDE00;stroke-width:2.793;stroke-linecap:round;stroke-linejoin:round;}
.st10{fill:#FFDE00;}
.st11{fill:none;stroke:#EA5B0C;stroke-width:2.793;stroke-linecap:round;stroke-linejoin:round;}
.st12{fill:#EA5B0C;}
</style>
<path class="st0" d="M485.3,205.5H8.5c-4.7,0-8.5-3.8-8.5-8.5V8.5C0,3.8,3.8,0,8.5,0h476.8c4.7,0,8.5,3.8,8.5,8.5V197
C493.8,201.6,490,205.5,485.3,205.5z"/>
<g>
<g>
<g>
<text transform="matrix(1 0 0 1 21.294 41.4023)" class="st1 st2 st3">struct mg_str k,v,s = mg_str(”a=333, b=777”);</text>
</g>
</g>
<g>
<g>
<text transform="matrix(1 0 0 1 21.294 117.5255)" class="st1 st2 st3">mg_commalist(&amp;s, &amp;k, &amp;v); </text>
</g>
</g>
<g>
<g>
<text transform="matrix(1 0 0 1 21.294 178.4241)" class="st1 st2 st3">mg_commalist(&amp;s, &amp;k, &amp;v); </text>
</g>
</g>
<g>
<g>
<text transform="matrix(1 0 0 1 291.5096 121.4556)" class="st4 st2 st3">// 1st call</text>
<text transform="matrix(1 0 0 1 291.5096 181.0857)" class="st4 st2 st3">// 2nd call</text>
</g>
</g>
</g>
<g>
<polyline class="st5" points="336.4,45.8 336.4,49.8 317.8,49.8 317.8,45.8 "/>
<g>
<path class="st5" d="M122.3,40.9"/>
<g>
<polyline class="st5" points="327.5,58.1 327.6,75.3 203.3,75.3 203.3,97.4 "/>
<path class="st6" d="M331,58.9c0,1.8-1.4,3.2-3.2,3.3s-3.2-1.4-3.3-3.2c0-1.8,1.4-3.2,3.2-3.3c0,0,0,0,0,0
C329.5,55.7,331,57.2,331,58.9z"/>
</g>
</g>
<path class="st6" d="M203.2,96.2c-1.8,0-3.2,1.3-3.3,3s1.4,3,3.2,3c1.8,0,3.2-1.3,3.3-3c0,0,0,0,0,0
C206.5,97.6,205,96.2,203.2,96.2z"/>
</g>
<g>
<polyline class="st7" points="407.4,45.8 407.4,49.8 388.8,49.8 388.8,45.8 "/>
<g>
<path class="st5" d="M193.4,40.9"/>
<g>
<polyline class="st7" points="398.6,58.1 398.6,130.3 203.4,130.3 203.4,158.4 "/>
<path class="st8" d="M402,58.9c0,1.8-1.4,3.2-3.2,3.3s-3.2-1.4-3.3-3.2c0-1.8,1.4-3.2,3.2-3.3c0,0,0,0,0,0
C400.6,55.7,402,57.2,402,58.9z"/>
</g>
</g>
<path class="st8" d="M203.2,156.7c-1.8,0-3.2,1.3-3.3,3s1.4,3,3.2,3c1.8,0,3.2-1.3,3.3-3c0,0,0,0,0,0
C206.5,158.1,205,156.7,203.2,156.7z"/>
</g>
<g>
<polyline class="st9" points="440.8,45.8 440.8,49.8 414.2,49.8 414.2,45.8 "/>
<g>
<path class="st5" d="M218.8,40.9"/>
<g>
<polyline class="st9" points="428,58.1 428,144.3 245.7,144.3 245.7,157.4 "/>
<path class="st10" d="M431.4,58.9c0,1.8-1.4,3.2-3.2,3.3s-3.2-1.4-3.3-3.2c0-1.8,1.4-3.2,3.2-3.3c0,0,0,0,0,0
C430,55.7,431.4,57.2,431.4,58.9z"/>
</g>
</g>
<path class="st10" d="M245.4,156.7c-1.8,0-3.2,1.3-3.3,3s1.4,3,3.2,3c1.8,0,3.2-1.3,3.3-3c0,0,0,0,0,0
C248.7,158.1,247.2,156.7,245.4,156.7z"/>
</g>
<g>
<polyline class="st11" points="372.8,45.8 372.8,49.8 343.2,49.8 343.2,45.8 "/>
<g>
<path class="st5" d="M164.7,40.9"/>
<g>
<polyline class="st11" points="358.3,57.9 358.3,86.1 245.7,86.3 245.7,97.4 "/>
<path class="st12" d="M361.4,58.9c0,1.8-1.4,3.2-3.2,3.3s-3.2-1.4-3.3-3.2c0-1.8,1.4-3.2,3.2-3.3c0,0,0,0,0,0
C359.9,55.7,361.4,57.2,361.4,58.9z"/>
</g>
</g>
<path class="st12" d="M245.7,96.2c-1.8,0-3.2,1.3-3.3,3s1.4,3,3.2,3c1.8,0,3.2-1.3,3.3-3c0,0,0,0,0,0
C248.9,97.6,247.4,96.2,245.7,96.2z"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 50 KiB

View File

@ -0,0 +1,98 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 25.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 483.3 164.9" style="enable-background:new 0 0 483.3 164.9;" xml:space="preserve">
<style type="text/css">
.st0{fill:#F2F3F3;stroke:#7A8387;stroke-width:1.2;stroke-linecap:round;stroke-linejoin:round;}
.st1{fill:#00983A;}
.st2{font-family:'Courier';}
.st3{font-size:16.7604px;}
.st4{fill:#7A8387;}
.st5{fill:none;stroke:#00983A;stroke-linecap:round;stroke-linejoin:round;}
.st6{fill:#F2F3F3;}
.st7{fill:none;stroke:#7A8387;stroke-linecap:round;stroke-linejoin:round;}
</style>
<g>
<g>
<g>
<polyline class="st0" points="460.6,85 23.2,85.1 23.2,60.3 460.6,60.3 "/>
<line class="st0" x1="23.2" y1="38.9" x2="23.2" y2="100.1"/>
<path class="st0" d="M460.6,85"/>
<line class="st0" x1="54.2" y1="60.6" x2="54.2" y2="84.3"/>
<line class="st0" x1="86.6" y1="60.6" x2="86.6" y2="84.3"/>
<line class="st0" x1="119.1" y1="60.6" x2="119.1" y2="84.3"/>
<line class="st0" x1="151.4" y1="60.6" x2="151.4" y2="84.3"/>
<line class="st0" x1="183.9" y1="60.6" x2="183.9" y2="84.3"/>
</g>
<g>
<text transform="matrix(1 0 0 1 21.1927 143.037)" class="st1 st2 st3">buf=NULL</text>
</g>
<g>
<text transform="matrix(1 0 0 1 146.7446 109.5964)" class="st4 st2 st3">non-allocated space</text>
</g>
<g>
<text transform="matrix(1 0 0 1 72.5758 32.3276)" class="st1 st2 st3">len=0</text>
</g>
<g>
<text transform="matrix(1 0 0 1 18.9444 34.7308)" class="st1 st2 st3">0</text>
</g>
<g>
<g>
<line class="st5" x1="22.9" y1="127.9" x2="22.9" y2="106.9"/>
<g>
<polygon class="st1" points="20.4,107.2 25.3,107.2 22.9,104.8 "/>
</g>
</g>
</g>
<g>
<g>
<line class="st5" x1="64.4" y1="29.1" x2="35.4" y2="29.1"/>
<g>
<polygon class="st1" points="35.8,31.6 35.8,26.7 33.3,29.1 "/>
</g>
</g>
</g>
<g>
<g>
<g>
<line class="st5" x1="64.4" y1="45.3" x2="35.4" y2="45.3"/>
<g>
<polygon class="st1" points="35.8,47.8 35.8,42.9 33.3,45.3 "/>
</g>
</g>
</g>
<g>
<text transform="matrix(1 0 0 1 73.2768 48.5211)" class="st1 st2 st3">size=0</text>
</g>
</g>
<g>
<path class="st4" d="M298.3,73c0,0.9-0.7,1.6-1.6,1.6c-0.9,0-1.6-0.7-1.6-1.6c0-0.9,0.7-1.6,1.6-1.6
C297.6,71.4,298.3,72.1,298.3,73z"/>
<path class="st4" d="M312,73c0,0.9-0.7,1.6-1.6,1.6c-0.9,0-1.6-0.7-1.6-1.6c0-0.9,0.7-1.6,1.6-1.6C311.3,71.4,312,72.1,312,73z"
/>
<path class="st4" d="M325.8,73c0,0.9-0.7,1.6-1.6,1.6c-0.9,0-1.6-0.7-1.6-1.6c0-0.9,0.7-1.6,1.6-1.6
C325,71.4,325.8,72.1,325.8,73z"/>
<path class="st4" d="M339.5,73c0,0.9-0.7,1.6-1.6,1.6c-0.9,0-1.6-0.7-1.6-1.6c0-0.9,0.7-1.6,1.6-1.6
C338.8,71.4,339.5,72.1,339.5,73z"/>
</g>
<g>
<line class="st6" x1="284.4" y1="116.4" x2="33.3" y2="116.4"/>
<g>
<line class="st7" x1="284.4" y1="116.4" x2="35.4" y2="116.4"/>
<g>
<polygon class="st4" points="35.8,118.8 35.8,114 33.3,116.4 "/>
</g>
</g>
</g>
<g>
<line class="st6" x1="272.5" y1="116.4" x2="460.8" y2="116.4"/>
<g>
<line class="st7" x1="272.5" y1="116.4" x2="458.7" y2="116.4"/>
<g>
<polygon class="st4" points="458.4,114 458.4,118.8 460.8,116.4 "/>
</g>
</g>
</g>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 3.4 KiB

View File

@ -0,0 +1,181 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 25.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 485.2 176.9" style="enable-background:new 0 0 485.2 176.9;" xml:space="preserve">
<style type="text/css">
.st0{opacity:0.2;fill:#00983A;}
.st1{fill:none;stroke:#7A8387;stroke-width:1.2;stroke-linecap:round;stroke-linejoin:round;}
.st2{fill:#F2F3F3;stroke:#7A8387;stroke-width:1.1979;stroke-linecap:round;stroke-linejoin:round;}
.st3{fill:#00983A;}
.st4{fill:#F2F3F3;stroke:#7A8387;stroke-width:1.2;stroke-linecap:round;stroke-linejoin:round;}
.st5{fill:none;stroke:#576174;stroke-width:1.2;stroke-linecap:round;stroke-linejoin:round;}
.st6{font-family:'Courier';}
.st7{font-size:16.7604px;}
.st8{fill:none;stroke:#00983A;stroke-linecap:round;stroke-linejoin:round;}
.st9{fill:#7A8387;}
.st10{fill:#576174;}
.st11{fill:none;stroke:#576174;stroke-linecap:round;stroke-linejoin:round;}
.st12{fill:none;stroke:#7A8387;stroke-linecap:round;stroke-linejoin:round;}
.st13{enable-background:new ;}
.st14{fill:#333A45;}
</style>
<polyline class="st0" points="322.9,97 183.1,97 183.1,72.3 322.9,72.3 "/>
<g>
<g>
<g>
<polyline class="st1" points="461.3,97 182.3,97 182.3,72.3 461.3,72.3 "/>
<polyline class="st2" points="461.3,97 323.6,97 323.6,72.3 461.3,72.3 "/>
<polyline class="st3" points="182.5,96.7 22.3,96.7 22.3,72.9 182.5,72.9 "/>
<line class="st4" x1="22.3" y1="50.8" x2="22.3" y2="112"/>
<line class="st4" x1="183.1" y1="50.8" x2="183.1" y2="112"/>
<line class="st4" x1="323.6" y1="50.8" x2="323.6" y2="112"/>
<path class="st4" d="M461.3,97"/>
<line class="st5" x1="53.2" y1="72.6" x2="53.2" y2="96.2"/>
<line class="st5" x1="85.7" y1="72.6" x2="85.7" y2="96.2"/>
<line class="st5" x1="118.2" y1="72.6" x2="118.2" y2="96.2"/>
<line class="st5" x1="150.7" y1="72.6" x2="150.7" y2="96.2"/>
<line class="st4" x1="215.2" y1="72.4" x2="215.2" y2="96.9"/>
<path class="st5" d="M22.3,72.3l160.8,0v24.9L22.3,97C22.3,97,22.4,72.3,22.3,72.3z"/>
<line class="st4" x1="323.5" y1="72.4" x2="323.5" y2="96.9"/>
<line class="st4" x1="291.3" y1="72.6" x2="291.3" y2="96.2"/>
<path class="st4" d="M215.2,97.2"/>
<path class="st4" d="M215.2,73.6"/>
</g>
<g>
<text transform="matrix(1 0 0 1 19.2741 155.0085)" class="st3 st6 st7">buf</text>
</g>
<g>
<g>
<line class="st8" x1="21.9" y1="139.8" x2="21.9" y2="118.8"/>
<g>
<polygon class="st3" points="19.5,119.2 24.4,119.2 21.9,116.7 "/>
</g>
</g>
</g>
<g>
<text transform="matrix(1 0 0 1 177.9259 155.0085)" class="st3 st6 st7">len=5</text>
</g>
<g>
<g>
<line class="st8" x1="183.1" y1="139.8" x2="183.1" y2="118.8"/>
<g>
<polygon class="st3" points="180.6,119.2 185.5,119.2 183.1,116.7 "/>
</g>
</g>
</g>
<g>
<text transform="matrix(1 0 0 1 318.893 155.0085)" class="st3 st6 st7">size=512</text>
</g>
<g>
<g>
<line class="st8" x1="323.7" y1="139.8" x2="323.7" y2="118.8"/>
<g>
<polygon class="st3" points="321.2,119.2 326.1,119.2 323.7,116.7 "/>
</g>
</g>
</g>
<g>
<path class="st9" d="M232.9,85c0,0.9-0.7,1.6-1.6,1.6c-0.9,0-1.6-0.7-1.6-1.6c0-0.9,0.7-1.6,1.6-1.6S232.9,84.1,232.9,85z"/>
<path class="st9" d="M246.7,85c0,0.9-0.7,1.6-1.6,1.6s-1.6-0.7-1.6-1.6c0-0.9,0.7-1.6,1.6-1.6S246.7,84.1,246.7,85z"/>
<path class="st9" d="M260.4,85c0,0.9-0.7,1.6-1.6,1.6c-0.9,0-1.6-0.7-1.6-1.6c0-0.9,0.7-1.6,1.6-1.6
C259.7,83.4,260.4,84.1,260.4,85z"/>
<path class="st9" d="M274.2,85c0,0.9-0.7,1.6-1.6,1.6c-0.9,0-1.6-0.7-1.6-1.6c0-0.9,0.7-1.6,1.6-1.6
C273.4,83.4,274.2,84.1,274.2,85z"/>
</g>
<g>
<path class="st9" d="M377.2,85c0,0.9-0.7,1.6-1.6,1.6c-0.9,0-1.6-0.7-1.6-1.6c0-0.9,0.7-1.6,1.6-1.6S377.2,84.1,377.2,85z"/>
<path class="st9" d="M390.9,85c0,0.9-0.7,1.6-1.6,1.6s-1.6-0.7-1.6-1.6c0-0.9,0.7-1.6,1.6-1.6C390.2,83.4,390.9,84.1,390.9,85z"
/>
<path class="st9" d="M404.7,85c0,0.9-0.7,1.6-1.6,1.6c-0.9,0-1.6-0.7-1.6-1.6c0-0.9,0.7-1.6,1.6-1.6
C404,83.4,404.7,84.1,404.7,85z"/>
<path class="st9" d="M418.4,85c0,0.9-0.7,1.6-1.6,1.6c-0.9,0-1.6-0.7-1.6-1.6c0-0.9,0.7-1.6,1.6-1.6
C417.7,83.4,418.4,84.1,418.4,85z"/>
</g>
<g>
<g>
<text transform="matrix(1 0 0 1 80.3886 51.0685)" class="st10 st6 st7">data</text>
</g>
<g>
<text transform="matrix(1 0 0 1 203.0975 51.0685)" class="st9 st6 st7">free space</text>
</g>
<g>
<g>
<line class="st11" x1="152.2" y1="57.9" x2="33.2" y2="57.9"/>
<g>
<polygon class="st10" points="33.6,60.3 33.6,55.5 31.1,57.9 "/>
</g>
</g>
</g>
<g>
<line class="st9" x1="143.1" y1="57.9" x2="174.2" y2="57.9"/>
<g>
<line class="st11" x1="143.1" y1="57.9" x2="172.1" y2="57.9"/>
<g>
<polygon class="st10" points="171.8,55.5 171.8,60.3 174.2,57.9 "/>
</g>
</g>
</g>
<g>
<g>
<line class="st12" x1="283.6" y1="57.9" x2="312.6" y2="57.9"/>
<g>
<polygon class="st9" points="312.3,55.5 312.3,60.3 314.7,57.9 "/>
</g>
</g>
</g>
<g>
<g>
<line class="st12" x1="285.6" y1="57.9" x2="196.6" y2="57.9"/>
<g>
<polygon class="st9" points="196.9,60.3 196.9,55.5 194.5,57.9 "/>
</g>
</g>
</g>
<g>
<text transform="matrix(1 0 0 1 331.1884 28.5121)" class="st13"><tspan x="0" y="0" class="st9 st6 st7">non-allocated </tspan><tspan x="45.3" y="20.1" class="st9 st6 st7">space</tspan></text>
</g>
<g>
<g>
<line class="st12" x1="423.5" y1="57.9" x2="459.4" y2="57.9"/>
<g>
<polygon class="st9" points="459.1,55.5 459.1,60.3 461.5,57.9 "/>
</g>
</g>
</g>
<g>
<g>
<line class="st12" x1="425.4" y1="57.9" x2="336.4" y2="57.9"/>
<g>
<polygon class="st9" points="336.8,60.3 336.8,55.5 334.3,57.9 "/>
</g>
</g>
</g>
</g>
<g>
<g>
<text transform="matrix(1 0 0 1 32.8557 89.2156)" class="st14 st6 st7">h</text>
</g>
</g>
<g>
<g>
<text transform="matrix(1 0 0 1 64.8908 89.2156)" class="st14 st6 st7">e</text>
</g>
</g>
<g>
<g>
<text transform="matrix(1 0 0 1 96.6088 89.2156)" class="st14 st6 st7">l</text>
</g>
</g>
<g>
<g>
<text transform="matrix(1 0 0 1 129.5955 89.2156)" class="st14 st6 st7">l</text>
</g>
</g>
<g>
<g>
<text transform="matrix(1 0 0 1 161.948 89.2156)" class="st14 st6 st7">o</text>
</g>
</g>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 6.5 KiB