plan9port

fork of plan9port with libvec, libstr and libsdb
Log | Files | Refs | README | LICENSE

encode.3 (1560B)


      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
     52 .MR fmtinstall (3)
     53 and
     54 .MR print (3)
     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
     83 .B \*9/src/lib9/u32.c
     84 .br
     85 .B \*9/src/lib9/u64.c