Skip to content

Commit

Permalink
Refresh the channel_port_mapping codegen
Browse files Browse the repository at this point in the history
Add an automation script to ease future updates.
  • Loading branch information
jwnimmer-tri authored and nosracd committed Mar 9, 2025
1 parent 050ce9e commit 319aa5e
Show file tree
Hide file tree
Showing 7 changed files with 279 additions and 207 deletions.
154 changes: 61 additions & 93 deletions lcm/lcmtypes/channel_port_map_update_t.c
Original file line number Diff line number Diff line change
@@ -1,90 +1,75 @@
/** THIS IS AN AUTOMATICALLY GENERATED FILE. DO NOT MODIFY
* BY HAND!!
*
* Generated by lcm-gen
**/
// THIS IS AN AUTOMATICALLY GENERATED FILE. DO NOT MODIFY
// BY HAND!!
//
// Generated by the regenerate.sh script in this directory

#include "channel_port_map_update_t.h"
#include <string.h>
#include "channel_port_map_update_t.h"

static int __channel_port_map_update_t_hash_computed;
static int64_t __channel_port_map_update_t_hash;
static uint64_t __channel_port_map_update_t_hash;

int64_t __channel_port_map_update_t_hash_recursive(const __lcm_hash_ptr *p)
uint64_t __channel_port_map_update_t_hash_recursive(const __lcm_hash_ptr *p)
{
const __lcm_hash_ptr *fp;
for (fp = p; fp != NULL; fp = fp->parent)
if (fp->v == __channel_port_map_update_t_get_hash)
return 0;

__lcm_hash_ptr cp;
cp.parent = p;
cp.v = (void *) __channel_port_map_update_t_get_hash;
cp.parent = p;
cp.v = __channel_port_map_update_t_get_hash;
(void) cp;

int64_t hash = 0x4216b98388375d0bLL + __int16_t_hash_recursive(&cp) +
__int16_t_hash_recursive(&cp) + __channel_to_port_t_hash_recursive(&cp);
uint64_t hash = (uint64_t)0x4216b98388375d0bLL
+ __int16_t_hash_recursive(&cp)
+ __int16_t_hash_recursive(&cp)
+ __channel_to_port_t_hash_recursive(&cp)
;

return (hash << 1) + ((hash >> 63) & 1);
return (hash<<1) + ((hash>>63)&1);
}

int64_t __channel_port_map_update_t_get_hash(void)
{
if (!__channel_port_map_update_t_hash_computed) {
__channel_port_map_update_t_hash = __channel_port_map_update_t_hash_recursive(NULL);
__channel_port_map_update_t_hash = (int64_t)__channel_port_map_update_t_hash_recursive(NULL);
__channel_port_map_update_t_hash_computed = 1;
}

return __channel_port_map_update_t_hash;
}

int __channel_port_map_update_t_encode_array(void *buf, int offset, int maxlen,
const channel_port_map_update_t *p, int elements)
int __channel_port_map_update_t_encode_array(void *buf, int offset, int maxlen, const channel_port_map_update_t *p, int elements)
{
int pos = 0, thislen, element;
int pos = 0, element;
int thislen;

for (element = 0; element < elements; element++) {
thislen =
__int16_t_encode_array(buf, offset + pos, maxlen - pos, &(p[element].num_ports), 1);
if (thislen < 0)
return thislen;
else
pos += thislen;

thislen =
__int16_t_encode_array(buf, offset + pos, maxlen - pos, &(p[element].num_channels), 1);
if (thislen < 0)
return thislen;
else
pos += thislen;

thislen = __channel_to_port_t_encode_array(buf, offset + pos, maxlen - pos,
p[element].mapping, p[element].num_channels);
if (thislen < 0)
return thislen;
else
pos += thislen;

thislen = __int16_t_encode_array(buf, offset + pos, maxlen - pos, &(p[element].num_ports), 1);
if (thislen < 0) return thislen; else pos += thislen;

thislen = __int16_t_encode_array(buf, offset + pos, maxlen - pos, &(p[element].num_channels), 1);
if (thislen < 0) return thislen; else pos += thislen;

thislen = __channel_to_port_t_encode_array(buf, offset + pos, maxlen - pos, p[element].mapping, p[element].num_channels);
if (thislen < 0) return thislen; else pos += thislen;

}
return pos;
}

