void Encoder::encodeSegment( DataDestination & destination, template_id_t templateId, const Messages::MessageAccessor & accessor) { Codecs::TemplateCPtr templatePtr; if(getTemplateRegistry()->getTemplate(templateId, templatePtr)) { if(templatePtr->getReset()) { reset(true); } Codecs::PresenceMap pmap(templatePtr->presenceMapBitCount()); DataDestination::BufferHandle header = destination.startBuffer(); destination.startBuffer(); // can we "copy" the template ID? if(templateId == templateId_) { pmap.setNextField(false); } else { pmap.setNextField(true); FieldInstruction::encodeUnsignedInteger(destination, getWorkingBuffer(), templateId); templateId_ = templateId; } encodeSegmentBody(destination, pmap, templatePtr, accessor); DataDestination::BufferHandle savedBuffer = destination.getBuffer(); destination.selectBuffer(header); static Messages::FieldIdentity pmapIdentity("PMAP", "Message"); destination.startField(pmapIdentity); pmap.encode(destination); destination.endField(pmapIdentity); destination.selectBuffer(savedBuffer); } else { throw EncodingError("[ERR D9] Unknown template ID."); } }