| <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 – 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 <u.h><br> |
| #include <libc.h> |
| <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table> |
| </font></tt> |
| <tt><font size=+1>int 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 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 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 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 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 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 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> 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><</font></tt> base 32<br> |
| <tt><font size=+1>[</font></tt> 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("%.*H\n", 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> |