int channel_port_map_update_t_encode(void *buf, int offset, int maxlen,
const channel_port_map_update_t *p)
int channel_port_map_update_t_encode(void *buf, int offset, int maxlen, const channel_port_map_update_t *p)
{
int pos = 0, thislen;
int64_t hash = __channel_port_map_update_t_get_hash();

thislen = __int64_t_encode_array(buf, offset + pos, maxlen - pos, &hash, 1);
if (thislen < 0)
return thislen;
else
pos += thislen;
if (thislen < 0) return thislen; else pos += thislen;

thislen = __channel_port_map_update_t_encode_array(buf, offset + pos, maxlen - pos, p, 1);
if (thislen < 0)
return thislen;
else
pos += thislen;
if (thislen < 0) return thislen; else pos += thislen;

return pos;
}
Expand All @@ -93,11 +78,13 @@ int __channel_port_map_update_t_encoded_array_size(const channel_port_map_update
{
int size = 0, element;
for (element = 0; element < elements; element++) {

size += __int16_t_encoded_array_size(&(p[element].num_ports), 1);

size += __int16_t_encoded_array_size(&(p[element].num_channels), 1);

size += __channel_to_port_t_encoded_array_size(p[element].mapping, p[element].num_channels);

}
return size;
}
Expand All @@ -107,73 +94,55 @@ int channel_port_map_update_t_encoded_size(const channel_port_map_update_t *p)
return 8 + __channel_port_map_update_t_encoded_array_size(p, 1);
}

int __channel_port_map_update_t_decode_array(const void *buf, int offset, int maxlen,
channel_port_map_update_t *p, int elements)
int __channel_port_map_update_t_decode_array(const void *buf, int offset, int maxlen, channel_port_map_update_t *p, int elements)
{
int pos = 0, thislen, element;

for (element = 0; element < elements; element++) {
thislen =
__int16_t_decode_array(buf, offset + pos, maxlen - pos, &(p[element].num_ports), 1);
if (thislen < 0)
return thislen;
else
pos += thislen;

thislen =
__int16_t_decode_array(buf, offset + pos, maxlen - pos, &(p[element].num_channels), 1);
if (thislen < 0)
return thislen;
else
pos += thislen;

p[element].mapping =
(channel_to_port_t *) lcm_malloc(sizeof(channel_to_port_t) * p[element].num_channels);
thislen = __channel_to_port_t_decode_array(buf, offset + pos, maxlen - pos,
p[element].mapping, p[element].num_channels);
if (thislen < 0)
return thislen;
else
pos += thislen;

thislen = __int16_t_decode_array(buf, offset + pos, maxlen - pos, &(p[element].num_ports), 1);
if (thislen < 0) return thislen; else pos += thislen;

thislen = __int16_t_decode_array(buf, offset + pos, maxlen - pos, &(p[element].num_channels), 1);
if (thislen < 0) return thislen; else pos += thislen;

p[element].mapping = (channel_to_port_t*) lcm_malloc(sizeof(channel_to_port_t) * p[element].num_channels);
thislen = __channel_to_port_t_decode_array(buf, offset + pos, maxlen - pos, p[element].mapping, p[element].num_channels);
if (thislen < 0) return thislen; else pos += thislen;

}
return pos;
}

int __channel_port_map_update_t_decode_array_cleanup(channel_port_map_update_t *p, int elements)
{
(void)p;
int element;
for (element = 0; element < elements; element++) {

__int16_t_decode_array_cleanup(&(p[element].num_ports), 1);

__int16_t_decode_array_cleanup(&(p[element].num_channels), 1);

__channel_to_port_t_decode_array_cleanup(p[element].mapping, p[element].num_channels);
if (p[element].mapping)
free(p[element].mapping);
if (p[element].mapping) free(p[element].mapping);

}
return 0;
}

