Ejemplo n.º 1
0
    public byte[] Encode()
    {
        byte[] file_data = Encoding.UTF8.GetBytes(FileContent);
        byte[] msg       = new byte[4 + 2 + 256 + 256 + 4 + file_data.Length];

        Buffer.BlockCopy(ProtocolMessageFactory.Converter.GetBytes((UInt32)msg.Length - 4), 0, msg, 0, 4);
        Buffer.BlockCopy(ProtocolMessageFactory.Converter.GetBytes((UInt16)MessageType.FileContent), 0, msg, 4, 2);

        Buffer.BlockCopy(RootPath.PaddedByteArray(256), 0, msg, 6, 256);
        Buffer.BlockCopy(RelativeName.PaddedByteArray(256), 0, msg, 262, 256);
        Buffer.BlockCopy(ProtocolMessageFactory.Converter.GetBytes((UInt32)file_data.Length), 0, msg, 518, 4);
        Buffer.BlockCopy(file_data, 0, msg, 522, file_data.Length);

        return(msg);
    }