private static Common.ObjectList DecodeList(ReadOnlyDatagram datagram) { var r = new Common.ObjectList(); uint count = 0; datagram.ReadUInt(out count, 8); byte[] temp = new byte[4]; for (int i = 0; i < count; ++i) { uint typeCode = 0; datagram.ReadUInt(out typeCode, 8); switch ((ScriptTypes)typeCode) { case ScriptTypes.List: r.Add(DecodeList(datagram)); break; case ScriptTypes.String: { String s; datagram.ReadString(out s); r.Add(s); } break; case ScriptTypes.Int32: datagram.ReadBytes(temp, 4); r.Add(BitConverter.ToInt32(temp, 0)); break; case ScriptTypes.UInt32: datagram.ReadBytes(temp, 4); r.Add(BitConverter.ToUInt32(temp, 0)); break; case ScriptTypes.Single: datagram.ReadBytes(temp, 4); r.Add(BitConverter.ToSingle(temp, 0)); break; case ScriptTypes.Bool: { uint b = 0; datagram.ReadUInt(out b, 8); if (b == 0) r.Add(null); else r.Add(true); } break; default: throw new InvalidProgramException("Error decoding message", null); } } return r; }
private static Common.ObjectList DecodeList(ReadOnlyDatagram datagram) { var r = new Common.ObjectList(); uint count = 0; datagram.ReadUInt(out count, 8); byte[] temp = new byte[4]; for (int i = 0; i < count; ++i) { uint typeCode = 0; datagram.ReadUInt(out typeCode, 8); switch ((ScriptTypes)typeCode) { case ScriptTypes.List: r.Add(DecodeList(datagram)); break; case ScriptTypes.String: { String s; datagram.ReadString(out s); r.Add(s); } break; case ScriptTypes.Int32: datagram.ReadBytes(temp, 4); r.Add(BitConverter.ToInt32(temp, 0)); break; case ScriptTypes.UInt32: datagram.ReadBytes(temp, 4); r.Add(BitConverter.ToUInt32(temp, 0)); break; case ScriptTypes.Single: datagram.ReadBytes(temp, 4); r.Add(BitConverter.ToSingle(temp, 0)); break; case ScriptTypes.Bool: { uint b = 0; datagram.ReadUInt(out b, 8); if (b == 0) { r.Add(null); } else { r.Add(true); } } break; default: throw new InvalidProgramException("Error decoding message", null); } } return(r); }