Exemplo n.º 1
0
        public static byte[] encoder(Message message)
        {
            int location = 0;
            byte[] finalMessage = new byte[getMessageSize(message) + 4];
            byte[] totalSizeMessage = BitConverter.GetBytes(getMessageSize(message));
            totalSizeMessage.CopyTo(finalMessage, location);
            location += 4;
            MessageItem mSource = new MessageItem(message.Source);
            mSource.getItemSizeAndContent().CopyTo(finalMessage, location);
            location += mSource.getItemLength();

            MessageItem mTarget = new MessageItem(message.Target);
            mTarget.getItemSizeAndContent().CopyTo(finalMessage, location);
            location += mTarget.getItemLength();

            MessageItem mOperation = new MessageItem(message.Operation);
            mOperation.getItemSizeAndContent().CopyTo(finalMessage, location);
            location += mOperation.getItemLength();

            MessageItem mStamp = new MessageItem(message.Stamp);
            mStamp.getItemSizeAndContent().CopyTo(finalMessage, location);
            location += mStamp.getItemLength();

            BitConverter.GetBytes(message.ListParams.Count).CopyTo(finalMessage, location);
            location += 4;

            foreach (string param in message.ListParams)
            {
                MessageItem mParam = new MessageItem(param);
                mParam.getItemSizeAndContent().CopyTo(finalMessage, location);
                location += mParam.getItemLength();
            }

            return finalMessage;
        }
Exemplo n.º 2
0
 public void Send(string service, string address, string operation, string stamp, List<string> param, int id)
 {
     Message msg = new Message(service, address, operation, stamp, param);
     mySelf.Send(id, MessageUtil.encoder(msg));
 }
Exemplo n.º 3
0
 public bool Send(string address, string service, string operation, string stamp, List<string> param)
 {
     Message msg = new Message(address, service, operation, stamp, param);
     return mySelf.Send(MessageUtil.encoder(msg));
 }
Exemplo n.º 4
0
        private static int getMessageSize(Message m)
        {
            int size = (new MessageItem(m.Source)).getItemLength() + (new MessageItem(m.Target)).getItemLength()
                + (new MessageItem(m.Operation)).getItemLength() + (new MessageItem(m.Stamp)).getItemLength()
                + 4; //4 pour le param count

            foreach (string param in m.ListParams)
            {
                size += (new MessageItem(param)).getItemLength();
            }
            return size;
        }