Esempio n. 1
0
        public void Write(T message, Action completed = null)
        {
            var sb = new StringBuilder(1024);

            sb.Append('{');
            {
                sb.Append("\"op\":\"publish\",");

                sb.Append("\"topic\":\"");
                sb.Append(Topic);
                sb.Append("\",");

                sb.Append("\"msg\":");
                Bridge.Serialize(message, message.GetType(), sb);
            }
            sb.Append('}');

            byte[] data = Encoding.ASCII.GetBytes(sb.ToString());
            Bridge.SendAsync(data, completed, Topic);
        }
Esempio n. 2
0
        public void Write(T message, Action completed = null)
        {
            if (enableLock == true & isSerializing == true)
            {
                return;
            }

            if (enableLock == true)
            {
                isSerializing = true;
            }

            var sb = new StringBuilder(1024);

            sb.Append('{');
            {
                sb.Append("\"op\":\"publish\",");

                sb.Append("\"topic\":\"");
                sb.Append(Topic);
                sb.Append("\",");

                sb.Append("\"msg\":");

                Bridge.Serialize(message, typeof(T), sb);
            }
            sb.Append('}');

            byte[] data = Encoding.ASCII.GetBytes(sb.ToString());
            Bridge.SendAsync(data, completed, Topic);

            if (enableLock == true)
            {
                isSerializing = false;
            }
        }