func writeMessage(message proto.Message, writer io.Writer) error {
	data, err := proto.Marshal(message)
	if err != nil {
		return err
	}

	messageName := proto.MessageName(message)
	nameBytes := []byte(messageName)
	nameLength := len(nameBytes)
	buf := make([]byte, 4)

	// 1 byte for name length + name length + data length
	binary.LittleEndian.PutUint32(buf, uint32(len(data)+1+nameLength))
	_, err = writer.Write(buf)
	if err != nil {
		return err
	}

	_, err = writer.Write([]byte{byte(nameLength)})
	if err != nil {
		return err
	}

	_, err = writer.Write(nameBytes)
	if err != nil {
		return err
	}

	_, err = writer.Write(data)
	if err != nil {
		return err
	}

	return nil
}
// writeMessage writes a message and message name to the provided writer.
writeMessage writes a message and message name to the provided writer.
// writeMessage writes a message and message name to the provided writer .
func writeMessage(message proto.Message, writer io.Writer) error {
	data, err := proto.Marshal(message)
	if err != nil {
		return err
	}
	messageName := proto.MessageName(message)
	nameBytes := []byte(messageName)
	nameLength := len(nameBytes)
	buf := make([]byte, 4)
	binary.LittleEndian.PutUint32(buf, uint32(len(data)+1+nameLength))
	_, err = writer.Write(buf)
	if err != nil {
		return err
	}
	_, err = writer.Write([]byte{byte(nameLength)})
	if err != nil {
		return err
	}
	_, err = writer.Write(nameBytes)
	if err != nil {
		return err
	}
	_, err = writer.Write(data)
	if err != nil {
		return err
	}
	return nil
}
func writeMessage ( message proto . Message , writer io . Writer ) error { data , err := proto . Marshal ( message ) if err != nil { return err } messageName := proto . MessageName ( message ) nameBytes := [ ] byte ( messageName ) nameLength := len ( nameBytes ) buf := make ( [ ] byte , 4 ) binary . LittleEndian . PutUint32 ( buf , uint32 ( len ( data ) + 1 + nameLength ) ) _ , err = writer . Write ( buf ) if err != nil { return err } _ , err = writer . Write ( [ ] byte { byte ( nameLength ) } ) if err != nil { return err } _ , err = writer . Write ( nameBytes ) if err != nil { return err } _ , err = writer . Write ( data ) if err != nil { return err } return nil }
writeMessage writes a message and message name to the provided writer.
writeMessage writes a message and message name to the provided writer .
// 1 byte for name length + name length + data length