Exemple #1
0
 typename std::enable_if<!HasFunc_WriteTo<T>::value, void>::type WriteSwitch( ByteBuffer& b, T const& v )
 {
     static_assert( std::is_pod<T>::value, "forget impl WriteTo func ?" );
     b.Reserve( b.dataLen + sizeof( T ) );
     ByteBuffer::WriteCore( b.buf + b.dataLen, v );
     b.dataLen += sizeof( T );
 };
ByteBuffer BytecodeHeader::GetByteBuffer()
{
  ByteBuffer buffer;

  auto bodyOffsetReservation = buffer.Reserve(4);

  // Write string constants
  buffer.WriteU32(constStringTable->constants.size());

  for (auto &key : constStringTable->constants)
    buffer.WriteString(key.val);

  // Write numeric constants
  buffer.WriteU32(constNumberTable->constants.size());

  for (auto &key : constNumberTable->constants)
    buffer.WriteU32(*reinterpret_cast<uint32_t *>(&key.val));

  buffer.WriteU32(buffer.GetLength(), bodyOffsetReservation);

  // Write function names and offsets

  return buffer;
}