Hi all, I'm doing a simple message serialization, message defines like 
below:
type Envelope struct {
    Magic uint32
    DataSize uint32
}

type Message struct {
    Envelope
    Data []byte
}

and I want to implement the io.WriterTo interface for Message
func (m *Message) WriteTo(w io.Writer) (n int64, err error) {
    err = binary.Write(w, binary.BigEndian, &m.Envelope)
    if err != nil {
        // here, how should I return a proper n? Since w maybe *net.TCPConn 
and binary.Write maybe write 1 bytes and peer has dropped the connection.
        return 0, fmt.Errorf("Write message envelope error: %s", err)
    }

    // multiple lines skipped
}

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to