private ArrayData(ByteBuffer buffer, Type fieldType) { using (SafeUnwrapByteBuffer unwrap = SafeUnwrapByteBuffer.Get(buffer, this.GetError)) { this.serverType = fieldType; this.originLength = buffer.ReadInt32(); if (this.originLength == -1) { this.isNull = true; } else { this.isBigArray = buffer.ReadBoolean(); if (this.isBigArray == false) { string typeHandlerType = buffer.ReadUnicodeString(); if (string.IsNullOrEmpty(typeHandlerType) == false) { TypeHandler subHandler = TypeHandlersManager.GetTypeHandler(typeHandlerType); if (subHandler != null) { TypeSignature typeSignature = (TypeSignature)buffer.ReadByte(); if (typeSignature != TypeSignature.Null) { Type subType = TypeHandlersManager.GetClientType(this.serverType, typeSignature); this.array = Array.CreateInstance(subHandler.type, this.originLength); for (int i = 0; i < this.originLength; i++) { try { this.array.SetValue(subHandler.Deserialize(buffer, subType), i); } catch (Exception ex) { InternalNGDebug.LogException("Array of type " + fieldType.Name + " (" + subType + ") at " + i + " failed.", ex); throw; } } } } else // Client does not know how to deserialize the element. { unwrap.ForceFallback(); } } } } } }
private NetField(ByteBuffer buffer) { using (SafeUnwrapByteBuffer unwrap = SafeUnwrapByteBuffer.Get(buffer, this.GetError)) { this.fieldType = Type.GetType(buffer.ReadUnicodeString()); this.name = buffer.ReadUnicodeString(); this.isPublic = buffer.ReadBoolean(); string typeHandlerType = buffer.ReadUnicodeString(); if (string.IsNullOrEmpty(typeHandlerType) == false) { this.handler = TypeHandlersManager.GetTypeHandler(typeHandlerType); if (this.handler != null) { this.typeSignature = (TypeSignature)buffer.ReadByte(); this.fieldType = this.fieldType ?? TypeHandlersManager.GetClientType(this.handler.type, this.typeSignature); if (this.typeSignature != TypeSignature.Null) { try { this.value = this.handler.Deserialize(buffer, this.fieldType ?? TypeHandlersManager.GetClientType(this.handler.type, this.typeSignature)); } catch (Exception ex) { InternalNGDebug.LogException("Member \"" + this.name + "\" of type \"" + this.fieldType + "\" failed.", ex); throw; } } } else // Client does not know how to deserialize this field. { unwrap.ForceFallback(); } } } }
public static Type GetClientType(Type type) { return(TypeHandlersManager.GetClientType(type, TypeHandlersManager.GetTypeSignature(type))); }