SensorShare.TypedMessage.GetBytes C# (CSharp) Method

GetBytes() public method

public GetBytes ( ) : byte[]
return byte[]
        public byte[] GetBytes()
        {
            byte[] messageBody;
               using (MemoryStream ms = new MemoryStream())
               {
              // Get byte array for type
              ms.Write(BitConverter.GetBytes((Int32)this.type), 0, sizeof(Int32));
              ms.Write(data, 0,data.Length);

              messageBody = new byte[ms.Length];
              messageBody = ms.ToArray();
               }
            return messageBody;
        }

Usage Example

 void networkNode_MessageReceived(object sender, MessageEventArgs args)
 {
     log.Append("networkNode_MessageReceived", String.Format("Message Received from {0}", args.SenderID.ToString()));
      TypedMessage message = new TypedMessage(args.Data, args.Data.Length);
      switch (message.type)
      {
     case MessageType.DescriptionRequest:
        log.Append("networkNode_MessageReceived", "Description Request received");
        DescriptionMessage description = new DescriptionMessage(CurrentServerData);
        TypedMessage reply = new TypedMessage(MessageType.DescriptionMessage, description.GetBytes());
        networkNode.SendDirect(reply.GetBytes(), args.SenderID);
        break;
     default:
        break;
      }
 }
All Usage Examples Of SensorShare.TypedMessage::GetBytes