// generated from rosidl_generator_c/resource/idl__functions.c.em
// with input from g29_msg:msg/G29Msg.idl
// generated code does not contain a copyright notice
#include "g29_msg/msg/detail/g29_msg__functions.h"

#include <assert.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>

#include "rcutils/allocator.h"


bool
g29_msg__msg__G29Msg__init(g29_msg__msg__G29Msg * msg)
{
  if (!msg) {
    return false;
  }
  // heartbeat
  // axis0
  // axis1
  // axis2
  // axis3
  // axis4
  // axis5
  // button0
  // button1
  // button2
  // button3
  // button4
  // button5
  // button6
  // button7
  // button8
  // button9
  // button10
  // button11
  // button12
  // button13
  // button14
  // button15
  // button16
  // button17
  // button18
  // button19
  // button20
  // button21
  // button22
  // button23
  // button24
  return true;
}

void
g29_msg__msg__G29Msg__fini(g29_msg__msg__G29Msg * msg)
{
  if (!msg) {
    return;
  }
  // heartbeat
  // axis0
  // axis1
  // axis2
  // axis3
  // axis4
  // axis5
  // button0
  // button1
  // button2
  // button3
  // button4
  // button5
  // button6
  // button7
  // button8
  // button9
  // button10
  // button11
  // button12
  // button13
  // button14
  // button15
  // button16
  // button17
  // button18
  // button19
  // button20
  // button21
  // button22
  // button23
  // button24
}

bool
g29_msg__msg__G29Msg__are_equal(const g29_msg__msg__G29Msg * lhs, const g29_msg__msg__G29Msg * rhs)
{
  if (!lhs || !rhs) {
    return false;
  }
  // heartbeat
  if (lhs->heartbeat != rhs->heartbeat) {
    return false;
  }
  // axis0
  if (lhs->axis0 != rhs->axis0) {
    return false;
  }
  // axis1
  if (lhs->axis1 != rhs->axis1) {
    return false;
  }
  // axis2
  if (lhs->axis2 != rhs->axis2) {
    return false;
  }
  // axis3
  if (lhs->axis3 != rhs->axis3) {
    return false;
  }
  // axis4
  if (lhs->axis4 != rhs->axis4) {
    return false;
  }
  // axis5
  if (lhs->axis5 != rhs->axis5) {
    return false;
  }
  // button0
  if (lhs->button0 != rhs->button0) {
    return false;
  }
  // button1
  if (lhs->button1 != rhs->button1) {
    return false;
  }
  // button2
  if (lhs->button2 != rhs->button2) {
    return false;
  }
  // button3
  if (lhs->button3 != rhs->button3) {
    return false;
  }
  // button4
  if (lhs->button4 != rhs->button4) {
    return false;
  }
  // button5
  if (lhs->button5 != rhs->button5) {
    return false;
  }
  // button6
  if (lhs->button6 != rhs->button6) {
    return false;
  }
  // button7
  if (lhs->button7 != rhs->button7) {
    return false;
  }
  // button8
  if (lhs->button8 != rhs->button8) {
    return false;
  }
  // button9
  if (lhs->button9 != rhs->button9) {
    return false;
  }
  // button10
  if (lhs->button10 != rhs->button10) {
    return false;
  }
  // button11
  if (lhs->button11 != rhs->button11) {
    return false;
  }
  // button12
  if (lhs->button12 != rhs->button12) {
    return false;
  }
  // button13
  if (lhs->button13 != rhs->button13) {
    return false;
  }
  // button14
  if (lhs->button14 != rhs->button14) {
    return false;
  }
  // button15
  if (lhs->button15 != rhs->button15) {
    return false;
  }
  // button16
  if (lhs->button16 != rhs->button16) {
    return false;
  }
  // button17
  if (lhs->button17 != rhs->button17) {
    return false;
  }
  // button18
  if (lhs->button18 != rhs->button18) {
    return false;
  }
  // button19
  if (lhs->button19 != rhs->button19) {
    return false;
  }
  // button20
  if (lhs->button20 != rhs->button20) {
    return false;
  }
  // button21
  if (lhs->button21 != rhs->button21) {
    return false;
  }
  // button22
  if (lhs->button22 != rhs->button22) {
    return false;
  }
  // button23
  if (lhs->button23 != rhs->button23) {
    return false;
  }
  // button24
  if (lhs->button24 != rhs->button24) {
    return false;
  }
  return true;
}

