4
0
mirror of https://github.com/cwinfo/matterbridge.git synced 2025-07-04 11:17:45 +00:00

Update dependencies (#2180)

* Update dependencies

* Fix whatsmeow API changes
This commit is contained in:
Wim
2024-08-27 19:04:05 +02:00
committed by GitHub
parent d16645c952
commit c4157a4d5b
589 changed files with 681707 additions and 198856 deletions

View File

@ -0,0 +1,32 @@
package armadilloutil
import (
"errors"
"fmt"
"google.golang.org/protobuf/proto"
"go.mau.fi/whatsmeow/proto/waCommon"
)
var ErrUnsupportedVersion = errors.New("unsupported subprotocol version")
func Unmarshal[T proto.Message](into T, msg *waCommon.SubProtocol, expectedVersion int32) (T, error) {
if msg.GetVersion() != expectedVersion {
return into, fmt.Errorf("%w %d in %T (expected %d)", ErrUnsupportedVersion, msg.GetVersion(), into, expectedVersion)
}
err := proto.Unmarshal(msg.GetPayload(), into)
return into, err
}
func Marshal[T proto.Message](msg T, version int32) (*waCommon.SubProtocol, error) {
payload, err := proto.Marshal(msg)
if err != nil {
return nil, err
}
return &waCommon.SubProtocol{
Payload: payload,
Version: &version,
}, nil
}