Package org.openmuc.jeebus.ship.message
Class MessageUtility
- java.lang.Object
-
- org.openmuc.jeebus.ship.message.MessageUtility
-
public class MessageUtility extends java.lang.Objectholds static utility methods related to message validation, de-/serialization and parsing preprocess methods separate MessageType (first byte in every message) from MessageValue
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidbeginObjectIfHasNext(com.google.gson.stream.JsonReader in)static voidcheckFieldName(com.google.gson.stream.JsonReader in, java.lang.String desiredName)static byte[]createErrorMsg(int errorType)constructs and formats an error messagestatic byte[]decodeHex(java.lang.String hexString)decode hexadecimal string to byte arraystatic AccessMethodsMsgdeserializeAm(byte[] json)static AccessMethodsRequestMsgdeserializeAmr(byte[] json)static CDEMsgdeserializeCde(byte[] json)static CloseMsgdeserializeConnCloseMsg(byte[] json)static HelloMsgdeserializeHello(byte[] json)static PinMsgdeserializePin(byte[] json)static ProtocolHandshakeMsgdeserializeProtH(byte[] json)static java.lang.StringencodeHex(byte[] bytes)encode byte array to hexadecimal string, not needed if restrict pinstatic java.lang.StringhexToPrettyFormat(java.lang.String hexString)Inserts a whitespace after every 4 characters for better graphical presentation.static booleanisHexDigits(java.lang.String s)static booleanisValidPin(java.lang.String pin)checks if PIN is valid, removes all spaces before checkingstatic java.lang.StringparseCmiMsgToString(byte[] msg)parse a cmi message for logging.static java.lang.StringparseShipMsgToString(byte[] msg)parse a message for loggingstatic AccessMethodsMsgpreprocessAmMsg(byte[] msg)static AccessMethodsRequestMsgpreprocessAmrMsg(byte[] msg)static CDEMsgpreprocessCDEMsg(byte[] msg)static CloseMsgpreprocessConnCloseMsg(byte[] msg)static HelloMsgpreprocessHelloMsg(byte[] msg)static PinMsgpreprocessPinMsg(byte[] msg)static ProtocolHandshakeMsgpreprocessProtHMsg(byte[] msg)If there are messages in the message queue, removes the message from the message queue and splits header from body and parses it into a ProtocolHandshake object.static booleanreadWrappedBoolean(com.google.gson.stream.JsonReader in)static intreadWrappedInt(com.google.gson.stream.JsonReader in)static java.lang.StringreadWrappedString(com.google.gson.stream.JsonReader in)static io.netty.handler.codec.http.websocketx.BinaryWebSocketFramewrapInBinaryFrame(byte[] msg)static voidwriteBooleanToObject(com.google.gson.stream.JsonWriter out, java.lang.String property, java.lang.Boolean value)static voidwriteIntToObject(com.google.gson.stream.JsonWriter out, java.lang.String property, java.lang.Integer value)static voidwriteStringToObject(com.google.gson.stream.JsonWriter out, java.lang.String property, java.lang.String value)
-
-
-
Method Detail
-
wrapInBinaryFrame
public static io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame wrapInBinaryFrame(byte[] msg)
-
deserializeHello
public static HelloMsg deserializeHello(byte[] json)
-
preprocessHelloMsg
public static HelloMsg preprocessHelloMsg(byte[] msg)
-
deserializeProtH
public static ProtocolHandshakeMsg deserializeProtH(byte[] json)
-
preprocessProtHMsg
public static ProtocolHandshakeMsg preprocessProtHMsg(byte[] msg)
If there are messages in the message queue, removes the message from the message queue and splits header from body and parses it into a ProtocolHandshake object.- Parameters:
msg- array of received message (message queue)- Returns:
- the parsed ProtocolHandshake object
- Throws:
java.lang.IllegalStateException- if something went wrong
-
deserializePin
public static PinMsg deserializePin(byte[] json)
-
preprocessPinMsg
public static PinMsg preprocessPinMsg(byte[] msg)
-
deserializeCde
public static CDEMsg deserializeCde(byte[] json)
-
preprocessCDEMsg
public static CDEMsg preprocessCDEMsg(byte[] msg)
-
deserializeAmr
public static AccessMethodsRequestMsg deserializeAmr(byte[] json)
-
preprocessAmrMsg
public static AccessMethodsRequestMsg preprocessAmrMsg(byte[] msg)
-
deserializeAm
public static AccessMethodsMsg deserializeAm(byte[] json)
-
preprocessAmMsg
public static AccessMethodsMsg preprocessAmMsg(byte[] msg)
-
deserializeConnCloseMsg
public static CloseMsg deserializeConnCloseMsg(byte[] json)
-
preprocessConnCloseMsg
public static CloseMsg preprocessConnCloseMsg(byte[] msg)
-
isHexDigits
public static boolean isHexDigits(java.lang.String s)
-
encodeHex
public static java.lang.String encodeHex(byte[] bytes)
encode byte array to hexadecimal string, not needed if restrict pin- Parameters:
bytes- byte array containing the hexadecimal values- Returns:
- the encoded hex
-
decodeHex
public static byte[] decodeHex(java.lang.String hexString)
decode hexadecimal string to byte array- Parameters:
hexString- the hexadecimal string to decode- Returns:
- the decoded hexadecimal string
-
hexToPrettyFormat
public static java.lang.String hexToPrettyFormat(java.lang.String hexString)
Inserts a whitespace after every 4 characters for better graphical presentation. Also cuts off '0x' at the beginning of the String if it exists.- Parameters:
hexString- the hexadecimal string to convert- Returns:
- the pretty print version of the string
-
createErrorMsg
public static byte[] createErrorMsg(int errorType)
constructs and formats an error message- Parameters:
errorType- the error type- Returns:
- the error message as a byte array
-
isValidPin
public static boolean isValidPin(java.lang.String pin)
checks if PIN is valid, removes all spaces before checking- Parameters:
pin- the PIN to be checked- Returns:
trueif PIN is valid,falseotherwise
-
parseShipMsgToString
public static java.lang.String parseShipMsgToString(byte[] msg)
parse a message for logging- Parameters:
msg- the received message- Returns:
- the parsed message
-
parseCmiMsgToString
public static java.lang.String parseCmiMsgToString(byte[] msg)
parse a cmi message for logging. Requires special handling because it only contains binary data- Parameters:
msg- the error message or CMI_STATE msg- Returns:
- the parsed message
-
writeStringToObject
public static void writeStringToObject(com.google.gson.stream.JsonWriter out, java.lang.String property, java.lang.String value) throws java.io.IOException- Throws:
java.io.IOException
-
writeIntToObject
public static void writeIntToObject(com.google.gson.stream.JsonWriter out, java.lang.String property, java.lang.Integer value) throws java.io.IOException- Throws:
java.io.IOException
-
writeBooleanToObject
public static void writeBooleanToObject(com.google.gson.stream.JsonWriter out, java.lang.String property, java.lang.Boolean value) throws java.io.IOException- Throws:
java.io.IOException
-
readWrappedString
public static java.lang.String readWrappedString(com.google.gson.stream.JsonReader in) throws java.io.IOException- Throws:
java.io.IOException
-
readWrappedInt
public static int readWrappedInt(com.google.gson.stream.JsonReader in) throws java.io.IOException- Throws:
java.io.IOException
-
readWrappedBoolean
public static boolean readWrappedBoolean(com.google.gson.stream.JsonReader in) throws java.io.IOException- Throws:
java.io.IOException
-
beginObjectIfHasNext
public static void beginObjectIfHasNext(com.google.gson.stream.JsonReader in) throws java.io.IOException- Throws:
java.io.IOException
-
checkFieldName
public static void checkFieldName(com.google.gson.stream.JsonReader in, java.lang.String desiredName) throws java.io.IOException- Throws:
java.io.IOException
-
-