aboutsummaryrefslogtreecommitdiff
path: root/man/man3/encode.html
blob: c7a8132c9a74a9904369c73b763ae5a6d8bfde07 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<head>
<title>encode(3) - Plan 9 from User Space</title>
<meta content="text/html; charset=utf-8" http-equiv=Content-Type>
</head>
<body bgcolor=#ffffff>
<table border=0 cellpadding=0 cellspacing=0 width=100%>
<tr height=10><td>
<tr><td width=20><td>
<tr><td width=20><td><b>ENCODE(3)</b><td align=right><b>ENCODE(3)</b>
<tr><td width=20><td colspan=2>
    <br>
<p><font size=+1><b>NAME     </b></font><br>

<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

    dec64, enc64, dec32, enc32, dec16, enc16, encodefmt &ndash; encoding
    byte arrays as strings<br>
    
</table>
<p><font size=+1><b>SYNOPSIS     </b></font><br>

<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

    <tt><font size=+1>#include &lt;u.h&gt;<br>
    #include &lt;libc.h&gt; 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>int &nbsp;&nbsp;&nbsp;dec64(uchar *out, int lim, char *in, int n) 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>int &nbsp;&nbsp;&nbsp;enc64(char *out, int lim, uchar *in, int n) 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>int &nbsp;&nbsp;&nbsp;dec32(uchar *out, int lim, char *in, int n) 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>int &nbsp;&nbsp;&nbsp;enc32(char *out, int lim, uchar *in, int n) 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>int &nbsp;&nbsp;&nbsp;dec16(uchar *out, int lim, char *in, int n) 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>int &nbsp;&nbsp;&nbsp;enc16(char *out, int lim, uchar *in, int n) 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>int &nbsp;&nbsp;&nbsp;encodefmt(Fmt*)<br>
    </font></tt>
</table>
<p><font size=+1><b>DESCRIPTION     </b></font><br>

<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>


<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

    <i>Enc16</i>, <i>enc32</i> and <i>enc64</i> create null terminated strings. They return
    the size of the encoded string (without the null) or -1 if the
    encoding fails. The encoding fails if <i>lim</i>, the length of the output
    buffer, is too small. 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    
    <i>Dec16</i>, <i>dec32</i> and <i>dec64</i> return the number of bytes decoded or -1
    if the decoding fails. The decoding fails if the output buffer
    is not large enough or, for base 32, if the input buffer length
    is not a multiple of 8. 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    
    <i>Encodefmt</i> can be used with <a href="../man3/fmtinstall.html"><i>fmtinstall</i>(3)</a> and <a href="../man3/print.html"><i>print</i>(3)</a> to print
    encoded representations of byte arrays. The verbs are<br>
    <tt><font size=+1>H</font></tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;base 16 (i.e. hexadecimal). The default encoding is in upper
    case. The <tt><font size=+1>l</font></tt> flag forces lower case.<br>
    <tt><font size=+1>&lt;</font></tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;base 32<br>
    <tt><font size=+1>[</font></tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;base 64 (same as MIME) 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    
    The length of the array is specified as <i>f2</i>. For example, to display
    a 15 byte array as hex:<br>
     
    <table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

        <tt><font size=+1>char x[15];<br>
         fmtinstall('H', encodefmt);<br>
         print(&quot;%.*H\n&quot;, sizeof x, x);<br>
        </font></tt>
    </table>
    
</table>
<p><font size=+1><b>SOURCE     </b></font><br>

<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

    <tt><font size=+1>/usr/local/plan9/src/lib9/u32.c<br>
    /usr/local/plan9/src/lib9/u64.c<br>
    </font></tt>
</table>

<td width=20>
<tr height=20><td>
</table>
<!-- TRAILER -->
<table border=0 cellpadding=0 cellspacing=0 width=100%>
<tr height=15><td width=10><td><td width=10>
<tr><td><td>
<center>
<a href="../../"><img src="../../dist/spaceglenda100.png" alt="Space Glenda" border=1></a>
</center>
</table>
<!-- TRAILER -->
</body></html>