标签:input puts cos 分享 flush build bug color hone
1 PersonMessage.Builder personBuilder = PersonMessage.CreateBuilder(); 2 personBuilder.Id = 123; 3 personBuilder.Age = 33; 4 personBuilder.Sex = PersonMessage.Types.Sex.Male; 5 personBuilder.Name = "protobuf"; 6 personBuilder.Phone = "1333333333"; 7 var person = personBuilder.Build(); 8 // 序列化到文件 9 using (var stream = File.Create("person.bin")) 10 { 11 CodedOutputStream cos = CodedOutputStream.CreateInstance(stream); 12 person.WriteTo(cos); 13 cos.Flush(); 14 } 15 16 // 从文件反序列化到对象 17 using (var stream = File.OpenRead("person.bin")) 18 { 19 CodedInputStream cis = CodedInputStream.CreateInstance(stream); 20 PersonMessage pm = PersonMessage.ParseFrom(cis); 21 Debug.Log("从person.bin反序列化到对象:"); 22 Debug.LogFormat("person‘s name:{0}, person‘s age:{1}, person‘s phone:{2}", pm.Name, pm.Age, pm.Phone); 23 }
查看生成的person.bin
在Unity3d中使用Google.ProtocolBuffers
标签:input puts cos 分享 flush build bug color hone
原文地址:http://www.cnblogs.com/linxmouse/p/7906362.html