So proto-buf is a no go. It requires you tag everything with [ProtoMember(n)] and I’m pretty sure it doesn’t work the way the built-in .NET binaryformatter works. I know for a fact that the built-in binary serialization handles private members automatically. None of the other serialization routines work that way.
There are only two places where the code is significantly different in the WinRT version of FyreVM: The InitOpcodeDict() routine required changes for WinRT:
Old Version:
private void InitOpcodeDict()
{
MethodInfo[] methods = typeof(Engine).GetMethods(BindingFlags.NonPublic | BindingFlags.Instance);
foreach (MethodInfo mi in methods)
{
object[] attrs = mi.GetCustomAttributes(typeof(OpcodeAttribute), false);
if (attrs.Length > 0)
{
OpcodeAttribute attr = (OpcodeAttribute)(attrs[0]);
Delegate handler = Delegate.CreateDelegate(typeof(OpcodeHandler), this, mi);
opcodeDict.Add(attr.Number, new Opcode(attr, (OpcodeHandler)handler));
}
}
WinRT Version:
private void InitOpcodeDict()
{
List<MethodInfo> methods = typeof(Engine).GetRuntimeMethods().Where<MethodInfo>(info => !info.IsStatic && !info.IsPublic).ToList<MethodInfo>();
foreach (MethodInfo mi in methods)
{
List<Attribute> attrs = mi.GetCustomAttributes(typeof(OpcodeAttribute), false).ToList<Attribute>();
if (attrs.Count > 0)
{
OpcodeAttribute attr = (OpcodeAttribute)(attrs[0]);
Delegate handler = mi.CreateDelegate(typeof(OpcodeHandler), this);
opcodeDict.Add(attr.Number, new Opcode(attr, (OpcodeHandler)handler));
}
}
}
…and the WriteToStream() routine in the Quetzal class:
[code] public void WriteToStream(Stream stream)
{
BigEndian.WriteInt32(stream, FORM); // IFF tag
BigEndian.WriteInt32(stream, 0); // file length (filled in later)
BigEndian.WriteInt32(stream, IFZS); // FORM sub-ID for Quetzal
uint totalSize = 4; // includes sub-ID
foreach (KeyValuePair<uint, byte[]> pair in chunks)
{
BigEndian.WriteInt32(stream, pair.Key); // chunk type
BigEndian.WriteInt32(stream, (uint)pair.Value.Length); // chunk length
stream.Write(pair.Value, 0, pair.Value.Length); // chunk data
totalSize += 8 + (uint)(pair.Value.Length);
}
if (totalSize % 2 == 1)
stream.WriteByte(0); // padding (not counted in file length)
stream.Seek(4, SeekOrigin.Begin);
BigEndian.WriteInt32(stream, totalSize);
//stream.SetLength(totalSize);
}
[/code]
Note the commented line at the end there. That is not commented out in the non-WinRT version of FyreVM.
I can’t explain the infinite loop.
David C.
www.textfyre.com