/[RomCheater]/trunk/RomCheater/Serialization/SearchResultWriter.cs
ViewVC logotype

Annotation of /trunk/RomCheater/Serialization/SearchResultWriter.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 401 - (hide annotations) (download)
Thu Jun 21 05:14:38 2012 UTC (8 years, 10 months ago) by william
File size: 2148 byte(s)
+ add serialization writer

1 william 401 using System;
2     using System.Collections.Generic;
3     using System.Linq;
4     using System.Text;
5     using System.IO;
6    
7     namespace RomCheater.Serialization
8     {
9     public interface ISearchResultWriter
10     {
11     void WriteResult<TValue>(uint address, TValue value) where TValue : IConvertible;
12     }
13     public class SearchResultWriter : SerializationWriter, ISearchResultWriter
14     {
15     public SearchResultWriter() : base() { }
16     public SearchResultWriter(int resultCount) : base(resultCount) { WriteHeader(); }
17     #region ISearchResultWriter members
18     public void WriteResult<TValue>(uint address, TValue value) where TValue : IConvertible
19     {
20    
21     Type t = typeof(TValue);
22    
23     binWriter.Write(address);
24     switch (t.Name.ToLower())
25     {
26     case "byte":
27     binWriter.Write(Convert.ToByte(value));
28     break;
29     case "sbyte":
30     binWriter.Write(Convert.ToSByte(value));
31     break;
32     case "uint16":
33     binWriter.Write(Convert.ToUInt16(value));
34     break;
35     case "int16":
36     binWriter.Write(Convert.ToInt16(value));
37     break;
38     case "uint32":
39     binWriter.Write(Convert.ToUInt32(value));
40     break;
41     case "int32":
42     binWriter.Write(Convert.ToInt32(value));
43     break;
44     case "uint64":
45     binWriter.Write(Convert.ToUInt64(value));
46     break;
47     case "int64":
48     binWriter.Write(Convert.ToInt64(value));
49     break;
50     }
51     }
52     #endregion
53    
54     private void WriteHeader()
55     {
56     // write magic: SRD
57     binWriter.Write(Encoding.UTF8.GetBytes("SRD"));
58     // write version (int)
59     binWriter.Write((int)1);
60     // write count (int)
61     binWriter.Write(ResultCount);
62     }
63     }
64     }

  ViewVC Help
Powered by ViewVC 1.1.22