byte to object and object to byte
2015-07-06 14:40
302 查看
public
byte[] Serialize()
{
var bf = newBinaryFormatter();
using (var ms = newMemoryStream())
{
using (var ds = newDeflateStream(ms, CompressionMode.Compress, true))
{
bf.Serialize(ds,
this);
}
return ms.ToArray();
}
}
publicstaticMiniPCMessage Deserialize(byte[] data, int offset, int count)
{
MiniPCMessage msg;
var formatter = newBinaryFormatter();
using (var ms = newMemoryStream(data, offset, count))
{
using (var ds = newDeflateStream(ms, CompressionMode.Decompress, true))
{
msg = formatter.Deserialize(ds)
asMiniPCMessage;
}
}
return msg;
}
byte[] Serialize()
{
var bf = newBinaryFormatter();
using (var ms = newMemoryStream())
{
using (var ds = newDeflateStream(ms, CompressionMode.Compress, true))
{
bf.Serialize(ds,
this);
}
return ms.ToArray();
}
}
publicstaticMiniPCMessage Deserialize(byte[] data, int offset, int count)
{
MiniPCMessage msg;
var formatter = newBinaryFormatter();
using (var ms = newMemoryStream(data, offset, count))
{
using (var ds = newDeflateStream(ms, CompressionMode.Decompress, true))
{
msg = formatter.Deserialize(ds)
asMiniPCMessage;
}
}
return msg;
}
相关文章推荐
- Objective-C语法之NSString与int和float的相互转换
- Objective-C Runtime中的并发内存分配
- html之object标签的classid收集
- IOS中的关联对象实现objc_setAssociatedObject
- Exception AttributeError: "'NoneType' object has no attribute错误
- (Java 功能代码)java去除List中重复数据之Object对象
- 介绍一下Objective-c常用的函数,常数变量
- [Objective-C] 不建议使用点语法糖
- [Objective-C] NSArray/NSDictionary/NSNumber 的语法糖
- [学习笔记—Objective-C]《Objective-C 程序设计 第6版》第十章 变量和数据类型
- [学习笔记—Objective-C]《Objective-C 程序设计 第6版》第九章 多态,动态类型和动态绑定
- object - c 坐标系统
- [Objective-C] 011_数据持久化_NSKeyedArchiver
- [Objective-C] 010_Foundation框架之NSSet与NSMutableSet
- Objective-C----打印 %
- Objective-C 中的BOOL ---未完成待续
- [Jackson] 使用ObjectMapper对含有任意key的JSON进行反序列化
- spring webservice 搭建出现的异常处理。异常: NAMESPACE_ERR: An attempt is made to create or change an object in a way whi
- WMI和ManagementObjectSearcher一些使用
- Objective-C(十三、字典类)——iOS开发基础