From 49fd749fe33ea19ab0f6dbfee28211dc366082b1 Mon Sep 17 00:00:00 2001 From: Greg Date: Fri, 10 May 2019 02:35:52 -0400 Subject: [PATCH] Use C.GoBytes() in examples/bluetooth. --- examples/bluetooth/main.go | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/examples/bluetooth/main.go b/examples/bluetooth/main.go index e02adb4..2d30d38 100644 --- a/examples/bluetooth/main.go +++ b/examples/bluetooth/main.go @@ -5,7 +5,6 @@ import "C" import ( "encoding/binary" "fmt" - "unsafe" "gitlab.wow.st/gmp/nswrap/examples/bluetooth/ns" ) @@ -59,24 +58,16 @@ func discoverServices(p *ns.CBPeripheral, e *ns.NSError) { } func hr(d *ns.NSData) int { - var x []byte if l := int(d.Length()); l < 4 { return 0 - } else { - bs := d.Bytes() - x = make([]byte,l) - for i := 0; i < l; i++ { - x[i] = *(*byte)(unsafe.Pointer(uintptr(bs) + uintptr(i))) - } } - var hr int + x := C.GoBytes(d.Bytes(),4) flags := x[0] if flags & 0x80 != 0 { // uint16 format - hr = int(binary.BigEndian.Uint16(x[1:2])) + return int(binary.BigEndian.Uint16(x[1:2])) } else { - hr = int(x[1]) + return int(x[1]) } - return hr } func discoverCharacteristics(p *ns.CBPeripheral, s *ns.CBService, e *ns.NSError) {