static bool checkBitSetPVField( PVFieldPtr const &pvField,BitSetPtr const &bitSet,int32 initialOffset) { int32 offset = initialOffset; int32 nbits = static_cast<int32>(pvField->getNumberFields()); if(nbits==1) return bitSet->get(offset); int32 nextSetBit = bitSet->nextSetBit(offset); if(nextSetBit>=(offset+nbits)) return false; if(nextSetBit<0) return false; if(bitSet->get(offset)) { if(nbits>1) { for(int32 i=offset+1; i<offset+nbits; i++) bitSet->clear(i); } return true; } bool atLeastOneBitSet = false; bool allBitsSet = true; PVStructurePtr pvStructure = static_pointer_cast<PVStructure>(pvField); offset = static_cast<int32>(pvStructure->getFieldOffset()) + 1; while(offset<initialOffset + nbits) { PVFieldPtr pvSubField = pvStructure->getSubField(offset); int32 nbitsNow = static_cast<int32>(pvSubField->getNumberFields()); if(nbitsNow==1) { if(bitSet->get(offset)) { atLeastOneBitSet = true; } else { allBitsSet = false; } offset++; } else { bool result = checkBitSetPVField(pvSubField,bitSet,offset); if(result) { atLeastOneBitSet = true; if(!bitSet->get(offset)) { allBitsSet = false; } } else { allBitsSet = false; } offset += static_cast<int32>(pvSubField->getNumberFields()); } } if(allBitsSet) { if(nbits>1) { for(int32 i=initialOffset+1; i<initialOffset+nbits; i++) { bitSet->clear(i); } } bitSet->set(initialOffset); } return atLeastOneBitSet; }
void PVStructure::deserialize(ByteBuffer *pbuffer, DeserializableControl *pcontrol, BitSet *pbitSet) { size_t offset = getFieldOffset(); size_t numberFields = getNumberFields(); int32 next = pbitSet->nextSetBit(offset); // no more changes or no changes in this structure if(next<0||next>=static_cast<int32>(offset+numberFields)) return; // entire structure if(static_cast<int32>(offset)==next) { deserialize(pbuffer, pcontrol); return; } size_t fieldsSize = pvFields.size(); for(size_t i = 0; i<fieldsSize; i++) { PVFieldPtr pvField = pvFields[i]; offset = pvField->getFieldOffset(); int32 inumberFields = pvField->getNumberFields(); next = pbitSet->nextSetBit(offset); // no more changes if(next<0) return; // no change in this pvField if(next>=static_cast<int32>(offset+inumberFields)) continue; // deserialize field or fields if(inumberFields==1) { pvField->deserialize(pbuffer, pcontrol); } else { PVStructurePtr pvStructure = std::tr1::static_pointer_cast<PVStructure>(pvField); pvStructure->deserialize(pbuffer, pcontrol, pbitSet); } } }