public class IMCDefinition extends java.lang.Object implements IMessageProtocol<IMCMessage>
Constructor and Description |
---|
IMCDefinition(java.io.File f)
Create a new IMCDefinition, loading the definitions from f
|
IMCDefinition(java.io.InputStream is)
Create a new IMCDefinition, loading the XML definitions from the given
InputStream |
Modifier and Type | Method and Description |
---|---|
<T extends IMCMessage> |
create(java.lang.Class<T> clazz,
java.lang.Object... values) |
IMCMessage |
create(java.lang.String name,
java.lang.Object... values)
Create a new message and fills it with given values
|
Header |
createHeader()
Create a new header compatible with these definitions
|
java.lang.Object |
deserialize(IMCFieldType type,
java.io.DataInput in,
java.lang.String context) |
void |
deserializeFields(IMCMessage message,
java.io.DataInput in) |
java.lang.String |
dumpPayload(IMCMessage message,
int numTabs) |
java.util.Collection<java.lang.String> |
getAbstractMessages() |
java.lang.String |
getAuthor()
Retrieve the definitions' author names found on the XML
|
java.util.Collection<java.lang.String> |
getConcreteMessages() |
java.lang.String |
getCreation()
Retrieve the creation date found on these definitions' XML
|
IMCMessageType |
getHeaderType() |
static IMCDefinition |
getInstance()
Retrieve (possibly reusing) default definitions
|
static IMCDefinition |
getInstance(java.io.InputStream isDefinitions)
Load the XML on the given
InputStream and changes the default
instance to this |
java.lang.String |
getLongName()
Retrieve the definitions' long name found on the XML
|
java.lang.String |
getMd5String()
Retrieve the generated MD5 hash for these definitions
|
int |
getMessageCount() |
int |
getMessageId(java.lang.String name) |
java.lang.String |
getMessageName(int id) |
java.util.Collection<java.lang.String> |
getMessageNames() |
java.lang.String |
getName()
Retrieve the definitions' name found on the XML
|
IMCAddressResolver |
getResolver()
Retrieve this definition's address resolver
|
long |
getSwappedWord()
Retrieve the swapped (little endian) synchronization word of this IMC
definition
|
long |
getSyncWord()
Retrieve the Synchronization word of this IMC definition
|
IMCMessageType |
getType(java.lang.Integer id)
Retrieve the message type of given message id
|
IMCMessageType |
getType(java.lang.String name)
Retrieve the message type of given message abbreviated name
|
java.lang.String |
getVersion()
Retrieve the version found on these definitions' XML
|
int |
headerLength()
Retrieve the header length in this IMC version
|
static void |
main(java.lang.String[] args) |
boolean |
messageExists(java.lang.String name)
Verify if a message with given abbreviated name exists in these
definitions
|
java.lang.String |
name() |
IMCMessage |
newMessage(int id) |
IMCMessage |
newMessage(java.lang.String name) |
IMCMessage |
nextMessage(java.nio.ByteBuffer buff)
Retrieve the next message from the buffer
|
IMCMessage |
nextMessage(IMCInputStream input)
Retrieve the next message from the given IMCInputStream
|
IMCMessage |
nextMessage(java.io.InputStream in)
Retrieve the next message in the given InputStream.
|
IMCMessage |
nextMessageOfType(int type,
java.nio.ByteBuffer buff)
Retrieve the next message of given type from current position in the
buffer
|
IMCMessage |
parseMessage(byte[] data)
Create and retrieve an IMCMessage that is serialized in an array of bytes
|
void |
readHeader(IMCInputStream iis,
IMCMessage header)
Read a message header from the given IMCInputStream
|
IMCMessage |
replicate(IMCMessage msg) |
int |
serializationSize(IMCMessage msg) |
void |
serialize(IMCMessage m,
IMCOutputStream os)
Serialize the given message to an IMCOutputStream
|
void |
serialize(IMCMessage m,
java.io.OutputStream os) |
int |
serializeFields(IMCMessage message,
IMCOutputStream out) |
java.util.Collection<java.lang.String> |
subtypesOf(java.lang.String msgAbbrev) |
IMCMessage |
unserialize(java.io.InputStream is) |
java.lang.String |
version()
Retrieve the version found on these definitions' XML
|
static java.lang.String |
versionOfFile(java.io.File f)
Utility method to retrieve the IMC version of a given file with XML
defitions
|
static void |
writeDefaultDefinitions(java.io.File destination) |
public IMCDefinition(java.io.File f) throws java.lang.Exception
f
- The file from where to read the definitions.java.lang.Exception
- In case there are problems reading the file.public IMCDefinition(java.io.InputStream is) throws java.lang.Exception
InputStream
is
- java.lang.Exception
public static void writeDefaultDefinitions(java.io.File destination) throws java.io.IOException
java.io.IOException
public static IMCDefinition getInstance()
public static IMCDefinition getInstance(java.io.InputStream isDefinitions)
InputStream
and changes the default
instance to thisisDefinitions
- InputStream
holding the XML definitionsInputStream
public int headerLength()
public Header createHeader()
public final IMCMessageType getHeaderType()
public final IMCMessageType getType(java.lang.Integer id)
id
- a (numeric) message idIMCMessageType
or null
if that type was not foundpublic final IMCMessageType getType(java.lang.String name)
name
- the abbreviated name of the wanted message typeIMCMessageType
or null
if that type was not foundpublic long getSyncWord()
public long getSwappedWord()
public java.lang.String version()
version
in interface IMessageProtocol<IMCMessage>
public java.lang.String getVersion()
public java.lang.String getCreation()
public java.lang.String name()
name
in interface IMessageProtocol<IMCMessage>
public java.lang.String getName()
public java.lang.String getLongName()
public java.lang.String getAuthor()
public java.lang.String getMd5String()
public IMCMessage parseMessage(byte[] data) throws java.io.IOException
data
- Where to read the message fromjava.io.IOException
- In case of a buffer underflowpublic IMCMessage nextMessageOfType(int type, java.nio.ByteBuffer buff) throws java.lang.Exception
type
- The type of the message to be retrievedbuff
- The buffer where to read the message fromjava.lang.Exception
- if end of the buffer is reachedpublic IMCMessage nextMessage(java.nio.ByteBuffer buff) throws java.lang.Exception
buff
- The buffer where to read the message fromjava.lang.Exception
- if end of the buffer is reachedpublic void readHeader(IMCInputStream iis, IMCMessage header) throws java.io.IOException
header
- Where to store the read dataiis
- Where to read the header fromjava.io.IOException
public IMCMessage nextMessage(IMCInputStream input) throws java.io.IOException
input
- where to read the message fromjava.io.IOException
- In case of any IO error (like end of input)public IMCMessage nextMessage(java.io.InputStream in) throws java.io.IOException
in
- Where to read the message fromjava.io.IOException
- IO errorspublic java.lang.Object deserialize(IMCFieldType type, java.io.DataInput in, java.lang.String context) throws java.io.IOException
java.io.IOException
public void deserializeFields(IMCMessage message, java.io.DataInput in) throws java.io.IOException
java.io.IOException
public java.lang.String dumpPayload(IMCMessage message, int numTabs) throws java.io.IOException
java.io.IOException
public int serializeFields(IMCMessage message, IMCOutputStream out) throws java.io.IOException
java.io.IOException
public int getMessageCount()
getMessageCount
in interface IMessageProtocol<IMCMessage>
public boolean messageExists(java.lang.String name)
name
- The name to be searched forpublic int getMessageId(java.lang.String name)
getMessageId
in interface IMessageProtocol<IMCMessage>
public java.lang.String getMessageName(int id)
getMessageName
in interface IMessageProtocol<IMCMessage>
public java.util.Collection<java.lang.String> getMessageNames()
getMessageNames
in interface IMessageProtocol<IMCMessage>
public java.util.Collection<java.lang.String> getConcreteMessages()
public java.util.Collection<java.lang.String> getAbstractMessages()
public IMCMessage newMessage(int id) throws java.lang.Exception
newMessage
in interface IMessageProtocol<IMCMessage>
java.lang.Exception
public IMCMessage newMessage(java.lang.String name) throws java.lang.Exception
newMessage
in interface IMessageProtocol<IMCMessage>
java.lang.Exception
public int serializationSize(IMCMessage msg)
serializationSize
in interface IMessageProtocol<IMCMessage>
public IMCMessage replicate(IMCMessage msg) throws java.lang.Exception
java.lang.Exception
public IMCMessage create(java.lang.String name, java.lang.Object... values)
name
- The abbreviated name of the message to be createdvalues
- A list of pairs <field,value> for initializing the
message. Example:
IMCMessage estimatedState = new IMCMessage("EstimatedState", "x", 10.0, "lat", 0.71, "ref", "NED");
public <T extends IMCMessage> T create(java.lang.Class<T> clazz, java.lang.Object... values)
public void serialize(IMCMessage m, IMCOutputStream os) throws java.lang.Exception
m
- The message to be serializedos
- Where to serialize the messagejava.lang.Exception
- IO errorspublic void serialize(IMCMessage m, java.io.OutputStream os) throws java.lang.Exception
serialize
in interface IMessageProtocol<IMCMessage>
java.lang.Exception
public IMCMessage unserialize(java.io.InputStream is) throws java.lang.Exception
unserialize
in interface IMessageProtocol<IMCMessage>
java.lang.Exception
public final IMCAddressResolver getResolver()
public java.util.Collection<java.lang.String> subtypesOf(java.lang.String msgAbbrev)
public static java.lang.String versionOfFile(java.io.File f)
f
- The XML file of the IMC definitions (IMC.xml)public static void main(java.lang.String[] args) throws java.lang.Exception
java.lang.Exception