diff options
| author | Jeff Halter <868228+jhalter@users.noreply.github.com> | 2021-08-12 19:00:13 -0700 |
|---|---|---|
| committer | Jeff Halter <868228+jhalter@users.noreply.github.com> | 2021-08-12 11:00:13 -0700 |
| commit | c5d9af5aa4d9fb20316be45ab1b775bcf61bcad5 (patch) | |
| tree | 300f7c6814d41ad12ff5665f3f14f24a54c62e4d /hotline/account.go | |
| parent | 72dd37f1abb2b550aaaac48eac677403d5664797 (diff) | |
More cleanup
Diffstat (limited to 'hotline/account.go')
| -rw-r--r-- | hotline/account.go | 40 |
1 files changed, 5 insertions, 35 deletions
diff --git a/hotline/account.go b/hotline/account.go index bcacc73..7368592 100644 --- a/hotline/account.go +++ b/hotline/account.go @@ -1,7 +1,6 @@ package hotline import ( - "encoding/binary" "github.com/jhalter/mobius/concat" ) @@ -14,41 +13,12 @@ type Account struct { Access *[]byte `yaml:"Access"` // 8 byte bitmap } -// Payload marshals an account to byte slice -// Example: -// 00 04 // fieldCount? -// 00 66 // 102 - fieldUserName -// 00 0d // 13 -// 61 64 6d 69 6e 69 73 74 72 61 74 6f 72 // administrator -// 00 69 // 105 fieldUserLogin (encoded) -// 00 05 // len -// 9e 9b 92 96 91 // encoded login name -// 00 6a // 106 fieldUserPassword -// 00 01 // len -// 78 -// 00 6e // fieldUserAccess -// 00 08 -// ff d3 cf ef ff 80 00 00 -func (a *Account) Payload() (out []byte) { - nameLen := make([]byte, 2) - binary.BigEndian.PutUint16(nameLen, uint16(len(a.Name))) - - loginLen := make([]byte, 2) - binary.BigEndian.PutUint16(loginLen, uint16(len(a.Login))) - +// MarshalBinary marshals an Account to byte slice +func (a *Account) MarshalBinary() (out []byte) { return concat.Slices( []byte{0x00, 0x3}, // param count -- always 3 - - []byte{0x00, 0x66}, // fieldUserName - nameLen, - []byte(a.Name), - - []byte{0x00, 0x69}, // fieldUserLogin - loginLen, - negateString([]byte(a.Login)), - - []byte{0x00, 0x6e}, // fieldUserAccess - []byte{0x00, 0x08}, - *a.Access, + NewField(fieldUserName, []byte(a.Name)).Payload(), + NewField(fieldUserLogin, negateString([]byte(a.Login))).Payload(), + NewField(fieldUserAccess, *a.Access).Payload(), ) } |