public IStyxMessage GetMessage() { IStyxMessage res = null; switch (type) { case MessageType.Twalk: case MessageType.Rwalk: res = new StyxWalkMessage(); break; case MessageType.Tversion: case MessageType.Rversion: res = new StyxVersionMessage(); break; case MessageType.Tclunk: case MessageType.Rclunk: res = new StyxClunkMessage(); break; case MessageType.Tstat: case MessageType.Rstat: res = new StyxStatMessage(); break; case MessageType.Topen: case MessageType.Ropen: res = new StyxOpenMessage(); break; case MessageType.Tread: case MessageType.Rread: res = new StyxReadMessage(); break; case MessageType.Tattach: case MessageType.Rattach: res = new StyxAttachMessage(); break; } if (res != null) { res.SetBinary(data); } return res; }
private IStyxMessage HandleRead(StyxReadMessage message) { if (!fid_list.ContainsKey(message.Fid)) { throw new Exception("Unknown fid"); } StyxFileSystemInterface fsitem = fid_list[message.Fid]; StyxMessage.QID qid; byte [] buffer = new byte[message.Count]; int readed; int res = fsitem.Read(buffer, 0, message.Offset, (int)message.Count, out readed ); if (res != 0) { throw new Exception("Read failed(" + res + ")"); } return new StyxReadMessage(message.Tag, buffer, (uint)readed ); }