Note that there are some explanatory texts on larger screens.

plurals
  1. POXml Serialization for Unusual Connection Protocol
    primarykey
    data
    text
    <p>In my application I have a <code>PacketList</code> class and <code>Packet</code> class. I'd like to be able to use the serialization helpers on <code>PacketList</code> to come up with something like the desired output, but have no idea what direction to go in.</p> <p>I am writing a program to imitate a server which has a peculiar protocol for sending data.</p> <p>Client sends data with format: <code>COMMAND|ARGUMENT_0|ARGUMENT_1|ARGUMENT_2|...|ARGUMENT_N\0</code>. Where <code>COMMAND</code> could be something like <code>MOVE</code> or <code>LOGIN</code>.</p> <p>The server would respond in the format:</p> <pre><code>&lt;p c='COUNT'&gt; &lt;m p='N' p0='COMMAND_0' p1='ARUGMENT_0' ... pN='ARGUMENT_N'/&gt; &lt;m p='N' p0='COMMAND_1' p1='ARUGMENT_0' ... pN='ARGUMENT_N'/&gt; &lt;m p='N' p0='COMMAND_2' p1='ARUGMENT_0' ... pN='ARGUMENT_N'/&gt; &lt;m p='N' p0='COMMAND_3' p1='ARUGMENT_0' ... pN='ARGUMENT_N'/&gt; ... &lt;m p='N' p0='COMMAND_COUNT' p1='ARUGMENT_0' ... pN='ARGUMENT_N'/&gt; &lt;/p&gt; </code></pre> <p>Where <code>COMMAND_0</code> could be something like <code>UPDATE_POSITION</code> or <code>AUTHENTICATED</code>.</p> <p>Yes, this is a silly way of doing things. No, I don't know why it's done this way. No, I can't change it.</p> <p>Anyways, I am looking to emulate the way that the server sends the packet back to the client. What I have gotten so far is:</p> <pre><code>XmlWriterSettings _Settings = new XmlWriterSettings { OmitXmlDeclaration = true, Indent = true }; StringBuilder _Xml = new StringBuilder(); XmlWriter _Writer = XmlWriter.Create(_Xml, _Settings); _Writer.WriteStartElement("p"); _Writer.WriteAttributeString("c", "1"); _Writer.WriteStartElement("m"); _Writer.WriteAttributeString("p", "2"); _Writer.WriteAttributeString("p0", "COMMAND"); _Writer.WriteAttributeString("p1", "ARGUMENT_0"); _Writer.WriteAttributeString("p2", "ARGUMENT_1"); _Writer.WriteEndElement(); // &lt;/m&gt; _Writer.WriteEndElement(); // &lt;/p&gt; _Writer.Flush(); Console.WriteLine(_Xml.ToString()); </code></pre> <p>This works properly and outputs:</p> <pre><code>&lt;p c="1"&gt; &lt;m p="2" p0="COMMAND" p1="ARGUMENT_0" p2="ARGUMENT_1" /&gt; &lt;/p&gt; </code></pre> <p>However, I'd like to implement this in a cleaner way.</p> <p>My <code>PacketList</code> basically contains a list of <code>Packet</code>s, and <code>Packet</code> contains a <code>String _Command</code> and <code>String[] _Arguments</code>.</p> <p>If anyone could guide me in the right direction it would be much appreciated.</p>
    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.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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