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);
}
}
Aggregations