/* AUTOMATICALY GENERATED by org.flib.net.CPickle.java */

#include <netinet/in.h>
#include <string.h>

#include <fcpickle_impl.h>
#include <sdodownloadconfirmmsg.h>

void SDODownloadConfirmMsg_init(SDODownloadConfirmMsg_t *o)
{
}

/// This value varies only if dynamic length arrays or String type are used.
/// @param o If class does not contain variable length field types (String) or superclass,/// then o can be NULL.
/// @return size of buffer needed to pickle object only data
int SDODownloadConfirmMsg_getObjectBufferSize(SDODownloadConfirmMsg_t *o)
{
    int size = 0;
    // get superclass size
    if(!o) return -1;
    size += SDOConfirmMsg_getObjectBufferSize(&(o->super));
    size += 0;
    return size;
}

/// This value varies only if dynamic length arrays or String type are used
/// @return size of buffer needed to pickle object data and service data
int SDODownloadConfirmMsg_getPacketBufferSize(SDODownloadConfirmMsg_t *o)
{
    int32_t len = 0;
    fcpickle_class_def_t class_def;
    class_def.className = "ocera.rtcan.SDODownloadConfirmMsg";
    len += FCPICKLE_PACKET_HEAD_SIZE;
    len += CPickleClassDef_getObjectBufferSize(&class_def);
    len += SDODownloadConfirmMsg_getObjectBufferSize(o);
    return len;
}

int SDODownloadConfirmMsg_pickleObject(SDODownloadConfirmMsg_t *o, uint8_t *buffer, int buff_len)
{
    int32_t len = 0;
    // pickle superclass
    {
        int i;
        i = SDOConfirmMsg_pickleObject(&(o->super), buffer+len, buff_len-len);
        if(i < 0) return i;
        len += i;
    }
    return len;
}

/// align structure to array and set network endianing
/// @param buffer sufficient size of buffer is  xx_getBufferSize()
/// @param buff_len actual size of buffer
/// @return number of filled bytes or negative value if error
int SDODownloadConfirmMsg_toNet(SDODownloadConfirmMsg_t *o, uint8_t *buffer, int buff_len)
{
    int32_t len = 0, i;
    CPickleHead_t head;
    CPickleClassDef_t class_def;
    // set class definition
    class_def.className = "ocera.rtcan.SDODownloadConfirmMsg";
    // check buffer size
    len = SDODownloadConfirmMsg_getPacketBufferSize(o);
    if(len > (size_t)buff_len) return -1;
    // set packet head
    memcpy(&(head.headMagic), "CPICKLE_", 8);
    head.termZero = '\0';
    head.packetSize = len;
    len = 0;
    // pickle all to packet
    i = CPickleHead_pickleObject(&head, buffer+len, buff_len-len);
    if(i < 0) return i;
    len += i;
    i = CPickleClassDef_pickleObject(&class_def, buffer+len, buff_len-len);
    if(i < 0) return i;
    len += i;
    i = SDODownloadConfirmMsg_pickleObject(o, buffer+len, buff_len-len);
    if(i < 0) return i;
    len += i;
    return len;
}

/// load object data from buffer and set host endianing
/// @param buffer data to read from
/// NOTE!! char* (String in Java) fields are backuped by buffer (no memory is allocated during loading)
/// @return number of read bytes or negative value if error
int SDODownloadConfirmMsg_unpickleObject(SDODownloadConfirmMsg_t *o, uint8_t *buffer, int buff_len)
{
    int32_t len = 0;
    // unpickle superclass
    {
        int i;
        i = SDOConfirmMsg_unpickleObject(&(o->super), buffer+len, buff_len-len);
        if(i < 0) return i;
        len += i;
    }
    return len;
}
/// load object and service data from buffer and set host endianing
/// @param buffer data to read from
/// NOTE!! char* (String in Java) fields are backuped by buffer (no memory is allocated during loading)
/// @return number of read bytes or negative value if error
int SDODownloadConfirmMsg_fromNet(SDODownloadConfirmMsg_t *o, uint8_t *buffer, int buff_len)
{
    int32_t len = 0, i;
    CPickleHead_t head;
    CPickleClassDef_t class_def;
    i = CPickleHead_unpickleObject(&head, buffer+len, buff_len-len);
    if(i < 0) return i;
    len += i;
    i = CPickleClassDef_unpickleObject(&class_def, buffer+len, buff_len-len);
    if(i < 0) return i;
    len += i;
    i = SDODownloadConfirmMsg_unpickleObject(o, buffer+len, buff_len-len);
    if(i < 0) return i;
    len += i;
    return len;
}

