package sftp

// Methods on the Request object to make working with the Flags bitmasks and
// Attr(ibutes) byte blob easier. Use Pflags() when working with an Open/Write
// request and AttrFlags() and Attributes() when working with SetStat requests.
import 

// FileOpenFlags defines Open and Write Flags. Correlate directly with with os.OpenFile flags
// (https://golang.org/pkg/os/#pkg-constants).
type FileOpenFlags struct {
	Read, Write, Append, Creat, Trunc, Excl bool
}

func newFileOpenFlags( uint32) FileOpenFlags {
	return FileOpenFlags{
		Read:   &sshFxfRead != 0,
		Write:  &sshFxfWrite != 0,
		Append: &sshFxfAppend != 0,
		Creat:  &sshFxfCreat != 0,
		Trunc:  &sshFxfTrunc != 0,
		Excl:   &sshFxfExcl != 0,
	}
}

// Pflags converts the bitmap/uint32 from SFTP Open packet pflag values,
// into a FileOpenFlags struct with booleans set for flags set in bitmap.
func ( *Request) () FileOpenFlags {
	return newFileOpenFlags(.Flags)
}

// FileAttrFlags that indicate whether SFTP file attributes were passed. When a flag is
// true the corresponding attribute should be available from the FileStat
// object returned by Attributes method. Used with SetStat.
type FileAttrFlags struct {
	Size, UidGid, Permissions, Acmodtime bool
}

func newFileAttrFlags( uint32) FileAttrFlags {
	return FileAttrFlags{
		Size:        ( & sshFileXferAttrSize) != 0,
		UidGid:      ( & sshFileXferAttrUIDGID) != 0,
		Permissions: ( & sshFileXferAttrPermissions) != 0,
		Acmodtime:   ( & sshFileXferAttrACmodTime) != 0,
	}
}

// AttrFlags returns a FileAttrFlags boolean struct based on the
// bitmap/uint32 file attribute flags from the SFTP packaet.
func ( *Request) () FileAttrFlags {
	return newFileAttrFlags(.Flags)
}

// FileMode returns the Mode SFTP file attributes wrapped as os.FileMode
func ( FileStat) () os.FileMode {
	return os.FileMode(.Mode)
}

// Attributes parses file attributes byte blob and return them in a
// FileStat object.
func ( *Request) () *FileStat {
	,  := unmarshalFileStat(.Flags, .Attrs)
	return 
}