本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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();
}
}
示例5: SendMessageAsync
/// <inheritdoc />
public async Task SendMessageAsync(IMessage message, CancellationToken cancellationToken)
{
await this.WriteMessageAsync(this.messageFactory.GetMessageType(message), message.ToByteArray(), cancellationToken).ConfigureAwait(false);
}