Ray Milkey | b9a8a18 | 2015-01-20 14:15:35 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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 | package org.onosproject.codec.impl; |
| 17 | |
| 18 | import org.onosproject.codec.CodecContext; |
| 19 | import org.onosproject.codec.JsonCodec; |
Ray Milkey | b9a8a18 | 2015-01-20 14:15:35 -0800 | [diff] [blame] | 20 | import org.onosproject.net.intent.Constraint; |
Ray Milkey | b9a8a18 | 2015-01-20 14:15:35 -0800 | [diff] [blame] | 21 | |
Ray Milkey | b9a8a18 | 2015-01-20 14:15:35 -0800 | [diff] [blame] | 22 | import com.fasterxml.jackson.databind.node.ObjectNode; |
| 23 | |
| 24 | import static com.google.common.base.Preconditions.checkNotNull; |
| 25 | |
| 26 | /** |
| 27 | * Constraint JSON codec. |
| 28 | */ |
Ray Milkey | 540b2ce | 2015-02-04 17:50:20 -0800 | [diff] [blame] | 29 | public final class ConstraintCodec extends JsonCodec<Constraint> { |
Ray Milkey | b9a8a18 | 2015-01-20 14:15:35 -0800 | [diff] [blame] | 30 | |
Ray Milkey | b82c42b | 2015-06-30 09:42:20 -0700 | [diff] [blame] | 31 | 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 Milkey | b9a8a18 | 2015-01-20 14:15:35 -0800 | [diff] [blame] | 43 | |
| 44 | @Override |
| 45 | public ObjectNode encode(Constraint constraint, CodecContext context) { |
| 46 | checkNotNull(constraint, "Constraint cannot be null"); |
| 47 | |
Ray Milkey | 6d7968e | 2015-07-06 14:30:02 -0700 | [diff] [blame] | 48 | final EncodeConstraintCodecHelper encodeCodec = |
| 49 | new EncodeConstraintCodecHelper(constraint, context); |
Ray Milkey | b9a8a18 | 2015-01-20 14:15:35 -0800 | [diff] [blame] | 50 | |
Ray Milkey | b82c42b | 2015-06-30 09:42:20 -0700 | [diff] [blame] | 51 | return encodeCodec.encode(); |
| 52 | } |
| 53 | |
| 54 | @Override |
| 55 | public Constraint decode(ObjectNode json, CodecContext context) { |
| 56 | checkNotNull(json, "JSON cannot be null"); |
| 57 | |
Ray Milkey | 6d7968e | 2015-07-06 14:30:02 -0700 | [diff] [blame] | 58 | final DecodeConstraintCodecHelper decodeCodec = |
| 59 | new DecodeConstraintCodecHelper(json); |
Ray Milkey | b82c42b | 2015-06-30 09:42:20 -0700 | [diff] [blame] | 60 | |
| 61 | return decodeCodec.decode(); |
Ray Milkey | b9a8a18 | 2015-01-20 14:15:35 -0800 | [diff] [blame] | 62 | } |
| 63 | } |