Пример #1
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);
  }
}
Пример #2
0
bool
FieldInstruction::checkNullAscii(WorkingBuffer & workingBuffer)
{
  // check for possible zeroPreamble on mandatory string
  if(workingBuffer.size() > 0 && workingBuffer[0] == 0)
  {
    workingBuffer.pop_front();
    // todo: check size == 0 || buffer[0] != 0
    // to detect overlong encoding [ERR R9]
  }
  return workingBuffer.size() == 0;
}
Пример #3
0
bool
FieldInstruction::checkEmptyAscii(WorkingBuffer & workingBuffer)
{
  bool empty = false;
  // check for possible zeroPreamble on mandatory string
  if(workingBuffer.size() > 0 && workingBuffer[0] == 0)
  {
    workingBuffer.pop_front();
    empty = workingBuffer.size() == 0;
    // todo: if !empty check buffer[0] == 0
    // to detect overlong encoding [ERR R9]
  }
  return empty;
}
bool
WorkingBuffer::operator ==(const WorkingBuffer & rhs) const
{
  if(size() != rhs.size())
  {
    return false;
  }
  return 0 == memcmp(buffer_.get(), rhs.buffer_.get(), size());
}
Пример #5
0
void
FieldInstruction::decodeByteVector(
  Codecs::Context & decoder,
  Codecs::DataSource & source,
  const std::string & name,
  WorkingBuffer & buffer,
  size_t length)
{
  buffer.clear(false, length);
  for(size_t pos = 0;
    pos < length;
    ++pos)
  {
    uchar byte = 0;
    if(!source.getByte(byte))
    {
      decoder.reportFatal("[ERR U03]", "End of file: Too few bytes in ByteVector.", name);
    }
    buffer.push(byte);
  }
}
Пример #6
0
bool
FieldInstruction::decodeAscii(
  Codecs::DataSource & source,
  WorkingBuffer & workingBuffer)
{
  workingBuffer.clear(false);
  uchar byte = 0;
  if(!source.getByte(byte))
  {
    return false;
  }
  while((byte & stopBit) == 0)
  {
    workingBuffer.push(byte);
    if(!source.getByte(byte))
    {
      // todo: exception?
      return false;
    }
  }
  workingBuffer.push(byte & dataBits);
  return true;
}
void
WorkingBuffer::append(const WorkingBuffer & rhs)
{
  size_t bytesToAppend = rhs.size();
  if(reverse_)
  {
    if(startPos_ < bytesToAppend)
    {
      grow(size() + bytesToAppend);
    }
    std::memcpy(buffer_.get() + startPos_ - bytesToAppend, rhs.buffer_.get() + rhs.startPos_, bytesToAppend);
    startPos_ -= bytesToAppend;
  }
  else
  {
    if(endPos_ + bytesToAppend > capacity_)
    {
      grow(size() + bytesToAppend);
    }
    std::memcpy(buffer_.get() + endPos_, rhs.buffer_.get() + rhs.startPos_, bytesToAppend);
    endPos_ += bytesToAppend;
  }
}