Last active
August 29, 2015 14:03
-
-
Save jzebedee/cff3a1e00669364821fd to your computer and use it in GitHub Desktop.
Talkin' bout ESP structure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Record : IEnumerable<Record> { | |
public byte[] ID; | |
public uint Size; | |
private List<Record> _children = new List(); | |
public Record(some data source) { | |
ID = read ID; | |
Size = read Size; | |
_children = read children; | |
} | |
} | |
class SomeTypeOfRecord : Record { | |
public object SomeTypeOfRecordSpecificData; | |
public SomeTypeOfRecord(some data source) : base(some data source) { | |
//the call to base has already executed, so now we have ID, Size, and _children set | |
//you can set SomeTypeOfRecordSpecificData either by serializing it yourself: | |
//e.g., a bunch of Read() and Write() calls from a data source | |
SomeTypeOfRecordSpecificData = new ExampleDataCustom(some data source, "idk"); | |
//or by setting up a data class with decorators to make a data contract | |
SomeTypeOfRecordSpecificData = SomeContractSerializer.Deserialize<ExampleDataContract>(some data source); | |
} | |
//see? now we apply that same principle to record: | |
//either decorate it with a contract, or put in a ctor + Write() | |
//to handle custom serialization | |
} | |
[SomeContractType] | |
class ExampleDataContract { | |
[SomeSerializeAttribute] | |
public uint SomeMember; | |
[SomeIgnoreAttribute] | |
public string SomeOtherJunk; | |
} | |
class ExampleDataCustom { | |
public uint SomeMember; | |
public string SomeOtherJunk; | |
public ExampleDataCustom(some data source, string otherJunk) { | |
SomeMember = (some data source).ReadUint(); | |
SomeOtherJunk = otherJunk; | |
} | |
public void Write(some data source) { | |
(some data source).WriteUint(SomeMember); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment