Thomas Vachuska | e0f804a | 2014-10-27 23:40:48 -0700 | [diff] [blame] | 1 | /* |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 2 | * Copyright 2014 Open Networking Laboratory |
Thomas Vachuska | e0f804a | 2014-10-27 23:40:48 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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 |
Thomas Vachuska | e0f804a | 2014-10-27 23:40:48 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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. |
Thomas Vachuska | e0f804a | 2014-10-27 23:40:48 -0700 | [diff] [blame] | 15 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.store.serializers; |
Thomas Vachuska | e0f804a | 2014-10-27 23:40:48 -0700 | [diff] [blame] | 17 | |
| 18 | import com.esotericsoftware.kryo.Kryo; |
| 19 | import com.esotericsoftware.kryo.Serializer; |
| 20 | import com.esotericsoftware.kryo.io.Input; |
| 21 | import com.esotericsoftware.kryo.io.Output; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 22 | import org.onosproject.core.DefaultApplicationId; |
Thomas Vachuska | e0f804a | 2014-10-27 23:40:48 -0700 | [diff] [blame] | 23 | |
| 24 | /** |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 25 | * Kryo Serializer for {@link org.onosproject.core.DefaultApplicationId}. |
Thomas Vachuska | e0f804a | 2014-10-27 23:40:48 -0700 | [diff] [blame] | 26 | */ |
| 27 | public final class DefaultApplicationIdSerializer extends Serializer<DefaultApplicationId> { |
| 28 | |
| 29 | /** |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 30 | * Creates {@link org.onosproject.core.DefaultApplicationId} serializer instance. |
Thomas Vachuska | e0f804a | 2014-10-27 23:40:48 -0700 | [diff] [blame] | 31 | */ |
| 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) { |
| 39 | kryo.writeObject(output, object.id()); |
| 40 | kryo.writeObject(output, object.name()); |
| 41 | } |
| 42 | |
| 43 | @Override |
| 44 | public DefaultApplicationId read(Kryo kryo, Input input, Class<DefaultApplicationId> type) { |
| 45 | short id = kryo.readObject(input, Short.class); |
| 46 | String name = kryo.readObject(input, String.class); |
| 47 | return new DefaultApplicationId(id, name); |
| 48 | } |
| 49 | } |