blob: 6d6dad46e81c2d6729af76bcb94ebceeee8f8c47 [file] [log] [blame]
Yi Tsenga87b40c2017-09-10 00:59:03 -07001/*
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
17package org.onosproject.codec.impl;
18
19import com.fasterxml.jackson.databind.node.ObjectNode;
20import org.onosproject.codec.CodecContext;
21import org.onosproject.codec.JsonCodec;
Carmelo Cascone87892e22017-11-13 16:01:29 -080022import org.onosproject.net.pi.model.PiMatchFieldModel;
Yi Tsenga87b40c2017-09-10 00:59:03 -070023
24/**
Carmelo Cascone87892e22017-11-13 16:01:29 -080025 * Codec for PiMatchFieldModel.
Yi Tsenga87b40c2017-09-10 00:59:03 -070026 */
Carmelo Cascone87892e22017-11-13 16:01:29 -080027public class PiMatchFieldModelCodec extends JsonCodec<PiMatchFieldModel> {
28 private static final String MATCH_TYPE = "matchType";
29 private static final String FIELD = "field";
Yi Tsenga87b40c2017-09-10 00:59:03 -070030 @Override
Carmelo Cascone87892e22017-11-13 16:01:29 -080031 public ObjectNode encode(PiMatchFieldModel matchFieldModel, CodecContext context) {
Yi Tsenga87b40c2017-09-10 00:59:03 -070032 ObjectNode result = context.mapper().createObjectNode();
Carmelo Cascone87892e22017-11-13 16:01:29 -080033 result.put(MATCH_TYPE, matchFieldModel.matchType().toString());
34 result.put(FIELD, matchFieldModel.id().toString());
Yi Tsenga87b40c2017-09-10 00:59:03 -070035 return result;
36 }
37}