void IMyCatValue.WriteValue(MyCatPacket packet, bool binary, object val, int length) { byte[] buffToWrite = (val as byte[]); if (buffToWrite == null) { char[] valAsChar = (val as Char[]); if (valAsChar != null) { buffToWrite = packet.Encoding.GetBytes(valAsChar); } else { string s = val.ToString(); if (length == 0) { length = s.Length; } else { s = s.Substring(0, length); } buffToWrite = packet.Encoding.GetBytes(s); } } // we assume zero length means write all of the value if (length == 0) { length = buffToWrite.Length; } if (buffToWrite == null) { throw new MyCatException("Only byte arrays and strings can be serialized by MyCatBinary"); } if (binary) { packet.WriteLength(length); packet.Write(buffToWrite, 0, length); } else { packet.WriteStringNoNull("X"); packet.WriteStringNoNull("\'"); packet.WriteStringNoNull(ToHexString(buffToWrite)); packet.WriteStringNoNull("\'"); } }
private void WriteOldGuid(MyCatPacket packet, Guid guid, bool binary) { byte[] bytes = guid.ToByteArray(); if (binary) { packet.WriteLength(bytes.Length); packet.Write(bytes); } else { packet.WriteStringNoNull("_binary "); packet.WriteByte((byte)'\''); EscapeByteArray(bytes, bytes.Length, packet); packet.WriteByte((byte)'\''); } }