Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 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 | */ |
Yuta HIGUCHI | ad4c218 | 2014-09-29 11:16:23 -0700 | [diff] [blame] | 16 | package org.onlab.onos.store.serializers; |
| 17 | |
Yuta HIGUCHI | f6d1170 | 2014-09-30 19:18:59 -0700 | [diff] [blame] | 18 | import java.nio.ByteBuffer; |
| 19 | |
Yuta HIGUCHI | ad4c218 | 2014-09-29 11:16:23 -0700 | [diff] [blame] | 20 | // TODO: To be replaced with SerializationService from IOLoop activity |
| 21 | /** |
| 22 | * Service to serialize Objects into byte array. |
| 23 | */ |
Yuta HIGUCHI | 971addc | 2014-10-07 23:23:17 -0700 | [diff] [blame] | 24 | public interface StoreSerializer { |
Yuta HIGUCHI | ad4c218 | 2014-09-29 11:16:23 -0700 | [diff] [blame] | 25 | |
| 26 | /** |
Yuta HIGUCHI | 672488d | 2014-10-07 09:23:43 -0700 | [diff] [blame] | 27 | * Serializes the specified object into bytes. |
Yuta HIGUCHI | ad4c218 | 2014-09-29 11:16:23 -0700 | [diff] [blame] | 28 | * |
| 29 | * @param obj object to be serialized |
| 30 | * @return serialized bytes |
| 31 | */ |
Yuta HIGUCHI | 53a285d | 2014-10-06 23:58:01 -0700 | [diff] [blame] | 32 | public byte[] encode(final Object obj); |
Yuta HIGUCHI | ad4c218 | 2014-09-29 11:16:23 -0700 | [diff] [blame] | 33 | |
| 34 | /** |
Yuta HIGUCHI | 672488d | 2014-10-07 09:23:43 -0700 | [diff] [blame] | 35 | * Serializes the specified object into bytes. |
Yuta HIGUCHI | f6d1170 | 2014-09-30 19:18:59 -0700 | [diff] [blame] | 36 | * |
| 37 | * @param obj object to be serialized |
| 38 | * @param buffer to write serialized bytes |
| 39 | */ |
Yuta HIGUCHI | 53a285d | 2014-10-06 23:58:01 -0700 | [diff] [blame] | 40 | public void encode(final Object obj, ByteBuffer buffer); |
Yuta HIGUCHI | f6d1170 | 2014-09-30 19:18:59 -0700 | [diff] [blame] | 41 | |
| 42 | /** |
Yuta HIGUCHI | 672488d | 2014-10-07 09:23:43 -0700 | [diff] [blame] | 43 | * Deserializes the specified bytes into an object. |
Yuta HIGUCHI | ad4c218 | 2014-09-29 11:16:23 -0700 | [diff] [blame] | 44 | * |
| 45 | * @param bytes bytes to be deserialized |
| 46 | * @return deserialized object |
| 47 | */ |
Yuta HIGUCHI | 53a285d | 2014-10-06 23:58:01 -0700 | [diff] [blame] | 48 | public <T> T decode(final byte[] bytes); |
Yuta HIGUCHI | ad4c218 | 2014-09-29 11:16:23 -0700 | [diff] [blame] | 49 | |
Yuta HIGUCHI | f6d1170 | 2014-09-30 19:18:59 -0700 | [diff] [blame] | 50 | /** |
Yuta HIGUCHI | 672488d | 2014-10-07 09:23:43 -0700 | [diff] [blame] | 51 | * Deserializes the specified bytes into an object. |
Yuta HIGUCHI | f6d1170 | 2014-09-30 19:18:59 -0700 | [diff] [blame] | 52 | * |
| 53 | * @param buffer bytes to be deserialized |
| 54 | * @return deserialized object |
| 55 | */ |
Yuta HIGUCHI | 53a285d | 2014-10-06 23:58:01 -0700 | [diff] [blame] | 56 | public <T> T decode(final ByteBuffer buffer); |
Yuta HIGUCHI | ad4c218 | 2014-09-29 11:16:23 -0700 | [diff] [blame] | 57 | } |