bool
g29_msg__msg__G29Msg__copy(
  const g29_msg__msg__G29Msg * input,
  g29_msg__msg__G29Msg * output)
{
  if (!input || !output) {
    return false;
  }
  // heartbeat
  output->heartbeat = input->heartbeat;
  // axis0
  output->axis0 = input->axis0;
  // axis1
  output->axis1 = input->axis1;
  // axis2
  output->axis2 = input->axis2;
  // axis3
  output->axis3 = input->axis3;
  // axis4
  output->axis4 = input->axis4;
  // axis5
  output->axis5 = input->axis5;
  // button0
  output->button0 = input->button0;
  // button1
  output->button1 = input->button1;
  // button2
  output->button2 = input->button2;
  // button3
  output->button3 = input->button3;
  // button4
  output->button4 = input->button4;
  // button5
  output->button5 = input->button5;
  // button6
  output->button6 = input->button6;
  // button7
  output->button7 = input->button7;
  // button8
  output->button8 = input->button8;
  // button9
  output->button9 = input->button9;
  // button10
  output->button10 = input->button10;
  // button11
  output->button11 = input->button11;
  // button12
  output->button12 = input->button12;
  // button13
  output->button13 = input->button13;
  // button14
  output->button14 = input->button14;
  // button15
  output->button15 = input->button15;
  // button16
  output->button16 = input->button16;
  // button17
  output->button17 = input->button17;
  // button18
  output->button18 = input->button18;
  // button19
  output->button19 = input->button19;
  // button20
  output->button20 = input->button20;
  // button21
  output->button21 = input->button21;
  // button22
  output->button22 = input->button22;
  // button23
  output->button23 = input->button23;
  // button24
  output->button24 = input->button24;
  return true;
}

g29_msg__msg__G29Msg *
g29_msg__msg__G29Msg__create()
{
  rcutils_allocator_t allocator = rcutils_get_default_allocator();
  g29_msg__msg__G29Msg * msg = (g29_msg__msg__G29Msg *)allocator.allocate(sizeof(g29_msg__msg__G29Msg), allocator.state);
  if (!msg) {
    return NULL;
  }
  memset(msg, 0, sizeof(g29_msg__msg__G29Msg));
  bool success = g29_msg__msg__G29Msg__init(msg);
  if (!success) {
    allocator.deallocate(msg, allocator.state);
    return NULL;
  }
  return msg;
}

void
g29_msg__msg__G29Msg__destroy(g29_msg__msg__G29Msg * msg)
{
  rcutils_allocator_t allocator = rcutils_get_default_allocator();
  if (msg) {
    g29_msg__msg__G29Msg__fini(msg);
  }
  allocator.deallocate(msg, allocator.state);
}


bool
g29_msg__msg__G29Msg__Sequence__init(g29_msg__msg__G29Msg__Sequence * array, size_t size)
{
  if (!array) {
    return false;
  }
  rcutils_allocator_t allocator = rcutils_get_default_allocator();
  g29_msg__msg__G29Msg * data = NULL;

  if (size) {
    data = (g29_msg__msg__G29Msg *)allocator.zero_allocate(size, sizeof(g29_msg__msg__G29Msg), allocator.state);
    if (!data) {
      return false;
    }
    // initialize all array elements
    size_t i;
    for (i = 0; i < size; ++i) {
      bool success = g29_msg__msg__G29Msg__init(&data[i]);
      if (!success) {
        break;
      }
    }
    if (i < size) {
      // if initialization failed finalize the already initialized array elements
      for (; i > 0; --i) {
        g29_msg__msg__G29Msg__fini(&data[i - 1]);
      }
      allocator.deallocate(data, allocator.state);
      return false;
    }
  }
  array->data = data;
  array->size = size;
  array->capacity = size;
  return true;
}

