Source File
packet-typing.go
Belonging Package
github.com/pkg/sftp
package sftpimport ()// all incoming packetstype requestPacket interface {encoding.BinaryUnmarshalerid() uint32}type responsePacket interface {encoding.BinaryMarshalerid() uint32}// interfaces to group typestype hasPath interface {requestPacketgetPath() string}type hasHandle interface {requestPacketgetHandle() string}type notReadOnly interface {notReadOnly()}// // define types by adding methods// hasPathfunc ( *sshFxpLstatPacket) () string { return .Path }func ( *sshFxpStatPacket) () string { return .Path }func ( *sshFxpRmdirPacket) () string { return .Path }func ( *sshFxpReadlinkPacket) () string { return .Path }func ( *sshFxpRealpathPacket) () string { return .Path }func ( *sshFxpMkdirPacket) () string { return .Path }func ( *sshFxpSetstatPacket) () string { return .Path }func ( *sshFxpStatvfsPacket) () string { return .Path }func ( *sshFxpRemovePacket) () string { return .Filename }func ( *sshFxpRenamePacket) () string { return .Oldpath }func ( *sshFxpSymlinkPacket) () string { return .Targetpath }func ( *sshFxpOpendirPacket) () string { return .Path }func ( *sshFxpOpenPacket) () string { return .Path }func ( *sshFxpExtendedPacketPosixRename) () string { return .Oldpath }func ( *sshFxpExtendedPacketHardlink) () string { return .Oldpath }// getHandlefunc ( *sshFxpFstatPacket) () string { return .Handle }func ( *sshFxpFsetstatPacket) () string { return .Handle }func ( *sshFxpReadPacket) () string { return .Handle }func ( *sshFxpWritePacket) () string { return .Handle }func ( *sshFxpReaddirPacket) () string { return .Handle }func ( *sshFxpClosePacket) () string { return .Handle }// notReadOnlyfunc ( *sshFxpWritePacket) () {}func ( *sshFxpSetstatPacket) () {}func ( *sshFxpFsetstatPacket) () {}func ( *sshFxpRemovePacket) () {}func ( *sshFxpMkdirPacket) () {}func ( *sshFxpRmdirPacket) () {}func ( *sshFxpRenamePacket) () {}func ( *sshFxpSymlinkPacket) () {}func ( *sshFxpExtendedPacketPosixRename) () {}func ( *sshFxpExtendedPacketHardlink) () {}// some packets with ID are missing id()func ( *sshFxpDataPacket) () uint32 { return .ID }func ( *sshFxpStatusPacket) () uint32 { return .ID }func ( *sshFxpStatResponse) () uint32 { return .ID }func ( *sshFxpNamePacket) () uint32 { return .ID }func ( *sshFxpHandlePacket) () uint32 { return .ID }func ( *StatVFS) () uint32 { return .ID }func ( *sshFxVersionPacket) () uint32 { return 0 }// take raw incoming packet data and build packet objectsfunc makePacket( rxPacket) (requestPacket, error) {var requestPacketswitch .pktType {case sshFxpInit:= &sshFxInitPacket{}case sshFxpLstat:= &sshFxpLstatPacket{}case sshFxpOpen:= &sshFxpOpenPacket{}case sshFxpClose:= &sshFxpClosePacket{}case sshFxpRead:= &sshFxpReadPacket{}case sshFxpWrite:= &sshFxpWritePacket{}case sshFxpFstat:= &sshFxpFstatPacket{}case sshFxpSetstat:= &sshFxpSetstatPacket{}case sshFxpFsetstat:= &sshFxpFsetstatPacket{}case sshFxpOpendir:= &sshFxpOpendirPacket{}case sshFxpReaddir:= &sshFxpReaddirPacket{}case sshFxpRemove:= &sshFxpRemovePacket{}case sshFxpMkdir:= &sshFxpMkdirPacket{}case sshFxpRmdir:= &sshFxpRmdirPacket{}case sshFxpRealpath:= &sshFxpRealpathPacket{}case sshFxpStat:= &sshFxpStatPacket{}case sshFxpRename:= &sshFxpRenamePacket{}case sshFxpReadlink:= &sshFxpReadlinkPacket{}case sshFxpSymlink:= &sshFxpSymlinkPacket{}case sshFxpExtended:= &sshFxpExtendedPacket{}default:return nil, fmt.Errorf("unhandled packet type: %s", .pktType)}if := .UnmarshalBinary(.pktBytes); != nil {// Return partially unpacked packet to allow callers to return// error messages appropriately with necessary id() method.return ,}return , nil}
![]() |
The pages are generated with Golds v0.6.7. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |