2024-08-31 13:44:19 -04:00
|
|
|
/*
|
2025-01-12 10:55:55 +11:00
|
|
|
* MIT License
|
2024-08-31 13:44:19 -04:00
|
|
|
*
|
2025-01-12 10:55:55 +11:00
|
|
|
* Copyright (c) PhotonVision
|
2024-08-31 13:44:19 -04:00
|
|
|
*
|
2025-01-12 10:55:55 +11:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
* furnished to do so, subject to the following conditions:
|
2024-08-31 13:44:19 -04:00
|
|
|
*
|
2025-01-12 10:55:55 +11:00
|
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
|
|
|
* copies or substantial portions of the Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
|
* SOFTWARE.
|
2024-08-31 13:44:19 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// THIS FILE WAS AUTO-GENERATED BY ./photon-serde/generate_messages.py. DO NOT MODIFY
|
|
|
|
|
|
|
|
|
|
package org.photonvision.struct;
|
|
|
|
|
|
|
|
|
|
import org.photonvision.common.dataflow.structures.Packet;
|
|
|
|
|
import org.photonvision.common.dataflow.structures.PacketSerde;
|
|
|
|
|
import org.photonvision.utils.PacketUtils;
|
|
|
|
|
|
|
|
|
|
// Assume that the base class lives here and we can import it
|
|
|
|
|
import org.photonvision.targeting.*;
|
|
|
|
|
|
2024-09-22 22:27:13 -04:00
|
|
|
// WPILib imports (if any)
|
|
|
|
|
import edu.wpi.first.util.struct.Struct;
|
|
|
|
|
{% for type in nested_wpilib_types -%}
|
|
|
|
|
import {{ get_message_by_name(type).java_import }};
|
|
|
|
|
{%- if not loop.last %},{% endif -%}
|
|
|
|
|
{%- endfor%}
|
2024-08-31 13:44:19 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Auto-generated serialization/deserialization helper for {{name}}
|
|
|
|
|
*/
|
|
|
|
|
public class {{ name }}Serde implements PacketSerde<{{name}}> {
|
|
|
|
|
|
2024-09-22 22:27:13 -04:00
|
|
|
@Override
|
|
|
|
|
public final String getInterfaceUUID() { return "{{ message_hash }}"; }
|
|
|
|
|
@Override
|
|
|
|
|
public final String getSchema() { return "{{ message_fmt }}"; }
|
|
|
|
|
@Override
|
|
|
|
|
public final String getTypeName() { return "{{ name }}"; }
|
2024-08-31 13:44:19 -04:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getMaxByteSize() {
|
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
throw new UnsupportedOperationException("Unimplemented method 'getMaxByteSize'");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void pack(Packet packet, {{ name }} value) {
|
|
|
|
|
{%- for field in fields -%}
|
2024-11-21 15:43:33 +11:00
|
|
|
{%- if field.type | is_shimmed %}
|
2024-08-31 13:44:19 -04:00
|
|
|
{{ get_message_by_name(field.type).java_encode_shim }}(packet, value.{{ field.name }});
|
2024-11-21 15:43:33 +11:00
|
|
|
{%- elif field.optional == True %}
|
2024-08-31 13:44:19 -04:00
|
|
|
// {{ field.name }} is optional! it better not be a VLA too
|
|
|
|
|
packet.encodeOptional(value.{{ field.name }});
|
2024-11-21 15:43:33 +11:00
|
|
|
{%- elif field.vla == True and field.type | is_intrinsic %}
|
2024-08-31 13:44:19 -04:00
|
|
|
// {{ field.name }} is a intrinsic VLA!
|
|
|
|
|
packet.encode(value.{{ field.name }});
|
2024-11-21 15:43:33 +11:00
|
|
|
{%- elif field.vla == True %}
|
2024-08-31 13:44:19 -04:00
|
|
|
// {{ field.name }} is a custom VLA!
|
|
|
|
|
packet.encodeList(value.{{ field.name }});
|
2024-11-21 15:43:33 +11:00
|
|
|
{%- elif field.type | is_intrinsic %}
|
2024-08-31 13:44:19 -04:00
|
|
|
// field {{ field.name }} is of intrinsic type {{ field.type }}
|
|
|
|
|
packet.encode(({{ type_map[field.type].java_type }}) value.{{ field.name }});
|
2024-11-21 15:43:33 +11:00
|
|
|
{%- else %}
|
2024-08-31 13:44:19 -04:00
|
|
|
// field {{ field.name }} is of non-intrinsic type {{ field.type }}
|
|
|
|
|
{{ field.type }}.photonStruct.pack(packet, value.{{ field.name }});
|
2024-11-21 15:43:33 +11:00
|
|
|
{%- endif %}
|
|
|
|
|
{%- if not loop.last %}
|
|
|
|
|
{% endif -%}
|
2024-08-31 13:44:19 -04:00
|
|
|
{% endfor%}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public {{ name }} unpack(Packet packet) {
|
|
|
|
|
var ret = new {{ name }}();
|
|
|
|
|
{% for field in fields -%}
|
2024-11-21 15:43:33 +11:00
|
|
|
{%- if field.type | is_shimmed %}
|
2024-08-31 13:44:19 -04:00
|
|
|
ret.{{ field.name }} = {{ get_message_by_name(field.type).java_decode_shim }}(packet);
|
2024-11-21 15:43:33 +11:00
|
|
|
{%- elif field.optional == True %}
|
2024-08-31 13:44:19 -04:00
|
|
|
// {{ field.name }} is optional! it better not be a VLA too
|
|
|
|
|
ret.{{ field.name }} = packet.decodeOptional({{ field.type }}.photonStruct);
|
2024-11-21 15:43:33 +11:00
|
|
|
{%- elif field.vla == True and not field.type | is_intrinsic %}
|
2024-08-31 13:44:19 -04:00
|
|
|
// {{ field.name }} is a custom VLA!
|
|
|
|
|
ret.{{ field.name }} = packet.decodeList({{ field.type }}.photonStruct);
|
2024-11-21 15:43:33 +11:00
|
|
|
{%- elif field.vla == True and field.type | is_intrinsic %}
|
2024-08-31 13:44:19 -04:00
|
|
|
// {{ field.name }} is a custom VLA!
|
|
|
|
|
ret.{{ field.name }} = packet.decode{{ type_map[field.type].java_type.title() }}List();
|
2024-11-21 15:43:33 +11:00
|
|
|
{%- elif field.type | is_intrinsic %}
|
2024-08-31 13:44:19 -04:00
|
|
|
// {{ field.name }} is of intrinsic type {{ field.type }}
|
|
|
|
|
ret.{{field.name}} = packet.{{ type_map[field.type].java_decode_method }}();
|
2024-11-21 15:43:33 +11:00
|
|
|
{%- else %}
|
2024-08-31 13:44:19 -04:00
|
|
|
// {{ field.name }} is of non-intrinsic type {{ field.type }}
|
|
|
|
|
ret.{{field.name}} = {{ field.type }}.photonStruct.unpack(packet);
|
2024-11-21 15:43:33 +11:00
|
|
|
{%- endif %}
|
|
|
|
|
{%- if not loop.last %}
|
|
|
|
|
{% endif -%}
|
2024-08-31 13:44:19 -04:00
|
|
|
{% endfor%}
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
2024-09-22 22:27:13 -04:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public PacketSerde<?>[] getNestedPhotonMessages() {
|
|
|
|
|
return new PacketSerde<?>[] {
|
|
|
|
|
{% for type in nested_photon_types -%}
|
|
|
|
|
{{ type }}.photonStruct
|
|
|
|
|
{%- if not loop.last %},{% endif -%}
|
|
|
|
|
{%- endfor%}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Struct<?>[] getNestedWpilibMessages() {
|
|
|
|
|
return new Struct<?>[] {
|
|
|
|
|
{% for type in nested_wpilib_types -%}
|
|
|
|
|
{{ type }}.struct
|
|
|
|
|
{%- if not loop.last %},{% endif -%}
|
|
|
|
|
{%- endfor%}
|
|
|
|
|
};
|
|
|
|
|
}
|
2024-11-21 15:43:33 +11:00
|
|
|
}{{'\n'}}
|