Files
2018-04-13 10:05:26 -07:00

31 lines
1.0 KiB
C#

// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
namespace DotNetty.Codecs.Redis.Tests
{
using System;
using System.Globalization;
using System.Text;
using DotNetty.Buffers;
static class RedisCodecTestUtil
{
internal static byte[] BytesOf(long value) => Encoding.ASCII.GetBytes(Convert.ToString(value, CultureInfo.InvariantCulture));
internal static byte[] BytesOf(string value) => Encoding.UTF8.GetBytes(value);
internal static byte[] BytesOf(IByteBuffer byteBuffer)
{
var data = new byte[byteBuffer.ReadableBytes];
byteBuffer.ReadBytes(data);
return data;
}
internal static string StringOf(IByteBuffer buf) => Encoding.UTF8.GetString(BytesOf(buf));
internal static IByteBuffer ByteBufOf(string s) => ByteBufOf(BytesOf(s));
internal static IByteBuffer ByteBufOf(byte[] data) => Unpooled.WrappedBuffer(data);
}
}