I am writing a asio binding. Objects need to be serialized into a buffer (void *),

for example, write utf8 string into buffer,
write int into buffer,
write long into buffer,

Here is my class

class Buffer
{
        private void *ptr;
        private int size;
        private int _cap;

        public this(int cap)
        {
                ptr = malloc(cap);
                this._cap = cap;
        }

        public ~this()
        {
                free(ptr);
        }

        public ubyte[] asArray()
        {
                ubyte[] ret = (cast(ubyte*)ptr)[0..cap];
                return ret;
        }

        public void* getPtr()
        {
                return ptr;
        }

        public int cap()
        {
                return _cap;
        }
}

how can i write a utf8 string into the buffer?

Reply via email to