public static async Task RunServerAsync(int port, EncoderFactory encryptor, DecoderFactory decryptor, bool isWorldClient) { MultithreadEventLoopGroup bossGroup = new MultithreadEventLoopGroup(1); MultithreadEventLoopGroup workerGroup = new MultithreadEventLoopGroup(); try { ServerBootstrap bootstrap = new ServerBootstrap(); bootstrap .Group(bossGroup, workerGroup) .Channel <TcpServerSocketChannel>() .ChildHandler(new ActionChannelInitializer <ISocketChannel>(channel => { SessionFactory.Instance.Sessions[channel.Id.AsLongText()] = 0; IChannelPipeline pipeline = channel.Pipeline; pipeline.AddLast((MessageToMessageDecoder <IByteBuffer>)decryptor.GetDecoder()); pipeline.AddLast(new ClientSession(channel, isWorldClient)); pipeline.AddLast((MessageToMessageEncoder <string>)encryptor.GetEncoder()); })); IChannel bootstrapChannel = await bootstrap.BindAsync(port).ConfigureAwait(false); Console.ReadLine(); await bootstrapChannel.CloseAsync().ConfigureAwait(false); } catch (Exception ex) { Logger.Log.Error(ex.Message); } finally { Task.WaitAll(bossGroup.ShutdownGracefullyAsync(), workerGroup.ShutdownGracefullyAsync()); } }
public void FunctionDataDecode_MixedParamTypes() { var encoded = "0x00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000100ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd4920000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000006300000000000000000000000000000000000000000000000000000000000000090000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffffff00000000000000000000000000000000000000000000000000000000000000096d7920737472696e670000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000098e4625b2d7424c403b46366150ab28df406340800000000000000000000000040515114eea1497d753659dff85910f838c6b234000000000000000000000000df0270a6bff43e7a3fd92372dfb549292d683d22"; var ethFunc = EthFunc.Create <bool, string, long, Address[], byte, ulong[]>( null, null, "bool", DecoderFactory.Decode, "string", DecoderFactory.Decode, "int56", DecoderFactory.Decode, "address[]", DecoderFactory.GetArrayDecoder(EncoderFactory.LoadEncoder("address", default(Address))), "uint8", DecoderFactory.Decode, "uint64[3]", DecoderFactory.GetArrayDecoder(EncoderFactory.LoadEncoder("uint64", default(ulong)))); var p1 = true; var p2 = "my string"; var p3 = (long)-11118; var p4 = new Address[] { "0x98E4625b2d7424C403B46366150AB28Df4063408", "0x40515114eEa1497D753659DFF85910F838c6B234", "0xDf0270A6BFf43e7A3Fd92372DfB549292D683D22" }; var p5 = (byte)99; var p6 = new ulong[] { 9, 0, ulong.MaxValue }; var(r1, r2, r3, r4, r5, r6) = ethFunc.ParseReturnData(encoded.HexToBytes()); Assert.Equal(p1, r1); Assert.Equal(p2, r2); Assert.Equal(p3, r3); Assert.Equal(p4, r4); Assert.Equal(p5, r5); Assert.Equal(p6, r6); }
public void Int24_2() { var encodedNum = "0000000000000000000000000000000000000000000000000000000000fed260"; var buff = new AbiDecodeBuffer(encodedNum, "int24"); DecoderFactory.Decode("int24", ref buff, out int result); Assert.Equal(0, buff.HeadCursor.Length); Assert.Equal(-77216, result); }
public void StringUnicode() { var encodedStr = "00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000028757466383b20342062797465733a20f0a0beb43b20332062797465733a20e28fb020776f726b7321000000000000000000000000000000000000000000000000"; var buff = new AbiDecodeBuffer(encodedStr, "string"); DecoderFactory.Decode("string", ref buff, out string result); Assert.Equal(0, buff.HeadCursor.Length); Assert.Equal("utf8; 4 bytes: 𠾴; 3 bytes: ⏰ works!", result); }
public void String() { var encodedStr = "0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000d48656c6c6f2c20776f726c642100000000000000000000000000000000000000"; var buff = new AbiDecodeBuffer(encodedStr, "bool"); DecoderFactory.Decode("string", ref buff, out string result); Assert.Equal(0, buff.HeadCursor.Length); Assert.Equal("Hello, world!", result); }
public void Address() { var encodedAddr = "00000000000000000000000011f4d0a3c12e86b4b5f39b213f7e19d048276dae"; var buff = new AbiDecodeBuffer(encodedAddr, "address"); DecoderFactory.Decode("address", ref buff, out Address address); Assert.Equal(0, buff.HeadCursor.Length); Assert.Equal("0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe".ToLowerInvariant(), address.ToString()); }
public void Boolean_False() { var encodedFalse = "0000000000000000000000000000000000000000000000000000000000000000"; var buff = new AbiDecodeBuffer(encodedFalse, "bool"); DecoderFactory.Decode("bool", ref buff, out bool decodedFalse); Assert.Equal(0, buff.HeadCursor.Length); Assert.False(decodedFalse); }
public void UInt8FixedArray() { var encodedArr = "00000000000000000000000000000000000000000000000000000000000000070000000000000000000000000000000000000000000000000000000000000026000000000000000000000000000000000000000000000000000000000000009600000000000000000000000000000000000000000000000000000000000000e70000000000000000000000000000000000000000000000000000000000000046"; var buff = new AbiDecodeBuffer(encodedArr, "uint8[5]"); DecoderFactory.Decode("uint8[5]", ref buff, out byte[] result, EncoderFactory.LoadEncoder("uint8", default(byte))); Assert.Equal(0, buff.HeadCursor.Length); byte[] expected = HexUtil.HexToBytes("072696e746"); Assert.Equal(expected, result); }
private PowerPcDisassembler.Decoder[] EnsureDecoders() { if (this.primaryDecoders == null) { this.Options.TryGetValue("Model", out var model); var factory = new DecoderFactory((string)model); this.primaryDecoders = factory.CreateDecoders(); } return(this.primaryDecoders); }
public void Int64FixedArray() { var encodedArr = "000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000011c20000000000000000000000000000000000000000000000007fffffffffffffff00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007fffffffffffffff"; var buff = new AbiDecodeBuffer(encodedArr, "int64[5]"); DecoderFactory.Decode("int64[5]", ref buff, out long[] result, EncoderFactory.LoadEncoder("int64", default(long))); Assert.Equal(0, buff.HeadCursor.Length); long[] expected = new long[] { 1, 4546, long.MaxValue, 0, long.MaxValue }; Assert.Equal(expected, result); }
public void Bytes() { var encodedBytes = "0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003d207072696e74657220746f6f6b20612067616c6c6579206f66207479706520616e6420736372616d626c656420697420746f206d616b65206120747970000000"; var buff = new AbiDecodeBuffer(encodedBytes, "bytes"); DecoderFactory.Decode("bytes", ref buff, out byte[] result); Assert.Equal(0, buff.HeadCursor.Length); byte[] expected = "207072696e74657220746f6f6b20612067616c6c6579206f66207479706520616e6420736372616d626c656420697420746f206d616b65206120747970".HexToBytes(); Assert.Equal(expected, result); }
public void UInt32() { var encodedNum = "00000000000000000000000000000000000000000000000000000000ffff5544"; var buff = new AbiDecodeBuffer(encodedNum, "uint32"); DecoderFactory.Decode("uint32", ref buff, out uint result); Assert.Equal(0, buff.HeadCursor.Length); uint expected = 4294923588; Assert.Equal(expected, result); }
public void UInt24() { var encodedNum = "0000000000000000000000000000000000000000000000000000000000005ba0"; var buff = new AbiDecodeBuffer(encodedNum, "uint24"); DecoderFactory.Decode("uint24", ref buff, out uint result); Assert.Equal(0, buff.HeadCursor.Length); uint expected = 23456; Assert.Equal(expected, result); }
public void Int56() { var encodedNum = "00000000000000000000000000000000000000000000000000ffffffffffd492"; var buff = new AbiDecodeBuffer(encodedNum, "int56"); DecoderFactory.Decode("int56", ref buff, out long result); Assert.Equal(0, buff.HeadCursor.Length); var expected = (long)-11118; Assert.Equal(expected, result); }
public void Bytes_M() { var encodedBytes22 = "072696e74657220746f6f6b20612067616c6c657920600000000000000000000"; var buff = new AbiDecodeBuffer(encodedBytes22, "bytes22"); DecoderFactory.Decode("bytes22", ref buff, out byte[] result); Assert.Equal(0, buff.HeadCursor.Length); byte[] expected = HexUtil.HexToBytes("072696e74657220746f6f6b20612067616c6c6579206"); Assert.Equal(expected, result); }
public void Boolean_BadInput_2() { var encodedTrue = "0000000000000000000000000000000000000000000000000000000000000002"; var buff = new AbiDecodeBuffer(encodedTrue, "bool"); try { DecoderFactory.Decode("bool", ref buff, out bool val); throw null; } catch (ArgumentException) { } }
public void Bytes_BadInput_BadLengthPrefix() { var encodedBytes = "0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000010000000000000000000003d207072696e74657220746f6f6b20612067616c6c6579206f66207479706520616e6420736372616d626c656420697420746f206d616b65206120747970000000"; var buff = new AbiDecodeBuffer(encodedBytes, "bytes"); try { DecoderFactory.Decode("bytes", ref buff, out byte[] result); throw null; } catch (ArgumentException) { } catch (OverflowException) { } }
public void String_BadInput_BadLengthPrefix() { var encodedBytes = "0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000060000000000000000000000000000000d48656c6c6f2c20776f726c642100000000000000000000000000000000000000"; var buff = new AbiDecodeBuffer(encodedBytes, "bytes"); try { DecoderFactory.Decode("bytes", ref buff, out byte[] result); throw null; } catch (ArgumentException) { } catch (OverflowException) { } }
/// <summary>Create a new Event Reader</summary> /// <param name="in"/> /// <exception cref="System.IO.IOException"/> public EventReader(DataInputStream @in) { this.@in = @in; this.version = @in.ReadLine(); if (!EventWriter.Version.Equals(version)) { throw new IOException("Incompatible event log version: " + version); } Schema myschema = new SpecificData(typeof(Event).GetClassLoader()).GetSchema(typeof( Event)); this.schema = Schema.Parse(@in.ReadLine()); this.reader = new SpecificDatumReader(schema, myschema); this.decoder = DecoderFactory.Get().JsonDecoder(schema, @in); }
/// <exception cref="System.Exception"/> public static void TestReflect(object value, Type type, string schema) { // check that schema matches expected Schema s = ((ReflectData)ReflectData.Get()).GetSchema(type); Assert.Equal(Schema.Parse(schema), s); // check that value is serialized correctly ReflectDatumWriter <object> writer = new ReflectDatumWriter <object>(s); ByteArrayOutputStream @out = new ByteArrayOutputStream(); writer.Write(value, EncoderFactory.Get().DirectBinaryEncoder(@out, null)); ReflectDatumReader <object> reader = new ReflectDatumReader <object>(s); object after = reader.Read(null, DecoderFactory.Get().BinaryDecoder(@out.ToByteArray (), null)); Assert.Equal(value, after); }
public HelloEvent(Meadow.JsonRpc.Types.FilterLogObject log) : base(log) { // Decode the log topic args. Span <byte> topicBytes = MemoryMarshal.AsBytes(new Span <Meadow.Core.EthTypes.Data>(log.Topics).Slice(1)); AbiTypeInfo[] topicTypes = Array.Empty <AbiTypeInfo>(); var topicBuff = new AbiDecodeBuffer(topicBytes, topicTypes); // Decode the log data args. Span <byte> dataBytes = log.Data; AbiTypeInfo[] dataTypes = new AbiTypeInfo[] { "string", "address" }; var dataBuff = new AbiDecodeBuffer(dataBytes, dataTypes); DecoderFactory.Decode(dataTypes[0], ref dataBuff, out _message); DecoderFactory.Decode(dataTypes[1], ref dataBuff, out _sender); // Add all the log args and their metadata to a collection that can be checked at runtime. LogArgs = new(string Name, string Type, bool Indexed, object Value)[] { ("_message", "string", false, _message), ("_sender", "address", false, _sender) };
public Transfer(Meadow.JsonRpc.Types.FilterLogObject log) : base(log) { // Decode the log topic args. Span <byte> topicBytes = MemoryMarshal.AsBytes(new Span <Meadow.Core.EthTypes.Data>(log.Topics).Slice(1)); AbiTypeInfo[] topicTypes = new AbiTypeInfo[] { "address", "address" }; var topicBuff = new AbiDecodeBuffer(topicBytes, topicTypes); DecoderFactory.Decode(topicTypes[0], ref topicBuff, out from); DecoderFactory.Decode(topicTypes[1], ref topicBuff, out to); // Decode the log data args. Span <byte> dataBytes = log.Data; AbiTypeInfo[] dataTypes = new AbiTypeInfo[] { "uint256" }; var dataBuff = new AbiDecodeBuffer(dataBytes, dataTypes); DecoderFactory.Decode(dataTypes[0], ref dataBuff, out tokens); // Add all the log args and their metadata to a collection that can be checked at runtime. LogArgs = new(string Name, string Type, bool Indexed, object Value)[] { ("from", "address", true, from), ("to", "address", true, to), ("tokens", "uint256", false, tokens) };
public void FunctionData_MultipleStringParams() { var strP1 = "first string"; var strP2 = "asdf"; var strP3 = "utf8; 4 bytes: 𠾴; 3 bytes: ⏰ works!"; var encoded = "000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000000c666972737420737472696e670000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000461736466000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000028757466383b20342062797465733a20f0a0beb43b20332062797465733a20e28fb020776f726b7321000000000000000000000000000000000000000000000000"; AbiDecodeBuffer buff = new AbiDecodeBuffer(encoded, "string", "string", "string"); DecoderFactory.Decode("string", ref buff, out string ru1); Assert.Equal(strP1, ru1); DecoderFactory.Decode("string", ref buff, out string ru2); Assert.Equal(strP2, ru2); DecoderFactory.Decode("string", ref buff, out string ru3); Assert.Equal(strP3, ru3); }
private Article ProcessArticle(ServerReply result, bool bodyOnly) { IBinaryDecoder decoder; if (result.IsGood) { Dictionary <string, string> dict; if (bodyOnly) { dict = new Dictionary <string, string>(); conn.ReadLine(); } else { dict = ReadHeader(); } decoder = DecoderFactory.DetermineDecoder(conn); if (decoder == null) { throw new Exception("Unable to determine binary post encoding."); } decoder.Decode( d => DownloadedChunk(this, new DownloadProgressEventArgs(d.BytesRead, d.Size, d.Filename, d.Part, d.TotalParts)) ); return(new Article { Headers = dict, Body = decoder.Result, Filename = decoder.Filename, Part = decoder.Part, TotalParts = decoder.TotalParts, ExpectedCrc32 = decoder.ExpectedCrc32, ActualCrc32 = decoder.ActualCrc32, Start = decoder.ByteOffset }); } return(null); }
public LogAccess(Meadow.JsonRpc.Types.FilterLogObject log) : base(log) { // Decode the log topic args. Span <byte> topicBytes = MemoryMarshal.AsBytes(new Span <Meadow.Core.EthTypes.Data>(log.Topics).Slice(1)); AbiTypeInfo[] topicTypes = new AbiTypeInfo[] { "address", "uint256" }; var topicBuff = new AbiDecodeBuffer(topicBytes, topicTypes); DecoderFactory.Decode(topicTypes[0], ref topicBuff, out by); DecoderFactory.Decode(topicTypes[1], ref topicBuff, out accessTime); // Decode the log data args. Span <byte> dataBytes = log.Data; AbiTypeInfo[] dataTypes = new AbiTypeInfo[] { "string", "string" }; var dataBuff = new AbiDecodeBuffer(dataBytes, dataTypes); DecoderFactory.Decode(dataTypes[0], ref dataBuff, out method); DecoderFactory.Decode(dataTypes[1], ref dataBuff, out desc); // Add all the log args and their metadata to a collection that can be checked at runtime. LogArgs = new(string Name, string Type, bool Indexed, object Value)[] { ("by", "address", true, by), ("accessTime", "uint256", true, accessTime), ("method", "string", false, method), ("desc", "string", false, desc) };
// Decode all layers private static void DecodeLayers() { // Create the decoder using the decoder factory IDecoder decoder = DecoderFactory.InititalizeDecoder(DecoderEnum.ASCII85Decoder); for (int i = 0; i < 6; i++) { // Get the payload from the file data string inputFile = GetPayload(layerData[i]); // Input file string outputFile = DecodeLayer(i, inputFile, decoder); // Output file string outputFilename = layerData[i + 1]; // Output the entire layer payload, including the plaintext File.WriteAllText($"{Directory}{outputFilename}", outputFile); } }
/// <exception cref="System.IO.IOException"/> public virtual void Open(InputStream @in) { this.inStream = @in; this.decoder = DecoderFactory.Get().BinaryDecoder(@in, this.decoder); }