use of org.onosproject.mapping.MappingTreatment in project onos by opennetworkinglab.
the class MappingTreatmentCodec method decode.
@Override
public MappingTreatment decode(ObjectNode json, CodecContext context) {
if (json == null || !json.isObject()) {
return null;
}
final JsonCodec<MappingInstruction> instructionCodec = context.codec(MappingInstruction.class);
JsonNode instructionJson = json.get(INSTRUCTIONS);
MappingTreatment.Builder builder = DefaultMappingTreatment.builder();
if (instructionJson != null) {
IntStream.range(0, instructionJson.size()).forEach(i -> builder.add(instructionCodec.decode(get(instructionJson, i), context)));
}
ObjectNode addressJson = get(json, ADDRESS);
if (addressJson != null) {
final JsonCodec<MappingAddress> addressCodec = context.codec(MappingAddress.class);
builder.withAddress(addressCodec.decode(addressJson, context));
}
return builder.build();
}
use of org.onosproject.mapping.MappingTreatment in project onos by opennetworkinglab.
the class MappingValueCodec method encode.
@Override
public ObjectNode encode(MappingValue value, CodecContext context) {
checkNotNull(value, "Mapping value cannot be null");
final ObjectNode result = context.mapper().createObjectNode();
final ArrayNode jsonTreatments = result.putArray(TREATMENTS);
final JsonCodec<MappingTreatment> treatmentCodec = context.codec(MappingTreatment.class);
final JsonCodec<MappingAction> actionCodec = context.codec(MappingAction.class);
for (final MappingTreatment treatment : value.treatments()) {
jsonTreatments.add(treatmentCodec.encode(treatment, context));
}
result.set(ACTION, actionCodec.encode(value.action(), context));
return result;
}
Aggregations