blob: 7caf3ba9d9e1d8c207eb8fec653b4f7788167982 [file] [log] [blame]
Jian Li80c12702016-02-20 08:58:19 +09001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Jian Li80c12702016-02-20 08:58:19 +09003 *
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 */
16package org.onosproject.cpman.codec;
17
18import com.fasterxml.jackson.databind.node.ObjectNode;
19import org.onosproject.codec.CodecContext;
20import org.onosproject.codec.JsonCodec;
Jian Li67e1e152016-04-18 17:52:58 -070021import org.onosproject.cpman.ControlLoadSnapshot;
Jian Li80c12702016-02-20 08:58:19 +090022
23/**
Jian Li67e1e152016-04-18 17:52:58 -070024 * Control load snapshot codec.
Jian Li80c12702016-02-20 08:58:19 +090025 */
Jian Li67e1e152016-04-18 17:52:58 -070026public final class ControlLoadSnapshotCodec extends JsonCodec<ControlLoadSnapshot> {
Jian Li80c12702016-02-20 08:58:19 +090027
28 private static final String TIME = "time";
29 private static final String LATEST = "latest";
30 private static final String AVERAGE = "average";
31
32 @Override
Jian Li67e1e152016-04-18 17:52:58 -070033 public ObjectNode encode(ControlLoadSnapshot controlLoadSnapshot, CodecContext context) {
Jian Li80c12702016-02-20 08:58:19 +090034 return context.mapper().createObjectNode()
Jian Li67e1e152016-04-18 17:52:58 -070035 .put(TIME, controlLoadSnapshot.time())
36 .put(LATEST, controlLoadSnapshot.latest())
37 .put(AVERAGE, controlLoadSnapshot.average());
Jian Li80c12702016-02-20 08:58:19 +090038 }
39}