Example #1
0
 public bool PackRequestData(TalkerCommand command, byte[] body, int usedBodySize, out byte[] data, TalkerMessageType type)
 {
     if ((command == null) || (command.Command == null))
     {
         throw new Exception("Invalid Argument!");
     }
     data = null;
     if ((body != null) && (usedBodySize > 0))
     {
         TalkerHead head = new TalkerHead();
         this.setFlag(ref head.bFlag, type, command.Command.Type);
         ADebug.Log(string.Concat(new object[] { "PackRequestData head flag:", head.bFlag, " commandType:", command.Command.Type }));
         this.Command           = command;
         head.bDomain           = (byte)command.Domain;
         head.bCmdFmt           = (byte)command.Command.Type;
         head.stCommand.iIntCmd = (int)command.Command.IntegerValue;
         if (command.Command.StringValue != null)
         {
             head.stCommand.szStrCmd = Encoding.UTF8.GetBytes(command.Command.StringValue);
         }
         if (type == TalkerMessageType.Response)
         {
             head.dwAsync = this.AsyncFlag;
         }
         else
         {
             head.dwAsync = this.SeqNum;
         }
         ADebug.Log(string.Concat(new object[] { "PackRequestData cmd: ", this.Command.ToString(), " type:", type, " async:", head.dwAsync }));
         byte[]             buffer = new byte[this.calculateHeadSize(head)];
         int                used   = 0;
         TdrError.ErrorType type2  = head.packTLV(ref buffer, buffer.Length, ref used, true);
         if (type2 != TdrError.ErrorType.TDR_NO_ERROR)
         {
             ADebug.Log(string.Concat(new object[] { "PackRequestData head.pack error:", type2, " usedBodySize:", usedBodySize, " usedHeadSize:", used, " headBufflen:", buffer.Length }));
             return(false);
         }
         int num3 = usedBodySize + used;
         data = new byte[num3];
         Array.Copy(buffer, data, used);
         Array.Copy(body, 0, data, used, usedBodySize);
         this.Request = null;
         return(true);
     }
     ADebug.Log("PackRequestData request.pack error");
     return(false);
 }
Example #2
0
        public bool PackRequestData(TalkerCommand command, byte[] body, int usedBodySize, out byte[] data, TalkerMessageType type)
        {
            if (command == null || command.Command == null)
            {
                throw new Exception("Invalid Argument!");
            }
            data = null;
            if (body == null || usedBodySize <= 0)
            {
                ADebug.Log("PackRequestData request.pack error");
                return(false);
            }
            TalkerHead talkerHead = new TalkerHead();

            this.setFlag(ref talkerHead.bFlag, type, command.Command.Type);
            ADebug.Log(string.Concat(new object[]
            {
                "PackRequestData head flag:",
                talkerHead.bFlag,
                " commandType:",
                command.Command.Type
            }));
            this.Command                 = command;
            talkerHead.bDomain           = (byte)command.Domain;
            talkerHead.bCmdFmt           = (byte)command.Command.Type;
            talkerHead.stCommand.iIntCmd = (int)command.Command.IntegerValue;
            if (command.Command.StringValue != null)
            {
                talkerHead.stCommand.szStrCmd = Encoding.get_UTF8().GetBytes(command.Command.StringValue);
            }
            if (type == TalkerMessageType.Response)
            {
                talkerHead.dwAsync = this.AsyncFlag;
            }
            else
            {
                talkerHead.dwAsync = this.SeqNum;
            }
            ADebug.Log(string.Concat(new object[]
            {
                "PackRequestData cmd: ",
                this.Command.ToString(),
                " type:",
                type,
                " async:",
                talkerHead.dwAsync
            }));
            int num = this.calculateHeadSize(talkerHead);

            byte[] array = new byte[num];
            int    num2  = 0;

            TdrError.ErrorType errorType = talkerHead.packTLV(ref array, array.Length, ref num2, true);
            if (errorType != TdrError.ErrorType.TDR_NO_ERROR)
            {
                ADebug.Log(string.Concat(new object[]
                {
                    "PackRequestData head.pack error:",
                    errorType,
                    " usedBodySize:",
                    usedBodySize,
                    " usedHeadSize:",
                    num2,
                    " headBufflen:",
                    array.Length
                }));
                return(false);
            }
            int num3 = usedBodySize + num2;

            data = new byte[num3];
            Array.Copy(array, data, num2);
            Array.Copy(body, 0, data, num2, usedBodySize);
            this.Request = null;
            return(true);
        }