当前位置: 首页 > news >正文

网站建设shebei谷歌 翻墙入口

网站建设shebei,谷歌 翻墙入口,设计上海展会2021,一级消防工程师考试题库及答案Protobuf 学习简记(三)Unity C#中的序列化与反序列化对文本的序列化与反序列化内存二进制流的序列化与反序列化方法一方法二参考链接对文本的序列化与反序列化 private void Text() {TestMsg1 myTestMsg new TestMsg1();myTestMsg.TestInt32 1;myTest…

Protobuf 学习简记(三)Unity C#中的序列化与反序列化

    • 对文本的序列化与反序列化
    • 内存二进制流的序列化与反序列化
      • 方法一
      • 方法二
    • 参考链接

对文本的序列化与反序列化

private void Text()
{TestMsg1 myTestMsg = new TestMsg1();myTestMsg.TestInt32 = 1;myTestMsg.ArrString.Add("wy");myTestMsg.ArrString.Add("pnb");myTestMsg.ArrString.Add("lzq");myTestMsg.Map1.Add(1, "ywj");myTestMsg.Map1.Add(2, "zzs");//序列化string path = Application.persistentDataPath + "/testMsg.msg";using (FileStream fs = new FileStream(path, FileMode.OpenOrCreate)){myTestMsg.WriteTo(fs);}//反序列化TestMsg1 newMyTestMsg;using (FileStream fs = new FileStream(path, FileMode.Open)){newMyTestMsg = TestMsg1.Parser.ParseFrom(fs);}Debug.Log(newMyTestMsg.TestInt32);Debug.Log(newMyTestMsg.ArrString);Debug.Log(newMyTestMsg.ArrString.Count);Debug.Log(newMyTestMsg.Map1[1]);Debug.Log(newMyTestMsg.Map1[2]);
}

内存二进制流的序列化与反序列化

方法一

private void Start2()
{TestMsg1 myTestMsg = new TestMsg1{TestInt32 = 1};myTestMsg.ArrString.Add("wy");myTestMsg.ArrString.Add("pnb");myTestMsg.ArrString.Add("lzq");myTestMsg.Map1.Add(1, "ywj");myTestMsg.Map1.Add(2, "zzs");//序列化byte[] buffer;using (MemoryStream ms = new MemoryStream()){myTestMsg.WriteTo(ms);buffer = ms.ToArray();}//反序列化TestMsg1 newMyTestMsg;using (MemoryStream ms = new MemoryStream(buffer)){newMyTestMsg = TestMsg1.Parser.ParseFrom(ms);}Debug.Log(newMyTestMsg.TestInt32);Debug.Log(newMyTestMsg.ArrString);Debug.Log(newMyTestMsg.ArrString.Count);Debug.Log(newMyTestMsg.Map1[1]);Debug.Log(newMyTestMsg.Map1[2]);
}

方法二

private void Start3()
{TestMsg1 myTestMsg = new TestMsg1{TestInt32 = 1};myTestMsg.ArrString.Add("wy");myTestMsg.ArrString.Add("pnb");myTestMsg.ArrString.Add("lzq");myTestMsg.Map1.Add(1, "ywj");myTestMsg.Map1.Add(2, "zzs");byte[] buffer = myTestMsg.ToByteArray();//序列化TestMsg1 newMyTestMsg = TestMsg1.Parser.ParseFrom(buffer);//反序列化1//TestMsg1 newMyTestMsg = new TestMsg1();//newMyTestMsg.MergeFrom(buffer);//反序列化2Debug.Log(newMyTestMsg.TestInt32);Debug.Log(newMyTestMsg.ArrString);Debug.Log(newMyTestMsg.ArrString.Count);Debug.Log(newMyTestMsg.Map1[1]);Debug.Log(newMyTestMsg.Map1[2]);
}

反序列化1与反序列化2都可以正常使用。

参考链接

  1. https://blog.csdn.net/zzzsss123333/article/details/125505066
  2. https://blog.csdn.net/u011723630/article/details/127464374

另外有《unity中使用protobuf-net库》的文章示例:

  1. https://www.jb51.cc/unity/3755981.html
  2. https://stackoverflow.com/questions/57714689/protobuf-net-il2cpp-system-reflection-emit-is-not-supported/57721927#57721927
http://www.zhongyajixie.com/news/9708.html

相关文章:

  • 餐饮门户网站 方案怎么做百度产品优化排名软件
  • 上海公安手机门户网站网址大全名称
  • 征婚网站上拉业务做恒指期货如何创建自己的网站
  • 东莞玩具加工东莞网站建设互联网下的网络营销
  • 北京网站建设方案策划网络营销推广方案前言
  • h5产品是什么意思关键词优化公司网站
  • 做miui主题网站天津优化代理
  • 建设工程投标文件在哪个网站有发布百度网盘下载慢怎么解决
  • 网站域名更改了怎么换海外推广方法有哪些
  • 网站进度条他妈到底怎么做网站关键词免费优化
  • 19年做网站网络广告营销方案策划内容
  • 服务器做内网网站产品策划推广方案
  • 博彩导航网站怎么做百度网络推广怎么做
  • 深圳宝安外贸网站建设公司东莞百度推广优化公司
  • 淄博网站制作设计地推推广方案
  • 永久免费的crm软件seo入门培训学多久
  • 东莞人才市场招聘信息2023seo关键词排名优化制作
  • 无为网站定制淘宝关键词排名优化技巧
  • 微信公众号微网站制作国际网站平台有哪些
  • 做淘宝要用的网站吗合肥百度网站排名优化
  • 网站注册备案之后怎么做青岛seo博客
  • 动态网站开发课程设计快速网站seo效果
  • 如何把网站做的和别人一样搜狗收录提交入口网址
  • iview可以做门户网站吗网络营销案例具体分析
  • 托管代运营关键词优化推广公司哪家好
  • 温州谷歌优化公司优化落实疫情防控新十条
  • 空滤网站怎么做投放广告的渠道有哪些
  • 怎样给网站登录界面做后台seo优化网页
  • 成都青羊区网站建设百度收录好的免费网站
  • 建湖做网站找哪家好seo自学网app