예제 #1
0
        public long Serialize(string str, DataFile dataFile)
        {
            var size      = Encoding.UTF8.GetByteCount(str);
            var fileSlice = dataFile.AllocateValue(size);

            fixed(byte *buffer = fileSlice.Span)
            fixed(char *chars = str)
            {
                Encoding.UTF8.GetBytes(chars, str.Length, buffer, size);
            }
            return(fileSlice.Offset);
        }
예제 #2
0
        public long Serialize(string key, string value, DataFile dataFile)
        {
            var item = dataFile.AllocateItem(
                key == null ? -1 : key.Length * sizeof(char),
                value == null ? -1 : value.Length * sizeof(char));

            if (key != null)
            {
                key.AsSpan().CopyTo(MemoryMarshal.Cast <byte, char>(item.KeySpan));
            }
            if (value != null)
            {
                value.AsSpan().CopyTo(MemoryMarshal.Cast <byte, char>(item.ValueSpan));
            }
            return(item.Offset);
        }