Пример #1
0
        public static void Main(string[] args)
        {
            PropertyBag <bool> props = new PropertyBag <bool>();

            props.Add(SwiftString.FromString("healthy"), true);
            props.Add(SwiftString.FromString("wealthy"), true);
            props.Add(SwiftString.FromString("wise"), false);
            foreach (var pair in props.Contents())
            {
                Console.WriteLine($"{pair.Item1} : {pair.Item2}");
            }
        }
        public static void PrintStringInfo(SwiftString str)
        {
            var stringRep   = new StringRep(str);
            var nsstringPtr = stringRep.BridgeObject;

            Console.WriteLine("Swift string: " + str.ToString());
            Console.Write($"Type: {stringRep.Discriminator} Ptr: {nsstringPtr.ToString ($"X{IntPtr.Size * 2}")} ");
            if (nsstringPtr != IntPtr.Zero)
            {
                // Here be dragons. I didn't see a good API to get the reference count for this object.
                // I intuited it by observing bytes in memory change on x64. This is clearly fragile.
                var refPtr   = nsstringPtr + (IntPtr.Size + sizeof(int));
                var refCount = Marshal.ReadInt32(refPtr);
                Console.Write($"RefCount: {refCount}");
            }
            Console.WriteLine();
        }
Пример #3
0
 public override void ViewDidLoad()
 {
     base.ViewDidLoad();
     this.Translate.TouchUpInside += (sender, e) => {
         using (IgPay igpay = new SwiftIgPay.IgPay(SwiftString.FromString(InputText.Text))) {
             StringBuilder sb = new StringBuilder();
             for (int i = 0; i < igpay.Count; i++)
             {
                 using (SwiftString str = igpay [i]) {
                     if (i > 0)
                     {
                         sb.Append(" ");
                     }
                     sb.Append(str.ToString());
                 }
             }
             OutputText.Text = sb.ToString();
         }
     };
 }
            public unsafe StringRep(SwiftString str)
            {
                // in Swift 5, a string in 64 bits is two machine words.
                // the first is a set of flags and a count
                // the second is a pointer, the high nibble of which is a discriminator that
                // determines the storage which may or may not point to the actual string data.
                // In some cases, it is a pointer to a bridge object. In others is a pointer that
                // if offset by a "bias" which is either 32 bytes on a 64 bit sysem or 20 on a 32 bit system.
                // In addition, there is no pointer to string data and instead the raw data is packing into the
                // pointer and count instead.
                // For 32 bit systems, the layout is...weird and I haven't fully unpacked it yet.
                if (IntPtr.Size == 4)
                    throw new NotImplementedException("32 bit swift string support needs to get hashed out.");
                fixed(byte *swiftData = str.SwiftData)
                {
                    ulong *flagsPtr = (ulong *)swiftData;

                    FlagsAndCount = *flagsPtr++;
                    Storage       = *flagsPtr;
                }
            }