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


C# IMessage.WriteTo方法代码示例

本文整理汇总了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);
            }
        }
开发者ID:ReptileZ,项目名称:mooege,代码行数:31,代码来源:PacketOut.cs

示例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;
 }
开发者ID:R-ichardBall,项目名称:or-tools,代码行数:8,代码来源:ProtoHelper.cs

示例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);
        }
开发者ID:ktj007,项目名称:mmo,代码行数:17,代码来源:MessageSession.cs

示例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);
 }
开发者ID:C9Kamis,项目名称:PoGo-UWP,代码行数:10,代码来源:CodedOutputStream.cs

示例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);
 }
开发者ID:602p,项目名称:krpc,代码行数:12,代码来源:ProtocolBuffers.cs

示例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;
 }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:9,代码来源:EvaluationTCPChannel.cs

示例7: WriteMessageNoTag

 public void WriteMessageNoTag(IMessage value)
 {
     WriteRawVarint32((uint)value.SerializedSize);
       value.WriteTo(this);
 }
开发者ID:ayende,项目名称:dotnet-protobufs,代码行数:5,代码来源:CodedOutputStream.cs

示例8: WriteMessage

 public void WriteMessage(int fieldNumber, IMessage value)
 {
     WriteTag(fieldNumber, WireFormat.WireType.LengthDelimited);
       WriteRawVarint32((uint)value.SerializedSize);
       value.WriteTo(this);
 }
开发者ID:ayende,项目名称:dotnet-protobufs,代码行数:6,代码来源:CodedOutputStream.cs

示例9: WriteGroupNoTag

 /// <summary>
 /// Writes a group field value, without a tag, to the stream.
 /// </summary>
 public void WriteGroupNoTag(IMessage value)
 {
     value.WriteTo(this);
 }
开发者ID:ayende,项目名称:dotnet-protobufs,代码行数:7,代码来源:CodedOutputStream.cs

示例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);
 }
开发者ID:ayende,项目名称:dotnet-protobufs,代码行数:9,代码来源:CodedOutputStream.cs


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