Java Doc for struct.java in  » Scripting » jython » org » python » modules » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Scripting » jython » org.python.modules 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.python.modules.struct

struct
public class struct (Code)
This module performs conversions between Python values and C structs represented as Python strings. It uses format strings (explained below) as compact descriptions of the lay-out of the C structs and the intended conversion to/from Python values.

The module defines the following exception and functions:

error
Exception raised on various occasions; argument is a string describing what is wrong.

pack (fmt, v1, v2, ...)
Return a string containing the values v1, v2, ... packed according to the given format. The arguments must match the values required by the format exactly.

unpack> (fmt, string)
Unpack the string (presumably packed by pack(fmt, ...)) according to the given format. The result is a tuple even if it contains exactly one item. The string must contain exactly the amount of data required by the format (i.e. len(string) must equal calcsize(fmt)).

calcsize (fmt)
Return the size of the struct (and hence of the string) corresponding to the given format.

Format characters have the following meaning; the conversion between C and Python values should be obvious given their types:

Format C Type Python
x pad byte no value
c char string of length 1
b signed char integer
B unsigned char integer
h short integer
H unsigned short integer
i int integer
I unsigned int integer
l long integer
L unsigned long integer
f float float
d double float
s char[] string
p char[] string

A format character may be preceded by an integral repeat count; e.g. the format string '4h' means exactly the same as 'hhhh'.

Whitespace characters between formats are ignored; a count and its format must not contain whitespace though.

For the "s" format character, the count is interpreted as the size of the string, not a repeat count like for the other format characters; e.g. '10s' means a single 10-byte string, while '10c' means 10 characters. For packing, the string is truncated or padded with null bytes as appropriate to make it fit. For unpacking, the resulting string always has exactly the specified number of bytes. As a special case, '0s' means a single, empty string (while '0c' means 0 characters).

The "p" format character can be used to encode a Pascal string. The first byte is the length of the stored string, with the bytes of the string following. If count is given, it is used as the total number of bytes used, including the length byte. If the string passed in to pack() is too long, the stored representation is truncated. If the string is too short, padding is used to ensure that exactly enough bytes are used to satisfy the count.

For the "I" and "L" format characters, the return value is a Python long integer.

By default, C numbers are represented in the machine's native format and byte order, and properly aligned by skipping pad bytes if necessary (according to the rules used by the C compiler).

Alternatively, the first character of the format string can be used to indicate the byte order, size and alignment of the packed data, according to the following table:

Character Byte order Size and alignment
@ native native
= native standard
< little-endian standard
> big-endian standard
! network (= big-endian) standard

If the first character is not one of these, "@" is assumed.

Native byte order is big-endian or little-endian, depending on the host system (e.g. Motorola and Sun are big-endian; Intel and DEC are little-endian).

Native size and alignment are defined as follows: short is 2 bytes; int and long are 4 bytes; float are 4 bytes and double are 8 bytes. Native byte order is chosen as big-endian.

Standard size and alignment are as follows: no alignment is required for any type (so you have to use pad bytes); short is 2 bytes; int and long are 4 bytes. float and double are 32-bit and 64-bit IEEE floating point numbers, respectively.

Note the difference between "@" and "=": both use native byte order, but the size and alignment of the latter is standardized.

The form "!" is available for those poor souls who claim they can't remember whether network byte order is big-endian or little-endian.

There is no way to indicate non-native byte order (i.e. force byte-swapping); use the appropriate choice of "<" or ">".

Examples (all using native byte order, size and alignment, on a big-endian machine):

 >>> from struct import *
 >>> pack('hhl', 1, 2, 3)
 '\000\001\000\002\000\000\000\003'
 >>> unpack('hhl', '\000\001\000\002\000\000\000\003')
 (1, 2, 3)
 >>> calcsize('hhl')
 8
 >>>
 

Hint: to align the end of a structure to the alignment requirement of a particular type, end the format with the code for that type with a repeat count of zero, e.g. the format 'llh0l' specifies two pad bytes at the end, assuming longs are aligned on 4-byte boundaries. This only works when native size and alignment are in effect; standard size and alignment does not enforce any alignment. For the complete documentation on the struct module, please see the "Python Library Reference"


The module is based on the original structmodule.c except that all mistakes and errors are my own. Original author unknown.


author:
   Finn Bock, bckfnn@pipmail.dknet.dk
version:
   struct.java,v 1.6 1999/04/17 12:04:34 fb Exp


Inner Class :static class FormatDef
Inner Class :static class ByteStream
Inner Class :static class PadFormatDef extends FormatDef
Inner Class :static class StringFormatDef extends FormatDef
Inner Class :static class PascalStringFormatDef extends StringFormatDef
Inner Class :static class CharFormatDef extends FormatDef
Inner Class :static class ByteFormatDef extends FormatDef
Inner Class :static class UnsignedByteFormatDef extends ByteFormatDef
Inner Class :static class LEShortFormatDef extends FormatDef
Inner Class :static class LEUnsignedShortFormatDef extends LEShortFormatDef
Inner Class :static class BEShortFormatDef extends FormatDef
Inner Class :static class BEUnsignedShortFormatDef extends BEShortFormatDef
Inner Class :static class LEIntFormatDef extends FormatDef
Inner Class :static class LEUnsignedIntFormatDef extends FormatDef
Inner Class :static class BEIntFormatDef extends FormatDef
Inner Class :static class BEUnsignedIntFormatDef extends FormatDef
Inner Class :static class LEUnsignedLongFormatDef extends FormatDef
Inner Class :static class BEUnsignedLongFormatDef extends FormatDef
Inner Class :static class LELongFormatDef extends FormatDef
Inner Class :static class BELongFormatDef extends FormatDef
Inner Class :static class LEFloatFormatDef extends FormatDef
Inner Class :static class LEDoubleFormatDef extends FormatDef
Inner Class :static class BEFloatFormatDef extends FormatDef
Inner Class :static class BEDoubleFormatDef extends FormatDef

Field Summary
public static  String__doc__
    
public static  PyStringerror
     Exception raised on various occasions; argument is a string describing what is wrong.


Method Summary
public static  intcalcsize(String format)
     Return the size of the struct (and hence of the string) corresponding to the given format.
public static  Stringpack(PyObject[] args)
     Return a string containing the values v1, v2, ...
public static  PyTupleunpack(String format, String string)
     Unpack the string (presumably packed by pack(fmt, ...)) according to the given format.

Field Detail
__doc__
public static String __doc__(Code)



error
public static PyString error(Code)
Exception raised on various occasions; argument is a string describing what is wrong.





Method Detail
calcsize
public static int calcsize(String format)(Code)
Return the size of the struct (and hence of the string) corresponding to the given format.



pack
public static String pack(PyObject[] args)(Code)
Return a string containing the values v1, v2, ... packed according to the given format. The arguments must match the values required by the format exactly.



unpack
public static PyTuple unpack(String format, String string)(Code)
Unpack the string (presumably packed by pack(fmt, ...)) according to the given format. The result is a tuple even if it contains exactly one item. The string must contain exactly the amount of data required by the format (i.e. len(string) must equal calcsize(fmt)).



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.