public void FromStringEx(string str) { int index = str.IndexOf('|'); Type = (EOnlineKeyValuePairDataType)int.Parse(str.Substring(0, index)); str = str.Substring(index + 1); switch (Type) { case EOnlineKeyValuePairDataType.Blob: string[] splitted = str.Split(','); byte[] buffer = new byte[splitted.Length]; for (int j = 0; j < splitted.Length; j++) { buffer[j] = byte.Parse(splitted[j]); } SetValue(buffer); break; default: FromString(str); break; } }
/// <summary> /// Copies the data and sets the type /// </summary> /// <param name="data">The new data to assign</param> public unsafe void SetValue(byte[] data) { Type = EOnlineKeyValuePairDataType.Blob; Data = new byte[data.Length]; Buffer.BlockCopy(data, 0, Data, 0, data.Length); }
/// <summary> /// Copies the data and sets the type /// </summary> /// <param name="data">The new data to assign</param> public void SetValue(float data) { Type = EOnlineKeyValuePairDataType.Float; Data = BitConverter.GetBytes(data); }
/// <summary> /// Copies the data and sets the type /// </summary> /// <param name="data">The new data to assign</param> public void SetValue(double data) { Type = EOnlineKeyValuePairDataType.Double; Data = BitConverter.GetBytes(data); }
/// <summary> /// Copies the data and sets the type /// </summary> /// <param name="data">The new data to assign</param> public void SetValue(bool data) { Type = EOnlineKeyValuePairDataType.Bool; Data = BitConverter.GetBytes(data); }
/// <summary> /// Copies the data and sets the type /// </summary> /// <param name="data">The new data to assign</param> public void SetValue(uint data) { Type = EOnlineKeyValuePairDataType.UInt32; Data = BitConverter.GetBytes(data); }
/// <summary> /// Copies the data and sets the type /// </summary> /// <param name="data">The new data to assign</param> public void SetValue(string data) { Type = EOnlineKeyValuePairDataType.String; Data = Encoding.Unicode.GetBytes(data); }
/// <summary> /// Cleans up the existing data and sets the type to Empty /// </summary> public void Empty() { Type = EOnlineKeyValuePairDataType.Empty; Data = null; }
/// <summary> /// Copies the data and sets the type /// </summary> /// <param name="data">The new data to assign</param> public void SetJsonValueFromString(string data) { Type = EOnlineKeyValuePairDataType.Json; Data = Encoding.Unicode.GetBytes(data); }
/// <summary> /// Copies the data and sets the type /// </summary> /// <param name="data">The new data to assign</param> public void SetValue(long data) { Type = EOnlineKeyValuePairDataType.Int64; Data = BitConverter.GetBytes(data); }