Example #1
0
        //----------------------------------------------------------------------
        public static ArraySegment <byte> GetEventBytes(StatusEvent evnt, ref byte[] buffer)
        {
            int count;

            count = 0;

            JsonBuffer.AppendByte((byte)'{', ref buffer, ref count);

            JsonBuffer.AppendProperty("type", evnt.EventType.ToString(), ref buffer, ref count);

            if (evnt.Id != 0)
            {
                JsonBuffer.AppendByte((byte)',', ref buffer, ref count);
                JsonBuffer.AppendProperty("id", evnt.Id.ToString(), ref buffer, ref count);
            }

            if (evnt.Name != null)
            {
                JsonBuffer.AppendByte((byte)',', ref buffer, ref count);
                JsonBuffer.AppendProperty("name", evnt.Name, ref buffer, ref count);
            }

            if (evnt.Text != null)
            {
                JsonBuffer.AppendByte((byte)',', ref buffer, ref count);
                JsonBuffer.AppendProperty("text", evnt.Text, ref buffer, ref count);
            }


            if (evnt.Status != null)
            {
                JsonBuffer.AppendByte((byte)',', ref buffer, ref count);
                JsonBuffer.AppendProperty("status", evnt.Status.Value.ToString(), ref buffer, ref count);
            }

            JsonBuffer.AppendByte((byte)'}', ref buffer, ref count);

            return(new ArraySegment <byte>(buffer, 0, count));
        }