コード例 #1
0
ファイル: ObjectDeserializer.cs プロジェクト: Blecki/BMud
 internal static Object DeserializeObject(ReadOnlyDatagram datagram, SerializerState state, Database database)
 {
     uint rawTypeCode = 0;
     if (!datagram.ReadUInt(out rawTypeCode, 8)) throw new DeserializeError();
     switch ((SerializedTypeCode)rawTypeCode)
     {
         case SerializedTypeCode.Null:
             return null;
         case SerializedTypeCode.Integer:
             {
                 uint value = 0;
                 if (!datagram.ReadUInt(out value, 32)) throw new DeserializeError();
                 return (int)value;
             }
         case SerializedTypeCode.String:
             {
                 String value = "";
                 if (!datagram.ReadString(out value)) throw new DeserializeError();
                 return value;
             }
         case SerializedTypeCode.List:
             {
                 uint length = 0;
                 if (!datagram.ReadUInt(out length, 16)) throw new DeserializeError();
                 var result = new MISP.ScriptList();
                 for (int i = 0; i < length; ++i)
                     result.Add(DeserializeObject(datagram, state, database));
                 return result;
             }
         case SerializedTypeCode.InternalObject:
             return state.ReadObject(datagram, SerializedTypeCode.InternalObject, database);
         case SerializedTypeCode.NamedObject:
             return state.ReadObject(datagram, SerializedTypeCode.NamedObject, database);
         default:
             throw new DeserializeError();
     }
 }