本文整理汇总了C#中IMessage.WriteTo方法的典型用法代码示例。如果您正苦于以下问题:C# IMessage.WriteTo方法的具体用法?C# IMessage.WriteTo怎么用?C# IMessage.WriteTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IMessage
的用法示例。
在下文中一共展示了IMessage.WriteTo方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PacketOut
public PacketOut(byte serviceId, uint methodId, uint token, ulong objectId, IMessage message)
{
var builder = bnet.protocol.Header.CreateBuilder()
.SetServiceId(serviceId)
.SetToken(token) // requestId.
.SetSize((uint)message.SerializedSize);
if (serviceId != MooNetRouter.ServiceReply)
builder.SetMethodId(methodId);
if (serviceId != MooNetRouter.ServiceReply && objectId != 0x0)
builder.SetObjectId(objectId);
var header = builder.Build();
var headerSize = (short)(header.SerializedSize);
using (var stream = new MemoryStream())
{
var output = CodedOutputStream.CreateInstance(stream);
output.WriteRawByte((byte)(headerSize >> 8));
output.WriteRawByte((byte)((headerSize & 0xff)));
header.WriteTo(output);
message.WriteTo(output);
output.Flush();
this.Data = stream.ToArray();
Logger.LogOutgoing(message, header);
}
}
示例2: ProtoToByteArray
public static byte[] ProtoToByteArray(IMessage message)
{
int size = message.CalculateSize();
byte[] buffer = new byte[size];
CodedOutputStream output = new CodedOutputStream(buffer);
message.WriteTo(output);
return buffer;
}
示例3: Send
public void Send(IMessage message)
{
byte[] messageBytes;
using (var memoryStream = new MemoryStream())
{
using (var memoryWriter = new BinaryWriter(memoryStream))
{
memoryWriter.Write(0); // for writing message-length
message.WriteTo(memoryWriter);
messageBytes = memoryStream.ToArray();
}
}
var lengthBytes = BitConverter.GetBytes(messageBytes.Length);
Array.Copy(lengthBytes, messageBytes, lengthBytes.Length);
Send(messageBytes);
}
示例4: WriteMessage
/// <summary>
/// Writes a message, without a tag, to the stream.
/// The data is length-prefixed.
/// </summary>
/// <param name="value">The value to write</param>
public void WriteMessage(IMessage value)
{
WriteLength(value.CalculateSize());
value.WriteTo(this);
}
示例5: WriteMessage
/// <summary>
/// Convert a Protocol Buffer message to a byte string.
/// </summary>
public static ByteString WriteMessage(IMessage message)
{
byte[] returnBytes;
using (var stream = new MemoryStream ()) {
message.WriteTo (stream);
returnBytes = stream.ToArray ();
}
return ByteString.CopyFrom (returnBytes);
}
示例6: EncodeDelimited
private byte[] EncodeDelimited(IMessage message) {
int messageSize = message.SerializedSize;
int headerSize = GetVarint32EncodedSize(messageSize);
byte[] buffer = new byte[headerSize + messageSize];
CodedOutputStream tmp = CodedOutputStream.CreateInstance(buffer);
tmp.WriteRawVarint32((uint)messageSize);
message.WriteTo(tmp);
return buffer;
}
示例7: WriteMessageNoTag
public void WriteMessageNoTag(IMessage value)
{
WriteRawVarint32((uint)value.SerializedSize);
value.WriteTo(this);
}
示例8: WriteMessage
public void WriteMessage(int fieldNumber, IMessage value)
{
WriteTag(fieldNumber, WireFormat.WireType.LengthDelimited);
WriteRawVarint32((uint)value.SerializedSize);
value.WriteTo(this);
}
示例9: WriteGroupNoTag
/// <summary>
/// Writes a group field value, without a tag, to the stream.
/// </summary>
public void WriteGroupNoTag(IMessage value)
{
value.WriteTo(this);
}
示例10: WriteGroup
/// <summary>
/// Writes a group field value, including tag, to the stream.
/// </summary>
public void WriteGroup(int fieldNumber, IMessage value)
{
WriteTag(fieldNumber, WireFormat.WireType.StartGroup);
value.WriteTo(this);
WriteTag(fieldNumber, WireFormat.WireType.EndGroup);
}