blob: a930d075815f390725fb6f64841f537fa7afdaab [file] [log] [blame]
Thomas Vachuskae0f804a2014-10-27 23:40:48 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2014-present Open Networking Laboratory
Thomas Vachuskae0f804a2014-10-27 23:40:48 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * 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
Thomas Vachuskae0f804a2014-10-27 23:40:48 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * 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.
Thomas Vachuskae0f804a2014-10-27 23:40:48 -070015 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.store.serializers;
Thomas Vachuskae0f804a2014-10-27 23:40:48 -070017
18import com.esotericsoftware.kryo.Kryo;
19import com.esotericsoftware.kryo.Serializer;
20import com.esotericsoftware.kryo.io.Input;
21import com.esotericsoftware.kryo.io.Output;
Brian O'Connorabafb502014-12-02 22:26:20 -080022import org.onosproject.core.DefaultApplicationId;
Thomas Vachuskae0f804a2014-10-27 23:40:48 -070023
24/**
Brian O'Connorabafb502014-12-02 22:26:20 -080025 * Kryo Serializer for {@link org.onosproject.core.DefaultApplicationId}.
Thomas Vachuskae0f804a2014-10-27 23:40:48 -070026 */
27public final class DefaultApplicationIdSerializer extends Serializer<DefaultApplicationId> {
28
29 /**
Brian O'Connorabafb502014-12-02 22:26:20 -080030 * Creates {@link org.onosproject.core.DefaultApplicationId} serializer instance.
Thomas Vachuskae0f804a2014-10-27 23:40:48 -070031 */
32 public DefaultApplicationIdSerializer() {
33 // non-null, immutable
34 super(false, true);
35 }
36
37 @Override
38 public void write(Kryo kryo, Output output, DefaultApplicationId object) {
Yuta HIGUCHId08e2e92016-07-10 00:15:10 -070039 output.writeShort(object.id());
40 output.writeString(object.name());
Thomas Vachuskae0f804a2014-10-27 23:40:48 -070041 }
42
43 @Override
44 public DefaultApplicationId read(Kryo kryo, Input input, Class<DefaultApplicationId> type) {
Yuta HIGUCHId08e2e92016-07-10 00:15:10 -070045 short id = input.readShort();
46 String name = input.readString();
Thomas Vachuskae0f804a2014-10-27 23:40:48 -070047 return new DefaultApplicationId(id, name);
48 }
49}