1
0

encode 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. .TH ENCODE 2
  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. .IR fmtinstall (2)
  53. and
  54. .IR print (2)
  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. char x[15];
  76. fmtinstall('H', encodefmt);
  77. print("%.*H\\n", sizeof x, x);
  78. .EE
  79. .SH SOURCE
  80. .B /sys/src/libc/port/u32.c
  81. .br
  82. .B /sys/src/libc/port/u64.c