GetObject() public méthode

public GetObject ( PeterO.Numbers.EInteger bigIndex ) : CBORObject
bigIndex PeterO.Numbers.EInteger
Résultat CBORObject
Exemple #1
0
        private static CBORObject ResolveSharedRefs(
            CBORObject obj,
            SharedRefs sharedRefs)
        {
            if (obj == null)
            {
                return(null);
            }
            CBORType type   = obj.Type;
            bool     hasTag = obj.HasMostOuterTag(29);

            if (hasTag)
            {
                CBORObject untagged = obj.UntagOne();
                if (untagged.IsTagged ||
                    untagged.Type != CBORType.Integer ||
                    untagged.AsNumber().IsNegative())
                {
                    throw new CBORException(
                              "Shared ref index must be an untagged integer 0 or greater");
                }
                return(sharedRefs.GetObject(untagged.AsEIntegerValue()));
            }
            hasTag = obj.HasMostOuterTag(28);
            if (hasTag)
            {
                obj = obj.UntagOne();
                sharedRefs.AddObject(obj);
            }
            if (type == CBORType.Map)
            {
                foreach (CBORObject key in obj.Keys)
                {
                    CBORObject value    = obj[key];
                    CBORObject newvalue = ResolveSharedRefs(value, sharedRefs);
                    if (value != newvalue)
                    {
                        obj[key] = newvalue;
                    }
                }
            }
            else if (type == CBORType.Array)
            {
                for (var i = 0; i < obj.Count; ++i)
                {
                    obj[i] = ResolveSharedRefs(obj[i], sharedRefs);
                }
            }
            return(obj);
        }
Exemple #2
0
        private static CBORObject ResolveSharedRefs(
            CBORObject obj,
            SharedRefs sharedRefs)
        {
            int  type   = obj.ItemType;
            bool hasTag = obj.MostOuterTag.Equals((EInteger)29);

            if (hasTag)
            {
                return(sharedRefs.GetObject(obj.AsEInteger()));
            }
            hasTag = obj.MostOuterTag.Equals((EInteger)28);
            if (hasTag)
            {
                obj = obj.Untag();
                sharedRefs.AddObject(obj);
            }
            if (type == CBORObject.CBORObjectTypeMap)
            {
                foreach (CBORObject key in obj.Keys)
                {
                    CBORObject value    = obj[key];
                    CBORObject newvalue = ResolveSharedRefs(value, sharedRefs);
                    if (value != newvalue)
                    {
                        obj[key] = newvalue;
                    }
                }
            }
            else if (type == CBORObject.CBORObjectTypeArray)
            {
                for (var i = 0; i < obj.Count; ++i)
                {
                    obj[i] = ResolveSharedRefs(obj[i], sharedRefs);
                }
            }
            return(obj);
        }