DecodeReal() public static method

public static DecodeReal ( IBerInput input, int length ) : double
input IBerInput
length int
return double
示例#1
0
        /// <summary>
        /// Decodes the value of the current TLV as double.
        /// Throws an exception in case of a format mismatch.
        /// </summary>
        /// <returns>The double value of the current TLV.</returns>
        public double GetReal()
        {
            if (IsContainer)
            {
                ThrowError(204, "Invalid Real encoding");
            }

            Debug.Assert(Value != null || Length == 0);
            Debug.Assert(Type == BerType.Real || BerType.IsApplicationDefined(Type));

            var input = new BerMemoryInput(Value);

            return(BerEncoding.DecodeReal(input, Length));
        }
示例#2
0
        public static object[] Decode(string format, IList <byte> data)
        {
            var input   = new BerMemoryInput(data);
            var objects = new List <object>();

            for (int charIndex = 0; charIndex < format.Length; charIndex++)
            {
                var ch = format[charIndex];

                switch (ch)
                {
                case '{':
                    DecodeHeader(input, TypeTags.Sequence);
                    break;

                case '}':
                {
                    if (input.ReadByte() != 0)
                    {
                        throw new BerException(4002, "Expected terminator");
                    }
                    if (input.ReadByte() != 0)
                    {
                        throw new BerException(4002, "Expected terminator");
                    }
                    break;
                }

                case 'b':
                {
                    DecodeHeader(input, TypeTags.Boolean);
                    objects.Add(BerEncoding.DecodeBoolean(input));
                    break;
                }

                case 'i':
                case 'd':
                {
                    var valueLength = DecodeHeader(input, TypeTags.Integer);
                    objects.Add(BerEncoding.DecodeInteger(input, valueLength));
                    break;
                }

                case 'l':
                case 't':
                {
                    var valueLength = DecodeHeader(input, TypeTags.Integer);
                    objects.Add(BerEncoding.DecodeLong(input, valueLength));
                    break;
                }

                case 's':
                {
                    var valueLength = DecodeHeader(input, TypeTags.UTF8String);
                    objects.Add(BerEncoding.DecodeUtf8String(input, valueLength));
                    break;
                }

                case 'y':
                {
                    var valueLength = DecodeHeader(input, TypeTags.OctetString);
                    objects.Add(BerEncoding.DecodeByteArray(input, valueLength));
                    break;
                }

                case 'f':
                case 'r':
                {
                    var valueLength = DecodeHeader(input, TypeTags.Real);
                    objects.Add(BerEncoding.DecodeReal(input, valueLength));
                    break;
                }

                case 'o':
                {
                    var valueLength = DecodeHeader(input, TypeTags.RelativeOid);
                    objects.Add(BerEncoding.DecodeRelativeOid(input, valueLength));
                    break;
                }

                case 'g':
                {
                    var valueLength = DecodeHeader(input, TypeTags.GeneralizedTime);
                    objects.Add(BerEncoding.DecodeGeneralizedTime(input, valueLength));
                    break;
                }
                }
            }

            return(objects.ToArray());
        }