00001 /* 00002 * Copyright (c) 2000, 2020, Oracle and/or its affiliates. 00003 * 00004 * Licensed under the Universal Permissive License v 1.0 as shown at 00005 * http://oss.oracle.com/licenses/upl. 00006 */ 00007 #ifndef COH_CODECS_HPP 00008 #define COH_CODECS_HPP 00009 00010 #include "coherence/lang.ns" 00011 00012 #include "coherence/io/pof/PofReader.hpp" 00013 #include "coherence/io/pof/PofWriter.hpp" 00014 #include "coherence/io/pof/reflect/Codec.hpp" 00015 00016 COH_OPEN_NAMESPACE4(coherence,io,pof,reflect) 00017 00018 using coherence::io::pof::PofReader; 00019 using coherence::io::pof::PofWriter; 00020 00021 /** 00022 * Codecs is a container for accessing default Codec implementations. 00023 * 00024 * @author hr 2011.06.29 00025 * 00026 * @since 3.7.1 00027 */ 00028 class COH_EXPORT Codecs 00029 : public extends<Object> 00030 { 00031 // ----- factory methods ------------------------------------------------ 00032 00033 public: 00034 /** 00035 * Based on the Class::View provided either instantiate if it 00036 * is unknown or use a default codec. 00037 * 00038 * @param vClz the class defining the codec to use or the type the 00039 * codec should handle 00040 * 00041 * @return codec that supports encoding and decoding of objects 00042 * of the specified type 00043 */ 00044 static Codec::View getCodec(Class::View vClz); 00045 00046 // ----- inner class: AbstractCodec ------------------------------------- 00047 00048 public: 00049 /** 00050 * Abstract Codec implementations that encodes objects by simply 00051 * delegating to PofWriter::writeObject. Generally the default 00052 * writeObject implementation does not need to be modified as the 00053 * current accommodation of types and conversion to POF is generally 00054 * accepted, with the deserialization being more likely to be 00055 * specific. 00056 * 00057 * @author hr 2011.06.29 00058 * 00059 * @since 3.7.1 00060 */ 00061 class COH_EXPORT AbstractCodec 00062 : public abstract_spec<AbstractCodec, 00063 extends<Object>, 00064 implements<Codec> > 00065 { 00066 // ----- Codec interface ---------------------------------------- 00067 00068 public: 00069 /** 00070 * {@inheritDoc} 00071 */ 00072 virtual void encode(PofWriter::Handle hOut, int32_t nIndex, Object::View v) const; 00073 }; 00074 00075 // ----- inner class: DefaultCodec -------------------------------------- 00076 00077 public: 00078 /** 00079 * Implementation of Codec that simply delegates to 00080 * PofReader::readObject and PofWriter::writeObject to deserialize and 00081 * serialize an object. 00082 * 00083 * @author hr 2011.06.29 00084 * 00085 * @since 3.7.1 00086 */ 00087 class COH_EXPORT DefaultCodec 00088 : public class_spec<DefaultCodec, 00089 extends<AbstractCodec> > 00090 { 00091 friend class factory<DefaultCodec>; 00092 00093 // ----- Codec interface ---------------------------------------- 00094 00095 public: 00096 /** 00097 * {@inheritDoc} 00098 */ 00099 virtual Object::Holder decode(PofReader::Handle hIn, int32_t nIndex) const; 00100 }; 00101 00102 // ----- constants ------------------------------------------------------ 00103 00104 public: 00105 /** 00106 * Returns a singleton instance of a Codecs::DefaultCodec. 00107 * 00108 * @return Codecs::DefaultCodec 00109 */ 00110 static Codec::View getDefault(); 00111 }; 00112 00113 COH_CLOSE_NAMESPACE4 00114 00115 #endif /* COH_CODECS_HPP */