void
g29_msg__msg__G29Msg__Sequence__fini(g29_msg__msg__G29Msg__Sequence * array)
{
  if (!array) {
    return;
  }
  rcutils_allocator_t allocator = rcutils_get_default_allocator();

  if (array->data) {
    // ensure that data and capacity values are consistent
    assert(array->capacity > 0);
    // finalize all array elements
    for (size_t i = 0; i < array->capacity; ++i) {
      g29_msg__msg__G29Msg__fini(&array->data[i]);
    }
    allocator.deallocate(array->data, allocator.state);
    array->data = NULL;
    array->size = 0;
    array->capacity = 0;
  } else {
    // ensure that data, size, and capacity values are consistent
    assert(0 == array->size);
    assert(0 == array->capacity);
  }
}

g29_msg__msg__G29Msg__Sequence *
g29_msg__msg__G29Msg__Sequence__create(size_t size)
{
  rcutils_allocator_t allocator = rcutils_get_default_allocator();
  g29_msg__msg__G29Msg__Sequence * array = (g29_msg__msg__G29Msg__Sequence *)allocator.allocate(sizeof(g29_msg__msg__G29Msg__Sequence), allocator.state);
  if (!array) {
    return NULL;
  }
  bool success = g29_msg__msg__G29Msg__Sequence__init(array, size);
  if (!success) {
    allocator.deallocate(array, allocator.state);
    return NULL;
  }
  return array;
}

void
g29_msg__msg__G29Msg__Sequence__destroy(g29_msg__msg__G29Msg__Sequence * array)
{
  rcutils_allocator_t allocator = rcutils_get_default_allocator();
  if (array) {
    g29_msg__msg__G29Msg__Sequence__fini(array);
  }
  allocator.deallocate(array, allocator.state);
}

bool
g29_msg__msg__G29Msg__Sequence__are_equal(const g29_msg__msg__G29Msg__Sequence * lhs, const g29_msg__msg__G29Msg__Sequence * rhs)
{
  if (!lhs || !rhs) {
    return false;
  }
  if (lhs->size != rhs->size) {
    return false;
  }
  for (size_t i = 0; i < lhs->size; ++i) {
    if (!g29_msg__msg__G29Msg__are_equal(&(lhs->data[i]), &(rhs->data[i]))) {
      return false;
    }
  }
  return true;
}

bool
g29_msg__msg__G29Msg__Sequence__copy(
  const g29_msg__msg__G29Msg__Sequence * input,
  g29_msg__msg__G29Msg__Sequence * output)
{
  if (!input || !output) {
    return false;
  }
  if (output->capacity < input->size) {
    const size_t allocation_size =
      input->size * sizeof(g29_msg__msg__G29Msg);
    rcutils_allocator_t allocator = rcutils_get_default_allocator();
    g29_msg__msg__G29Msg * data =
      (g29_msg__msg__G29Msg *)allocator.reallocate(
      output->data, allocation_size, allocator.state);
    if (!data) {
      return false;
    }
    // If reallocation succeeded, memory may or may not have been moved
    // to fulfill the allocation request, invalidating output->data.
    output->data = data;
    for (size_t i = output->capacity; i < input->size; ++i) {
      if (!g29_msg__msg__G29Msg__init(&output->data[i])) {
        // If initialization of any new item fails, roll back
        // all previously initialized items. Existing items
        // in output are to be left unmodified.
        for (; i-- > output->capacity; ) {
          g29_msg__msg__G29Msg__fini(&output->data[i]);
        }
        return false;
      }
    }
    output->capacity = input->size;
  }
  output->size = input->size;
  for (size_t i = 0; i < input->size; ++i) {
    if (!g29_msg__msg__G29Msg__copy(
        &(input->data[i]), &(output->data[i])))
    {
      return false;
    }
  }
  return true;
}
