Exemplo n.º 1
0
        void ITransactionPayloadEncoder.Encode(BinaryWriter writer, ExodusTransaction transaction)
        {
            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }

            if (transaction == null)
            {
                throw new ArgumentNullException(nameof(transaction));
            }

            Encode(writer, transaction);
        }
Exemplo n.º 2
0
        protected override void Encode(BinaryWriter writer, ExodusTransaction transaction)
        {
            var simpleSend = transaction as SimpleSendV0;

            if (simpleSend == null)
            {
                throw new ArgumentException("The transaction could not be used as a simple send.", nameof(transaction));
            }

            switch (simpleSend.Version)
            {
            case 0:
                EncodePropertyId(writer, simpleSend.Property);
                EncodePropertyAmount(writer, simpleSend.Amount);
                break;

            default:
                throw new NotSupportedException("The version is not supported.");
            }
        }
Exemplo n.º 3
0
        public byte[] Encode(ExodusTransaction transaction)
        {
            if (transaction == null)
            {
                throw new ArgumentNullException(nameof(transaction));
            }

            using (var stream = new MemoryStream())
                using (var writer = new BinaryWriter(stream, Encoding.UTF8))
                {
                    writer.Write(IPAddress.HostToNetworkOrder((short)transaction.Version));
                    writer.Write(IPAddress.HostToNetworkOrder((short)transaction.Id));

                    if (!this.encoders.TryGetValue(transaction.Id, out var encoder))
                    {
                        throw new ArgumentException("The transaction type is not supported.", nameof(transaction));
                    }

                    encoder.Encode(writer, transaction);
                    return(stream.ToArray());
                }
        }
Exemplo n.º 4
0
 protected abstract void Encode(BinaryWriter writer, ExodusTransaction transaction);