private void SerializeType(BitWriter bitWriter, string value)
        {
            var bytes = Encoding.UTF8.GetBytes(value);

            bitWriter.WriteBytes(bytes);

            var x = new BitReader(bitWriter.ToArray());
            var y = x.ReadBytes(bytes.Length);
            var z = Encoding.UTF8.GetString(y);

            // null terminator
            bitWriter.WriteByte((byte)0);
        }
        private void SerializeType(BitWriter bitWriter, object value)
        {
            var bytes = value switch
            {
                char c => BitConverter.GetBytes(c),
                double d => BitConverter.GetBytes(d),
                short s => BitConverter.GetBytes(s),
                int i => BitConverter.GetBytes(i),
                long l => BitConverter.GetBytes(l),
                float f => BitConverter.GetBytes(f),
                ushort s => BitConverter.GetBytes(s),
                uint i => BitConverter.GetBytes(i),
                ulong l => BitConverter.GetBytes(l),
                _ => throw new InvalidOperationException($"Type of {value.GetType()} not supported.")
            };

            bitWriter.WriteBytes(bytes);
        }
    }
Ejemplo n.º 3
0
        private void SerializeType(BitWriter bitWriter, Guid value)
        {
            var bytes = value.ToByteArray();

            bitWriter.WriteBytes(bytes);
        }