IORegisterClass(IOData, super)


IOData *IOData::init()
{
	if(!super::init())
		return 0;

	_buffer = 0;
	_length = 0;

	return this;
}

IOData *IOData::initWithBytes(uint8_t *bytes, size_t length)
{
	if(!super::init())
		return 0;

	_length = length;
	_buffer = (uint8_t *)kalloc(length);

	if(!_buffer)
	{
		release();
		return 0;
	}

	memcpy(_buffer, bytes, length);
	return this;
}

void IOData::free()
{
	if(_buffer)
		kfree(_buffer);

	super::free();
}


void IOData::appendBytes(uint8_t *bytes, size_t length)
{
	size_t nlength = _length + length;
	uint8_t *nbuffer = (uint8_t *)kalloc(nlength);

	if(nbuffer)
	{
		memcpy(nbuffer, _buffer, _length);
		memcpy(&nbuffer[_length], bytes, length);

		kfree(_buffer);

		_buffer = nbuffer;
		_length = length;
	}
}

uint8_t *IOData::bytes() const
{
	return _buffer;
}

size_t IOData::length() const
{
	return _length;
}
