Google APIs Client Library for C++
|
00001 /* 00002 * \copyright Copyright 2013 Google Inc. All Rights Reserved. 00003 * \license @{ 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 * 00017 * @} 00018 */ 00019 00020 00021 #ifndef APISERVING_CLIENTS_CPP_DATA_BASE64_CODEC_H_ 00022 #define APISERVING_CLIENTS_CPP_DATA_BASE64_CODEC_H_ 00023 00024 #include <string> 00025 using std::string; 00026 #include "googleapis/client/data/codec.h" 00027 #include <glog/logging.h> 00028 #include "googleapis/base/macros.h" 00029 #include "googleapis/strings/stringpiece.h" 00030 #include "googleapis/util/status.h" 00031 namespace googleapis { 00032 00033 namespace client { 00034 00035 /* 00036 * Provdes a codec for encoding and decoding reader streams using Base64. 00037 * @ingroup DataLayerCodec 00038 * 00039 * Base64 is specified in http://tools.ietf.org/html/rfc4648 00040 * 00041 * @see Base64CodecFactory 00042 */ 00043 class Base64Codec : public Codec { 00044 public: 00045 /* 00046 * Standard constructor. 00047 * 00048 * param[in] chunk_size The desired chunk size to use when 00049 * encoding / decoding streams might be adjusted 00050 * slightly internally for comaptability with base-64. 00051 * param[in] websafe If true then use the websafe base64 encoding. 00052 */ 00053 Base64Codec(int chunk_size, bool websafe); 00054 00055 /* 00056 * Standard destructor. 00057 */ 00058 virtual ~Base64Codec(); 00059 00060 /* 00061 * Returns a reader that will encode another reader using this codec. 00062 * 00063 * @param[in] reader The caller maintain ownership. 00064 * @param[in] deleter The managed deleter may be used to delete the 00065 * reader. NULL indicates an unmanaged reader. 00066 * @param[out] status Will indicate ok or reason for failure. 00067 * 00068 * @return The reader will be an InvalidDataReader on failure, not NULL. 00069 */ 00070 virtual DataReader* NewManagedEncodingReader( 00071 DataReader* reader, Closure* deleter, util::Status* status); 00072 00073 /* 00074 * Returns a reader that will decode another reader using this codec. 00075 * 00076 * @param[in] reader The caller maintain ownership. 00077 * @param[in] deleter The managed deleter may be used to delete the 00078 * reader. NULL indicates an unmanaged reader. 00079 * @param[out] status Will indicate ok or reason for failure. 00080 * 00081 * @return The reader will be an InvalidDataReader on failure, not NULL. 00082 */ 00083 virtual DataReader* NewManagedDecodingReader( 00084 DataReader* reader, Closure* deleter, util::Status* status); 00085 00086 private: 00087 int chunk_size_; 00088 bool websafe_; 00089 00090 DISALLOW_COPY_AND_ASSIGN(Base64Codec); 00091 }; 00092 00093 /* 00094 * CodecFactory for creating and configuring Base64Codecs. 00095 * @ingroup DataLayerCodec 00096 */ 00097 class Base64CodecFactory : public CodecFactory { 00098 public: 00099 /* 00100 * Standard constructor. 00101 * 00102 * This will construct standard (non-websafe) base64 encodings by default. 00103 */ 00104 Base64CodecFactory(); 00105 00106 /* 00107 * Sets the desired chunk size for codecs. 00108 * 00109 * @param[in] size The desired size used to configure new Codec instances. 00110 */ 00111 void set_chunk_size(int size) { chunk_size_ = size; } 00112 00113 /* 00114 * Returns the desired chunk size. 00115 */ 00116 int chunk_size() const { return chunk_size_; } 00117 00118 /* 00119 * Whether to construct encoders with the websafe encoding. 00120 */ 00121 void set_websafe(bool websafe) { websafe_ = websafe; } 00122 00123 /* 00124 * Returns whether to construct encoders with the websafe encoding. 00125 */ 00126 bool websafe() const { return websafe_; } 00127 00128 /* 00129 * Standard destructor. 00130 */ 00131 ~Base64CodecFactory(); 00132 00133 /* 00134 * Constructs and configures a new codec instance. 00135 * 00136 * @param[out] status ok or reason for failure. 00137 * @return NULL on failure. 00138 */ 00139 virtual Codec* New(util::Status* status); 00140 00141 00142 private: 00143 int chunk_size_; 00144 bool websafe_; 00145 00146 DISALLOW_COPY_AND_ASSIGN(Base64CodecFactory); 00147 }; 00148 00149 } // namespace client 00150 00151 } // namespace googleapis 00152 #endif // APISERVING_CLIENTS_CPP_DATA_BASE64_CODEC_H_