예제 #1
0
        public long Serialize(string value, DataFile dataFile)
        {
            var fileSlice = dataFile.AllocateValue(value == null ? -1 : value.Length * sizeof(char));

            if (value != null)
            {
                value.AsSpan().CopyTo(MemoryMarshal.Cast <byte, char>(fileSlice.Span));
            }
            return(fileSlice.Offset);
        }
예제 #2
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);
        }