using System.Collections.Generic;
using LeanCloud.Storage;
namespace LeanCloud.Realtime {
///
/// 图像消息
///
public class LCIMImageMessage : LCIMFileMessage {
///
/// 图像宽度
///
public int Width {
get; private set;
}
///
/// 图像高度
///
public int Height {
get; private set;
}
internal LCIMImageMessage() : base() {
}
public LCIMImageMessage(LCFile file) : base(file) {
}
internal override Dictionary Encode() {
Dictionary data = base.Encode();
Dictionary fileData = data[MessageFileKey] as Dictionary;
Dictionary metaData = fileData[MessageDataMetaDataKey] as Dictionary;
if (File.MetaData != null) {
if (File.MetaData.TryGetValue(MessageDataMetaWidthKey, out object width)) {
metaData[MessageDataMetaWidthKey] = width;
}
if (File.MetaData.TryGetValue(MessageDataMetaHeightKey, out object height)) {
metaData[MessageDataMetaHeightKey] = height;
}
}
return data;
}
internal override void Decode(Dictionary msgData) {
base.Decode(msgData);
if (File.MetaData == null) {
return;
}
if (File.MetaData.TryGetValue(MessageDataMetaWidthKey, out object width) &&
int.TryParse(width as string, out int w)) {
Width = w;
}
if (File.MetaData.TryGetValue(MessageDataMetaHeightKey, out object height) &&
int.TryParse(height as string, out int h)) {
Height = h;
}
}
public override int MessageType => ImageMessageType;
}
}