1
0
mirror of https://github.com/Mrs4s/MiraiGo.git synced 2025-05-04 11:07:40 +08:00

style: cleanup dynamic proto encode

This commit is contained in:
Mrs4s 2021-11-06 15:27:56 +08:00
parent af5e25d1cc
commit 4dfdc22a70
No known key found for this signature in database
GPG Key ID: 3186E98FA19CE3A7
2 changed files with 6 additions and 6 deletions

View File

@ -12,7 +12,7 @@ type encoder struct {
bytes.Buffer
}
func EncodeDynamicProtoMessage(msg DynamicProtoMessage) []byte {
func (msg DynamicProtoMessage) Encode() []byte {
en := &encoder{}
for id, value := range msg {
key := id << 3
@ -52,7 +52,7 @@ func EncodeDynamicProtoMessage(msg DynamicProtoMessage) []byte {
_, _ = en.Write(b)
case DynamicProtoMessage:
en.uvarint(key | 2)
b := EncodeDynamicProtoMessage(v)
b := v.Encode()
en.uvarint(uint64(len(b)))
_, _ = en.Write(b)
}

View File

@ -81,7 +81,7 @@ func (c *QQClient) syncChannelFirstView() {
func (s *ChannelService) GetGuildMembers(guildId uint64) (bots []*GuildMemberInfo, members []*GuildMemberInfo, admins []*GuildMemberInfo, err error) {
seq := s.c.nextSeq()
u1 := uint32(1)
payload := s.c.packOIDBPackage(3931, 1, binary.EncodeDynamicProtoMessage(binary.DynamicProtoMessage{ // todo: 可能还需要处理翻页的情况?
payload := s.c.packOIDBPackage(3931, 1, binary.DynamicProtoMessage{ // todo: 可能还需要处理翻页的情况?
1: guildId, // guild id
2: uint32(3),
3: uint32(0),
@ -91,7 +91,7 @@ func (s *ChannelService) GetGuildMembers(guildId uint64) (bots []*GuildMemberInf
6: uint32(0),
8: uint32(500), // max response?
14: uint32(2),
}))
}.Encode())
packet := packets.BuildUniPacket(s.c.Uin, seq, "OidbSvcTrpcTcp.0xf5b_1", 1, s.c.OutGoingPacketSessionId, []byte{}, s.c.sigInfo.d2Key, payload)
rsp, err := s.c.sendAndWaitDynamic(seq, packet)
if err != nil {
@ -134,11 +134,11 @@ func (s *ChannelService) GetGuildMemberProfileInfo(guildId, tinyId uint64) (*Gui
}
flags[99] = uint32(1)
flags[100] = uint32(1)
payload := s.c.packOIDBPackage(3976, 1, binary.EncodeDynamicProtoMessage(binary.DynamicProtoMessage{
payload := s.c.packOIDBPackage(3976, 1, binary.DynamicProtoMessage{
1: flags,
3: tinyId,
4: guildId,
}))
}.Encode())
packet := packets.BuildUniPacket(s.c.Uin, seq, "OidbSvcTrpcTcp.0xf88_1", 1, s.c.OutGoingPacketSessionId, []byte{}, s.c.sigInfo.d2Key, payload)
rsp, err := s.c.sendAndWaitDynamic(seq, packet)
if err != nil {