From 89f5e275773e9063895bb05150336e537d30c87b Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Wed, 9 Feb 2011 19:59:13 -0500 Subject: [PATCH] not everything is boolean Use correct calls to (de)serialize POD types --- pvDataApp/factory/PVDataCreateFactory.cpp | 26 ++++++++-------- pvDataApp/misc/byteBuffer.h | 37 +++++++++++++++++++++++ 2 files changed, 50 insertions(+), 13 deletions(-) diff --git a/pvDataApp/factory/PVDataCreateFactory.cpp b/pvDataApp/factory/PVDataCreateFactory.cpp index 0f93a86..15d648f 100644 --- a/pvDataApp/factory/PVDataCreateFactory.cpp +++ b/pvDataApp/factory/PVDataCreateFactory.cpp @@ -68,7 +68,7 @@ template void BasePVScalar::serialize(ByteBuffer *pbuffer, SerializableControl *pflusher) { pflusher->ensureBuffer(1); - pbuffer->putBoolean(value); + pbuffer->put(value); } template @@ -76,7 +76,7 @@ void BasePVScalar::deserialize(ByteBuffer *pbuffer, DeserializableControl *pflusher) { pflusher->ensureData(1); - value = pbuffer->getBoolean(); + value = pbuffer->get(); } template @@ -181,7 +181,7 @@ template int DefaultPVArray::get(int offset, int len, PVArrayData *data) { int n = len; - int length = PVArray::getLength(); + int length = this->getLength(); if(offset+len > length) { n = length-offset; if(n<0) n = 0; @@ -201,13 +201,13 @@ int DefaultPVArray::put(int offset,int len, } if(from==value) return len; if(len<1) return 0; - int length = PVArray::getLength(); - int capacity = PVArray::getCapacity(); + int length = this->getLength(); + int capacity = this->getCapacity(); if(offset+len > length) { int newlength = offset + len; if(newlength>capacity) { setCapacity(newlength); - newlength = PVArray::getCapacity(); + newlength = this->getCapacity(); len = newlength - offset; if(len<=0) return 0; } @@ -216,7 +216,7 @@ int DefaultPVArray::put(int offset,int len, for(int i=0;isetLength(length); this->postPut(); return len; } @@ -232,7 +232,7 @@ void DefaultPVArray::shareData(pointer shareValue,int capacity,int length) template void DefaultPVArray::serialize(ByteBuffer *pbuffer, SerializableControl *pflusher) { - serialize(pbuffer, pflusher, 0, PVArray::getLength()); + serialize(pbuffer, pflusher, 0, this->getLength()); } template @@ -241,20 +241,20 @@ void DefaultPVArray::deserialize(ByteBuffer *pbuffer, int size = SerializeHelper::readSize(pbuffer, pcontrol); if(size>=0) { // prepare array, if necessary - if(size>PVArray::getCapacity()) PVArray::setCapacity(size); + if(size>this->getCapacity()) this->setCapacity(size); // retrieve value from the buffer int i = 0; while(true) { int maxIndex = std::min(size-i, pbuffer->getRemaining())+i; for(; igetBoolean(); + value[i] = pbuffer->get(); if(iensureData(1); // // TODO is there a better way to ensureData? else break; } // set new length - PVArray::setLength(size); + this->setLength(size); PVField::postPut(); } // TODO null arrays (size == -1) not supported @@ -264,7 +264,7 @@ template void DefaultPVArray::serialize(ByteBuffer *pbuffer, SerializableControl *pflusher, int offset, int count) { // cache - int length = PVArray::getLength(); + int length = this->getLength(); // check bounds if(offset<0) @@ -282,7 +282,7 @@ void DefaultPVArray::serialize(ByteBuffer *pbuffer, while(true) { int maxIndex = std::min(end-i, pbuffer->getRemaining())+i; for(; iputBoolean(value[i]); + pbuffer->put(value[i]); if(iflushSerializeBuffer(); else diff --git a/pvDataApp/misc/byteBuffer.h b/pvDataApp/misc/byteBuffer.h index 0723fb4..9a1ddf4 100644 --- a/pvDataApp/misc/byteBuffer.h +++ b/pvDataApp/misc/byteBuffer.h @@ -67,6 +67,8 @@ namespace epics { */ ByteBuffer* rewind(); + template inline T get(); + /** * Relative boolean read, {@code position} is incremented by * {@code 1}. @@ -221,6 +223,7 @@ namespace epics { //virtual String getString() = 0; // TODO + template inline void put(T); /** * Relative bulk @em put method. It transfers {@code count} bytes @@ -502,6 +505,40 @@ namespace epics { }; + template + inline T ByteBuffer::get(){} // not valid + template<> + inline bool ByteBuffer::get(){return getBoolean();} + template<> + inline int8 ByteBuffer::get(){return getByte();} + template<> + inline int16 ByteBuffer::get(){return getShort();} + template<> + inline int32 ByteBuffer::get(){return getInt();} + template<> + inline int64 ByteBuffer::get(){return getLong();} + template<> + inline float ByteBuffer::get(){return getFloat();} + template<> + inline double ByteBuffer::get(){return getDouble();} + + template + inline void ByteBuffer::put(T){} // not valid + template<> + inline void ByteBuffer::put(bool v){putBoolean(v);} + template<> + inline void ByteBuffer::put(int8 v){putByte(v);} + template<> + inline void ByteBuffer::put(int16 v){putShort(v);} + template<> + inline void ByteBuffer::put(int32 v){putInt(v);} + template<> + inline void ByteBuffer::put(int64 v){putLong(v);} + template<> + inline void ByteBuffer::put(float v){putFloat(v);} + template<> + inline void ByteBuffer::put(double v){putDouble(v);} + } } #endif /* BYTEBUFFER_H */