de.sciss.net
Class OSCPacketCodec.Atom
java.lang.Object
de.sciss.net.OSCPacketCodec.Atom
- Enclosing class:
- OSCPacketCodec
public abstract static class OSCPacketCodec.Atom
- extends Object
The Atom
class represents a combination of
an encoder and decoder of a Java respectively OSC atom.
While typically an Atom
does a one-to-one
mapping between a single Java class and a single OSC
type tag, other mappings are possible, such as different
type tags for the same Java class, or decoding the
same typetag into different Java classes.
An example of the first case would be a colour atom:
The decodeAtom
method would require a
'r'
typetag and return a java.awt.Color
object, with a body similar to this:
return new java.awt.Color( b.getInt(), true );
The encodeAtom
and getTypeTag
methods would require its argument to be a java.awt.Color
,
getTypeTag
would return 'r'
,
getAtomSize
would return 4
, and
encodeAtom
would do something like
tb.put( (byte) 'r' );
db.putInt( ((java.awt.Color) o).getRGB() );
And example of the latter case (one-to-many mapping) would be
a codec for the 'T'
("true") and 'F'
("false") typetags. This codec would be registered once
as an encoder, using putEncoder( Boolean.class, myAtomCodec )
,
and twice as a decoder, using putDecoder( (byte) 'F', myAtomCodec )
and putDecoder( (byte) 'T', myAtomCodec )
. The codec's
getAtomSize
method would return 0
, getTypeTag
would return
((Boolean) o).booleanValue() ? (byte) 'T' : (byte) 'F'
decodeAtom
would return
Boolean.valueOf( typeTag == (byte) 'T' )
and finally encodeAtom
would be:
tb.put( this.getTypeTag( o ));
- See Also:
OSCPacketCodec.putDecoder( byte, de.sciss.net.OSCPacketCodec.Atom )
,
OSCPacketCodec.putEncoder( java.lang.Class, de.sciss.net.OSCPacketCodec.Atom )
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
OSCPacketCodec.Atom
public OSCPacketCodec.Atom()
decodeAtom
public abstract Object decodeAtom(byte typeTag,
ByteBuffer b)
throws IOException
- Throws:
IOException
encodeAtom
public abstract void encodeAtom(Object o,
ByteBuffer tb,
ByteBuffer db)
throws IOException
- Throws:
IOException
getTypeTag
public abstract byte getTypeTag(Object o)
getAtomSize
public abstract int getAtomSize(Object o)
throws IOException
- Throws:
IOException