rsc | cfa37a7 | 2004-04-10 18:53:55 +0000 | [diff] [blame] | 1 | .TH ENCODE 3 |
| 2 | .SH NAME |
| 3 | dec64, enc64, dec32, enc32, dec16, enc16, encodefmt \- encoding byte arrays as strings |
| 4 | .SH SYNOPSIS |
| 5 | .B #include <u.h> |
| 6 | .br |
| 7 | .B #include <libc.h> |
| 8 | .PP |
| 9 | .B |
| 10 | int dec64(uchar *out, int lim, char *in, int n) |
| 11 | .PP |
| 12 | .B |
| 13 | int enc64(char *out, int lim, uchar *in, int n) |
| 14 | .PP |
| 15 | .B |
| 16 | int dec32(uchar *out, int lim, char *in, int n) |
| 17 | .PP |
| 18 | .B |
| 19 | int enc32(char *out, int lim, uchar *in, int n) |
| 20 | .PP |
| 21 | .B |
| 22 | int dec16(uchar *out, int lim, char *in, int n) |
| 23 | .PP |
| 24 | .B |
| 25 | int enc16(char *out, int lim, uchar *in, int n) |
| 26 | .PP |
| 27 | .B |
| 28 | int encodefmt(Fmt*) |
| 29 | .SH DESCRIPTION |
| 30 | .PP |
| 31 | .IR Enc16 , |
| 32 | .I enc32 |
| 33 | and |
| 34 | .I enc64 |
| 35 | create null terminated strings. They return the size of the |
| 36 | encoded string (without the null) or -1 if the encoding fails. |
| 37 | The encoding fails if |
| 38 | .IR lim , |
| 39 | the length of the output buffer, is too small. |
| 40 | .PP |
| 41 | .IR Dec16 , |
| 42 | .I dec32 |
| 43 | and |
| 44 | .I dec64 |
| 45 | return the number of bytes decoded or -1 if the decoding fails. |
| 46 | The decoding fails if the output buffer is not large enough or, |
| 47 | for base 32, if the input buffer length is not a multiple |
| 48 | of 8. |
| 49 | .PP |
| 50 | .I Encodefmt |
| 51 | can be used with |
rsc | bf8a59f | 2004-04-11 03:42:27 +0000 | [diff] [blame] | 52 | .IR fmtinstall (3) |
rsc | cfa37a7 | 2004-04-10 18:53:55 +0000 | [diff] [blame] | 53 | and |
rsc | bf8a59f | 2004-04-11 03:42:27 +0000 | [diff] [blame] | 54 | .IR print (3) |
rsc | cfa37a7 | 2004-04-10 18:53:55 +0000 | [diff] [blame] | 55 | to print encoded representations of byte arrays. |
| 56 | The verbs are |
| 57 | .TP |
| 58 | .B H |
| 59 | base 16 (i.e. hexadecimal). The default encoding is |
| 60 | in upper case. The |
| 61 | .B l |
| 62 | flag forces lower case. |
| 63 | .TP |
| 64 | .B < |
| 65 | base 32 |
| 66 | .TP |
| 67 | .B [ |
| 68 | base 64 (same as MIME) |
| 69 | .PD |
| 70 | .PP |
| 71 | The length of the array is specified as |
| 72 | .IR f2 . |
| 73 | For example, to display a 15 byte array as hex: |
| 74 | .EX |
| 75 | |
| 76 | char x[15]; |
| 77 | |
| 78 | fmtinstall('H', encodefmt); |
| 79 | print("%.*H\\n", sizeof x, x); |
| 80 | |
| 81 | .EE |
| 82 | .SH SOURCE |
rsc | c3674de | 2005-01-11 17:37:33 +0000 | [diff] [blame] | 83 | .B \*9/src/lib9/u32.c |
rsc | cfa37a7 | 2004-04-10 18:53:55 +0000 | [diff] [blame] | 84 | .br |
rsc | c3674de | 2005-01-11 17:37:33 +0000 | [diff] [blame] | 85 | .B \*9/src/lib9/u64.c |