home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / programming / python / pyhtml / pyhtmldoc / p / packer_obj next >
Encoding:
Text File  |  1996-11-14  |  4.1 KB  |  80 lines

  1. <TITLE>Packer Objects -- Python library reference</TITLE>
  2. Next: <A HREF="../u/unpacker_objects" TYPE="Next">Unpacker Objects</A>  
  3. Prev: <A HREF="../x/xdrlib" TYPE="Prev">xdrlib</A>  
  4. Up: <A HREF="../x/xdrlib" TYPE="Up">xdrlib</A>  
  5. Top: <A HREF="../t/top" TYPE="Top">Top</A>  
  6. <H2>10.16.1. Packer Objects</H2>
  7. <CODE>Packer</CODE> is the class for packing data into XDR representation.
  8. The <CODE>Packer</CODE> class is instantiated with no arguments.
  9. <P>
  10. <DL><DT><B>get_buffer</B> () -- function of module xdrlib<DD>
  11. Returns the current pack buffer as a string.
  12. </DL>
  13. <DL><DT><B>reset</B> () -- function of module xdrlib<DD>
  14. Resets the pack buffer to the empty string.
  15. </DL>
  16. In general, you can pack any of the most common XDR data types by
  17. calling the appropriate <CODE>pack_<VAR>type</VAR></CODE> method.  Each method
  18. takes a single argument, the value to pack.  The following simple data
  19. type packing methods are supported: <CODE>pack_uint</CODE>, <CODE>pack_int</CODE>,
  20. <CODE>pack_enum</CODE>, <CODE>pack_bool</CODE>, <CODE>pack_uhyper</CODE>,
  21. and <CODE>pack_hyper</CODE>.
  22. <P>
  23. The following methods pack floating point numbers, however they
  24. require C library support.  Without the optional C built-in module,
  25. both of these methods will raise an <CODE>xdrlib.ConversionError</CODE>
  26. exception.  See the note at the end of this chapter for details.
  27. <P>
  28. <DL><DT><B>pack_float</B> (<VAR>value</VAR>) -- function of module xdrlib<DD>
  29. Packs the single-precision floating point number <VAR>value</VAR>.
  30. </DL>
  31. <DL><DT><B>pack_double</B> (<VAR>value</VAR>) -- function of module xdrlib<DD>
  32. Packs the double-precision floating point number <VAR>value</VAR>.
  33. </DL>
  34. The following methods support packing strings, bytes, and opaque data:
  35. <P>
  36. <DL><DT><B>pack_fstring</B> (<VAR>n</VAR>, <VAR>s</VAR>) -- function of module xdrlib<DD>
  37. Packs a fixed length string, <VAR>s</VAR>.  <VAR>n</VAR> is the length of the
  38. string but it is <I>not</I> packed into the data buffer.  The string
  39. is padded with null bytes if necessary to guaranteed 4 byte alignment.
  40. </DL>
  41. <DL><DT><B>pack_fopaque</B> (<VAR>n</VAR>, <VAR>data</VAR>) -- function of module xdrlib<DD>
  42. Packs a fixed length opaque data stream, similarly to
  43. <CODE>pack_fstring</CODE>.
  44. </DL>
  45. <DL><DT><B>pack_string</B> (<VAR>s</VAR>) -- function of module xdrlib<DD>
  46. Packs a variable length string, <VAR>s</VAR>.  The length of the string is
  47. first packed as an unsigned integer, then the string data is packed
  48. with <CODE>pack_fstring</CODE>.
  49. </DL>
  50. <DL><DT><B>pack_opaque</B> (<VAR>data</VAR>) -- function of module xdrlib<DD>
  51. Packs a variable length opaque data string, similarly to
  52. <CODE>pack_string</CODE>.
  53. </DL>
  54. <DL><DT><B>pack_bytes</B> (<VAR>bytes</VAR>) -- function of module xdrlib<DD>
  55. Packs a variable length byte stream, similarly to <CODE>pack_string</CODE>.
  56. </DL>
  57. The following methods support packing arrays and lists:
  58. <P>
  59. <DL><DT><B>pack_list</B> (<VAR>list</VAR>, <VAR>pack_item</VAR>) -- function of module xdrlib<DD>
  60. Packs a <VAR>list</VAR> of homogeneous items.  This method is useful for
  61. lists with an indeterminate size; i.e. the size is not available until
  62. the entire list has been walked.  For each item in the list, an
  63. unsigned integer <CODE>1</CODE> is packed first, followed by the data value
  64. from the list.  <VAR>pack_item</VAR> is the function that is called to pack
  65. the individual item.  At the end of the list, an unsigned integer
  66. <CODE>0</CODE> is packed.
  67. </DL>
  68. <DL><DT><B>pack_farray</B> (<VAR>n</VAR>, <VAR>array</VAR>, <VAR>pack_item</VAR>) -- function of module xdrlib<DD>
  69. Packs a fixed length list (<VAR>array</VAR>) of homogeneous items.  <VAR>n</VAR>
  70. is the length of the list; it is <I>not</I> packed into the buffer,
  71. but a <CODE>ValueError</CODE> exception is raised if <CODE>len(array)</CODE> is not
  72. equal to <VAR>n</VAR>.  As above, <VAR>pack_item</VAR> is the function used to
  73. pack each element.
  74. </DL>
  75. <DL><DT><B>pack_array</B> (<VAR>list</VAR>, <VAR>pack_item</VAR>) -- function of module xdrlib<DD>
  76. Packs a variable length <VAR>list</VAR> of homogeneous items.  First, the
  77. length of the list is packed as an unsigned integer, then each element
  78. is packed as in <CODE>pack_farray</CODE> above.
  79. </DL>
  80.