同步代码

This commit is contained in:
TsMask
2023-08-21 11:00:22 +08:00
parent 2735cc3009
commit 788f01674a
37 changed files with 2211 additions and 1 deletions

46
omc/omc_pack.go Normal file
View File

@@ -0,0 +1,46 @@
package omc
import (
"errors"
"fmt"
"strings"
)
type MsgBody struct {
UID string
RawData []byte
MsgName string
Msg map[string]string
Keys []string
}
// Decode
// reqLoginAlarm;user=yiy;key=qw#$@;type=msg
func (o *MsgBody) Decode() error {
multi := strings.Split(string(o.RawData), ";")
if len(multi) < 1 {
return errors.New("invalid msg body")
}
for i := 1; i < len(multi); i++ {
m := strings.Split(multi[i], "=")
if len(m) != 2 {
return errors.New("invalid msg body")
}
o.Msg[m[0]] = m[1]
}
return nil
}
// Pack
// reqLoginAlarm;user=yiy;key=qw#$@;type=msg
func (o *MsgBody) Pack() error {
var multi []string
multi = append(multi, o.MsgName)
for _, key := range o.Keys {
item := fmt.Sprintf("%s=%s", key, o.Msg[key])
multi = append(multi, item)
}
raw := strings.Join(multi, ";")
o.RawData = []byte(raw)
return nil
}