using System; using System.IO; using System.Runtime.Serialization; using System.Runtime.Serialization.Formatters.Binary; namespace Dscf.Global.Utils { public class ObjectUtils { /// <summary> /// 对像转成 byte 数组 /// <…
This sample shows how to turn object to byte[], as well as turn byte[] to object. So,I can turn any types of object into byte[],which can be saved and transported properly. Attention!Attention!Attention!(Important things should be repeated three time…
相比于encoding, 使用unsafe性能更高 type MyStruct struct { A int B int } var sizeOfMyStruct = int(unsafe.Sizeof(MyStruct{})) func MyStructToBytes(s *MyStruct) []byte { var x reflect.SliceHeader x.Len = sizeOfMyStruct x.Cap = sizeOfMyStruct x.Data = uintptr(uns…