// Auto-generated, do not edit
package messages

import (
	"fmt"
)
<% $messages.each do |msg| %>
func Decode<%= msg.name %>(reader BytesReader) (Message, error) {
    var err error = nil
    msg := &<%= msg.name %>{}
    <%= msg.attributes.map { |attr|
    "	if msg.#{attr.name}, err = reader.Read#{attr.type.to_s.pascal_case}(); err != nil {
            return nil, err
        }" }.join "\n" %>
        return msg, err
}
<% end %>
func ReadMessage(t uint64, reader BytesReader) (Message, error) {
	switch t {<% $messages.each do |msg| %>
	case <%= msg.id %>:
		return Decode<%= msg.name %>(reader)<% end %>
	}
	return nil, fmt.Errorf("unknown message code: %v", t)
}
