go-rfb/encoding_desktopname.go
Vasiliy Tolstov f6acfdfdad add ability to check supported status
Signed-off-by: Vasiliy Tolstov <v.tolstov@selfip.ru>
2017-07-14 02:01:24 +03:00

40 lines
980 B
Go

package vnc
import "encoding/binary"
// DesktopNamePseudoEncoding represents a desktop size message from the server.
type DesktopNamePseudoEncoding struct {
Name []byte
}
func (*DesktopNamePseudoEncoding) Supported(Conn) bool {
return true
}
func (*DesktopNamePseudoEncoding) Type() EncodingType { return EncDesktopNamePseudo }
// Read implements the Encoding interface.
func (enc *DesktopNamePseudoEncoding) Read(c Conn, rect *Rectangle) error {
var length uint32
if err := binary.Read(c, binary.BigEndian, &length); err != nil {
return err
}
name := make([]byte, length)
if err := binary.Read(c, binary.BigEndian, &name); err != nil {
return err
}
enc.Name = name
return nil
}
func (enc *DesktopNamePseudoEncoding) Write(c Conn, rect *Rectangle) error {
if err := binary.Write(c, binary.BigEndian, uint32(len(enc.Name))); err != nil {
return err
}
if err := binary.Write(c, binary.BigEndian, enc.Name); err != nil {
return err
}
return c.Flush()
}