46 lines
1.1 KiB
Text
46 lines
1.1 KiB
Text
// Auto-generated, do not edit
|
|
package messages
|
|
|
|
import "encoding/binary"
|
|
|
|
const (
|
|
<% $messages.each do |msg| %>
|
|
Msg<%= msg.name %> = <%= msg.id %>
|
|
<% end %>
|
|
)
|
|
|
|
<% $messages.each do |msg| %>
|
|
type <%= msg.name %> struct {
|
|
message
|
|
<%= msg.attributes.map { |attr|
|
|
" #{attr.name} #{attr.type_go}" }.join "\n" %>
|
|
}
|
|
|
|
func (msg *<%= msg.name %>) Encode() []byte {
|
|
buf := make([]byte, <%= msg.attributes.count * 10 + 1 %><%= msg.attributes.map { |attr| "+len(msg.#{attr.name})" if attr.lengh_encoded }.compact.join %>)
|
|
buf[0] = <%= msg.id %>
|
|
p := 1
|
|
<%= msg.attributes.map { |attr|
|
|
" p = Write#{attr.type.to_s.pascal_case}(msg.#{attr.name}, buf, p)" }.join "\n" %>
|
|
return buf[:p]
|
|
}
|
|
|
|
func (msg *<%= msg.name %>) EncodeWithIndex() []byte {
|
|
encoded := msg.Encode()
|
|
if IsIOSType(msg.TypeID()) {
|
|
return encoded
|
|
}
|
|
data := make([]byte, len(encoded)+8)
|
|
copy(data[8:], encoded[:])
|
|
binary.LittleEndian.PutUint64(data[0:], msg.Meta().Index)
|
|
return data
|
|
}
|
|
|
|
func (msg *<%= msg.name %>) Decode() Message {
|
|
return msg
|
|
}
|
|
|
|
func (msg *<%= msg.name %>) TypeID() int {
|
|
return <%= msg.id %>
|
|
}
|
|
<% end %>
|