int channel_port_map_update_t_decode(const void *buf, int offset, int maxlen,
channel_port_map_update_t *p)
int channel_port_map_update_t_decode(const void *buf, int offset, int maxlen, channel_port_map_update_t *p)
{
int pos = 0, thislen;
int64_t hash = __channel_port_map_update_t_get_hash();

int64_t this_hash;
thislen = __int64_t_decode_array(buf, offset + pos, maxlen - pos, &this_hash, 1);
if (thislen < 0)
return thislen;
else
pos += thislen;
if (this_hash != hash)
return -1;
if (thislen < 0) return thislen; else pos += thislen;
if (this_hash != hash) return -1;

thislen = __channel_port_map_update_t_decode_array(buf, offset + pos, maxlen - pos, p, 1);
if (thislen < 0)
return thislen;
else
pos += thislen;
if (thislen < 0) return thislen; else pos += thislen;

return pos;
}
Expand All @@ -183,27 +152,25 @@ int channel_port_map_update_t_decode_cleanup(channel_port_map_update_t *p)
return __channel_port_map_update_t_decode_array_cleanup(p, 1);
}

int __channel_port_map_update_t_clone_array(const channel_port_map_update_t *p,
channel_port_map_update_t *q, int elements)
int __channel_port_map_update_t_clone_array(const channel_port_map_update_t *p, channel_port_map_update_t *q, int elements)
{
int element;
for (element = 0; element < elements; element++) {

__int16_t_clone_array(&(p[element].num_ports), &(q[element].num_ports), 1);

__int16_t_clone_array(&(p[element].num_channels), &(q[element].num_channels), 1);

q[element].mapping =
(channel_to_port_t *) lcm_malloc(sizeof(channel_to_port_t) * q[element].num_channels);
__channel_to_port_t_clone_array(p[element].mapping, q[element].mapping,
p[element].num_channels);
q[element].mapping = (channel_to_port_t*) lcm_malloc(sizeof(channel_to_port_t) * q[element].num_channels);
__channel_to_port_t_clone_array(p[element].mapping, q[element].mapping, p[element].num_channels);

}
return 0;
}

channel_port_map_update_t *channel_port_map_update_t_copy(const channel_port_map_update_t *p)
{
channel_port_map_update_t *q =
(channel_port_map_update_t *) malloc(sizeof(channel_port_map_update_t));
channel_port_map_update_t *q = (channel_port_map_update_t*) malloc(sizeof(channel_port_map_update_t));
__channel_port_map_update_t_clone_array(p, q, 1);
return q;
}
Expand All @@ -213,3 +180,4 @@ void channel_port_map_update_t_destroy(channel_port_map_update_t *p)
__channel_port_map_update_t_decode_array_cleanup(p, 1);
free(p);
}

99 changes: 70 additions & 29 deletions lcm/lcmtypes/channel_port_map_update_t.h
Original file line number Diff line number Diff line change
@@ -1,53 +1,94 @@
/**
* Generated by running lcm-gen -c --c-no-pubsub channel_port_mapping.lcm
*
* and then modified by hand to replace
* #include <lcm/lcm_coretypes.h>
* with
* #include "../lcm_coretypes.h"
**/
// THIS IS AN AUTOMATICALLY GENERATED FILE. DO NOT MODIFY
// BY HAND!!
//
// Generated by the regenerate.sh script in this directory

#ifndef _channel_port_map_update_t_h
#define _channel_port_map_update_t_h

#include <stdint.h>
#include <stdlib.h>
#include "../lcm_coretypes.h"

#ifndef _channel_port_map_update_t_h
#define _channel_port_map_update_t_h

