import com.fasterxml.jackson.core.JsonGenerator; //导入方法依赖的package包/类
public static void serializeFlowMod(JsonGenerator jGen, OFFlowMod flowMod) throws IOException, JsonProcessingException {
jGen.configure(Feature.WRITE_NUMBERS_AS_STRINGS, true); // IMHO this just looks nicer and is easier to read if everything is quoted
jGen.writeStartObject();
jGen.writeStringField("version", flowMod.getVersion().toString()); // return the enum names
jGen.writeStringField("command", flowMod.getCommand().toString());
jGen.writeNumberField("cookie", flowMod.getCookie().getValue());
jGen.writeNumberField("priority", flowMod.getPriority());
jGen.writeNumberField("idleTimeoutSec", flowMod.getIdleTimeout());
jGen.writeNumberField("hardTimeoutSec", flowMod.getHardTimeout());
jGen.writeStringField("outPort", flowMod.getOutPort().toString());
switch (flowMod.getVersion()) {
case OF_10:
break;
case OF_11:
jGen.writeNumberField("flags", OFFlowModFlagsSerializerVer11.toWireValue(flowMod.getFlags()));
jGen.writeNumberField("cookieMask", flowMod.getCookieMask().getValue());
jGen.writeStringField("outGroup", flowMod.getOutGroup().toString());
jGen.writeStringField("tableId", flowMod.getTableId().toString());
break;
case OF_12:
jGen.writeNumberField("flags", OFFlowModFlagsSerializerVer12.toWireValue(flowMod.getFlags()));
jGen.writeNumberField("cookieMask", flowMod.getCookieMask().getValue());
jGen.writeStringField("outGroup", flowMod.getOutGroup().toString());
jGen.writeStringField("tableId", flowMod.getTableId().toString());
break;
case OF_13:
jGen.writeNumberField("flags", OFFlowModFlagsSerializerVer13.toWireValue(flowMod.getFlags()));
jGen.writeNumberField("cookieMask", flowMod.getCookieMask().getValue());
jGen.writeStringField("outGroup", flowMod.getOutGroup().toString());
break;
case OF_14:
jGen.writeNumberField("flags", OFFlowModFlagsSerializerVer14.toWireValue(flowMod.getFlags()));
jGen.writeNumberField("cookieMask", flowMod.getCookieMask().getValue());
jGen.writeStringField("outGroup", flowMod.getOutGroup().toString());
jGen.writeStringField("tableId", flowMod.getTableId().toString());
break;
default:
logger.error("Could not decode OFVersion {}", flowMod.getVersion());
break;
}
MatchSerializer.serializeMatch(jGen, flowMod.getMatch());
// handle OF1.1+ instructions with actions within
if (flowMod.getVersion() == OFVersion.OF_10) {
jGen.writeObjectFieldStart("actions");
OFActionListSerializer.serializeActions(jGen, flowMod.getActions());
jGen.writeEndObject();
} else {
OFInstructionListSerializer.serializeInstructionList(jGen, flowMod.getInstructions());
} // end not-empty instructions (else)
jGen.writeEndObject();
}