blob: e605791f1ec3daeab5330983508b033ea58bfd1b [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2014-present Open Networking Laboratory
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07003 *
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 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.store.serializers;
Yuta HIGUCHIad4c2182014-09-29 11:16:23 -070017
Yuta HIGUCHI91768e32014-11-22 05:06:35 -080018import java.io.InputStream;
19import java.io.OutputStream;
Yuta HIGUCHIf6d11702014-09-30 19:18:59 -070020import java.nio.ByteBuffer;
21
Yuta HIGUCHIad4c2182014-09-29 11:16:23 -070022// TODO: To be replaced with SerializationService from IOLoop activity
23/**
24 * Service to serialize Objects into byte array.
25 */
Yuta HIGUCHI971addc2014-10-07 23:23:17 -070026public interface StoreSerializer {
Yuta HIGUCHIad4c2182014-09-29 11:16:23 -070027
28 /**
Yuta HIGUCHI672488d2014-10-07 09:23:43 -070029 * Serializes the specified object into bytes.
Yuta HIGUCHIad4c2182014-09-29 11:16:23 -070030 *
31 * @param obj object to be serialized
32 * @return serialized bytes
33 */
Sho SHIMIZU3310a342015-05-13 12:14:05 -070034 byte[] encode(final Object obj);
Yuta HIGUCHIad4c2182014-09-29 11:16:23 -070035
36 /**
Yuta HIGUCHI672488d2014-10-07 09:23:43 -070037 * Serializes the specified object into bytes.
Yuta HIGUCHIf6d11702014-09-30 19:18:59 -070038 *
39 * @param obj object to be serialized
40 * @param buffer to write serialized bytes
41 */
Sho SHIMIZU3310a342015-05-13 12:14:05 -070042 void encode(final Object obj, ByteBuffer buffer);
Yuta HIGUCHIf6d11702014-09-30 19:18:59 -070043
44 /**
Yuta HIGUCHI91768e32014-11-22 05:06:35 -080045 * Serializes the specified object into bytes.
46 *
47 * @param obj object to be serialized
48 * @param stream to write serialized bytes
49 */
Sho SHIMIZU3310a342015-05-13 12:14:05 -070050 void encode(final Object obj, final OutputStream stream);
Yuta HIGUCHI91768e32014-11-22 05:06:35 -080051
52 /**
Yuta HIGUCHI672488d2014-10-07 09:23:43 -070053 * Deserializes the specified bytes into an object.
Yuta HIGUCHIad4c2182014-09-29 11:16:23 -070054 *
55 * @param bytes bytes to be deserialized
56 * @return deserialized object
Yuta HIGUCHI5c947272014-11-03 21:39:21 -080057 * @param <T> decoded type
Yuta HIGUCHIad4c2182014-09-29 11:16:23 -070058 */
Sho SHIMIZU3310a342015-05-13 12:14:05 -070059 <T> T decode(final byte[] bytes);
Yuta HIGUCHIad4c2182014-09-29 11:16:23 -070060
Yuta HIGUCHIf6d11702014-09-30 19:18:59 -070061 /**
Yuta HIGUCHI672488d2014-10-07 09:23:43 -070062 * Deserializes the specified bytes into an object.
Yuta HIGUCHIf6d11702014-09-30 19:18:59 -070063 *
64 * @param buffer bytes to be deserialized
65 * @return deserialized object
Yuta HIGUCHI5c947272014-11-03 21:39:21 -080066 * @param <T> decoded type
Yuta HIGUCHIf6d11702014-09-30 19:18:59 -070067 */
Sho SHIMIZU3310a342015-05-13 12:14:05 -070068 <T> T decode(final ByteBuffer buffer);
Yuta HIGUCHI91768e32014-11-22 05:06:35 -080069
70 /**
71 * Deserializes the specified bytes into an object.
72 *
73 * @param stream stream containing the bytes to be deserialized
74 * @return deserialized object
75 * @param <T> decoded type
76 */
Sho SHIMIZU3310a342015-05-13 12:14:05 -070077 <T> T decode(final InputStream stream);
Madan Jampanidc012972016-04-25 11:13:26 -070078
79 /**
80 * Returns a copy of the specfied object.
81 *
82 * @param object object to copy
83 * @return a copy of the object
84 * @param <T> object type
85 */
86 <T> T copy(final T object);
Yuta HIGUCHIad4c2182014-09-29 11:16:23 -070087}