Apache Qpid - AMQP Messaging for Java JMS, C++, Python, Ruby, and .NET | Apache Qpid Documentation |
00001 #ifndef QPID_FRAMING_BUFFER_H 00002 #define QPID_FRAMING_BUFFER_H 00003 00004 /* 00005 * 00006 * Licensed to the Apache Software Foundation (ASF) under one 00007 * or more contributor license agreements. See the NOTICE file 00008 * distributed with this work for additional information 00009 * regarding copyright ownership. The ASF licenses this file 00010 * to you under the Apache License, Version 2.0 (the 00011 * "License"); you may not use this file except in compliance 00012 * with the License. You may obtain a copy of the License at 00013 * 00014 * http://www.apache.org/licenses/LICENSE-2.0 00015 * 00016 * Unless required by applicable law or agreed to in writing, 00017 * software distributed under the License is distributed on an 00018 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 00019 * KIND, either express or implied. See the License for the 00020 * specific language governing permissions and limitations 00021 * under the License. 00022 * 00023 */ 00024 00025 #include "qpid/Exception.h" 00026 #include "qpid/CommonImportExport.h" 00027 #include "qpid/sys/IntegerTypes.h" 00028 00029 #include <string> 00030 00031 namespace qpid { 00032 namespace framing { 00033 00034 struct QPID_COMMON_CLASS_EXTERN OutOfBounds : qpid::Exception { 00035 OutOfBounds() : qpid::Exception(std::string("Out of Bounds")) {} 00036 }; 00037 00038 class Content; 00039 class FieldTable; 00040 00041 class QPID_COMMON_CLASS_EXTERN Buffer 00042 { 00043 uint32_t size; 00044 char* data; 00045 uint32_t position; 00046 00047 public: 00048 void checkAvailable(uint32_t count) { if (position + count > size) throw OutOfBounds(); } 00049 00050 QPID_COMMON_EXTERN Buffer(char* data=0, uint32_t size=0); 00051 00052 QPID_COMMON_EXTERN void reset(); 00053 00054 QPID_COMMON_INLINE_EXTERN uint32_t available() { return size - position; } 00055 QPID_COMMON_INLINE_EXTERN uint32_t getSize() { return size; } 00056 QPID_COMMON_INLINE_EXTERN uint32_t getPosition() { return position; } 00057 QPID_COMMON_INLINE_EXTERN void setPosition(uint32_t p) { position = p; } 00058 QPID_COMMON_INLINE_EXTERN char* getPointer() { return data; } 00059 00060 QPID_COMMON_EXTERN void putOctet(uint8_t i); 00061 QPID_COMMON_EXTERN void putShort(uint16_t i); 00062 QPID_COMMON_EXTERN void putLong(uint32_t i); 00063 QPID_COMMON_EXTERN void putLongLong(uint64_t i); 00064 QPID_COMMON_EXTERN void putInt8(int8_t i); 00065 QPID_COMMON_EXTERN void putInt16(int16_t i); 00066 QPID_COMMON_EXTERN void putInt32(int32_t i); 00067 QPID_COMMON_EXTERN void putInt64(int64_t i); 00068 QPID_COMMON_EXTERN void putFloat(float f); 00069 QPID_COMMON_EXTERN void putDouble(double f); 00070 QPID_COMMON_EXTERN void putBin128(const uint8_t* b); 00071 00072 QPID_COMMON_EXTERN uint8_t getOctet(); 00073 QPID_COMMON_EXTERN uint16_t getShort(); 00074 QPID_COMMON_EXTERN uint32_t getLong(); 00075 QPID_COMMON_EXTERN uint64_t getLongLong(); 00076 QPID_COMMON_EXTERN int8_t getInt8(); 00077 QPID_COMMON_EXTERN int16_t getInt16(); 00078 QPID_COMMON_EXTERN int32_t getInt32(); 00079 QPID_COMMON_EXTERN int64_t getInt64(); 00080 QPID_COMMON_EXTERN float getFloat(); 00081 QPID_COMMON_EXTERN double getDouble(); 00082 00083 template <int n> 00084 QPID_COMMON_EXTERN uint64_t getUInt(); 00085 00086 template <int n> 00087 QPID_COMMON_EXTERN void putUInt(uint64_t); 00088 00089 QPID_COMMON_EXTERN void putShortString(const std::string& s); 00090 QPID_COMMON_EXTERN void putMediumString(const std::string& s); 00091 QPID_COMMON_EXTERN void putLongString(const std::string& s); 00092 QPID_COMMON_EXTERN void getShortString(std::string& s); 00093 QPID_COMMON_EXTERN void getMediumString(std::string& s); 00094 QPID_COMMON_EXTERN void getLongString(std::string& s); 00095 QPID_COMMON_EXTERN void getBin128(uint8_t* b); 00096 00097 QPID_COMMON_EXTERN void putRawData(const std::string& s); 00098 QPID_COMMON_EXTERN void getRawData(std::string& s, uint32_t size); 00099 00100 QPID_COMMON_EXTERN void putRawData(const uint8_t* data, size_t size); 00101 QPID_COMMON_EXTERN void getRawData(uint8_t* data, size_t size); 00102 00103 template <class T> void put(const T& data) { data.encode(*this); } 00104 template <class T> void get(T& data) { data.decode(*this); } 00105 00106 QPID_COMMON_EXTERN void dump(std::ostream&) const; 00107 }; 00108 00109 std::ostream& operator<<(std::ostream&, const Buffer&); 00110 00111 }} // namespace qpid::framing 00112 00113 00114 #endif