public static string ToDebuggedHex(this ISerializedType st) { BytesList list = new BytesList(); st.ToBytes(list); return(list.RawList().Aggregate("", (a, b) = \ > \ a + ',' + B16.Encode(b))); }
public byte[] ToBytes() { var list = new BytesList(); ToBytes(list, f = \ > \ f.IsSerialised); return(list.Bytes()); }
public static UDPPackage Parse(byte[] bytes) { Stream stream = new MemoryStream(bytes); BinaryReader reader = new BinaryReader(stream); uint crc = reader.ReadUInt32(); uint checkCRC = CRC32.Calculate(reader.ReadBytes(bytes.Length - 4)); if (crc != checkCRC) { return(new UDPPackage()); //пакет битый } stream.Position = 4; uint sign = reader.ReadUInt32(); ushort parts = reader.ReadUInt16(); BytesList body = new BytesList(); if (parts == 0) { body.Add(reader.ReadBytes(bytes.Length - 4 - 4 - 2)); return(new UDPPackage(body, sign)); } else { ushort part = reader.ReadUInt16(); ushort partsPackageId = reader.ReadUInt16(); body.Add(reader.ReadBytes(bytes.Length - 4 - 4 - 2 - 2 - 2)); return(new UDPPackage(partsPackageId, parts, part, body, sign)); } }
public static string ToHex(this ISerializedType st) { BytesList list = new BytesList(); st.ToBytes(list); return(list.BytesHex()); }
public byte[] SigningData() { var list = new BytesList(); list.Put(HashPrefix.TxSign.Bytes()); ToBytes(list, f = \ > \ f.IsSigningField); return(list.Bytes()); }
private static Feature NewBytesListFeature(IEnumerable <byte[]> value) { var bytesList = new BytesList(); bytesList.Values.AddRange(value); return(new Feature() { BytesList = bytesList }); }
private IItem CreateItem(byte[] tx, byte[] meta) { var bl = new BytesList(); var s = new BinarySerializer(bl); s.AddLengthEncoded(tx); s.AddLengthEncoded(meta); var bytes = bl.Bytes(); return(new ByteItem(bytes)); }
public UDPPackage(BytesList body, UInt32 sign = 0) { this.Body = body; this.Sign = sign; BytesList preCRCData = new BytesList(); preCRCData.AddUInt(this.Sign); preCRCData.AddUShort(this.Parts);//==0 preCRCData.Add(body); this.CRC = CRC32.Calculate(preCRCData); this.FullData.AddUInt(this.CRC); this.FullData.Add(preCRCData); }
public ShellCommand(CommandBaseUDP command, ushort initPartsPackageId) { if (command.BytesList.Count > maxByteSize) { ushort parts = (ushort)(command.BytesList.Count / maxByteSize); this.PartsPackageId = initPartsPackageId; for (ushort part = 0; part < parts; part++) { BytesList data = new BytesList(); data.Add(command.BytesList.GetBytes(maxByteSize * part, maxByteSize)); this.Packages.Add(new UDPPackage(this.PartsPackageId, parts, part, data)); } } else { this.Packages.Add(new UDPPackage(command.BytesList)); } }
public void Prepare(IKeyPair keyPair, Amount fee, UInt32 sequence, UInt32 lastLedgerSequence) { // This won't always be specified if (lastLedgerSequence != null) { Txn.Add(UInt32.LastLedgerSequence, lastLedgerSequence); } Txn.Add(UInt32.Sequence, sequence); Txn.Add(Amount.Fee, fee); Txn.Add(VariableLength.SigningPubKey, keyPair.PubBytes()); if (Transaction.CanonicalFlagDeployed) { Txn.SetCanonicalSignatureFlag(); } SigningHash = Txn.SigningHash(); if (PreviousSigningHash != null && SigningHash.Equals(PreviousSigningHash)) { return; } try { byte[] signature = keyPair.Sign(SigningHash.Bytes); Txn.Add(VariableLength.TxnSignature, signature); var blob = new BytesList(); Hash256.HalfSha512 id = Hash256.Prefixed256(HashPrefix.TransactionId); Txn.ToBytesSink(new MultiSink(blob, id)); TxBlob = blob.BytesHex(); Hash = id.Finish(); } catch (Exception e) { // electric paranoia PreviousSigningHash = null; throw new ApplicationException("Something went wrong.", e); } PreviousSigningHash = SigningHash; }
public UDPPackage(ushort partsPackageId, ushort parts, ushort part, BytesList body, UInt32 sign = 0) { this.PartsPackageId = partsPackageId; this.Parts = parts; this.Part = part; this.Body = body; this.Sign = sign; BytesList preCRCData = new BytesList(); preCRCData.AddUInt(this.Sign); preCRCData.AddUShort(this.Parts);//!=0 preCRCData.AddUShort(this.Part); preCRCData.AddUShort(this.PartsPackageId); preCRCData.Add(body); this.CRC = CRC32.Calculate(preCRCData); this.FullData.AddUInt(this.CRC); this.FullData.Add(preCRCData); }
public void TestNested() { var ba1 = new BytesList(); var ba2 = new BytesList(); ba1.Add(new[] { (byte)'a', (byte)'b', (byte)'c' }); ba1.Add(new[] { (byte)'d', (byte)'e' }); ba2.Add(new[] { (byte)'f', (byte)'g' }); ba2.Add((byte)'h'); ba2.Add(ba1); Assert.AreEqual(8, ba2.BytesLength); byte[] bytes = ba2.Bytes(); var ascii = Encoding.ASCII.GetString(bytes); Assert.AreEqual("fghabcde", ascii); }
public BinaryWriter(BytesList list) { _list = list; }