inline const uint8_t*
Block::wire() const
{
  if (!hasWire())
    throw Error("(Block::wire) Underlying wire buffer is empty");

  return &*m_begin;
}
inline Buffer::const_iterator
Block::end() const
{
  if (!hasWire())
    throw Error("Underlying wire buffer is empty");

  return m_end;
}
Example #3
0
const uint8_t*
Block::wire() const
{
  if (!hasWire())
    BOOST_THROW_EXCEPTION(Error("(Block::wire) Underlying wire buffer is empty"));

  return &*m_begin;
}
Example #4
0
Buffer::const_iterator
Block::end() const
{
  if (!hasWire())
    BOOST_THROW_EXCEPTION(Error("Underlying wire buffer is empty"));

  return m_end;
}
Example #5
0
Buffer::const_iterator
Block::begin() const
{
  if (!hasWire())
    throw Error("Underlying wire buffer is empty");

  return m_begin;
}
inline size_t
Block::size() const
{
  if (hasWire() || hasValue()) {
    return m_size;
  }
  else
    throw Error("Block size cannot be determined (undefined block size)");
}
Example #7
0
size_t
Block::size() const
{
  if (hasWire() || hasValue()) {
    return m_size;
  }
  else
    BOOST_THROW_EXCEPTION(Error("Block size cannot be determined (undefined block size)"));
}
Example #8
0
void
Block::encode()
{
  if (hasWire())
    return;

  OBufferStream os;
  Tlv::writeVarNumber(os, type());

  if (hasValue())
    {
      Tlv::writeVarNumber(os, value_size());
      os.write(reinterpret_cast<const char*>(value()), value_size());
    }
  else if (m_subBlocks.size() == 0)
    {
      Tlv::writeVarNumber(os, 0);
    }
  else
    {
      size_t valueSize = 0;
      for (element_const_iterator i = m_subBlocks.begin(); i != m_subBlocks.end(); ++i) {
        valueSize += i->size();
      }

      Tlv::writeVarNumber(os, valueSize);

      for (element_const_iterator i = m_subBlocks.begin(); i != m_subBlocks.end(); ++i) {
        if (i->hasWire())
          os.write(reinterpret_cast<const char*>(i->wire()), i->size());
        else if (i->hasValue()) {
          Tlv::writeVarNumber(os, i->type());
          Tlv::writeVarNumber(os, i->value_size());
          os.write(reinterpret_cast<const char*>(i->value()), i->value_size());
        }
        else
          throw Error("Underlying value buffer is empty");
      }
    }

  // now assign correct block

  m_buffer = os.buf();
  m_begin = m_buffer->begin();
  m_end   = m_buffer->end();
  m_size  = m_end - m_begin;

  m_value_begin = m_buffer->begin();
  m_value_end   = m_buffer->end();

  Tlv::readType(m_value_begin, m_value_end);
  Tlv::readVarNumber(m_value_begin, m_value_end);
}