github.com/amitbet/vnc2video@v0.0.0-20190616012314-9d50b9dab1d9/encoding_desktopname.go (about) 1 package vnc2video 2 3 import "encoding/binary" 4 5 // DesktopNamePseudoEncoding represents a desktop size message from the server. 6 type DesktopNamePseudoEncoding struct { 7 Name []byte 8 } 9 10 func (*DesktopNamePseudoEncoding) Supported(Conn) bool { 11 return true 12 } 13 func (*DesktopNamePseudoEncoding) Reset() error { 14 return nil 15 } 16 func (*DesktopNamePseudoEncoding) Type() EncodingType { return EncDesktopNamePseudo } 17 18 // Read implements the Encoding interface. 19 func (enc *DesktopNamePseudoEncoding) Read(c Conn, rect *Rectangle) error { 20 var length uint32 21 if err := binary.Read(c, binary.BigEndian, &length); err != nil { 22 return err 23 } 24 name := make([]byte, length) 25 if err := binary.Read(c, binary.BigEndian, &name); err != nil { 26 return err 27 } 28 enc.Name = name 29 return nil 30 } 31 32 func (enc *DesktopNamePseudoEncoding) Write(c Conn, rect *Rectangle) error { 33 if err := binary.Write(c, binary.BigEndian, uint32(len(enc.Name))); err != nil { 34 return err 35 } 36 if err := binary.Write(c, binary.BigEndian, enc.Name); err != nil { 37 return err 38 } 39 40 return c.Flush() 41 }