コード例 #1
0
        // TODO: deduplicate, merge with other one
        internal Dictionary <string, string> Dump()
        {
            UIntPtr cntp = (UIntPtr)0;
            IntPtr  data = LibRdKafka.topic_conf_dump(handle, out cntp);

            if (data == IntPtr.Zero)
            {
                throw new Exception("Zero data");
            }

            try
            {
                if (((int)cntp & 1) != 0)
                {
                    // Expect Key -> Value, so even number of strings
                    throw new Exception("Invalid number of config entries");
                }

                var dict = new Dictionary <string, string>();
                for (int i = 0; i < (int)cntp / 2; i++)
                {
                    dict.Add(Marshal.PtrToStringAnsi(Marshal.ReadIntPtr(data, 2 * i * Marshal.SizeOf <IntPtr>())),
                             Marshal.PtrToStringAnsi(Marshal.ReadIntPtr(data, (2 * i + 1) * Marshal.SizeOf <IntPtr>())));
                }
                // Filter out callback pointers
                return(dict.Where(kv => !kv.Key.EndsWith("_cb")).ToDictionary(kv => kv.Key, kv => kv.Value));
            }
            finally
            {
                LibRdKafka.conf_dump_free(data, cntp);
            }
        }