Serializer.java 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Copyright 2010-2011 the original author or authors.
  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. */
  16. package com.sdyc.ndmp.protobuf.serializer;
  17. import java.io.Serializable;
  18. /**
  19. * Basic interface serialization and deserialization of Objects to byte arrays (binary data).
  20. * <p/>
  21. * It is recommended that implementations are designed to handle null objects/empty arrays on serialization and deserialization side.
  22. * Note that Redis does not accept null keys or values but can return null replies (for non existing keys).
  23. *
  24. * @author ZhenQin
  25. */
  26. public interface Serializer<T> extends Serializable {
  27. /**
  28. * Serialize the given object to binary data.
  29. *
  30. * @param t object to serialize
  31. * @return the equivalent binary data
  32. */
  33. byte[] serialize(T t);
  34. /**
  35. * Deserialize an object from the given binary data.
  36. *
  37. * @param bytes object binary representation
  38. * @return the equivalent object instance
  39. */
  40. T deserialize(byte[] bytes);
  41. }