Exemplo n.º 1
0
        public async Task Write(byte[] value, CancellationToken cancellationToken = default)
        {
            using (var binaryWriter = new AsyncBinaryWriter(this.stream, true))
            {
                await binaryWriter.WriteIntAsync(value.Length, cancellationToken).ConfigureAwait(false);

                await binaryWriter.WriteBytesAsync(value, cancellationToken).ConfigureAwait(false);
            }
        }
Exemplo n.º 2
0
        public async Task Write(int value, CancellationToken cancellationToken = default)
        {
            using (var binaryWriter = new AsyncBinaryWriter(this.stream, true))
            {
                var bytes = BitConverter.GetBytes(value);
                await binaryWriter.WriteIntAsync(bytes.Length, cancellationToken).ConfigureAwait(false);

                await binaryWriter.WriteBytesAsync(bytes, cancellationToken).ConfigureAwait(false);
            }
        }
Exemplo n.º 3
0
        public async Task Write(string value, CancellationToken cancellationToken = default)
        {
            using (var binaryWriter = new AsyncBinaryWriter(this.stream, true))
            {
                var bytes = System.Text.Encoding.UTF8.GetBytes(value);
                await binaryWriter.WriteIntAsync(bytes.Length, cancellationToken).ConfigureAwait(false);

                await binaryWriter.WriteBytesAsync(bytes, cancellationToken).ConfigureAwait(false);
            }
        }
Exemplo n.º 4
0
        public async Task Write <T>(T value, CancellationToken cancellationToken = default)
        {
            using var binaryWriter = new AsyncBinaryWriter(this.stream, true);
            var jsonString = JsonConvert.SerializeObject(value, typeof(T), new JsonSerializerSettings {
                TypeNameHandling = TypeNameHandling.Auto
            });
            var jsonBytes = System.Text.Encoding.UTF8.GetBytes(jsonString);

            await binaryWriter.WriteIntAsync(jsonBytes.Length, cancellationToken).ConfigureAwait(false);

            await binaryWriter.WriteBytesAsync(jsonBytes, cancellationToken).ConfigureAwait(false);
        }