void PVUnionArray::serialize(ByteBuffer *pbuffer, SerializableControl *pflusher, size_t offset, size_t count) const { const_svector temp(view()); temp.slice(offset, count); ArrayConstPtr array = this->getArray(); if (array->getArraySizeType() != Array::fixed) SerializeHelper::writeSize(temp.size(), pbuffer, pflusher); else if (count != array->getMaximumCapacity()) throw std::length_error("fixed array cannot be partially serialized"); for(size_t i = 0; i<count; i++) { if(pbuffer->getRemaining()<1) pflusher->flushSerializeBuffer(); if(temp[i].get()==NULL) { pbuffer->putByte(0); } else { pbuffer->putByte(1); temp[i]->serialize(pbuffer, pflusher); } } }
DefaultPVArray<T>::DefaultPVArray(ScalarArrayConstPtr const & scalarArray) : PVValueArray<T>(scalarArray), value() { ArrayConstPtr array = this->getArray(); if (array->getArraySizeType() == Array::fixed) { // this->setLength(array->getMaximumCapacity()); this->setCapacityMutable(false); } }
void DefaultPVArray<T>::serialize(ByteBuffer *pbuffer, SerializableControl *pflusher, size_t offset, size_t count) const { //TODO: avoid incrementing the ref counter... const_svector temp(value); temp.slice(offset, count); count = temp.size(); ArrayConstPtr array = this->getArray(); if (array->getArraySizeType() != Array::fixed) SerializeHelper::writeSize(count, pbuffer, pflusher); else if (count != array->getMaximumCapacity()) throw std::length_error("fixed array cannot be partially serialized"); const T* cur = temp.data(); // try to avoid copying into the buffer // this is only possible if we do not need to do endian-swapping if (!pbuffer->reverse<T>()) if (pflusher->directSerialize(pbuffer, (const char*)cur, count, sizeof(T))) return; while(count) { const size_t empty = pbuffer->getRemaining(); const size_t space_for = empty/sizeof(T); if(space_for==0) { pflusher->flushSerializeBuffer(); // Can we be certain that more space is now free??? // If not then we spinnnnnnnnn continue; } const size_t n2send = std::min(count, space_for); pbuffer->putArray(cur, n2send); cur += n2send; count -= n2send; } }