Esempio n. 1
0
        public static byte[] GetReplayMetadataBytes(ReplayMetadata rpmd)
        {
            DataContractJsonSerializerSettings settings = new DataContractJsonSerializerSettings()
            {
                UseSimpleDictionaryFormat = true,
                EmitTypeInformation       = EmitTypeInformation.Never,
            };

            MemoryStream ms1 = new MemoryStream();
            DataContractJsonSerializer ser1 = new DataContractJsonSerializer(typeof(List <PlayerStats>), settings);

            ser1.WriteObject(ms1, rpmd.playerStats);
            ms1.Position = 0;
            StreamReader sr1   = new StreamReader(ms1);
            String       json1 = sr1.ReadToEnd();

            rpmd.statsJson = json1;

            MemoryStream ms = new MemoryStream();
            DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(ReplayMetadata), settings);

            ser.WriteObject(ms, rpmd);
            ms.Position = 0;
            StreamReader sr   = new StreamReader(ms);
            String       json = sr.ReadToEnd();

            return(Encoding.UTF8.GetBytes(json));
        }
Esempio n. 2
0
        public void Save(BinaryWriter _writer)
        {
            m_rawmetadata = ReplayMetadata.GetReplayMetadataBytes(m_metadata);
            int offsetDifference = m_rawmetadata.Length - m_metadataLength;

            m_metadataLength       = m_rawmetadata.Length;
            m_payloadHeaderOffset += offsetDifference;
            m_payloadOffset       += offsetDifference;

            _writer.Write(m_magic);
            _writer.Write(m_signature);
            _writer.Write(m_headerLength);
            _writer.Write(m_fileLength);
            _writer.Write(m_metadataOffset);
            _writer.Write(m_metadataLength);
            _writer.Write(m_payloadHeaderOffset);
            _writer.Write(m_payloadHeaderLength);
            _writer.Write(m_payloadOffset);
            _writer.Write(m_rawmetadata);
        }
Esempio n. 3
0
        public ReplayHeader(Stream p_stream)
        {
            using (BinaryReader r = new BinaryReader(p_stream, Encoding.UTF8, true))
            {
                // the magic byte identifiers
                m_magic = r.ReadBytes(6);

                // file hash
                m_signature = r.ReadBytes(256);

                // various lengths and offsets
                m_headerLength        = r.ReadInt16();
                m_fileLength          = r.ReadInt32();
                m_metadataOffset      = r.ReadInt32();
                m_metadataLength      = r.ReadInt32();
                m_payloadHeaderOffset = r.ReadInt32();
                m_payloadHeaderLength = r.ReadInt32();
                m_payloadOffset       = r.ReadInt32();

                // json metadata
                m_rawmetadata = r.ReadBytes(m_metadataLength);
                m_metadata    = ReplayMetadata.Deserialize(m_rawmetadata);
            }
        }