- java.lang.Object
-
- org.praxislive.internal.osc.OSCPacket
-
- Direct Known Subclasses:
OSCBundle,OSCMessage
public abstract class OSCPacket extends Object
OSCPacketis the superclass of OSC messages and bundles. It provides methods that apply to both of these OSC packet types, like calculating the packet's size encoding the packet from a given byte buffer or decoding a received message from a given buffer.- Version:
- 0.33, 25-Feb-08
- Author:
- Hanns Holger Rutz
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedOSCPacket()Constructs a newOSCPacket.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static OSCPacketdecode(ByteBuffer b)Creates a new packet decoded from the ByteBuffer, using the default codec.voidencode(ByteBuffer b)Encodes the contents of this packet into the providedByteBuffer, beginning at the buffer's current position, using the default codec.voidencode(OSCPacketCodec c, ByteBuffer b)Encodes the contents of this packet into the providedByteBuffer, beginning at the buffer's current position, using a given codec.intgetSize()Calculates and returns the packet's size in bytes, using the default codec.intgetSize(OSCPacketCodec c)Calculates and returns the packet's size in bytes, using a given codec.static voidprintHexOn(PrintStream stream, ByteBuffer b)Prints a hexdump version of a packet to a given stream.static voidprintTextOn(PrintStream stream, OSCPacket p)Prints a text version of a packet to a given stream.
-
-
-
Method Detail
-
getSize
public final int getSize() throws IOExceptionCalculates and returns the packet's size in bytes, using the default codec.- Returns:
- the size of the packet in bytes, including the initial
osc command and aligned to 4-byte boundary. this
is the amount of bytes written by the
encodemethod. - Throws:
IOException- if an error occurs during the calculation- See Also:
getSize( OSCPacketCodec )
-
getSize
public final int getSize(OSCPacketCodec c) throws IOException
Calculates and returns the packet's size in bytes, using a given codec.- Parameters:
c- the codec that is shall used for encoding the packet- Returns:
- the size of the packet in bytes, including the initial
osc command and aligned to 4-byte boundary. this
is the amount of bytes written by the
encodemethod. - Throws:
IOException- if an error occurs during the calculation- See Also:
OSCPacketCodec.getSize( OSCPacket )
-
encode
public final void encode(ByteBuffer b) throws IOException
Encodes the contents of this packet into the providedByteBuffer, beginning at the buffer's current position, using the default codec. To write the encoded packet, you will typically callflip()on the buffer, thenwrite()on the channel.- Parameters:
b-ByteBufferpointing right at the beginning of the osc packet. buffer position will be right after the end of the packet when the method returns.- Throws:
IOException- in case some of the writing procedures failed.- See Also:
encode( OSCPacketCodec, ByteBuffer )
-
encode
public final void encode(OSCPacketCodec c, ByteBuffer b) throws IOException
Encodes the contents of this packet into the providedByteBuffer, beginning at the buffer's current position, using a given codec. To write the encoded packet, you will typically callflip()on the buffer, thenwrite()on the channel.- Parameters:
b-ByteBufferpointing right at the beginning of the osc packet. buffer position will be right after the end of the packet when the method returns.c- the codec that is shall used for encoding the packet- Throws:
IOException- in case some of the writing procedures failed.- See Also:
OSCPacketCodec.encode( OSCPacket, ByteBuffer )
-
decode
public static OSCPacket decode(ByteBuffer b) throws IOException
Creates a new packet decoded from the ByteBuffer, using the default codec. This method simply calls the equivalent method inOSCPacketCodec.- Parameters:
b-ByteBufferpointing right at the beginning of the packet. the buffer's limited should be set appropriately to allow the complete packet to be read. when the method returns, the buffer's position is right after the end of the packet.- Returns:
- new decoded OSC packet
- Throws:
IOException- in case some of the reading or decoding p rocedures failed.IllegalArgumentException- occurs in some cases of buffer underflow- See Also:
OSCPacketCodec.decode( ByteBuffer )
-
printTextOn
public static void printTextOn(PrintStream stream, OSCPacket p)
Prints a text version of a packet to a given stream. The format is similar to scsynth using dump mode 1. Bundles will be printed with each message on a separate line and increasing indent.- Parameters:
stream- the print stream to use, for exampleSystem.outp- the packet to print (either a message or bundle)
-
printHexOn
public static void printHexOn(PrintStream stream, ByteBuffer b)
Prints a hexdump version of a packet to a given stream. The format is similar to scsynth using dump mode 2. UnlikeprintTextOnthis takes a raw received or encoded byte buffer and not a decoded instance ofOSCPacket.- Parameters:
stream- the print stream to use, for exampleSystem.outb- the byte buffer containing the packet. read position should be at the very beginning of the packet, limit should be at the end of the packet. this method alters the buffer position in a manner that a successiveflip()will restore the original position and limit.- See Also:
Buffer.limit(),Buffer.position()
-
-