feat: guacd for rdp/vnc

This commit is contained in:
ttk
2024-02-21 18:21:35 +08:00
parent a7f670422c
commit eed3db67cb
3 changed files with 244 additions and 13 deletions

View File

@@ -0,0 +1,46 @@
package guacd
import (
"fmt"
"strings"
)
const Delimiter = ';'
type Instruction struct {
Opcode string
Args []string
cache string
}
func NewInstruction(opcode string, args ...string) *Instruction {
return &Instruction{
Opcode: opcode,
Args: args,
}
}
func (i *Instruction) String() string {
if len(i.cache) > 0 {
return i.cache
}
i.cache = fmt.Sprintf("%d.%s", len(i.Opcode), i.Opcode)
for _, value := range i.Args {
i.cache += fmt.Sprintf(",%d.%s", len(value), value)
}
i.cache += string(Delimiter)
return i.cache
}
func (i *Instruction) Parse(content string) *Instruction {
if strings.LastIndex(content, ";") > 0 {
content = strings.TrimRight(content, ";")
}
elements := strings.Split(content, ",")
var args = make([]string, len(elements))
for i, e := range elements {
args[i] = strings.Split(e, ".")[1]
}
return NewInstruction(args[0], args[1:]...)
}