blob: a94bcba6110a9be68891dd1a6892693a4d62fb1e [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;
22import org.onosproject.net.pi.model.PiHeaderFieldTypeModel;
23import org.onosproject.net.pi.model.PiHeaderModel;
24import org.onosproject.net.pi.model.PiTableMatchFieldModel;
25
26/**
27 * Codec for PiTableMatchFieldModel.
28 */
29public class PiTableMatchFieldModelCodec extends JsonCodec<PiTableMatchFieldModel> {
30 private static final String MATCH_TYPE = "matchType";
31 private static final String HEADER = "header";
32 private static final String FIELD = "field";
33 @Override
34 public ObjectNode encode(PiTableMatchFieldModel tableMatchField, CodecContext context) {
35 ObjectNode result = context.mapper().createObjectNode();
36 result.put(MATCH_TYPE, tableMatchField.matchType().toString());
37 PiHeaderModel header = tableMatchField.field().header();
38 PiHeaderFieldTypeModel field = tableMatchField.field().type();
39 ObjectNode headerData = context.encode(header, PiHeaderModel.class);
40 ObjectNode headerFieldData = context.encode(field, PiHeaderFieldTypeModel.class);
41 result.set(HEADER, headerData);
42 result.set(FIELD, headerFieldData);
43 return result;
44 }
45}