Exemplo n.º 1
0
        internal static async Task SendFramed(NetworkStream stream, byte[] bytes)
        {
            var lengthBytes = SafeBitConverter.GetBytes(bytes.Length);
            await stream.WriteAsync(lengthBytes, 0, 4).ConfigureAwait(false);

            if (bytes.Length > 0)
            {
                await stream.WriteAsync(bytes, 0, bytes.Length).ConfigureAwait(false);
            }
        }
Exemplo n.º 2
0
        public byte[] Serialize(object msg)
        {
            var type        = msg.GetType();
            var ser         = new DataContractSerializer(type);
            var typeName    = TypeId.GetId(type);
            var nameBytes   = Encoding.UTF8.GetBytes(typeName);
            var lengthBytes = SafeBitConverter.GetBytes(nameBytes.Length);

            using (var ms = new MemoryStream())
            {
                ms.Write(lengthBytes, 0, lengthBytes.Length);
                ms.Write(nameBytes, 0, nameBytes.Length);
                ser.WriteObject(ms, msg);
                return(ms.ToArray());
            }
        }
Exemplo n.º 3
0
 public override int GetHashCode() =>
 FNV1a32.Hash(SafeBitConverter.GetBytes(Increments), SafeBitConverter.GetBytes(Decrements));