예제 #1
0
파일: Msg.cs 프로젝트: bojanskr/nats.net
        /// <summary>
        /// Initializes a new instance of the <see cref="Msg"/> class with a subject, reply, header, and data.
        /// </summary>
        /// <param name="subject">Subject of the message.</param>
        /// <param name="reply">A reply subject, or <c>null</c>.</param>
        /// <param name="header">Message headers or <c>null</c>.</param>
        /// <param name="data">A byte array containing the message payload.</param>
        public Msg(string subject, string reply, MsgHeader header, byte[] data)
        {
            if (string.IsNullOrWhiteSpace(subject))
            {
                throw new ArgumentException("Subject cannot be null, empty, or whitespace.", nameof(subject));
            }

            this.Subject = subject;
            this.Reply   = reply;
            this.Header  = header;
            this.Data    = data;
        }
예제 #2
0
 /// <summary>
 /// Copies the entries from an existing MsgHeader instance to a
 /// new MsgHeader instance.
 /// </summary>
 /// <remarks>
 /// The header cannot be empty or contain invalid fields.
 /// </remarks>
 /// <param name="header">the NATS message header to copy.</param>
 public MsgHeader(MsgHeader header)
 {
     if (header == null)
     {
         throw new ArgumentNullException("header");
     }
     if (header.Count == 0)
     {
         throw new ArgumentException("header", "header cannot be empty");
     }
     foreach (string s in header.Keys)
     {
         nvc[s] = header[s];
     }
 }
예제 #3
0
        internal Msg(MsgArg arg, Subscription s, byte[] payload, long totalLen)
        {
            subject = arg.subject;
            reply   = arg.reply;
            sub     = s;

            if (arg.hdr > 0)
            {
                header = new MsgHeader(payload, arg.hdr);
            }

            // make a deep copy of the bytes for this message.
            if (totalLen > 0)
            {
                data = new byte[totalLen];
                Array.Copy(payload, (int)arg.hdr, data, 0, (int)(totalLen - arg.hdr));
            }
            else
            {
                data = Empty;
            }
        }
예제 #4
0
파일: Msg.cs 프로젝트: bojanskr/nats.net
 /// <summary>
 /// Initializes a new instance of the <see cref="Msg"/> class with a subject, header, and data.
 /// </summary>
 /// <param name="subject">Subject of the message.</param>
 /// <param name="header">Message headers or <c>null</c>.</param>
 /// <param name="data">A byte array containing the message payload.</param>
 public Msg(string subject, MsgHeader header, byte[] data)
     : this(subject, null, header, data)
 {
 }