c# - Deserializing a different List with protobuf-net -
i have problem deserialization protobuf-net. serialize list<> when deserialize list<> returned not identical first. there missing data. not understand why.
i initialize list<> in ctr
public ctr() { datetime date = new datetime(2012 , 12, 03); ; lkvisiteuriddto visitid= new lkvisiteuriddto(10, 11, 12); purgedatetimedto datetime= new purgedatetimedto(date, true); contractprotobuf proto = new contractprotobuf(); (int = 0; < 5; i++) { proto.m_index = + 1; proto.m_technicalkey = "m_technicalkey" + i; proto.m_logicalkey = visitid; proto.m_purgetime = datetime; protocontractlist.add(proto); } } public byte[] serialization() { memorystream ms = new memorystream(); try { serializer.serialize(ms, protocontractlist); arr = ms.toarray(); return arr; } catch { console.writeline("la sérialisation protobuf échoué"); return null; } { ms.close(); } } public list<contractprotobuf> deserialization() { memorystream ms = new memorystream(arr,false); try { listeretour = serializer.deserialize<list<contractprotobuf>>(ms); return (listeretour); } catch (exception e) { console.writeline("la désérialisation protobuf échoué"); return null; } { ms.close(); } } so question how have same result ?
here structure
[protocontract] public struct contractprotobuf { [protomember(1)] public int m_index; [protomember(2)] public string m_technicalkey; [protomember(3)] public lkvisiteuriddto m_logicalkey; [protomember(4)] public purgedatetimedto m_purgetime; } i create list of contractprotobuf , add data values "that not have consequence."
public ctr() { datetime date = new datetime(2012 , 12, 03); ; (int = 0; < 5; i++) { lkvisiteuriddto visitid= new lkvisiteuriddto(10, 11, 12); purgedatetimedto datetime= new purgedatetimedto(date, true); contractprotobuf proto = new contractprotobuf(); proto.m_index = + 1; proto.m_technicalkey = "m_technicalkey" + i; proto.m_logicalkey = visitid; proto.m_purgetime = datetime; protocontractlist.add(proto); } }
i serialize list gets byte [] , when deserialize byte [], return list not contain same values in type purgedatetimedto , lkvisiteuriddto .
in return list find datetime {01/01/0001 0:00:00} , visitid {0,0,0} m.index , m_technicalkey have value
you don't show dtos, if assume contractprotobuf class, adding same instance each time. equally, adding same visit each time. normally, expect these different, example:
public ctr() { datetime date = new datetime(2012 , 12, 03); ; (int = 0; < 5; i++) { lkvisiteuriddto visitid= new lkvisiteuriddto(10, 11, 12); purgedatetimedto datetime= new purgedatetimedto(date, true); contractprotobuf proto = new contractprotobuf(); proto.m_index = + 1; proto.m_technicalkey = "m_technicalkey" + i; proto.m_logicalkey = visitid; proto.m_purgetime = datetime; protocontractlist.add(proto); } } but - impossible sure without more information. if can provide complete (i.e. runnable) example, i'll happy further.
Comments
Post a Comment