Thomas Vachuska | 58de416 | 2015-09-10 16:15:33 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 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 | */ |
Ayaka Koshibe | 08e457a | 2015-06-25 17:11:54 -0700 | [diff] [blame] | 16 | package org.onosproject.store.serializers; |
| 17 | |
| 18 | import org.onosproject.net.DefaultAnnotations; |
| 19 | |
| 20 | import com.esotericsoftware.kryo.Kryo; |
| 21 | import com.esotericsoftware.kryo.Serializer; |
| 22 | import com.esotericsoftware.kryo.io.Input; |
| 23 | import com.esotericsoftware.kryo.io.Output; |
| 24 | |
| 25 | import java.util.HashMap; |
| 26 | |
| 27 | public class AnnotationsSerializer extends Serializer<DefaultAnnotations> { |
| 28 | |
| 29 | public AnnotationsSerializer() { |
| 30 | super(false, true); |
| 31 | } |
| 32 | |
| 33 | @Override |
| 34 | public void write(Kryo kryo, Output output, DefaultAnnotations object) { |
| 35 | kryo.writeObject(output, object.asMap()); |
| 36 | } |
| 37 | |
| 38 | @Override |
| 39 | public DefaultAnnotations read(Kryo kryo, Input input, Class<DefaultAnnotations> type) { |
| 40 | DefaultAnnotations.Builder b = DefaultAnnotations.builder(); |
| 41 | HashMap<String, String> map = kryo.readObject(input, HashMap.class); |
| 42 | map.forEach((k, v) -> b.set(k, v)); |
| 43 | |
| 44 | return b.build(); |
| 45 | } |
| 46 | |
| 47 | } |