private ITFtpCommand ParseInternal(byte[] message) { TFtpStreamReader reader = new TFtpStreamReader(new MemoryStream(message)); ushort opcode = reader.ReadUInt16(); switch (opcode) { case ReadRequest.OpCode: return(ParseReadRequest(reader)); case WriteRequest.OpCode: return(ParseWriteRequest(reader)); case Data.OpCode: return(ParseData(reader)); case Acknowledgement.OpCode: return(ParseAcknowledgement(reader)); case Error.OpCode: return(ParseError(reader)); case OptionAcknowledgement.OpCode: return(ParseOptionAcknowledgement(reader)); default: throw new TFtpParserException("Invalid opcode"); } }
private Data ParseData(TFtpStreamReader reader) { ushort blockNumber = reader.ReadUInt16(); byte[] data = reader.ReadBytes(10000); return(new Data(blockNumber, data)); }
private Error ParseError(TFtpStreamReader reader) { ushort errorCode = reader.ReadUInt16(); string message = ParseNullTerminatedString(reader); return(new Error(errorCode, message)); }
private Acknowledgement ParseAcknowledgement(TFtpStreamReader reader) { ushort blockNumber = reader.ReadUInt16(); return(new Acknowledgement(blockNumber)); }