hello i use a form of message parsing in which i write fields into a buffered stream, and then extract a byte array repesantaition of that stream
MyMessage _message = new MyMessage("me","you",MessageType.peer_me开发者_开发问答ssage,4252422) ;
// in the constructor String sender,String receiver,MessageType(enumaraition) m_type,Int32 id
byte [] buffer = myEncoder.encode(message) ;
now when i pass this to myDecoder it decodes it in the same metter and it works great ! how i do that is not the issue
my issue is that in some cases of misscommunicaition i need to store the byte[] array (buffer) for farther use , and i'm trying to do that in an xmlDocumant under a tag HERE IN THE INNER TEXT IS WHERE I WOULD LIKE TO SAVE THAT ARRAY OF BYTES
ive tryed -->
utf8Encoding.Ascii.getString(buffer)
which save some kind of repsantaition
but it changes values of field wich are not strings... when i take it out by using
utf8Encoding.Ascii.getBytes(packet_node.innerText) ;
1)THE QUESTION IS HOW WOULD U GO ABOUT SAVING THAT BYTE ARRAY TO A XMLNODE 2)i've also tried just writing the fields one by one in each tag
<Packet>
<sender>me</sender>
<receiver>him</receiver>
<MessageType> ..?? how would i represent a byte as a string ? </MessageType>
<Id> 4252353523 </Id> here i have no problem but i still would have to always prase the value back and forth in other uses from int to string ..
</Packet>
3) so my conclusion is to serialize the byte array to an xmldocument .. just that i don't want it to be a document but just one node in an existing document
Encode it as a base-64 string. Just remember to decode it when you read it back.
byte[] bytes = ...;
string encoded = Convert.ToBase64String(bytes);
byte[] decoded = Convert.FromBase64String(encoded);
精彩评论