当前位置: 首页>>代码示例>>C#>>正文


C# IMessage.ToByteArray方法代码示例

本文整理汇总了C#中IMessage.ToByteArray方法的典型用法代码示例。如果您正苦于以下问题:C# IMessage.ToByteArray方法的具体用法?C# IMessage.ToByteArray怎么用?C# IMessage.ToByteArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IMessage的用法示例。


在下文中一共展示了IMessage.ToByteArray方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SendResponse

        private static void SendResponse(IClient client, int requestId, IMessage message)
        {
            var packet = new Packet(
                new Header(0xfe, 0x0, requestId, (uint)message.SerializedSize),
                message.ToByteArray());

            client.Send(packet);
        }
开发者ID:superk,项目名称:d3sharp,代码行数:8,代码来源:PacketRouter.cs

示例2: CallMethod

        public void CallMethod(MethodDescriptor method, IRpcController controller, IMessage request, IMessage responsePrototype, Action<IMessage> done, ulong objectId)
        {
            var serviceName = method.Service.FullName;
            var serviceHash = StringHashHelper.HashString(serviceName);

            if (!this.Services.ContainsKey(serviceHash))
            {
                Logger.Error("Not bound to client service {0} [0x{1}] yet.", serviceName, serviceHash.ToString("X8"));
                return;
            }

            var serviceId = this.Services[serviceHash];
            var packet = new Packet(
                new Header((byte)serviceId, (uint)(method.Index + 1), this._requestCounter++, (uint)request.SerializedSize, objectId),
                request.ToByteArray());

            this.Send(packet);
        }
开发者ID:xynoman,项目名称:d3sharp,代码行数:18,代码来源:Client.cs

示例3: CallMethod

        public void CallMethod(MethodDescriptor method, IMessage request, ulong localObjectId)
        {
            var serviceName = method.Service.FullName;
            var serviceHash = StringHashHelper.HashIdentity(serviceName);

            if (!this.Services.ContainsKey(serviceHash))
            {
                Logger.Error("Not bound to client service {0} [0x{1}] yet.", serviceName, serviceHash.ToString("X8"));
                return;
            }

            var serviceId = this.Services[serviceHash];
            var remoteObjectId = GetRemoteObjectID(localObjectId);

            Logger.Debug("Calling {0} localObjectId={1}, remoteObjectId={2}", method.FullName, localObjectId, remoteObjectId);

            var packet = new BNetPacket(
                new BNetHeader((byte)serviceId, (uint)(method.Index + 1), this._requestCounter++, (uint)request.SerializedSize, remoteObjectId),
                request.ToByteArray());

            this.Connection.Send(packet);
        }
开发者ID:Yshayy,项目名称:d3sharp,代码行数:22,代码来源:BNetClient.cs

示例4: Send

        public async Task Send(IMessage message, BnetServiceHash serviceHash = BnetServiceHash.None, uint methodId = 0)
        {
            await tlsSemaphore.WaitAsync();

            try
            {
                var messageData = message.ToByteArray();
                var header = new Header
                {
                    Token = messageToken++,
                    ServiceId = 0xFE,
                    Size = (uint)messageData.Length
                };

                if (serviceHash != BnetServiceHash.None)
                {
                    header.ServiceId = 0;
                    header.ServiceHash = (uint)serviceHash;
                    header.MethodId = methodId;
                }

                var headerData = header.ToByteArray();
                var packetData = new byte[2 + headerData.Length + messageData.Length];

                packetData[0] = (byte)(headerData.Length >> 8);
                packetData[1] = (byte)(headerData.Length & 0xFF);

                Buffer.BlockCopy(headerData, 0, packetData, 2, headerData.Length);
                Buffer.BlockCopy(messageData, 0, packetData, 2 + headerData.Length, messageData.Length);

                await tlsStream.WriteAsync(packetData, 0, packetData.Length);
            }
            finally
            {
                // Always release the semaphore to prevent a permanent wait/lock of it.
                tlsSemaphore.Release();
            }
        }
开发者ID:Arctium-Emulation,项目名称:Project-WoW,代码行数:38,代码来源:BnetSession.cs

示例5: SendMessageAsync

 /// <inheritdoc />
 public async Task SendMessageAsync(IMessage message, CancellationToken cancellationToken)
 {
     await this.WriteMessageAsync(this.messageFactory.GetMessageType(message), message.ToByteArray(), cancellationToken).ConfigureAwait(false);
 }
开发者ID:sshipsey,项目名称:Mumble.NET,代码行数:5,代码来源:Connection.cs


注:本文中的IMessage.ToByteArray方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。