void MyFrame::OutputNetNode(unsigned char *auxbuf, int *size, int ind, bool node_code, int max_node_length, NetNode * pN, int endian_arch, bool aStarSupported) { // // exporting a Node into NETWORK-DATA // int n_star; int i; NetArc **arc_array; NetArc *pA; unsigned char *out = auxbuf; *out++ = GAIA_NET_NODE; gaiaExport32(out, ind, 1, endian_arch); // the Node internal index out += 4; if (node_code) { // Nodes are identified by a TEXT Code memset(out, '\0', max_node_length); strcpy((char *) out, pN->GetCode().ToUTF8()); out += max_node_length; } else { // Nodes are identified by an INTEGER Id gaiaExportI64(out, pN->GetId(), 1, endian_arch); out += 8; } if (aStarSupported) { // in order to support the A* algorithm [X,Y] are required for each node gaiaExport64(out, pN->GetX(), 1, endian_arch); out += 8; gaiaExport64(out, pN->GetY(), 1, endian_arch); out += 8; } arc_array = pN->PrepareOutcomings(&n_star); gaiaExport16(out, n_star, 1, endian_arch); // # of outcoming arcs out += 2; for (i = 0; i < n_star; i++) { // exporting the outcoming arcs pA = *(arc_array + i); *out++ = GAIA_NET_ARC; gaiaExportI64(out, pA->GetRowId(), 1, endian_arch); // the Arc rowid out += 8; gaiaExport32(out, pA->GetTo()->GetInternalIndex(), 1, endian_arch); // the ToNode internal index out += 4; gaiaExport64(out, pA->GetCost(), 1, endian_arch); // the Arc Cost out += 8; *out++ = GAIA_NET_END; } if (arc_array) delete[]arc_array; *out++ = GAIA_NET_END; *size = out - auxbuf; }
int main (int argc, char *argv[]) { unsigned char buf_in[8]; unsigned char buf_out[8]; short shrt_val; int int_val; sqlite3_int64 i64_val; float flt_val; double dbl_val; /* testing short values [16 bit] */ buf_in[0] = 0xdf; buf_in[1] = 0xfd; shrt_val = gaiaImport16(buf_in, LITTLE_ENDIAN_ENCODED, LITTLE_ENDIAN_ARCH); gaiaExport16(buf_out, shrt_val, LITTLE_ENDIAN_ENCODED, LITTLE_ENDIAN_ARCH); if (buf_out[0] != 0xdf || buf_out[1] != 0xfd) { fprintf(stderr, "endian INT16 (1): got 0x%02x%02x, expected 0xdffd\n", buf_out[0], buf_out[1]); return -1; } shrt_val = gaiaImport16(buf_in, BIG_ENDIAN_ENCODED, BIG_ENDIAN_ARCH); gaiaExport16(buf_out, shrt_val, BIG_ENDIAN_ENCODED, BIG_ENDIAN_ARCH); if (buf_out[0] != 0xdf || buf_out[1] != 0xfd) { fprintf(stderr, "endian INT16 (2): got 0x%02x%02x, expected 0xdffd\n", buf_out[0], buf_out[1]); return -2; } shrt_val = gaiaImport16(buf_in, BIG_ENDIAN_ENCODED, LITTLE_ENDIAN_ARCH); gaiaExport16(buf_out, shrt_val, LITTLE_ENDIAN_ENCODED, LITTLE_ENDIAN_ARCH); if (buf_out[0] != 0xfd || buf_out[1] != 0xdf) { fprintf(stderr, "endian INT16 (3): got 0x%02x%02x, expected 0xfddf\n", buf_out[0], buf_out[1]); return -3; } shrt_val = gaiaImport16(buf_in, BIG_ENDIAN_ENCODED, BIG_ENDIAN_ARCH); gaiaExport16(buf_out, shrt_val, LITTLE_ENDIAN_ENCODED, BIG_ENDIAN_ARCH); if (buf_out[0] != 0xfd || buf_out[1] != 0xdf) { fprintf(stderr, "endian INT16 (4): got 0x%02x%02x, expected 0xfddf\n", buf_out[0], buf_out[1]); return -4; } shrt_val = gaiaImport16(buf_in, LITTLE_ENDIAN_ENCODED, LITTLE_ENDIAN_ARCH); gaiaExport16(buf_out, shrt_val, BIG_ENDIAN_ENCODED, LITTLE_ENDIAN_ARCH); if (buf_out[0] != 0xdf || buf_out[1] != 0xfd) { fprintf(stderr, "endian 16 bit (5): got 0x%02x%02x, expected 0xdffd\n", buf_out[0], buf_out[1]); return -5; } shrt_val = gaiaImport16(buf_in, LITTLE_ENDIAN_ENCODED, BIG_ENDIAN_ARCH); gaiaExport16(buf_out, shrt_val, BIG_ENDIAN_ENCODED, BIG_ENDIAN_ARCH); if (buf_out[0] != 0xfd || buf_out[1] != 0xdf) { fprintf(stderr, "endian INT16 (6): got 0x%02x%02x, expected 0xfddf\n", buf_out[0], buf_out[1]); return -6; } /* testing int values [32 bit] */ buf_in[0] = 0xdf; buf_in[1] = 0xec; buf_in[2] = 0xce; buf_in[3] = 0xfd; int_val = gaiaImport32(buf_in, LITTLE_ENDIAN_ENCODED, LITTLE_ENDIAN_ARCH); gaiaExport32(buf_out, int_val, LITTLE_ENDIAN_ENCODED, LITTLE_ENDIAN_ARCH); if (buf_out[0] != 0xdf || buf_out[1] != 0xec || buf_out[2] != 0xce || buf_out[3] != 0xfd) { fprintf(stderr, "endian INT32 (1): got 0x%02x%02x%02x%02x, expected 0xdfeccefd\n", buf_out[0], buf_out[1], buf_out[2], buf_out[3]); return -7; } int_val = gaiaImport32(buf_in, BIG_ENDIAN_ENCODED, BIG_ENDIAN_ARCH); gaiaExport32(buf_out, int_val, BIG_ENDIAN_ENCODED, BIG_ENDIAN_ARCH); if (buf_out[0] != 0xdf || buf_out[1] != 0xec || buf_out[2] != 0xce || buf_out[3] != 0xfd) { fprintf(stderr, "endian INT32 (2): got 0x%02x%02x%02x%02x, expected 0xdfeccefd\n", buf_out[0], buf_out[1], buf_out[2], buf_out[3]); return -8; } int_val = gaiaImport32(buf_in, BIG_ENDIAN_ENCODED, LITTLE_ENDIAN_ARCH); gaiaExport32(buf_out, int_val, LITTLE_ENDIAN_ENCODED, LITTLE_ENDIAN_ARCH); if (buf_out[0] != 0xfd || buf_out[1] != 0xce || buf_out[2] != 0xec || buf_out[3] != 0xdf) { fprintf(stderr, "endian INT32 (3): got 0x%02x%02x%02x%02x, expected 0xfdceecdf\n", buf_out[0], buf_out[1], buf_out[2], buf_out[3]); return -9; } int_val = gaiaImport32(buf_in, BIG_ENDIAN_ENCODED, BIG_ENDIAN_ARCH); gaiaExport32(buf_out, int_val, LITTLE_ENDIAN_ENCODED, BIG_ENDIAN_ARCH); if (buf_out[0] != 0xfd || buf_out[1] != 0xce || buf_out[2] != 0xec || buf_out[3] != 0xdf) { fprintf(stderr, "endian INT32 (4): got 0x%02x%02x%02x%02x, expected 0xfdceecdf\n", buf_out[0], buf_out[1], buf_out[2], buf_out[3]); return -10; } int_val = gaiaImport32(buf_in, LITTLE_ENDIAN_ENCODED, LITTLE_ENDIAN_ARCH); gaiaExport32(buf_out, int_val, BIG_ENDIAN_ENCODED, LITTLE_ENDIAN_ARCH); if (buf_out[0] != 0xfd || buf_out[1] != 0xce || buf_out[2] != 0xec || buf_out[3] != 0xdf) { fprintf(stderr, "endian INT32 (5): got 0x%02x%02x%02x%02x, expected 0xfdceecdf\n", buf_out[0], buf_out[1], buf_out[2], buf_out[3]); return -11; } int_val = gaiaImport32(buf_in, LITTLE_ENDIAN_ENCODED, BIG_ENDIAN_ARCH); gaiaExport32(buf_out, int_val, BIG_ENDIAN_ENCODED, BIG_ENDIAN_ARCH); if (buf_out[0] != 0xfd || buf_out[1] != 0xce || buf_out[2] != 0xec || buf_out[3] != 0xdf) { fprintf(stderr, "endian INT32 (6): got 0x%02x%02x%02x%02x, expected 0xfdceecdf\n", buf_out[0], buf_out[1], buf_out[2], buf_out[3]); return -12; } /* testing long values [64 bit] */ buf_in[0] = 0xdf; buf_in[1] = 0xec; buf_in[2] = 0xa8; buf_in[3] = 0x63; buf_in[4] = 0x36; buf_in[5] = 0x8a; buf_in[6] = 0xce; buf_in[7] = 0xfd; i64_val = gaiaImportI64(buf_in, LITTLE_ENDIAN_ENCODED, LITTLE_ENDIAN_ARCH); gaiaExportI64(buf_out, i64_val, LITTLE_ENDIAN_ENCODED, LITTLE_ENDIAN_ARCH); if (buf_out[0] != 0xdf || buf_out[1] != 0xec || buf_out[2] != 0xa8 || buf_out[3] != 0x63 || buf_out[4] != 0x36 || buf_out[5] != 0x8a || buf_out[6] != 0xce || buf_out[7] != 0xfd) { fprintf(stderr, "endian INT64 (1): got 0x%02x%02x%02x%02x%02x%02x%02x%02x, expected 0xdfeca863368acefd\n", buf_out[0], buf_out[1], buf_out[2], buf_out[3], buf_out[4], buf_out[5], buf_out[6], buf_out[7]); return -13; } i64_val = gaiaImportI64(buf_in, BIG_ENDIAN_ENCODED, BIG_ENDIAN_ARCH); gaiaExportI64(buf_out, i64_val, BIG_ENDIAN_ENCODED, BIG_ENDIAN_ARCH); if (buf_out[0] != 0xdf || buf_out[1] != 0xec || buf_out[2] != 0xa8 || buf_out[3] != 0x63 || buf_out[4] != 0x36 || buf_out[5] != 0x8a || buf_out[6] != 0xce || buf_out[7] != 0xfd) { fprintf(stderr, "endian INT64 (2): got 0x%02x%02x%02x%02x%02x%02x%02x%02x, expected 0xdfeca863368acefd\n", buf_out[0], buf_out[1], buf_out[2], buf_out[3], buf_out[4], buf_out[5], buf_out[6], buf_out[7]); return -14; } i64_val = gaiaImportI64(buf_in, BIG_ENDIAN_ENCODED, LITTLE_ENDIAN_ARCH); gaiaExportI64(buf_out, i64_val, LITTLE_ENDIAN_ENCODED, LITTLE_ENDIAN_ARCH); if (buf_out[0] != 0xfd || buf_out[1] != 0xce || buf_out[2] != 0x8a || buf_out[3] != 0x36 || buf_out[4] != 0x63 || buf_out[5] != 0xa8 || buf_out[6] != 0xec || buf_out[7] != 0xdf) { fprintf(stderr, "endian INT64 (3): got 0x%02x%02x%02x%02x%02x%02x%02x%02x, expected 0xfdce8a3663a8ecdf\n", buf_out[0], buf_out[1], buf_out[2], buf_out[3], buf_out[4], buf_out[5], buf_out[6], buf_out[7]); return -15; } i64_val = gaiaImportI64(buf_in, BIG_ENDIAN_ENCODED, BIG_ENDIAN_ARCH); gaiaExportI64(buf_out, i64_val, LITTLE_ENDIAN_ENCODED, BIG_ENDIAN_ARCH); if (buf_out[0] != 0xfd || buf_out[1] != 0xce || buf_out[2] != 0x8a || buf_out[3] != 0x36 || buf_out[4] != 0x63 || buf_out[5] != 0xa8 || buf_out[6] != 0xec || buf_out[7] != 0xdf) { fprintf(stderr, "endian INT64 (4): got 0x%02x%02x%02x%02x%02x%02x%02x%02x, expected 0xfdce8a3663a8ecdf\n", buf_out[0], buf_out[1], buf_out[2], buf_out[3], buf_out[4], buf_out[5], buf_out[6], buf_out[7]); return -16; } i64_val = gaiaImportI64(buf_in, LITTLE_ENDIAN_ENCODED, LITTLE_ENDIAN_ARCH); gaiaExportI64(buf_out, i64_val, BIG_ENDIAN_ENCODED, LITTLE_ENDIAN_ARCH); if (buf_out[0] != 0xfd || buf_out[1] != 0xce || buf_out[2] != 0x8a || buf_out[3] != 0x36 || buf_out[4] != 0x63 || buf_out[5] != 0xa8 || buf_out[6] != 0xec || buf_out[7] != 0xdf) { fprintf(stderr, "endian INT64 (5): got 0x%02x%02x%02x%02x%02x%02x%02x%02x, expected 0xfdce8a3663a8ecdf\n", buf_out[0], buf_out[1], buf_out[2], buf_out[3], buf_out[4], buf_out[5], buf_out[6], buf_out[7]); return -17; } i64_val = gaiaImportI64(buf_in, LITTLE_ENDIAN_ENCODED, BIG_ENDIAN_ARCH); gaiaExportI64(buf_out, i64_val, BIG_ENDIAN_ENCODED, BIG_ENDIAN_ARCH); if (buf_out[0] != 0xfd || buf_out[1] != 0xce || buf_out[2] != 0x8a || buf_out[3] != 0x36 || buf_out[4] != 0x63 || buf_out[5] != 0xa8 || buf_out[6] != 0xec || buf_out[7] != 0xdf) { fprintf(stderr, "endian INT64 (6): got 0x%02x%02x%02x%02x%02x%02x%02x%02x, expected 0xfdce8a3663a8ecdf\n", buf_out[0], buf_out[1], buf_out[2], buf_out[3], buf_out[4], buf_out[5], buf_out[6], buf_out[7]); return -18; } /* testing float values */ buf_in[0] = 0xdf; buf_in[1] = 0xec; buf_in[2] = 0xce; buf_in[3] = 0xfd; flt_val = gaiaImportF32(buf_in, LITTLE_ENDIAN_ENCODED, LITTLE_ENDIAN_ARCH); gaiaExportF32(buf_out, flt_val, LITTLE_ENDIAN_ENCODED, LITTLE_ENDIAN_ARCH); if (buf_out[0] != 0xdf || buf_out[1] != 0xec || buf_out[2] != 0xce || buf_out[3] != 0xfd) { fprintf(stderr, "endian FLOAT (1): got 0x%02x%02x%02x%02x, expected 0xdfeccefd\n", buf_out[0], buf_out[1], buf_out[2], buf_out[3]); return -19; } flt_val = gaiaImportF32(buf_in, BIG_ENDIAN_ENCODED, BIG_ENDIAN_ARCH); gaiaExportF32(buf_out, flt_val, BIG_ENDIAN_ENCODED, BIG_ENDIAN_ARCH); if (buf_out[0] != 0xdf || buf_out[1] != 0xec || buf_out[2] != 0xce || buf_out[3] != 0xfd) { fprintf(stderr, "endian FLOAT (2): got 0x%02x%02x%02x%02x, expected 0xdfeccefd\n", buf_out[0], buf_out[1], buf_out[2], buf_out[3]); return -20; } flt_val = gaiaImportF32(buf_in, BIG_ENDIAN_ENCODED, LITTLE_ENDIAN_ARCH); gaiaExportF32(buf_out, flt_val, LITTLE_ENDIAN_ENCODED, LITTLE_ENDIAN_ARCH); if (buf_out[0] != 0xfd || buf_out[1] != 0xce || buf_out[2] != 0xec || buf_out[3] != 0xdf) { fprintf(stderr, "endian FLOAT (3): got 0x%02x%02x%02x%02x, expected 0xfdceecdf\n", buf_out[0], buf_out[1], buf_out[2], buf_out[3]); return -21; } flt_val = gaiaImportF32(buf_in, BIG_ENDIAN_ENCODED, BIG_ENDIAN_ARCH); gaiaExportF32(buf_out, flt_val, LITTLE_ENDIAN_ENCODED, BIG_ENDIAN_ARCH); if (buf_out[0] != 0xfd || buf_out[1] != 0xce || buf_out[2] != 0xec || buf_out[3] != 0xdf) { fprintf(stderr, "endian FLOAT (4): got 0x%02x%02x%02x%02x, expected 0xfdceecdf\n", buf_out[0], buf_out[1], buf_out[2], buf_out[3]); return -22; } flt_val = gaiaImportF32(buf_in, LITTLE_ENDIAN_ENCODED, LITTLE_ENDIAN_ARCH); gaiaExportF32(buf_out, flt_val, BIG_ENDIAN_ENCODED, LITTLE_ENDIAN_ARCH); if (buf_out[0] != 0xfd || buf_out[1] != 0xce || buf_out[2] != 0xec || buf_out[3] != 0xdf) { fprintf(stderr, "endian FLOAT (5): got 0x%02x%02x%02x%02x, expected 0xfdceecdf\n", buf_out[0], buf_out[1], buf_out[2], buf_out[3]); return -23; } flt_val = gaiaImportF32(buf_in, LITTLE_ENDIAN_ENCODED, BIG_ENDIAN_ARCH); gaiaExportF32(buf_out, flt_val, BIG_ENDIAN_ENCODED, BIG_ENDIAN_ARCH); if (buf_out[0] != 0xfd || buf_out[1] != 0xce || buf_out[2] != 0xec || buf_out[3] != 0xdf) { fprintf(stderr, "endian FLOAT (6): got 0x%02x%02x%02x%02x, expected 0xfdceecdf\n", buf_out[0], buf_out[1], buf_out[2], buf_out[3]); return -24; } /* testing double values */ buf_in[0] = 0xdf; buf_in[1] = 0xec; buf_in[2] = 0xa8; buf_in[3] = 0x63; buf_in[4] = 0x36; buf_in[5] = 0x8a; buf_in[6] = 0xce; buf_in[7] = 0xfd; dbl_val = gaiaImport64(buf_in, LITTLE_ENDIAN_ENCODED, LITTLE_ENDIAN_ARCH); gaiaExport64(buf_out, dbl_val, LITTLE_ENDIAN_ENCODED, LITTLE_ENDIAN_ARCH); if (buf_out[0] != 0xdf || buf_out[1] != 0xec || buf_out[2] != 0xa8 || buf_out[3] != 0x63 || buf_out[4] != 0x36 || buf_out[5] != 0x8a || buf_out[6] != 0xce || buf_out[7] != 0xfd) { fprintf(stderr, "endian DOUBLE (1): got 0x%02x%02x%02x%02x%02x%02x%02x%02x, expected 0xdfeca863368acefd\n", buf_out[0], buf_out[1], buf_out[2], buf_out[3], buf_out[4], buf_out[5], buf_out[6], buf_out[7]); return -25; } dbl_val = gaiaImport64(buf_in, BIG_ENDIAN_ENCODED, BIG_ENDIAN_ARCH); gaiaExport64(buf_out, dbl_val, BIG_ENDIAN_ENCODED, BIG_ENDIAN_ARCH); if (buf_out[0] != 0xdf || buf_out[1] != 0xec || buf_out[2] != 0xa8 || buf_out[3] != 0x63 || buf_out[4] != 0x36 || buf_out[5] != 0x8a || buf_out[6] != 0xce || buf_out[7] != 0xfd) { fprintf(stderr, "endian DOUBLE (2): got 0x%02x%02x%02x%02x%02x%02x%02x%02x, expected 0xdfeca863368acefd\n", buf_out[0], buf_out[1], buf_out[2], buf_out[3], buf_out[4], buf_out[5], buf_out[6], buf_out[7]); return -26; } dbl_val = gaiaImport64(buf_in, BIG_ENDIAN_ENCODED, LITTLE_ENDIAN_ARCH); gaiaExport64(buf_out, dbl_val, LITTLE_ENDIAN_ENCODED, LITTLE_ENDIAN_ARCH); if (buf_out[0] != 0xfd || buf_out[1] != 0xce || buf_out[2] != 0x8a || buf_out[3] != 0x36 || buf_out[4] != 0x63 || buf_out[5] != 0xa8 || buf_out[6] != 0xec || buf_out[7] != 0xdf) { fprintf(stderr, "endian DOUBLE (3): got 0x%02x%02x%02x%02x%02x%02x%02x%02x, expected 0xfdce8a3663a8ecdf\n", buf_out[0], buf_out[1], buf_out[2], buf_out[3], buf_out[4], buf_out[5], buf_out[6], buf_out[7]); return -27; } dbl_val = gaiaImport64(buf_in, BIG_ENDIAN_ENCODED, BIG_ENDIAN_ARCH); gaiaExport64(buf_out, dbl_val, LITTLE_ENDIAN_ENCODED, BIG_ENDIAN_ARCH); if (buf_out[0] != 0xfd || buf_out[1] != 0xce || buf_out[2] != 0x8a || buf_out[3] != 0x36 || buf_out[4] != 0x63 || buf_out[5] != 0xa8 || buf_out[6] != 0xec || buf_out[7] != 0xdf) { fprintf(stderr, "endian DOUBLE (4): got 0x%02x%02x%02x%02x%02x%02x%02x%02x, expected 0xfdce8a3663a8ecdf\n", buf_out[0], buf_out[1], buf_out[2], buf_out[3], buf_out[4], buf_out[5], buf_out[6], buf_out[7]); return -28; } dbl_val = gaiaImport64(buf_in, LITTLE_ENDIAN_ENCODED, LITTLE_ENDIAN_ARCH); gaiaExport64(buf_out, dbl_val, BIG_ENDIAN_ENCODED, LITTLE_ENDIAN_ARCH); if (buf_out[0] != 0xfd || buf_out[1] != 0xce || buf_out[2] != 0x8a || buf_out[3] != 0x36 || buf_out[4] != 0x63 || buf_out[5] != 0xa8 || buf_out[6] != 0xec || buf_out[7] != 0xdf) { fprintf(stderr, "endian DOUBLE (5): got 0x%02x%02x%02x%02x%02x%02x%02x%02x, expected 0xfdce8a3663a8ecdf\n", buf_out[0], buf_out[1], buf_out[2], buf_out[3], buf_out[4], buf_out[5], buf_out[6], buf_out[7]); return -29; } dbl_val = gaiaImport64(buf_in, LITTLE_ENDIAN_ENCODED, BIG_ENDIAN_ARCH); gaiaExport64(buf_out, dbl_val, BIG_ENDIAN_ENCODED, BIG_ENDIAN_ARCH); if (buf_out[0] != 0xfd || buf_out[1] != 0xce || buf_out[2] != 0x8a || buf_out[3] != 0x36 || buf_out[4] != 0x63 || buf_out[5] != 0xa8 || buf_out[6] != 0xec || buf_out[7] != 0xdf) { fprintf(stderr, "endian DOUBLE (6): got 0x%02x%02x%02x%02x%02x%02x%02x%02x, expected 0xfdce8a3663a8ecdf\n", buf_out[0], buf_out[1], buf_out[2], buf_out[3], buf_out[4], buf_out[5], buf_out[6], buf_out[7]); return -30; } return 0; }