internal string Get(string name)
        {
            UIntPtr       destSize = (UIntPtr)0;
            StringBuilder sb       = null;

            ConfRes res = Librdkafka.conf_get(handle, name, null, ref destSize);

            if (res == ConfRes.Ok)
            {
                sb  = new StringBuilder((int)destSize);
                res = Librdkafka.conf_get(handle, name, sb, ref destSize);
            }
            if (res != ConfRes.Ok)
            {
                if (res == ConfRes.Unknown)
                {
                    throw new InvalidOperationException($"No such configuration property: {name}");
                }
                throw new Exception("Unknown error while getting configuration property");
            }
            return(sb?.ToString());
        }
        internal void Set(string name, string value)
        {
            var     errorStringBuilder = new StringBuilder(Librdkafka.MaxErrorStringLength);
            ConfRes res = Librdkafka.conf_set(handle, name, value,
                                              errorStringBuilder, (UIntPtr)errorStringBuilder.Capacity);

            if (res == ConfRes.Ok)
            {
                return;
            }
            else if (res == ConfRes.Invalid)
            {
                throw new ArgumentException(errorStringBuilder.ToString());
            }
            else if (res == ConfRes.Unknown)
            {
                throw new InvalidOperationException(errorStringBuilder.ToString());
            }
            else
            {
                throw new Exception("Unknown error while setting configuration property");
            }
        }
        internal static void conf_set_bytes(IntPtr conf, string name, byte[] value)
        {
            var errorStringBuilder = new StringBuilder(MaxErrorStringLength);

            IntPtr pointerToValueBytes = Marshal.AllocHGlobal(value.Length);

            try
            {
                Marshal.Copy(value, 0, pointerToValueBytes, value.Length);

                ConfRes result = _conf_set_bytes(
                    conf,
                    name,
                    pointerToValueBytes,
                    (uint)value.Length,
                    errorStringBuilder,
                    (UIntPtr)errorStringBuilder.Capacity);

                switch (result)
                {
                case ConfRes.Ok:
                    return;

                case ConfRes.Invalid:
                case ConfRes.Unknown:
                    throw new InvalidOperationException(errorStringBuilder.ToString());

                default:
                    throw new Exception(
                              string.Format("Unknown error while setting bytes for property \"{0}\"", name));
                }
            }
            finally
            {
                Marshal.FreeHGlobal(pointerToValueBytes);
            }
        }
Esempio n. 4
0
        internal void Set(string name, string value)
        {
            // TODO: Constant instead of 512?
            var     errorStringBuilder = new StringBuilder(512);
            ConfRes res = LibRdKafka.topic_conf_set(handle, name, value,
                                                    errorStringBuilder, (UIntPtr)errorStringBuilder.Capacity);

            if (res == ConfRes.Ok)
            {
                return;
            }
            else if (res == ConfRes.Invalid)
            {
                throw new InvalidOperationException(errorStringBuilder.ToString());
            }
            else if (res == ConfRes.Unknown)
            {
                throw new InvalidOperationException(errorStringBuilder.ToString());
            }
            else
            {
                throw new Exception("Unknown error while setting configuration property");
            }
        }