org.jmythapi.protocol
Interface IMythPacket

All Superinterfaces:
IVersionable
All Known Implementing Classes:
ClientErrorPacket, MythPacket

public interface IMythPacket
extends IVersionable

This interface represents a protocol packet that can be send over network.

Package Structure:

In general a protocol packet just consists of a list of arguments. When this arguments should be send over network, the argument values need to be separated by the delimeter DELIM and the first 8 bytes of the resulting byte stream must contain the size of the payload.
Take a look into the MythTV Wiki for more details.

The following example shows how a MythTV-packet looks like.

A request packet
24      
QUERY_FREE_SPACE_SUMMARY
A response packet.
32      
0[]:[]18761596[]:[]0[]:[]2985552

Usage example:

The following is done internally by the a backend-connection when sending a request to the backend and receiving a response packet:

    // convert a sendable object to a packet
    IMythPacket req = sendableObj.getPacket();
    
    // convert the packet into bytes and send it via the output stream
    PacketUtils.writeTo(req, socketOutputStream);
 
    // read the response packet from input stream
    IMythPacket resp = PacketUtils.readFrom(protoVersion, socketInputStream);
 
As shown in the above example the PacketUtils class provides convenient methods to read and write a packet.

See Also:
PacketUtils.writeTo, PacketUtils.readFrom

Field Summary
static String DELIM
          The delimeter used to separate the packet arguments when sending them over network.
 
Method Summary
 String getPacketArg(int idx)
          Gets the packet argument value at the given position.
 List<String> getPacketArgs()
          Gets the packet arguments.
 int getPacketArgsLength()
          Gets the amount of the packet arguments.
 Date getPacketCreationTime()
          Gets the time when this packet was created.
 
Methods inherited from interface org.jmythapi.IVersionable
getVersionNr
 

Field Detail

DELIM

static final String DELIM
The delimeter used to separate the packet arguments when sending them over network.

See Also:
Constant Field Values
Method Detail

getPacketArgs

List<String> getPacketArgs()
Gets the packet arguments.

Returns:
the packet arguments as list.

getPacketArgsLength

int getPacketArgsLength()
Gets the amount of the packet arguments.

Returns:
the amount of arguments.

getPacketArg

String getPacketArg(int idx)
Gets the packet argument value at the given position.

Parameters:
idx - the position of the desired argument
Returns:
the argument value.

getPacketCreationTime

Date getPacketCreationTime()
Gets the time when this packet was created.

Returns:
the packet creation time


Copyright © 2008-2013. All Rights Reserved.