Skip to content

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

@longjiangyuan

Description

@longjiangyuan
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
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions