mirror of
https://github.com/Azure/DotNetty.git
synced 2026-10-19 06:31:20 +08:00
4f28a55b48
Motivation .NET Core tooling allows building for both .NET Framework and .NET Standard while easing pains of running tests and packaging. Modifications - csproj -> xproj + project.json - support for .NET Standard 1.3 - build script is now based on CAKE - using dotnet CLI for building, testing, packing - strong name by default (snk included) Result DotNetty works on .NET Core and any other platform supporting .NET Standard 1.3+.
28 lines
1.0 KiB
C#
28 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 Factorial
|
|
{
|
|
using System.Collections.Generic;
|
|
using System.Numerics;
|
|
using DotNetty.Buffers;
|
|
using DotNetty.Codecs;
|
|
using DotNetty.Transport.Channels;
|
|
|
|
public class NumberEncoder : MessageToMessageEncoder<System.Numerics.BigInteger>
|
|
{
|
|
protected override void Encode(IChannelHandlerContext context, System.Numerics.BigInteger message, List<object> output)
|
|
{
|
|
IByteBuffer buffer = context.Allocator.Buffer();
|
|
|
|
//https://msdn.microsoft.com/en-us/library/system.numerics.biginteger.tobytearray(v=vs.110).aspx
|
|
//BigInteger.ToByteArray() return a Little-Endian bytes
|
|
//IByteBuffer is Big-Endian by default
|
|
byte[] data = message.ToByteArray();
|
|
buffer.WriteByte((byte)'F');
|
|
buffer.WriteInt(data.Length);
|
|
buffer.WriteBytes(data);
|
|
output.Add(buffer);
|
|
}
|
|
}
|
|
} |