openreplay/mobs/templates/frontend~app~player~MessageDistributor~messages~RawMessageReader.ts.erb
2022-09-12 12:18:55 +02:00

36 lines
1 KiB
Text

// Auto-generated, do not edit
/* eslint-disable */
import PrimitiveReader from './PrimitiveReader'
import type { RawMessage } from './raw'
export default class RawMessageReader extends PrimitiveReader {
readMessage(): RawMessage | null {
const p = this.p
const resetPointer = () => {
this.p = p
return null
}
const tp = this.readUint()
if (tp === null) { return resetPointer() }
switch (tp) {
<% $messages.select { |msg| msg.replayer }.each do |msg| %>
case <%= msg.id %>: {
<%= msg.attributes.map { |attr|
" const #{attr.name.camel_case} = this.read#{attr.type.to_s.pascal_case}(); if (#{attr.name.camel_case} === null) { return resetPointer() }" }.join "\n" %>
return {
tp: "<%= msg.name.snake_case %>",
<%= msg.attributes.map { |attr|
" #{attr.name.camel_case}," }.join "\n" %>
};
}
<% end %>
default:
throw new Error(`Unrecognizable message type: ${ tp }; Pointer at the position ${this.p} of ${this.buf.length}`)
return null;
}
}
}