Skip to content

Commit 0fa4be9

Browse files
author
Drakirus
committed
bugfix: message size was using int instead uint
fixes #163: When using StandardMessageCodec, the Flutter Framework encode the value's size using it's own format: https://api.flutter.dev/flutter/services/StandardMessageCodec/readSize.html When the size value is above 254, the format used is **unsigned** int 16 or 32.
1 parent a6ff8ec commit 0fa4be9

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

plugin/standard-message-codec.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,22 +103,26 @@ func (s StandardMessageCodec) writeSize(buf *bytes.Buffer, value int) error {
103103
return err
104104
}
105105
} else if value <= 0xffff {
106-
// write as int16
106+
// write as uint16
107107
err = buf.WriteByte(254)
108108
if err != nil {
109109
return err
110110
}
111-
err = s.writeInt16(buf, int16(value))
111+
num := make([]byte, 2)
112+
endian.PutUint16(num, uint16(value))
113+
_, err = buf.Write(num)
112114
if err != nil {
113115
return err
114116
}
115117
} else {
116-
// write as int32
118+
// write as uint32
117119
err = buf.WriteByte(255)
118120
if err != nil {
119121
return err
120122
}
121-
err = s.writeInt32(buf, int32(value))
123+
num := make([]byte, 4)
124+
endian.PutUint32(num, uint32(value))
125+
_, err = buf.Write(num)
122126
if err != nil {
123127
return err
124128
}
@@ -382,11 +386,11 @@ func (s StandardMessageCodec) readSize(buf *bytes.Buffer) (size int, err error)
382386
if b < 254 {
383387
return int(b), nil
384388
} else if b == 254 {
385-
v, err := s.readInt16(buf)
386-
return int(v), err
389+
v := endian.Uint16(buf.Next(2))
390+
return int(v), nil
387391
}
388-
v, err := s.readInt32(buf)
389-
return int(v), err
392+
v := endian.Uint32(buf.Next(4))
393+
return int(v), nil
390394
}
391395

392396
// readAlignment reads empty alignment bytes from the buffer. Because

0 commit comments

Comments
 (0)