Top Description Inners Fields Constructors Methods
org.python.modules

public Class marshal

extends Object
Class Inheritance
Imports
java.io.DataInputStream, .DataOutputStream, .EOFException, .IOException, .InputStream, .OutputStream, java.math.BigInteger, java.nio.BufferUnderflowException, .ByteBuffer, .ByteOrder, .CharBuffer, java.nio.charset.Charset, java.util.ArrayList, .HashMap, .List, .Map, org.python.core.Abstract, .CPython311Code, .EOFError, .Exposed.Default, .Exposed.Member, .Exposed.PythonStaticMethod, .OSError, .Py, .PyBaseObject, .PyBool, .PyBytes, .PyCode, .PyDict, .PyException, .PyFloat, .PyList, .PyLong, .PyObjectUtil, .PyObjectUtil.NoConversion, .PySequence, .PySequence.OfInt, .PyTuple, .PyType, .PyUnicode, .StopIteration, .TypeError, .ValueError, org.python.core.stringlib.ByteArrayBuilder, .IntArrayBuilder

Write Python objects to files and read them back. This is primarily intended for writing and reading compiled Python code, even though dicts, lists, sets a nd frozensets, not commonly seen in code objects, are supported. Version 3 of this protocol properly supports circular links and sharing.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
marshal.BoolCodec

Codec for Python bool.

private static class
marshal.BytesCodec

Codec for Python bytes.

public static class
marshal.BytesReader

A Reader that has a ByteBuffer as its source.

pack-priv static class
marshal.BytesWriter

A Writer that has a ByteArrayBuilder as its destination.

pack-priv static interface
marshal.Codec

A Codec groups together the code for writing and reading instances of a particular Python type.

private static class
marshal.CodeCodec

Codec for Python code.

private static interface
marshal.Decoder

We apply a particular Decoder to the stream after we read a type code byte that tells us which one to use, to decode the data following.

private static class
marshal.DictCodec

Codec for Python dict.

private static class
marshal.FloatCodec

Codec for Python float.

private static class
marshal.IntCodec

Codec for Python int.

private static class
marshal.ListCodec

Codec for Python list.

public abstract static class
marshal.Reader

A marshal.Reader holds either an InputStream or a java.nio.ByteBuffer (maybe wrapping a byte[]) provided by the caller, from which it will read during the time that the marshal module is de-serialising objects from it.

private static class
marshal.RefCodec

Pseudo-Codec for records containing a reference, which must previously have been defined (and not still be null).

private static class
marshal.SingletonCodec

Codec for several Python singletons.

private static class
marshal.StrCodec

Codec for Python str.

public static class
marshal.StreamReader

A Reader that has a java.io.InputStream as its source.

pack-priv static class
marshal.StreamWriter

A Writer that has a java.io.OutputStream as its destination.

private static class
marshal.TupleCodec

Codec for Python int.

private static class
pack-priv abstract static class
marshal.Writer

A marshal.Writer holds an OutputStream during the time that the marshal module is serialising objects to it.

Field Summary

Modifier and TypeField and Description
private static final BigInteger
BIG_MASK15

A mask for the low 15 bits.

private static HashMap<PyType, marshal.Codec>
codecForType

A mapping from Python type to the Codec that is able to encode and decode that type.

private static HashMap<Integer, marshal.Decoder>
decoderForCode

A mapping from the type code to the Decoder able to render the record as a Python object.

private static final int
FLAG_REF

We add this to a TYPE_* code to indicate that the encoded object is cached at the next free index.

private static final int
MASK15

A mask for the low 15 bits.

private static final int
private static final int
TYPE_ASCII

The record encodes a str (counted bytes follow)

private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
TYPE_DICT

The record encodes a dict (key-value pairs follow)

private static final int
TYPE_ELLIPSIS

The record encodes Ellipsis (in one byte)

private static final int
TYPE_FALSE

The record encodes False (in one byte)

private static final int
private static final int
private static final int
TYPE_INT

The record encodes an int (4 bytes follow)

private static final int
private static final int
private static final int
TYPE_LIST

The record encodes a list (counted objects follow)

private static final int
TYPE_LONG

The record encodes an int (counted 15-bit digits)

private static final int
TYPE_NONE

The record encodes None (in one byte)

private static final int
private static final int
private static final int
private static final int
TYPE_SHORT_ASCII

The record encodes a str (counted bytes follow)

private static final int
private static final int
TYPE_SMALL_TUPLE

The record encodes a tuple (counted objects follow)

private static final int
TYPE_STOPITER

The record encodes the type StopIteration

private static final int
TYPE_TRUE

The record encodes True (in one byte)

private static final int
TYPE_TUPLE

The record encodes a tuple (counted objects follow)

private static final int
TYPE_UNICODE

The record encodes a str (counted code points follow)

private static final int
pack-priv static final int

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static void
dump(Object
to write
value
,
Object
on which to write
file
,
int
of the format to use
version
)

marshal.dump(value, file, version=4): Write the value on the open file.

public static PyBytes

Returns:

bytes containing result
dumps
(Object
to write
value
,
int
of the format to use
version
)

marshal.dumps(value, version=4): Return a bytes object into which the given value has been written, as to a file using dump(Object, Object, int).

public static Object

Returns:

the object read
load
(Object
to read
file
)

marshal.load(file): read one value from an open file and return it.

public static Object

Returns:

the object read
loads
(Object
to read
bytes
)

marshal.loads(bytes): read one value from a bytes-like object and return it.

private static void
register(marshal.Codec
to register
codec
)

Associate a codec with its target Python type in codecForType and each read method it supplies with the type code it supports.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait