blob: 740c7d68d9c5ed8b589f8a7f5a5793ab9cf60489 [file] [log] [blame]
Pier Ventredb252cc2016-10-21 21:54:26 -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 */
16
17package org.onosproject.driver.extensions.codec;
18
19import com.fasterxml.jackson.databind.node.ObjectNode;
20import org.onosproject.codec.CodecContext;
21import org.onosproject.codec.JsonCodec;
22import org.onosproject.driver.extensions.Ofdpa3SetQosIndex;
23
24import static com.google.common.base.Preconditions.checkNotNull;
25import static org.onlab.util.Tools.nullIsIllegal;
26
27/**
28 * JSON Codec for Ofdpa set qos index class.
29 */
30public class Ofdpa3SetQosIndexCodec extends JsonCodec<Ofdpa3SetQosIndex> {
31
32 private static final String QOS_INDEX = "qosIndex";
33
34 private static final String MISSING_MEMBER_MESSAGE = " member is required in Ofdpa3SetQosIndex";
35 private static final String MISSING_QOS_INDEX_TYPE_MESSAGE = "qosIndex cannot be null";
36
37 @Override
38 public ObjectNode encode(Ofdpa3SetQosIndex qosIndex, CodecContext context) {
39 checkNotNull(qosIndex, MISSING_QOS_INDEX_TYPE_MESSAGE);
40 return context.mapper().createObjectNode()
41 .put(QOS_INDEX, qosIndex.qosIndex());
42 }
43
44 @Override
45 public Ofdpa3SetQosIndex decode(ObjectNode json, CodecContext context) {
46 if (json == null || !json.isObject()) {
47 return null;
48 }
49
50 // parse ofdpa qos index
51 int qosIndex = (int) nullIsIllegal(json.get(QOS_INDEX),
52 QOS_INDEX + MISSING_MEMBER_MESSAGE).asInt();
53 return new Ofdpa3SetQosIndex(qosIndex);
54 }
55}