timehop / apns

A Go package to interface with the Apple Push Notification Service
https://godoc.org/github.com/timehop/apns
MIT License
185 stars 47 forks source link

improve Notification.ToBinary() to reduce memory copy #67

Open longjiangyuan opened 8 years ago

longjiangyuan commented 8 years ago
var placeholder = [5]byte{}

func (n Notification) ToBinary() ([]byte, error) {
   ....
   /* write header place holder*/
   buf.Write(placeholder[:])

   /* write fields: token,payload... etc */
   ...

   /* rewrite header */
   b = buf.Bytes()
   b[0] = commandID
   binary.BigEndian.PutUint32(b[1:5], uint32(len(b)-5))
   return b, nil
}
nathany commented 8 years ago

If you want to do a pull request I can merge it, but I'm no longer helping with the maintenance of this project. There is a new HTTP/2 Notification API and a library I'm writing for that.

https://github.com/RobotsAndPencils/buford