- java.lang.Object
-
- org.praxislive.internal.osc.OSCPacketCodec.Atom
-
- Enclosing class:
- OSCPacketCodec
public abstract static class OSCPacketCodec.Atom extends Object
TheAtomclass represents a combination of an encoder and decoder of a Java respectively OSC atom. While typically anAtomdoes 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
decodeAtommethod would require a'r'typetag and return ajava.awt.Colorobject, with a body similar to this:return new java.awt.Color( b.getInt(), true );TheencodeAtomandgetTypeTagmethods would require its argument to be ajava.awt.Color,getTypeTagwould return'r',getAtomSizewould return4, andencodeAtomwould do something liketb.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, usingputEncoder( Boolean.class, myAtomCodec ), and twice as a decoder, usingputDecoder( (byte) 'F', myAtomCodec )andputDecoder( (byte) 'T', myAtomCodec ). The codec'sgetAtomSizemethod would return0,getTypeTagwould return((Boolean) o).booleanValue() ? (byte) 'T' : (byte) 'F'decodeAtomwould returnBoolean.valueOf( typeTag == (byte) 'T' )and finallyencodeAtomwould be:tb.put( this.getTypeTag( o ));
-
-
Constructor Summary
Constructors Constructor Description Atom()
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description abstract ObjectdecodeAtom(byte typeTag, ByteBuffer b)abstract voidencodeAtom(Object o, ByteBuffer tb, ByteBuffer db)abstract intgetAtomSize(Object o)abstract bytegetTypeTag(Object o)
-
-
-
Method Detail
-
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
-
-