paypal/gatt: Fix Notifier.Write to not include framing bytes when calculated
the number of bytes written.
Change-Id: I84aba2038def930ea5bc3abe4f0ace54766f2c7a
diff --git a/go/src/github.com/paypal/gatt/README.google b/go/src/github.com/paypal/gatt/README.google
index 347be70..bef8607 100644
--- a/go/src/github.com/paypal/gatt/README.google
+++ b/go/src/github.com/paypal/gatt/README.google
@@ -11,3 +11,6 @@
- Disabled tests in xpc/xpc_darwin_test.go because of https://github.com/paypal/gatt/issues/64
which is okay for now since we aren't actively using paypal/gatt on OS X, but should be changed
at some point.
+- Modified central_linux.go to make Notifier.Write return the correct integer value of
+ bytes written. It was incorrectly including framing bytes in the returned value. The upstream
+ pull request is at https://github.com/paypal/gatt/pull/69.
\ No newline at end of file
diff --git a/go/src/github.com/paypal/gatt/central_linux.go b/go/src/github.com/paypal/gatt/central_linux.go
index 3ae6994..ef23ace 100644
--- a/go/src/github.com/paypal/gatt/central_linux.go
+++ b/go/src/github.com/paypal/gatt/central_linux.go
@@ -413,10 +413,19 @@
func (c *central) sendNotification(a *attr, data []byte) (int, error) {
w := newL2capWriter(c.mtu)
- w.WriteByteFit(attOpHandleNotify)
- w.WriteUint16Fit(a.pvt.(*Descriptor).char.vh)
+ added := 0
+ if w.WriteByteFit(attOpHandleNotify) {
+ added += 1
+ }
+ if w.WriteUint16Fit(a.pvt.(*Descriptor).char.vh) {
+ added += 2
+ }
w.WriteFit(data)
- return c.l2conn.Write(w.Bytes())
+ n, err := c.l2conn.Write(w.Bytes())
+ if err != nil {
+ return n, err
+ }
+ return n - added, err
}
func readHandleRange(b []byte) (start, end uint16) {