blob: 5ffc1c553da4bf48493c41aa491fc148f5f666ca [file] [log] [blame]
Yuta HIGUCHI776f0742016-11-03 15:51:14 -07001/*
2 * Copyright 2016-present Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.codec.impl;
17
18import org.onosproject.codec.CodecContext;
19import org.onosproject.codec.JsonCodec;
20import org.onosproject.net.ConnectPoint;
21import org.onosproject.net.FilteredConnectPoint;
22import org.onosproject.net.flow.TrafficSelector;
23
24import com.fasterxml.jackson.databind.node.ObjectNode;
25
26/**
27 * JSON Codec for {@link FilteredConnectPoint}.
28 */
29public class FilteredConnectPointCodec extends JsonCodec<FilteredConnectPoint> {
30
31 private static final String CONNECT_POINT = "connectPoint";
32 private static final String TRAFFIC_SELECTOR = "trafficSelector";
33
34
35 @Override
36 public ObjectNode encode(FilteredConnectPoint entity,
37 CodecContext context) {
38 ObjectNode node = context.mapper().createObjectNode();
39 node.set(CONNECT_POINT, context.encode(entity.connectPoint(), ConnectPoint.class));
40 node.set(TRAFFIC_SELECTOR, context.encode(entity.trafficSelector(), TrafficSelector.class));
41 return node;
42 }
43
44 @Override
45 public FilteredConnectPoint decode(ObjectNode json, CodecContext context) {
46 ConnectPoint cp = context.decode(json.get(CONNECT_POINT), ConnectPoint.class);
47 TrafficSelector ts = context.decode(json.get(TRAFFIC_SELECTOR), TrafficSelector.class);
48 return new FilteredConnectPoint(cp, ts);
49 }
50}