T
TJO
Can someone recomend a good technique for removing BOF and EOF markers from
a byte[]? I am passing a byte[] thru an FTP socket. I am serializing an
object into a byte[] and then adding an EOF marker and a BOF marker to the
byte[]. On the receiving end I need to remove the markers and then
deserialize my object. My object does not seem to deserialize so I am not
sure I am removing the EOF and BOF properly. All advice welcome. Thank
you.
Here is the code snippet.
byte[] bof = Encoding.Ascii.GetBytes("<BOF>");
byte[] eof = Encoding.Ascii.GetBytes("<EOF>");
byte[] myobjbytes = myobj.Serialize();
// Create empty byte[] of combined objects
byte[] combinedBytes = new byte[ eof.Length + myobjbytes.Lengh +
bof.Length ];
// Copy contents of objects to empty byte[]
System.Buffer.BlockCopy(
bof, 0,
myobjbytes, 0, bof.Length);
System.Buffer.BlockCopy(
myobjbytes , 0,
combinedBytes, bof.Length, myobjbytes .Length);
System.Buffer.BlockCopy(
eof, 0,
combinedBytes, bof.Length + myobjbytes.Length, eof.Length);
// Send byte[] thru the socket
// Now I want to trim off the EOF and BOF then Deserialize my object.
// Here is my attept but the remaining object does not like to be
deserialized
private byte[] TrimBOF_EOF(string BOF, string EOF, byte[] bytes)
{
string s = new string(Encoding.ASCII.GetChars(bytes));
s = s.Remove(0, BOF.Length);
// Get position of EOF
int EOFPos = s.LastIndexOf(EOF);
// Trim EOF mark thru the end of the string
if(EOFPos > -1)
s = s.Remove(s.Length-EOF.Length, EOF.Length);
return Encoding.ASCII.GetBytes(s);
}
a byte[]? I am passing a byte[] thru an FTP socket. I am serializing an
object into a byte[] and then adding an EOF marker and a BOF marker to the
byte[]. On the receiving end I need to remove the markers and then
deserialize my object. My object does not seem to deserialize so I am not
sure I am removing the EOF and BOF properly. All advice welcome. Thank
you.
Here is the code snippet.
byte[] bof = Encoding.Ascii.GetBytes("<BOF>");
byte[] eof = Encoding.Ascii.GetBytes("<EOF>");
byte[] myobjbytes = myobj.Serialize();
// Create empty byte[] of combined objects
byte[] combinedBytes = new byte[ eof.Length + myobjbytes.Lengh +
bof.Length ];
// Copy contents of objects to empty byte[]
System.Buffer.BlockCopy(
bof, 0,
myobjbytes, 0, bof.Length);
System.Buffer.BlockCopy(
myobjbytes , 0,
combinedBytes, bof.Length, myobjbytes .Length);
System.Buffer.BlockCopy(
eof, 0,
combinedBytes, bof.Length + myobjbytes.Length, eof.Length);
// Send byte[] thru the socket
// Now I want to trim off the EOF and BOF then Deserialize my object.
// Here is my attept but the remaining object does not like to be
deserialized

private byte[] TrimBOF_EOF(string BOF, string EOF, byte[] bytes)
{
string s = new string(Encoding.ASCII.GetChars(bytes));
s = s.Remove(0, BOF.Length);
// Get position of EOF
int EOFPos = s.LastIndexOf(EOF);
// Trim EOF mark thru the end of the string
if(EOFPos > -1)
s = s.Remove(s.Length-EOF.Length, EOF.Length);
return Encoding.ASCII.GetBytes(s);
}