Jian Li | 4508352 | 2017-03-20 18:46:07 +0900 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Jian Li | 4508352 | 2017-03-20 18:46:07 +0900 | [diff] [blame] | 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 | */ |
Jian Li | 2e818b0 | 2017-04-12 19:28:30 +0900 | [diff] [blame] | 16 | package org.onosproject.mapping.codec; |
Jian Li | 4508352 | 2017-03-20 18:46:07 +0900 | [diff] [blame] | 17 | |
| 18 | import com.fasterxml.jackson.databind.node.ObjectNode; |
| 19 | import org.onosproject.codec.CodecContext; |
| 20 | import org.onosproject.codec.JsonCodec; |
| 21 | import org.onosproject.mapping.addresses.MappingAddress; |
| 22 | import org.slf4j.Logger; |
| 23 | import org.slf4j.LoggerFactory; |
| 24 | |
| 25 | /** |
| 26 | * Mapping address codec. |
| 27 | */ |
| 28 | public final class MappingAddressCodec extends JsonCodec<MappingAddress> { |
| 29 | |
Ray Milkey | 9c9cde4 | 2018-01-12 14:22:06 -0800 | [diff] [blame] | 30 | private static final Logger log = |
Jian Li | 4508352 | 2017-03-20 18:46:07 +0900 | [diff] [blame] | 31 | LoggerFactory.getLogger(MappingAddressCodec.class); |
| 32 | |
Ray Milkey | 9c9cde4 | 2018-01-12 14:22:06 -0800 | [diff] [blame] | 33 | static final String TYPE = "type"; |
| 34 | static final String IPV4 = "ipv4"; |
| 35 | static final String IPV6 = "ipv6"; |
| 36 | static final String MAC = "mac"; |
| 37 | static final String DN = "dn"; |
| 38 | static final String AS = "as"; |
Jian Li | 4508352 | 2017-03-20 18:46:07 +0900 | [diff] [blame] | 39 | |
| 40 | @Override |
| 41 | public ObjectNode encode(MappingAddress address, CodecContext context) { |
| 42 | EncodeMappingAddressCodecHelper encoder = |
| 43 | new EncodeMappingAddressCodecHelper(address, context); |
| 44 | return encoder.encode(); |
| 45 | } |
| 46 | |
| 47 | @Override |
| 48 | public MappingAddress decode(ObjectNode json, CodecContext context) { |
Jian Li | f92a2ea | 2017-04-05 16:06:06 +0900 | [diff] [blame] | 49 | if (json == null || !json.isObject()) { |
| 50 | return null; |
| 51 | } |
| 52 | |
Jian Li | 4508352 | 2017-03-20 18:46:07 +0900 | [diff] [blame] | 53 | DecodeMappingAddressCodecHelper decoder = |
| 54 | new DecodeMappingAddressCodecHelper(json); |
| 55 | return decoder.decode(); |
| 56 | } |
| 57 | } |