Exemple #1
0
        public DictPair(string name = "", GTXValue value = null)
        {
            this.Name = name;

            if (value == null)
            {
                this.Value = new GTXValue();
            }
            else
            {
                this.Value = value;
            }
        }
        public override bool Equals(object obj)
        {
            if ((obj == null) || !this.GetType().Equals(obj.GetType()))
            {
                return(false);
            }
            else
            {
                GTXValue gtxValue = (GTXValue)obj;

                return(this.Choice.Equals(gtxValue.Choice) &&
                       ((this.ByteArray == null || gtxValue.ByteArray == null) ? this.ByteArray == gtxValue.ByteArray : Enumerable.SequenceEqual(this.ByteArray, gtxValue.ByteArray)) &&
                       this.Integer.Equals(gtxValue.Integer) &&
                       ((this.Dict == null || gtxValue.Dict == null) ? this.Dict == gtxValue.Dict : Enumerable.SequenceEqual(this.Dict, gtxValue.Dict)) &&
                       ((this.Array == null || gtxValue.Array == null) ? this.Array == gtxValue.Array : Enumerable.SequenceEqual(this.Array, gtxValue.Array)));
            }
        }
        private static byte GetValueSize(GTXValue gtxValue)
        {
            switch (gtxValue.Choice)
            {
            case (GTXValueChoice.ByteArray):
            {
                byte size = (byte)(gtxValue.ByteArray.Length + 2);
                if (size > 127)
                {
                    size += 1;
                }

                return(size);
            }

            case (GTXValueChoice.String):
            {
                byte size = (byte)(gtxValue.String.Length + 2);
                if (size > 127)
                {
                    size += 1;
                }

                return(size);
            }

            case (GTXValueChoice.Integer):
            {
                byte size = (byte)(ASN1Util.GetMaxAmountOfBytesForInteger(gtxValue.Integer) + 2);
                if (size > 127)
                {
                    size += 1;
                }

                return(size);
            }

            case (GTXValueChoice.Array):
            {
                byte choiceSize = (byte)2;

                foreach (var val in gtxValue.Array)
                {
                    var tmpSize = GetValueSize(val);

                    if (tmpSize > 127)
                    {
                        choiceSize += (byte)(tmpSize + 3);
                    }
                    else
                    {
                        choiceSize += (byte)(tmpSize + 2);
                    }
                }

                if (choiceSize > 127)
                {
                    choiceSize += 1;
                }

                return(choiceSize);
            }

            case (GTXValueChoice.Dict):
            {
                byte choiceSize = (byte)2;

                foreach (var val in gtxValue.Dict)
                {
                    var tmpSize = (byte)((val.Name.Length + 2) + GetValueSize(val.Value));

                    if (tmpSize > 127)
                    {
                        choiceSize += (byte)(tmpSize + 5);
                    }
                    else
                    {
                        choiceSize += (byte)(tmpSize + 4);
                    }
                }

                if (choiceSize > 127)
                {
                    choiceSize += 1;
                }

                return(choiceSize);
            }

            default:
            {
                throw new System.Exception("Chromia.PostchainClient.GTX.Messages GTXValue.GetValueSize() GTXValueChoice.Default case. Unknown choice " + gtxValue.Choice);
            }
            }
        }