void TMemoryBuffer::writeSlow(const uint8_t* buf, uint32_t len) {
  ensureCanWrite(len);

  // Copy into the buffer and increment wBase_.
  memcpy(wBase_, buf, len);
  wBase_ += len;
}
void CCByteBuffer::writeCString(const string& value) {
    if(m_writePos + value.length() + 1 > m_bufferSize) {
        if(m_external) {
            CCLOGWARN("external mode: buffer size is not enough to write");
            return;
        }
        ensureCanWrite(value.length() + 1);
    }
    
	memcpy(&m_buffer[m_writePos], value.c_str(), value.length() + 1);
	m_writePos += (value.length() + 1);
}
void CCByteBuffer::writePascalString(const string& value) {
    if(m_writePos + value.length() + sizeof(uint16) > m_bufferSize) {
        if(m_external) {
            CCLOGWARN("external mode: buffer size is not enough to write");
            return;
        }
        ensureCanWrite(value.length() + sizeof(uint16));
    }
	
	write<uint16>(value.length());
	memcpy(&m_buffer[m_writePos], value.c_str(), value.length());
	m_writePos += value.length();
}
void CCByteBuffer::writeLine(const string& value) {
    if(m_writePos + value.length() + 2 * sizeof(char) > m_bufferSize) {
        if(m_external) {
            CCLOGWARN("external mode: buffer size is not enough to write");
            return;
        }
        ensureCanWrite(value.length() + 2 * sizeof(char));
    }
    
	memcpy(&m_buffer[m_writePos], value.c_str(), value.length());
	m_writePos += value.length();
	write<char>('\r');
	write<char>('\n');
}