public byte[] Serialize()
        {
            using (MemoryStream stream = new MemoryStream())
                using (BinaryWriter writer = new BinaryWriter(stream))
                {
                    if (Protobuf)
                    {
                        writer.Write(MessageTypeUtils.MergeMessage((uint)MessageType, Protobuf));
                        using (MemoryStream protoStream = new MemoryStream())
                        {
                            Serializer.Serialize(protoStream, (Header as GameCoordinatorProtobufHeader));
                            writer.Write((uint)protoStream.Length);
                            writer.Write(protoStream.ToArray());
                        }
                    }
                    else
                    {
                        writer.Write((ushort)1);
                        writer.Write(SteamGid.Invalid);
                        writer.Write(Header.JobId);
                    }

                    writer.Write(_body.Serialize());
                    return(stream.ToArray());
                }
        }
Exemple #2
0
 /// <summary>
 /// Serializes this message as a byte array and optionally positions the job ID in the header as though we are a server
 /// </summary>
 /// <param name="server"></param>
 /// <returns></returns>
 public byte[] Serialize(bool server)
 {
     using (MemoryStream stream = new MemoryStream())
         using (BinaryWriter writer = new BinaryWriter(stream))
         {
             writer.Write(MessageTypeUtils.MergeMessage(MessageType, Protobuf));
             if (Header is ProtobufClientHeader head)
             {
                 using (MemoryStream protoStream = new MemoryStream())
                 {
                     Serializer.Serialize(protoStream, (Header as ProtobufClientHeader).CreateProtobuf(server));
                     byte[] content = protoStream.ToArray();
                     writer.Write(content.Length);
                     writer.Write(content);
                 }
             }
             else if (Header is ClientHeader extended)
             {
                 writer.Write((byte)36);
                 writer.Write((ushort)2);
                 writer.Write(server ? SteamGid.Invalid : extended.JobId);
                 writer.Write(server ? extended.JobId : SteamGid.Invalid);
                 writer.Write((byte)239);
                 writer.Write(extended.SteamId);
                 writer.Write(extended.SessionId);
             }
             else
             {
                 writer.Write(server ? SteamGid.Invalid : Header.JobId);
                 writer.Write(server ? Header.JobId : SteamGid.Invalid);
             }
             writer.Write(_body.Serialize());
             return(stream.ToArray());
         }
 }
 protected internal async Task SendAsync(GameCoordinatorMessageType messageType, bool protobuf, byte[] data)
 {
     await SendAsync(NetworkMessage
                     .CreateAppRoutedMessage(MessageType.ClientToGC,
                                             new CMsgGCClient
     {
         appid   = (uint)AppId,
         msgtype = MessageTypeUtils.MergeMessage((uint)messageType, protobuf),
         payload = data
     },
                                             AppId));
 }