py4j

## Class Protocol

- java.lang.Object
- - py4j.Protocol

-     public class Protocol
      extends Object

  This class defines the protocol used to communicate between two virtual machines (e.g., Python and Java).

  Currently, the protocol requires type information (e.g., is this string an integer, an object reference or a boolean?) to be embedded with each command part. The rational is that the source virtual machine is usually better at determining the type of objects it sends.

  An input command is usually composed of:

  - A command name (e.g., c for call)
  - Optionally, a sub command name (e.g., 'a' for concatenate in the list command)
  - A list of command parts (e.g., the name of a method, the value of a parameter, etc.)
  - The End of Command marker (e)

  The various parts of a command are separated by \n characters. These characters are automatically escaped and unescaped in Strings on both sides (Java and Python).

  An output command is usually composed of:

  - A success or error code (y for yes, x for exception)
  - A return value (e.g., n for null, v for void, or any other value like a String)

  This class should be used only if the user creates new commands.

  Author:
    Barthelemy Dagenais

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static char` | `ARRAY_TYPE`
    `static char` | `BOOLEAN_TYPE`
    `static char` | `BYTES_TYPE`
    `static char` | `CLASS_TYPE`
    `static char` | `DECIMAL_TYPE`
    `static String` | `DEFAULT_JVM_OBJECT_ID`
    `static char` | `DOUBLE_TYPE`
    `static char` | `END`
    `static char` | `END_OUTPUT`
    `static String` | `ENTRY_POINT_OBJECT_ID`
    `static char` | `ERROR`
    `static String` | `ERROR_COMMAND`
    `static char` | `INTEGER_TYPE`
    `static char` | `ITERATOR_TYPE`
    `static char` | `LIST_TYPE`
    `static char` | `LONG_TYPE`
    `static char` | `MAP_TYPE`
    `static char` | `METHOD_TYPE`
    `static char` | `NO_MEMBER`
    `static String` | `NO_SUCH_FIELD`
    `static char` | `NULL_TYPE`
    `static char` | `PACKAGE_TYPE`
    `static String` | `PYTHON_INFINITY`
    `static String` | `PYTHON_NAN`
    `static String` | `PYTHON_NEGATIVE_INFINITY`
    `static char` | `PYTHON_PROXY_TYPE`
    `static char` | `REFERENCE_TYPE`
    `static char` | `SET_TYPE`
    `static String` | `STATIC_PREFIX`
    `static char` | `STRING_TYPE`
    `static char` | `SUCCESS`
    `static char` | `VOID`
    `static String` | `VOID_COMMAND`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Protocol()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static String` | `encodeBytes(byte[] bytes)` Transform the byte array into Base64 characters.
    `static boolean` | `getBoolean(String commandPart)` Assumes that commandPart is not empty.
    `static byte[]` | `getBytes(String commandPart)` Assumes that commandPart is not empty.
    `static BigDecimal` | `getDecimal(String commandPart)` Assumes that commandPart is not empty.
    `static double` | `getDouble(String commandPart)` Assumes that commandPart is not empty.
    `static int` | `getInteger(String commandPart)` Assumes that commandPart is not empty.
    `static long` | `getLong(String commandPart)` Assumes that commandPart is not empty.
    `static String` | `getMemberOutputCommand(char memberType)`
    `static String` | `getMemberOutputCommand(char memberType, String fqn)`
    `static String` | `getNoSuchFieldOutputCommand()`
    `static Object` | `getNull(String commandPart)` Method provided for consistency.
    `static Object` | `getObject(String commandPart, Gateway gateway)`
    `static String` | `getOutputCommand(ReturnObject rObject)`
    `static String` | `getOutputErrorCommand()`
    `static String` | `getOutputErrorCommand(String errorMessage)`
    `static String` | `getOutputErrorCommand(Throwable throwable)`
    `static String` | `getOutputVoidCommand()`
    `static char` | `getPrimitiveType(Object primitiveObject)`
    `static Object` | `getPythonProxy(String commandPart, Gateway gateway)` Assumes that commandPart is not empty.
    `static Object` | `getReference(String commandPart, Gateway gateway)` Assumes that commandPart is not empty.
    `static Object` | `getReturnValue(String returnMessage, Gateway gateway)`
    `static Throwable` | `getRootThrowable(Throwable throwable, boolean skipInvocation)`
    `static String` | `getString(String commandPart)` Assumes that commandPart is not empty.
    `static String` | `getThrowableAsString(Throwable throwable)`
    `static boolean` | `isBoolean(String commandPart)` Assumes that commandPart is not empty.
    `static boolean` | `isBytes(String commandPart)` Assumes that commandPart is not empty.
    `static boolean` | `isDecimal(String commandPart)` Assumes that commandPart is not empty.
    `static boolean` | `isDouble(String commandPart)` Assumes that commandPart is not empty.
    `static boolean` | `isEmpty(String commandPart)`
    `static boolean` | `isEnd(String commandPart)` Assumes that commandPart is not empty.
    `static boolean` | `isError(String returnMessage)` Assumes that commandPart is not null.
    `static boolean` | `isInteger(String commandPart)` Assumes that commandPart is not empty.
    `static boolean` | `isLong(String commandPart)` Assumes that commandPart is not empty.
    `static boolean` | `isNull(String commandPart)` Assumes that commandPart is not empty.
    `static boolean` | `isPythonProxy(String commandPart)` Assumes that commandPart is not empty.
    `static boolean` | `isReference(String commandPart)` Assumes that commandPart is not empty.
    `static boolean` | `isString(String commandPart)` Assumes that commandPart is not empty.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### BYTES_TYPE

          public static final char BYTES_TYPE

      See Also:
        Constant Field Values

    - #### INTEGER_TYPE

          public static final char INTEGER_TYPE

      See Also:
        Constant Field Values

    - #### LONG_TYPE

          public static final char LONG_TYPE

      See Also:
        Constant Field Values

    - #### BOOLEAN_TYPE

          public static final char BOOLEAN_TYPE

      See Also:
        Constant Field Values

    - #### DOUBLE_TYPE

          public static final char DOUBLE_TYPE

      See Also:
        Constant Field Values

    - #### DECIMAL_TYPE

          public static final char DECIMAL_TYPE

      See Also:
        Constant Field Values

    - #### STRING_TYPE

          public static final char STRING_TYPE

      See Also:
        Constant Field Values

    - #### REFERENCE_TYPE

          public static final char REFERENCE_TYPE

      See Also:
        Constant Field Values

    - #### LIST_TYPE

          public static final char LIST_TYPE

      See Also:
        Constant Field Values

    - #### SET_TYPE

          public static final char SET_TYPE

      See Also:
        Constant Field Values

    - #### ARRAY_TYPE

          public static final char ARRAY_TYPE

      See Also:
        Constant Field Values

    - #### MAP_TYPE

          public static final char MAP_TYPE

      See Also:
        Constant Field Values

    - #### ITERATOR_TYPE

          public static final char ITERATOR_TYPE

      See Also:
        Constant Field Values

    - #### NULL_TYPE

          public static final char NULL_TYPE

      See Also:
        Constant Field Values

    - #### PYTHON_PROXY_TYPE

          public static final char PYTHON_PROXY_TYPE

      See Also:
        Constant Field Values

    - #### PACKAGE_TYPE

          public static final char PACKAGE_TYPE

      See Also:
        Constant Field Values

    - #### CLASS_TYPE

          public static final char CLASS_TYPE

      See Also:
        Constant Field Values

    - #### METHOD_TYPE

          public static final char METHOD_TYPE

      See Also:
        Constant Field Values

    - #### NO_MEMBER

          public static final char NO_MEMBER

      See Also:
        Constant Field Values

    - #### VOID

          public static final char VOID

      See Also:
        Constant Field Values

    - #### END

          public static final char END

      See Also:
        Constant Field Values

    - #### END_OUTPUT

          public static final char END_OUTPUT

      See Also:
        Constant Field Values

    - #### ERROR

          public static final char ERROR

      See Also:
        Constant Field Values

    - #### SUCCESS

          public static final char SUCCESS

      See Also:
        Constant Field Values

    - #### ERROR_COMMAND

          public static final String ERROR_COMMAND

      See Also:
        Constant Field Values

    - #### VOID_COMMAND

          public static final String VOID_COMMAND

      See Also:
        Constant Field Values

    - #### NO_SUCH_FIELD

          public static final String NO_SUCH_FIELD

      See Also:
        Constant Field Values

    - #### ENTRY_POINT_OBJECT_ID

          public static final String ENTRY_POINT_OBJECT_ID

      See Also:
        Constant Field Values

    - #### DEFAULT_JVM_OBJECT_ID

          public static final String DEFAULT_JVM_OBJECT_ID

      See Also:
        Constant Field Values

    - #### STATIC_PREFIX

          public static final String STATIC_PREFIX

      See Also:
        Constant Field Values

    - #### PYTHON_NAN

          public static final String PYTHON_NAN

      See Also:
        Constant Field Values

    - #### PYTHON_INFINITY

          public static final String PYTHON_INFINITY

      See Also:
        Constant Field Values

    - #### PYTHON_NEGATIVE_INFINITY

          public static final String PYTHON_NEGATIVE_INFINITY

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### Protocol

          public Protocol()

  - ### Method Detail

    - #### encodeBytes

          public static String encodeBytes(byte[] bytes)

      Transform the byte array into Base64 characters.

      Parameters:
        `bytes` -
      Returns:

    - #### getBoolean

          public static final boolean getBoolean(String commandPart)

      Assumes that commandPart is not empty.

      Parameters:
        `commandPart` -
      Returns:
        The boolean value corresponding to this command part.

    - #### getBytes

          public static final byte[] getBytes(String commandPart)

      Assumes that commandPart is not empty.

      Parameters:
        `commandPart` -
      Returns:
        The byte array corresponding to this command part.

    - #### getDecimal

          public static final BigDecimal getDecimal(String commandPart)

      Assumes that commandPart is not empty.

      Parameters:
        `commandPart` -
      Returns:
        The decimal value corresponding to this command part.

    - #### getDouble

          public static final double getDouble(String commandPart)

      Assumes that commandPart is not empty.

      Parameters:
        `commandPart` -
      Returns:
        The double value corresponding to this command part.

    - #### getInteger

          public static final int getInteger(String commandPart)

      Assumes that commandPart is not empty.

      Parameters:
        `commandPart` -
      Returns:
        The integer value corresponding to this command part.

    - #### getLong

          public static final long getLong(String commandPart)

      Assumes that commandPart is not empty.

      Parameters:
        `commandPart` -
      Returns:
        The long value corresponding to this command part.

    - #### getMemberOutputCommand

          public static final String getMemberOutputCommand(char memberType)

    - #### getMemberOutputCommand

          public static final String getMemberOutputCommand(char memberType,
                                                            String fqn)

    - #### getNoSuchFieldOutputCommand

          public static String getNoSuchFieldOutputCommand()

    - #### getNull

          public static final Object getNull(String commandPart)

      Method provided for consistency. Just returns null.

      Parameters:
        `commandPart` -
      Returns:
        null.

    - #### getObject

          public static final Object getObject(String commandPart,
                                               Gateway gateway)

    - #### getOutputCommand

          public static final String getOutputCommand(ReturnObject rObject)

    - #### getOutputErrorCommand

          public static final String getOutputErrorCommand()

    - #### getOutputErrorCommand

          public static final String getOutputErrorCommand(String errorMessage)

    - #### getOutputErrorCommand

          public static final String getOutputErrorCommand(Throwable throwable)

    - #### getOutputVoidCommand

          public static final String getOutputVoidCommand()

    - #### getPrimitiveType

          public static char getPrimitiveType(Object primitiveObject)

    - #### getPythonProxy

          public static Object getPythonProxy(String commandPart,
                                              Gateway gateway)

      Assumes that commandPart is not empty.

      Parameters:
        `commandPart` -
      Returns:
        A Python proxy specified in this command part.

    - #### getReference

          public static final Object getReference(String commandPart,
                                                  Gateway gateway)

      Assumes that commandPart is not empty.

      Parameters:
        `commandPart` -
      Returns:
        The object referenced in this command part.

    - #### getReturnValue

          public static final Object getReturnValue(String returnMessage,
                                                    Gateway gateway)

    - #### getRootThrowable

          public static final Throwable getRootThrowable(Throwable throwable,
                                                         boolean skipInvocation)

    - #### getString

          public static final String getString(String commandPart)

      Assumes that commandPart is not empty.

      Parameters:
        `commandPart` -
      Returns:
        The reference contained in this command part.

    - #### getThrowableAsString

          public static final String getThrowableAsString(Throwable throwable)

    - #### isBoolean

          public static final boolean isBoolean(String commandPart)

      Assumes that commandPart is not empty.

      Parameters:
        `commandPart` -
      Returns:
        True if the command part is a boolean

    - #### isBytes

          public static final boolean isBytes(String commandPart)

      Assumes that commandPart is not empty.

      Parameters:
        `commandPart` -
      Returns:
        True if the command part is a byte array

    - #### isDecimal

          public static final boolean isDecimal(String commandPart)

      Assumes that commandPart is not empty.

      Parameters:
        `commandPart` -
      Returns:
        True if the command part is a decimal

    - #### isDouble

          public static final boolean isDouble(String commandPart)

      Assumes that commandPart is not empty.

      Parameters:
        `commandPart` -
      Returns:
        True if the command part is a double

    - #### isEmpty

          public static final boolean isEmpty(String commandPart)

    - #### isEnd

          public static final boolean isEnd(String commandPart)

      Assumes that commandPart is not empty.

      Parameters:
        `commandPart` -
      Returns:
        True if the command part is the end token

    - #### isError

          public static final boolean isError(String returnMessage)

      Assumes that commandPart is not null.

      Parameters:
        `returnMessage` -
      Returns:
        True if the return message is an error

    - #### isInteger

          public static final boolean isInteger(String commandPart)

      Assumes that commandPart is not empty.

      Parameters:
        `commandPart` -
      Returns:
        True if the command part is an integer

    - #### isLong

          public static final boolean isLong(String commandPart)

      Assumes that commandPart is not empty.

      Parameters:
        `commandPart` -
      Returns:
        True if the command part is a long

    - #### isNull

          public static final boolean isNull(String commandPart)

      Assumes that commandPart is not empty.

      Parameters:
        `commandPart` -
      Returns:
        True if the command part is null

    - #### isPythonProxy

          public static final boolean isPythonProxy(String commandPart)

      Assumes that commandPart is not empty.

      Parameters:
        `commandPart` -
      Returns:
        True if the command part is a python proxy

    - #### isReference

          public static final boolean isReference(String commandPart)

      Assumes that commandPart is not empty.

      Parameters:
        `commandPart` -
      Returns:
        True if the command part is a reference

    - #### isString

          public static final boolean isString(String commandPart)

      Assumes that commandPart is not empty.

      Parameters:
        `commandPart` -
      Returns:
        True if the command part is a reference