public void FixedArrayOversizedException() { long[] bytes = new long[] { 1, 4546, long.MaxValue, 0, 1, 2 }; var encoder = EncoderFactory.LoadEncoder("int64[5]", bytes, EncoderFactory.LoadEncoder("int64", default(long))); Assert.Throws <ArgumentOutOfRangeException>(() => encoder.ToEncodedHex()); }
internal DbfRecord(BinaryReader reader, DbfHeader header, List <DbfField> fields, byte[] memoData, Encoding encoding) { this.fields = fields; Data = new List <object>(); // Read record marker. byte marker = reader.ReadByte(); // Read entire record as sequence of bytes. // Note that record length includes marker. byte[] row = reader.ReadBytes(header.RecordLength - 1); // Read data for each field. int offset = 0; foreach (DbfField field in fields) { // Copy bytes from record buffer into field buffer. byte[] buffer = new byte[field.Length]; Array.Copy(row, offset, buffer, 0, field.Length); offset += field.Length; IEncoder encoder = EncoderFactory.GetEncoder(field.Type); Data.Add(encoder.Decode(buffer, memoData, encoding)); } }
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 virtual void writeCompressed(ExtendedDataOutput output) { int dataType = (int)this.getDataType(); int unitLength = getUnitLength(this.getDataType()); int elementCount = this.rows(); int maxCompressedLength = this.rows() * sizeof(long) * 8 * 2 + 64 * 3; ByteBuffer outBuffer = ByteBuffer.Allocate(Math.Max(maxCompressedLength, 65536)); outBuffer.order(output.GetType() == typeof(LittleEndianDataOutputStream)); short flag = (short)((short)DATA_FORM.DF_VECTOR << 8 | (short)DATA_TYPE.DT_COMPRESS & 0xff); outBuffer.WriteShort(flag); outBuffer.WriteInt(0); // compressedBytes outBuffer.WriteInt(1); // cols outBuffer.WriteByte((byte)0); // version outBuffer.WriteByte((byte)1); // flag bit0:littleEndian bit1:containChecksum outBuffer.WriteByte(unchecked ((byte)-1)); // charcode outBuffer.WriteByte((byte)compressedMethod); outBuffer.WriteByte((byte)dataType); outBuffer.WriteByte((byte)unitLength); outBuffer.WriteByte((byte)0); outBuffer.WriteByte((byte)0); outBuffer.WriteInt(-1); //extra outBuffer.WriteInt(elementCount); outBuffer.WriteInt(-1); //TODO: checkSum EncoderFactory.Get(compressedMethod).compress(this, elementCount, unitLength, maxCompressedLength, outBuffer); int compressedLength = outBuffer.ReadableBytes - 10; outBuffer.PutInt(compressedLength, 2); byte[] tmp = new byte[outBuffer.ReadableBytes]; output.write(outBuffer.ToArray()); }
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 NextTest(bool increment) { if (_count == 5) { this.Controls.Clear(); Controls.Add(new FinishControl(0, 5)); } var function = RandomGenerator.NextTrithemiusFunction(); var key = RandomGenerator.NextKey(); var message = RandomGenerator.NextENGMessage(); IAlphabetEncoder trithemius = EncoderFactory .CreateEncoder(EncoderType.Trithemius) .SetMonoAlphabet(Alphabet.GetMono(MonoAlphabet.ENG)) .Configure(key, (Func <int, int>)function); _enc = trithemius; _mes = message; label7.Text = function.ToString(); label8.Text = key.ToString(); lbDescription.Text = message; if (increment) { _count++; } lbCurrentTask.Text = _count.ToString(); }
public void Setup() { factory = new EncoderFactory(); request = new Mock<HttpRequestBase>(); headers = new NameValueCollection(); request.Setup(r => r.Headers).Returns(headers); }
static void Main(string[] args) { var ENG_ALPHA = Alphabet.GetMono(MonoAlphabet.ENG); var UTF16 = Alphabet.GetMono(MonoAlphabet.UTF16); IAlphabetEncoder caesar = EncoderFactory .CreateEncoder(EncoderType.Caesar) .SetMonoAlphabet(UTF16) .Configure(1); IAlphabetEncoder trithemius = EncoderFactory .CreateEncoder(EncoderType.Trithemius) .SetMonoAlphabet(ENG_ALPHA) .Configure(2, new Func <int, int>(x => x + 1)); IAlphabetEncoder vigener = EncoderFactory .CreateEncoder(EncoderType.Vigenere) .Configure("Lemon"); IAlphabetEncoder diffiHelman = EncoderFactory .CreateEncoder(EncoderType.DiffiHelman) .Configure(5, 23, new List <int>() { 23, 43 }); IAlphabetEncoder elgamal = EncoderFactory .CreateEncoder(EncoderType.Elgamal) .Configure(11, 2, 8, 9); IAlphabetEncoder des = EncoderFactory .CreateBitEncoder(BitEncodingType.Des) .Configure("чр3Ъ"); Console.WriteLine(caesar.Encode("Azb12365.,&^%$@")); Console.WriteLine(trithemius.Decode(trithemius.Encode("Azb"))); Console.WriteLine(vigener.Encode("ATTACKATDAWN")); Console.WriteLine(diffiHelman.Decode(null)); Console.WriteLine(elgamal.Decode("5")); Console.WriteLine(elgamal.Encode("6,9")); string input = "Input"; BitMessage mess = BitMessage.Parse(input); string binary = mess.ToBinaryString(); string output = mess.ToString(); Console.WriteLine($"\n{input}\n{binary}\n{output}"); byte[] b = new UnicodeEncoding().GetBytes(des.Encode("Do you know")); string str = new UnicodeEncoding().GetString(b); Console.WriteLine(str); b.ToList().ForEach(x => Console.WriteLine(x)); Console.ReadLine(); }
/// <summary> /// Return the encoded contents, including mime /// header. /// </summary> /// <returns></returns> public String ToDataString() { IEncoder encoder = EncoderFactory.GetEncoder(Encoding); StringBuilder sb = new StringBuilder(); sb.Append(GetInternalMimeHeader(encoder)); sb.Append(GetEncodedContents(encoder)); return(sb.ToString()); }
/// <exception cref="System.IO.IOException"/> internal EventWriter(FSDataOutputStream @out) { this.@out = @out; @out.WriteBytes(Version); @out.WriteBytes("\n"); @out.WriteBytes(Event.Schema$.ToString()); @out.WriteBytes("\n"); this.encoder = EncoderFactory.Get().JsonEncoder(Event.Schema$, @out); }
public void ExportSubfile(string arcname, string name, string path) { var subfile = GetSubfile(arcname, name); using (FileStream fs = new FileStream(path, FileMode.Create)) using (IEncoder encoder = EncoderFactory.GetEncoder(subfile, Archive)) using (Stream stream = encoder.Decode()) stream.CopyTo(fs); }
/// <summary> /// Deploys the contract. <para/> /// </summary> /// <param name = "total"><c>uint256</c></param> /// <param name = "rpcClient">The RPC client to be used for this contract instance.</param> /// <param name = "defaultFromAccount">If null then the first account returned by eth_accounts will be used.</param> /// <returns>An contract instance pointed at the deployed contract address.</returns> public static async Task <ERC20Basic> Deploy(Meadow.Core.EthTypes.UInt256 total, Meadow.JsonRpc.Client.IJsonRpcClient rpcClient, Meadow.JsonRpc.Types.TransactionParams transactionParams = null, Meadow.Core.EthTypes.Address?defaultFromAccount = null) { transactionParams = transactionParams ?? new Meadow.JsonRpc.Types.TransactionParams(); defaultFromAccount = defaultFromAccount ?? transactionParams.From ?? (await rpcClient.Accounts())[0]; transactionParams.From = transactionParams.From ?? defaultFromAccount; var encodedParams = Meadow.Core.AbiEncoding.EncoderUtil.Encode(EncoderFactory.LoadEncoder("uint256", total)); var contractAddr = await ContractFactory.Deploy(rpcClient, BYTECODE_BYTES.Value, transactionParams, encodedParams); return(new ERC20Basic(rpcClient, contractAddr, defaultFromAccount.Value)); }
public Stream ReadSubfile(string archiveName, string name) { var file = GetSubfile(archiveName, name); if (file == null) { throw new Exception("Couldn't find the subfile " + archiveName + "/" + name); } using (IEncoder encoder = EncoderFactory.GetEncoder(file, Archive)) return(encoder.Decode()); }
public void FunctionDataEncode_MultipleStringParams() { var funcSig = "echoMultipleDynamic(string,string,string)"; var strP1 = "first string"; var strP2 = "asdf"; var strP3 = "utf8; 4 bytes: 𠾴; 3 bytes: ⏰ works!"; var callData = EncoderUtil.GetFunctionCallBytes( funcSig, EncoderFactory.LoadEncoder("string", strP1), EncoderFactory.LoadEncoder("string", strP2), EncoderFactory.LoadEncoder("string", strP3)); var expectedEncode = "0x14d6b8fa000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000000c666972737420737472696e670000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000461736466000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000028757466383b20342062797465733a20f0a0beb43b20332062797465733a20e28fb020776f726b7321000000000000000000000000000000000000000000000000"; Assert.Equal(expectedEncode, callData.ToHexString(hexPrefix: true)); }
public CalculationResult Calculate(string input) { var result = CalculationResult.StartCalculations (input, _monoAlphabet, EncoderType.Trithemius, _codingType, out IMonoAlphabet alpha); IAlphabetEncoder trithemius = EncoderFactory .CreateEncoder(EncoderType.Trithemius) .SetMonoAlphabet(alpha) .Configure(_key, (Func <int, int>)_map); var output = _codingType == CodingType.Encoding ? trithemius.Encode(input) : trithemius.Decode(input); return(result.WithKey(_key.ToString()).WithFunction(_map).EndCalculations(output)); }
public CalculationResult Calculate(string input) { var result = CalculationResult.StartCalculations (input, _monoAlphabet, EncoderType.Caesar, _codingType, out IMonoAlphabet alpha); IAlphabetEncoder caesar = EncoderFactory .CreateEncoder(EncoderType.Caesar) .SetMonoAlphabet(alpha) .Configure(_key); var output = _codingType == CodingType.Encoding ? caesar.Encode(input) : caesar.Decode(input); return(result.WithKey(_key.ToString()).EndCalculations(output)); }
internal void Write(BinaryWriter writer) { // Write marker (always "not deleted") writer.Write((byte)0x20); int index = 0; foreach (DbfField field in fields) { IEncoder encoder = EncoderFactory.GetEncoder(field.Type); byte[] buffer = encoder.Encode(field, data[index]); writer.Write(buffer); index++; } }
/// <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 void Int56() { var num = (long)-11118; var encoder = EncoderFactory.LoadEncoder("int56", num); Assert.IsType <Int64Encoder>(encoder); var encodedSize = encoder.GetEncodedSize(); Assert.Equal(32, encodedSize); Span <byte> data = new byte[encodedSize]; var buff = new AbiEncodeBuffer(data, "int56"); encoder.Encode(ref buff); Assert.Equal(0, buff.HeadCursor.Length); var result = HexUtil.GetHexFromBytes(data, hexPrefix: false); Assert.Equal("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd492", result); }
public void Int256_2() { BigInteger num = 4294923588; var encoder = EncoderFactory.LoadEncoder("int256", num); Assert.IsType <Int256Encoder>(encoder); var encodedSize = encoder.GetEncodedSize(); Assert.Equal(32, encodedSize); Span <byte> data = new byte[encodedSize]; var buff = new AbiEncodeBuffer(data, "int256"); encoder.Encode(ref buff); Assert.Equal(0, buff.HeadCursor.Length); var result = HexUtil.GetHexFromBytes(data, hexPrefix: false); Assert.Equal("00000000000000000000000000000000000000000000000000000000ffff5544", result); }
public void Address() { Address myAddr = "0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe"; var encoder = EncoderFactory.LoadEncoder("address", myAddr); Assert.IsType <AddressEncoder>(encoder); var encodedSize = encoder.GetEncodedSize(); Assert.Equal(32, encodedSize); Span <byte> data = new byte[encodedSize]; var buffer = new AbiEncodeBuffer(data, "address"); encoder.Encode(ref buffer); Assert.Equal(0, buffer.HeadCursor.Length); var result = HexUtil.GetHexFromBytes(data, hexPrefix: false); Assert.Equal("00000000000000000000000011f4d0a3c12e86b4b5f39b213f7e19d048276dae", result); }
public void Int24_1() { int num = 77216; var encoder = EncoderFactory.LoadEncoder("int24", num); Assert.IsType <Int32Encoder>(encoder); var encodedSize = encoder.GetEncodedSize(); Assert.Equal(32, encodedSize); Span <byte> data = new byte[encodedSize]; var buff = new AbiEncodeBuffer(data, "int24"); encoder.Encode(ref buff); Assert.Equal(0, buff.HeadCursor.Length); var result = HexUtil.GetHexFromBytes(data, hexPrefix: false); Assert.Equal("0000000000000000000000000000000000000000000000000000000000012da0", result); }
/// <summary> /// From a RIFF wave. WIP. /// </summary> /// <param name="r"></param> public FISP(RiffWave r) { regions = new List <RegionInfo>(); tracks = new List <TrackInfo>(); data = new DataInfo(); stream = new StreamInfo(); //Data. if (r.fmt.bitsPerSample == 16) { short[][] pcm16 = new short[r.data.channels.Count][]; for (int i = 0; i < r.data.channels.Count; i++) { pcm16[i] = r.data.channels[i].pcm16.ToArray(); } data.data = pcm16.ToList(); } else { byte[][] pcm8 = new byte[r.data.channels.Count][]; for (int i = 0; i < r.data.channels.Count; i++) { pcm8[i] = r.data.channels[i].pcm8.ToArray(); } data.data = EncoderFactory.Pcm8ToPcm16(pcm8).ToList(); } //Stream info. stream.sampleRate = r.fmt.sampleRate; stream.encoding = 2; if (data.data.Count > 0) { stream.loopEnd = (uint)data.data[0].Length; } if (r.smpl != null) { if (r.smpl.loops.Count > 0) { stream.isLoop = true; stream.loopStart = stream.originalLoopStart = r.smpl.loops[0].startSample; stream.loopEnd = stream.originalLoopEnd = r.smpl.loops[0].endSample; } } }
public void UInt8FixedArray() { byte[] bytes = HexUtil.HexToBytes("072696e746"); var encoder = EncoderFactory.LoadEncoder("uint8[5]", bytes, EncoderFactory.LoadEncoder("uint8", default(byte))); Assert.IsType <FixedArrayEncoder <byte> >(encoder); var encodedSize = encoder.GetEncodedSize(); Assert.True(encodedSize % 32 == 0); Assert.Equal(160, encodedSize); Span <byte> data = new byte[encodedSize]; var buff = new AbiEncodeBuffer(data, "uint8[5]"); encoder.Encode(ref buff); Assert.Equal(0, buff.HeadCursor.Length); var result = HexUtil.GetHexFromBytes(data); Assert.Equal("00000000000000000000000000000000000000000000000000000000000000070000000000000000000000000000000000000000000000000000000000000026000000000000000000000000000000000000000000000000000000000000009600000000000000000000000000000000000000000000000000000000000000e70000000000000000000000000000000000000000000000000000000000000046", result); }
public void String() { var str = "Hello, world!"; var encoder = EncoderFactory.LoadEncoder("string", str); Assert.IsType <StringEncoder>(encoder); var encodedSize = encoder.GetEncodedSize(); Assert.True(encodedSize % 32 == 0); Assert.Equal(96, encodedSize); Span <byte> data = new byte[encodedSize]; var buff = new AbiEncodeBuffer(data, "string"); encoder.Encode(ref buff); Assert.Equal(0, buff.HeadCursor.Length); var result = HexUtil.GetHexFromBytes(data); Assert.Equal("0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000d48656c6c6f2c20776f726c642100000000000000000000000000000000000000", result); }
public void StringUnicode() { var str = "utf8; 4 bytes: 𠾴; 3 bytes: ⏰ works!"; var encoder = EncoderFactory.LoadEncoder("string", str); Assert.IsType <StringEncoder>(encoder); var encodedSize = encoder.GetEncodedSize(); Assert.True(encodedSize % 32 == 0); Assert.Equal(128, encodedSize); Span <byte> data = new byte[encodedSize]; var buff = new AbiEncodeBuffer(data, "string"); encoder.Encode(ref buff); Assert.Equal(0, buff.HeadCursor.Length); var result = HexUtil.GetHexFromBytes(data); Assert.Equal("00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000028757466383b20342062797465733a20f0a0beb43b20332062797465733a20e28fb020776f726b7321000000000000000000000000000000000000000000000000", result); }
public Tuple <AnswerType, string> CheckAnswer( IQuestion currentQuestion, MonoAlphabet mono, PolyAlphabet poly, params object[] args) { IAlphabetEncoder encoder = EncoderFactory .CreateEncoder(currentQuestion.EncodingType) .SetMonoAlphabet(Alphabet.GetMono(mono)) .Configure(args); string answer = String.Empty; switch (currentQuestion.CodingType) { case CodingType.Decoding: answer = encoder.Decode(currentQuestion.Description.Description); if (currentQuestion.Answer.Answer.ToLower() .Equals(answer.ToLower())) { return(new Tuple <AnswerType, string> (AnswerType.Correct, answer)); } break; case CodingType.Encoding: answer = encoder.Encode(currentQuestion.Description.Description); if (currentQuestion.Answer.Answer.ToLower() .Equals(answer.ToLower())) { return(new Tuple <AnswerType, string> (AnswerType.Correct, answer)); } break; } return(new Tuple <AnswerType, string> (AnswerType.NotCorrect, answer)); }
public void LargeString() { var str = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book."; var encoder = EncoderFactory.LoadEncoder("string", str); Assert.IsType <StringEncoder>(encoder); var encodedSize = encoder.GetEncodedSize(); Assert.True(encodedSize % 32 == 0); Assert.Equal(320, encodedSize); Span <byte> data = new byte[encodedSize]; var buff = new AbiEncodeBuffer(data, "string"); encoder.Encode(ref buff); Assert.Equal(0, buff.HeadCursor.Length); var result = HexUtil.GetHexFromBytes(data); Assert.Equal("000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000f54c6f72656d20497073756d2069732073696d706c792064756d6d792074657874206f6620746865207072696e74696e6720616e64207479706573657474696e6720696e6475737472792e204c6f72656d20497073756d20686173206265656e2074686520696e6475737472792773207374616e646172642064756d6d79207465787420657665722073696e6365207468652031353030732c207768656e20616e20756e6b6e6f776e207072696e74657220746f6f6b20612067616c6c6579206f66207479706520616e6420736372616d626c656420697420746f206d616b65206120747970652073706563696d656e20626f6f6b2e0000000000000000000000", result); }
public void Bytes() { byte[] bytes = HexUtil.HexToBytes("207072696e74657220746f6f6b20612067616c6c6579206f66207479706520616e6420736372616d626c656420697420746f206d616b65206120747970"); var encoder = EncoderFactory.LoadEncoder("bytes", bytes); Assert.IsType <BytesEncoder>(encoder); var encodedSize = encoder.GetEncodedSize(); Assert.True(encodedSize % 32 == 0); Assert.Equal(128, encodedSize); Span <byte> data = new byte[encodedSize]; var buff = new AbiEncodeBuffer(data, "bytes"); encoder.Encode(ref buff); Assert.Equal(0, buff.HeadCursor.Length); var result = HexUtil.GetHexFromBytes(data); Assert.Equal("0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003d207072696e74657220746f6f6b20612067616c6c6579206f66207479706520616e6420736372616d626c656420697420746f206d616b65206120747970000000", result); }
public void Int64FixedArray() { long[] bytes = new long[] { 1, 4546, long.MaxValue, 0, long.MaxValue }; var encoder = EncoderFactory.LoadEncoder("int64[5]", bytes, EncoderFactory.LoadEncoder("int64", default(long))); Assert.IsType <FixedArrayEncoder <long> >(encoder); var encodedSize = encoder.GetEncodedSize(); Assert.True(encodedSize % 32 == 0); Assert.Equal(160, encodedSize); Span <byte> data = new byte[encodedSize]; var buff = new AbiEncodeBuffer(data, "int64[5]"); encoder.Encode(ref buff); Assert.Equal(0, buff.HeadCursor.Length); var result = HexUtil.GetHexFromBytes(data); Assert.Equal("000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000011c20000000000000000000000000000000000000000000000007fffffffffffffff00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007fffffffffffffff", result); }
public void Bytes_M() { byte[] bytes = HexUtil.HexToBytes("072696e74657220746f6f6b20612067616c6c6579206"); var encoder = EncoderFactory.LoadEncoder("bytes22", bytes); Assert.IsType <BytesMEncoder>(encoder); var encodedSize = encoder.GetEncodedSize(); Assert.True(encodedSize % 32 == 0); Assert.Equal(32, encodedSize); Span <byte> data = new byte[encodedSize]; var buff = new AbiEncodeBuffer(data, "bytes22"); encoder.Encode(ref buff); Assert.Equal(0, buff.HeadCursor.Length); var result = HexUtil.GetHexFromBytes(data); Assert.Equal("072696e74657220746f6f6b20612067616c6c657920600000000000000000000", result); }