Search in sources :

Example 1 with MessageType

use of de.rwth.idsg.steve.ocpp.ws.data.MessageType in project steve by RWTH-i5-IDSG.

the class Deserializer method accept.

/**
 * Parsing with streaming API is cumbersome, but only it allows to parse the String step for step
 * and build, if any, a corresponding error message.
 */
@Override
public void accept(CommunicationContext context) {
    try (JsonParser parser = mapper.getFactory().createParser(context.getIncomingString())) {
        // set cursor to '['
        parser.nextToken();
        parser.nextToken();
        int messageTypeNr = parser.getIntValue();
        parser.nextToken();
        String messageId = parser.getText();
        MessageType messageType = MessageType.fromTypeNr(messageTypeNr);
        switch(messageType) {
            case CALL:
                handleCall(context, messageId, parser);
                break;
            case CALL_RESULT:
                handleResult(context, messageId, parser);
                break;
            case CALL_ERROR:
                handleError(context, messageId, parser);
                break;
            default:
                throw new SteveException("Unknown enum type");
        }
    } catch (IOException e) {
        throw new SteveException("Deserialization of incoming string failed: %s", context.getIncomingString(), e);
    }
}
Also used : IOException(java.io.IOException) MessageType(de.rwth.idsg.steve.ocpp.ws.data.MessageType) JsonParser(com.fasterxml.jackson.core.JsonParser) SteveException(de.rwth.idsg.steve.SteveException)

Aggregations

JsonParser (com.fasterxml.jackson.core.JsonParser)1 SteveException (de.rwth.idsg.steve.SteveException)1 MessageType (de.rwth.idsg.steve.ocpp.ws.data.MessageType)1 IOException (java.io.IOException)1