Yi Tseng | a87b40c | 2017-09-10 00:59:03 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-present Open Networking Foundation |
| 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 | |
| 17 | package org.onosproject.codec.impl; |
| 18 | |
| 19 | import com.fasterxml.jackson.databind.node.ObjectNode; |
| 20 | import org.onosproject.codec.CodecContext; |
| 21 | import org.onosproject.codec.JsonCodec; |
| 22 | import org.onosproject.net.pi.model.PiHeaderModel; |
| 23 | import org.onosproject.net.pi.model.PiHeaderTypeModel; |
| 24 | |
| 25 | /** |
| 26 | * Codec for PiHeaderModel. |
| 27 | */ |
| 28 | public class PiHeaderModelCodec extends JsonCodec<PiHeaderModel> { |
| 29 | private static final String NAME = "name"; |
| 30 | private static final String TYPE = "type"; |
| 31 | private static final String IS_META = "isMetadata"; |
| 32 | private static final String INDEX = "index"; |
| 33 | |
| 34 | @Override |
| 35 | public ObjectNode encode(PiHeaderModel header, CodecContext context) { |
| 36 | ObjectNode result = context.mapper().createObjectNode(); |
| 37 | ObjectNode headerTypeData = context.encode(header.type(), PiHeaderTypeModel.class); |
| 38 | result.put(NAME, header.name()); |
| 39 | result.set(TYPE, headerTypeData); |
| 40 | result.put(IS_META, header.isMetadata()); |
| 41 | result.put(INDEX, header.index()); |
| 42 | return result; |
| 43 | } |
| 44 | } |