示例#1
0
void
Encoder::encodeMessage(
  DataDestination & destination,
  template_id_t templateId,
  const Messages::MessageAccessor & accessor)
{
  destination.startMessage(templateId);
  encodeSegment(destination, templateId, accessor);
  destination.endMessage();
}
示例#2
0
void
FieldInstruction::encodeSignedInteger(DataDestination & destination, WorkingBuffer & buffer, int64 value)
{
  if (value >= 0)
  {
    if (value < 0x0000000000000040LL)
    {
      destination.putByte(((value & 0x7F) | 0x80)); // .... .... .... ..7f
    }
    else if (value < 0x0000000000002000LL)
    {
      destination.putByte(((value >> 7)   & 0x7F)); // .... .... .... 3F8.
      destination.putByte(((value & 0x7F) | 0x80)); // .... .... .... ..7f
    }
    else if (value < 0x0000000000100000LL)
示例#3
0
void
Encoder::encodeGroup(
  DataDestination & destination,
  const Codecs::SegmentBodyPtr & group,
  const Messages::MessageAccessor & accessor)
{
  size_t presenceMapBits = group->presenceMapBitCount();
  Codecs::PresenceMap pmap(presenceMapBits);
  pmap.setVerbose(this->verboseOut_);

  // The presence map for the group will go into the current buffer
  // that will be the last thing to appear in that buffer
  DataDestination::BufferHandle pmapBuffer = destination.getBuffer();
  DataDestination::BufferHandle bodyBuffer = pmapBuffer;
  if(presenceMapBits > 0)
  {
    bodyBuffer = destination.startBuffer();
  }
  encodeSegmentBody(destination, pmap, group, accessor);
  // remember the buffer we're presently working on
  bodyBuffer = destination.getBuffer();
  if(presenceMapBits > 0)
  {
    destination.selectBuffer(pmapBuffer);
    static Messages::FieldIdentity pmapIdentity("PMAP", "Group");
    destination.startField(pmapIdentity);
    pmap.encode(destination);
    destination.endField(pmapIdentity);
  }
  // and just continue working in the buffer where we built the group body
  destination.selectBuffer(bodyBuffer);
}
示例#4
0
void
Encoder::encodeSegmentBody(
  DataDestination & destination,
  Codecs::PresenceMap & pmap,
  const Codecs::SegmentBodyCPtr & segment,
  const Messages::MessageAccessor & accessor)
{
  size_t instructionCount = segment->size();
  for( size_t nField = 0; nField < instructionCount; ++nField)
  {
    PROFILE_POINT("encode field");
    Codecs::FieldInstructionCPtr instruction;
    if(segment->getInstruction(nField, instruction))
    {
      destination.startField(*(instruction->getIdentity()));
      instruction->encode(destination, pmap, *this, accessor);
      destination.endField(*(instruction->getIdentity()));
    }
  }
}
示例#5
0
void
FieldInstruction::encodeSignedInteger(DataDestination & destination, WorkingBuffer & buffer, int64 value)
{
  encodeToWorkingBuffer(buffer, value);
  for(const uchar * it = buffer.begin();
    it != buffer.end();
    ++it)
  {
    destination.putByte(*it);
  }
}
void
PresenceMap::encode(DataDestination & destination)
{
  if(bytePosition_ == 0 && bitMask_ == startByteMask)
  {
    return;
  }
  size_t bpos = bytePosition_;
  // if the last byte is unused, don't write it.
  if(bitMask_ == startByteMask)
  {
    bpos -= 1;
  }
  while(bpos > 0 && bits_[bpos] == 0)
  {
    bpos--;
  }
  bits_[bpos] |= stopBit;
  for(size_t pos = 0; pos <= bpos; ++pos)
  {
    destination.putByte(bits_[pos]);
  }
  if(vout_)
  {
    (*vout_) << "pmap["  <<  bpos << "]->" << std::hex;
    for(size_t pos = 0; pos <= bpos; ++pos)
    {
      (*vout_) << ' ' << std::setw(2) << static_cast<unsigned short>(bits_[pos]);
    }
    (*vout_) << " = ";
    for(size_t pos = 0; pos <= bpos; ++pos)
    {
      uchar byte = bits_[pos];
      for(uchar mask = startByteMask; mask != 0; mask >>= 1)
      {
        (*vout_) << ((byte & mask) ? 'T' : 'f');
      }
    }

    (*vout_) << std::dec << std::endl;
  }
}
示例#7
0
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.");
  }
}