I'm currently doing a POC to prove that Protobuf-net is faster than the native C# serializer. But I'm experiencing a bug? on the serialize response.
Here is the Error
nativeResult
<?xml version="1.0"?>
<userInformation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<age>22</age>
<education>Cavite State University</education>
<name>Ronald Estacion</name>
<address>
<city>Cavite</city>
<country>PH</country>
<street>Torjak Street</street>
<subd>Yari ka ngayon</subd>
</address>
</userInformation>
protoresult
Here is my code.
var nativeSerializer = new XmlSerializer(typeof(UserInformation));
var nativeStream = new MemoryStream();
var protoStream = new MemoryStream();
nativeSerializer.Serialize(nativeStream, CreateDetaulUserInformation());
var nativeResult = Encoding.UTF8.GetString(nativeStream.ToArray());
Serializer.Serialize(protoStream, CreateDetaulUserInformation());
var protoResult = Encoding.UTF8.GetString(protoStream.ToArray());
Here is the UserInformation object.
//[ProtoContract]
[XmlType("address")]
public class Address
{
//[ProtoMember(1)]
[XmlElement("city", Order = 1)]
public string City { get; set; }
//[ProtoMember(2)]
[XmlElement("country", Order = 2)]
public string Country { get; set; }
//[ProtoMember(3)]
[XmlElement("street", Order = 3)]
public string Street { get; set; }
//[ProtoMember(4)]
[XmlElement("subd", Order = 4)]
public string Subdivision { get; set; }
}
//[ProtoContract]
[XmlType("userInformation")]
public class UserInformation
{
//[ProtoMember(1)]
[XmlElement("age", Order = 1)]
public int Age { get; set; }
//[ProtoMember(2)]
[XmlElement("education", Order = 2)]
public string Education { get; set; }
//[ProtoMember(3)]
[XmlElement("name", Order = 3)]
public string Name { get; set; }
//[ProtoMember(4)]
[XmlElement("address", Order = 4)]
public Address Address { get; set; }
}
NOTE: I've also tried using ProtoContract
as the attribute but it has the same result. Protobuf-net supports XmlType
aswell so i commented those attributes.