forked from saily/vnc2video
-
Notifications
You must be signed in to change notification settings - Fork 0
/
encoding_desktopname.go
41 lines (35 loc) · 1.06 KB
/
encoding_desktopname.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package vnc2video
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) Reset() error {
return nil
}
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()
}