Note that there are some explanatory texts on larger screens.

plurals
  1. POprotobuf-net OverwriteList on Byte Array
    primarykey
    data
    text
    <p>What I am doing is attempting to send an IPEndpoint through protobuf-net and what I observed is that when deserializing the array of 4 bytes into the IP4 address, the set code recieves a value of 8 bytes. Four bytes containing the orignal address, and 4 more bytes containing the address that was serialized. By stepping through the code I have been able to confirm that when Deserialize is called, it first reads the bytes, and then sets they bytes.</p> <p>After doing some reading I learned about OverwriteList, and as can been seen in the example below, I have set that to true. However the setter is still provided an 8 byte value.</p> <p>Does anyone have a clue what I am doing wrong?</p> <p>This sample code should throw an exception when used with protobuf-net r480, Visual Studio 2010 as a .Net 4.0 console application.</p> <pre> using ProtoBuf; using System.Net; using System.IO; namespace ConsoleApplication1 { [ProtoContract] class AddressOWner { private IPEndPoint endpoint; public AddressOWner() { endpoint = new IPEndPoint(new IPAddress(new byte[] {8,8,8,8}), 0); } public AddressOWner(IPEndPoint newendpoint) { this.endpoint = newendpoint; } [ProtoMember(1, OverwriteList=true)] public byte[] AddressBytes { get { return endpoint.Address.GetAddressBytes(); } set { endpoint.Address = new IPAddress(value); } } } class Program { static void Main(string[] args) { AddressOWner ao = new AddressOWner(new IPEndPoint(new IPAddress(new byte[] { 192, 168, 1, 1 }), 80)); MemoryStream ms = new MemoryStream(); Serializer.Serialize(ms, ao); byte[] messageData = ms.GetBuffer(); ms = new MemoryStream(messageData); AddressOWner aoCopy = Serializer.Deserialize&lt;AddressOWner&gt;(ms); } } } </pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload