blob: aa94b243a353d0bfb0ff4de49043874c7b9e2ffa [file] [log] [blame]
Ray Milkeyb9a8a182015-01-20 14:15:35 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Ray Milkeyb9a8a182015-01-20 14:15:35 -08003 *
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;
Ray Milkeyb9a8a182015-01-20 14:15:35 -080020import org.onosproject.net.intent.Constraint;
Ray Milkeyb9a8a182015-01-20 14:15:35 -080021
Ray Milkeyb9a8a182015-01-20 14:15:35 -080022import com.fasterxml.jackson.databind.node.ObjectNode;
23
24import static com.google.common.base.Preconditions.checkNotNull;
25
26/**
27 * Constraint JSON codec.
28 */
Ray Milkey540b2ce2015-02-04 17:50:20 -080029public final class ConstraintCodec extends JsonCodec<Constraint> {
Ray Milkeyb9a8a182015-01-20 14:15:35 -080030
Ray Milkeyb82c42b2015-06-30 09:42:20 -070031 protected static final String MISSING_MEMBER_MESSAGE =
32 " member is required in Constraint";
33 protected static final String TYPE = "type";
34 protected static final String TYPES = "types";
35 protected static final String INCLUSIVE = "inclusive";
36 protected static final String KEY = "key";
37 protected static final String THRESHOLD = "threshold";
38 protected static final String BANDWIDTH = "bandwidth";
39 protected static final String LAMBDA = "lambda";
40 protected static final String LATENCY_MILLIS = "latencyMillis";
41 protected static final String OBSTACLES = "obstacles";
42 protected static final String WAYPOINTS = "waypoints";
Ray Milkeyb9a8a182015-01-20 14:15:35 -080043
44 @Override
45 public ObjectNode encode(Constraint constraint, CodecContext context) {
46 checkNotNull(constraint, "Constraint cannot be null");
47
Ray Milkey6d7968e2015-07-06 14:30:02 -070048 final EncodeConstraintCodecHelper encodeCodec =
49 new EncodeConstraintCodecHelper(constraint, context);
Ray Milkeyb9a8a182015-01-20 14:15:35 -080050
Ray Milkeyb82c42b2015-06-30 09:42:20 -070051 return encodeCodec.encode();
52 }
53
54 @Override
55 public Constraint decode(ObjectNode json, CodecContext context) {
56 checkNotNull(json, "JSON cannot be null");
57
Ray Milkey6d7968e2015-07-06 14:30:02 -070058 final DecodeConstraintCodecHelper decodeCodec =
59 new DecodeConstraintCodecHelper(json);
Ray Milkeyb82c42b2015-06-30 09:42:20 -070060
61 return decodeCodec.decode();
Ray Milkeyb9a8a182015-01-20 14:15:35 -080062 }
63}