#ifdef __cplusplus
extern "C" {
#endif

#include "channel_to_port_t.h"
typedef struct _channel_port_map_update_t channel_port_map_update_t;
struct _channel_port_map_update_t {
int16_t num_ports;
int16_t num_channels;
struct _channel_port_map_update_t
{
int16_t num_ports;

/**
* size of the port range for the mappings
*/
int16_t num_channels;

/**
* LCM Type: channel_to_port_t[num_channels]
*/
channel_to_port_t *mapping;
};

channel_port_map_update_t *channel_port_map_update_t_copy(const channel_port_map_update_t *p);
void channel_port_map_update_t_destroy(channel_port_map_update_t *p);
/**
* Create a deep copy of a channel_port_map_update_t.
* When no longer needed, destroy it with channel_port_map_update_t_destroy()
*/
channel_port_map_update_t* channel_port_map_update_t_copy(const channel_port_map_update_t* to_copy);

/**
* Destroy an instance of channel_port_map_update_t created by channel_port_map_update_t_copy()
*/
void channel_port_map_update_t_destroy(channel_port_map_update_t* to_destroy);

/**
* Encode a message of type channel_port_map_update_t into binary form.
*
* @param buf The output buffer.
* @param offset Encoding starts at this byte offset into @p buf.
* @param maxlen Maximum number of bytes to write. This should generally
* be equal to channel_port_map_update_t_encoded_size().
* @param msg The message to encode.
* @return The number of bytes encoded, or <0 if an error occured.
*/
int channel_port_map_update_t_encode(void *buf, int offset, int maxlen, const channel_port_map_update_t *p);

int channel_port_map_update_t_encode(void *buf, int offset, int maxlen,
const channel_port_map_update_t *p);
int channel_port_map_update_t_decode(const void *buf, int offset, int maxlen,
channel_port_map_update_t *p);
/**
* Decode a message of type channel_port_map_update_t from binary form.
* When decoding messages containing strings or variable-length arrays, this
* function may allocate memory. When finished with the decoded message,
* release allocated resources with channel_port_map_update_t_decode_cleanup().
*
* @param buf The buffer containing the encoded message
* @param offset The byte offset into @p buf where the encoded message starts.
* @param maxlen The maximum number of bytes to read while decoding.
* @param msg Output parameter where the decoded message is stored
* @return The number of bytes decoded, or <0 if an error occured.
*/
int channel_port_map_update_t_decode(const void *buf, int offset, int maxlen, channel_port_map_update_t *msg);

/**
* Release resources allocated by channel_port_map_update_t_decode()
* @return 0
*/
int channel_port_map_update_t_decode_cleanup(channel_port_map_update_t *p);

/**
* Check how many bytes are required to encode a message of type channel_port_map_update_t
*/
int channel_port_map_update_t_encoded_size(const channel_port_map_update_t *p);

// LCM support functions. Users should not call these
int64_t __channel_port_map_update_t_get_hash(void);
int64_t __channel_port_map_update_t_hash_recursive(const __lcm_hash_ptr *p);
int __channel_port_map_update_t_encode_array(void *buf, int offset, int maxlen,
const channel_port_map_update_t *p, int elements);
int __channel_port_map_update_t_decode_array(const void *buf, int offset, int maxlen,
channel_port_map_update_t *p, int elements);
uint64_t __channel_port_map_update_t_hash_recursive(const __lcm_hash_ptr *p);
int __channel_port_map_update_t_encode_array(
void *buf, int offset, int maxlen, const channel_port_map_update_t *p, int elements);
int __channel_port_map_update_t_decode_array(
const void *buf, int offset, int maxlen, channel_port_map_update_t *p, int elements);
int __channel_port_map_update_t_decode_array_cleanup(channel_port_map_update_t *p, int elements);
int __channel_port_map_update_t_encoded_array_size(const channel_port_map_update_t *p,
int elements);
int __channel_port_map_update_t_clone_array(const channel_port_map_update_t *p,
channel_port_map_update_t *q, int elements);
int __channel_port_map_update_t_encoded_array_size(const channel_port_map_update_t *p, int elements);
int __channel_port_map_update_t_clone_array(const channel_port_map_update_t *p, channel_port_map_update_t *q, int elements);

#ifdef __cplusplus
}
Expand Down
Loading

0 comments on commit 319aa5e

Please sign in to comment.