mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-24 01:31:44 +00:00
62 lines
2.7 KiB
Django/Jinja
62 lines
2.7 KiB
Django/Jinja
###############################################################################
|
|
## Copyright (C) Photon Vision.
|
|
###############################################################################
|
|
## This program is free software: you can redistribute it and/or modify
|
|
## it under the terms of the GNU General Public License as published by
|
|
## the Free Software Foundation, either version 3 of the License, or
|
|
## (at your option) any later version.
|
|
##
|
|
## This program is distributed in the hope that it will be useful,
|
|
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
## GNU General Public License for more details.
|
|
##
|
|
## You should have received a copy of the GNU General Public License
|
|
## along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
###############################################################################
|
|
|
|
###############################################################################
|
|
## THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py.
|
|
## --> DO NOT MODIFY <--
|
|
###############################################################################
|
|
|
|
from ..targeting import *
|
|
|
|
class {{ name }}Serde:
|
|
|
|
# Message definition md5sum. See photon_packet.adoc for details
|
|
MESSAGE_VERSION = "{{ message_hash }}"
|
|
MESSAGE_FORMAT = "{{ message_fmt }}"
|
|
|
|
@staticmethod
|
|
def unpack(packet: 'Packet') -> '{{ name }}':
|
|
ret = {{ name }}()
|
|
{% for field in fields -%}
|
|
{%- if field.type | is_shimmed %}
|
|
ret.{{ field.name }} = {{ get_message_by_name(field.type).python_decode_shim }}()
|
|
{%- elif field.optional == True %}
|
|
# {{ field.name }} is optional! it better not be a VLA too
|
|
ret.{{ field.name }} = packet.decodeOptional({{ field.type }}.photonStruct)
|
|
{%- elif field.vla == True and not field.type | is_intrinsic %}
|
|
# {{ field.name }} is a custom VLA!
|
|
ret.{{ field.name }} = packet.decodeList({{ field.type }}.photonStruct)
|
|
{%- elif field.vla == True and field.type | is_intrinsic %}
|
|
# {{ field.name }} is a custom VLA!
|
|
ret.{{ field.name }} = packet.decode{{ type_map[field.type].java_type.title() }}List()
|
|
{%- elif field.type | is_intrinsic %}
|
|
# {{ field.name }} is of intrinsic type {{ field.type }}
|
|
ret.{{field.name}} = packet.{{ type_map[field.type].java_decode_method }}()
|
|
{%- else %}
|
|
# {{ field.name }} is of non-intrinsic type {{ field.type }}
|
|
ret.{{field.name}} = {{ field.type }}.photonStruct.unpack(packet)
|
|
{%- endif %}
|
|
{%- if not loop.last %}
|
|
{% endif -%}
|
|
{% endfor%}
|
|
|
|
return ret
|
|
|
|
|
|
# Hack ourselves into the base class
|
|
{{ name }}.photonStruct = {{ name }}Serde()
|