use scf/pack instead of protobuf
authoryu.dongliang <18588496441@163.com>
Sat, 9 Mar 2024 14:14:18 +0000 (22:14 +0800)
committeryu.dongliang <18588496441@163.com>
Sat, 9 Mar 2024 14:14:18 +0000 (22:14 +0800)
14 files changed:
Makefile
main.c
pack/Makefile [new file with mode: 0644]
pack/main.c [new file with mode: 0644]
pack/scf_pack.c [new file with mode: 0644]
pack/scf_pack.h [new file with mode: 0644]
scf_def.h
scf_eda.pb-c.c [deleted file]
scf_eda.pb-c.h [deleted file]
scf_eda_pack.c [moved from scf_eda_pb.c with 83% similarity]
scf_eda_pack.h [new file with mode: 0644]
scf_eda_pb.h [deleted file]
ses_core.h
ses_layout.c

index 2dddcd7a931dd9883a0ea61adb5cf0c3c1ec53d6..e61f46b39cedc2f58944b9a41b53ac0646308beb 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
 CFILES += main.c
-CFILES += scf_eda.pb-c.c
-CFILES += scf_eda_pb.c
+CFILES += scf_eda_pack.c
+CFILES += pack/scf_pack.c
 CFILES += ses_layout.c
 CFILES += ses_graph.c
 CFILES += ses_utils.c
@@ -24,9 +24,9 @@ CFILES += ses_step_output.c
 
 CFLAGS += -g -D_GNU_SOURCE
 CFLAGS += -I./
+CFLAGS += -I./pack
 
 LDFLAGS += -lm
-LDFLAGS += -lprotobuf-c
 LDFLAGS += -lcairo
 
 all:
diff --git a/main.c b/main.c
index dc466e422e6e98ca721e6096923f1be9a1b090c2..66bb4ea3c749f66388875c7cdf39cd37ee3f2108 100644 (file)
--- a/main.c
+++ b/main.c
@@ -64,13 +64,13 @@ int main(int argc, char* argv[])
 
        fseek(fp, 0, SEEK_END);
 
-       long len = ftell(fp);
+       int len = ftell(fp);
        if (len < 0) {
-               scf_loge("pb len: %ld\n", len);
+               scf_loge("pb len: %d\n", len);
                return -EINVAL;
        }
 
-       uint8_t* pb = malloc(len);
+       uint8_t* pb = calloc(1, len);
        if (!pb) {
                scf_loge("malloc error\n");
                return -ENOMEM;
@@ -88,8 +88,16 @@ int main(int argc, char* argv[])
 
        ScfEcomponent* c;
        ScfEfunction*  f;
-       ScfEboard*     b = scf_eboard__unpack(NULL, len, pb);
+       ScfEboard*     b = NULL;
 
+       int ret = ScfEboard_unpack(&b, pb, len);
+       if (ret < 0) {
+               scf_loge("ScfEboard__unpack error: %d\n", ret);
+               return ret;
+       }
+
+//     print_board(b);
+#if 1
        ses_layout_board(b);
 
        size_t i;
@@ -101,9 +109,9 @@ int main(int argc, char* argv[])
 
                ses_steps_analyse(f, 5, 1);
        }
+#endif
 
-//     print_board(b);
-
-//     scf_eboard__free_unpacked(b, NULL);
+       ScfEboard_free(b);
+       free(pb);
        return 0;
 }
diff --git a/pack/Makefile b/pack/Makefile
new file mode 100644 (file)
index 0000000..3d682e6
--- /dev/null
@@ -0,0 +1,10 @@
+CFILES += scf_pack.c
+CFILES += main.c
+
+CFLAGS += -g
+CFLAGS += -I../
+
+LDFLAGS +=
+
+all:
+       gcc $(CFLAGS) $(CFILES) $(LDFLAGS)
diff --git a/pack/main.c b/pack/main.c
new file mode 100644 (file)
index 0000000..7b6abb8
--- /dev/null
@@ -0,0 +1,69 @@
+#include"scf_pack.h"
+
+typedef struct {
+       SCF_PACK_DEF_VAR(int, x); // int x;
+       SCF_PACK_DEF_VAR(int, y); // int y;
+       SCF_PACK_DEF_VARS(int, z);
+} A;
+
+SCF_PACK_TYPE(A)
+SCF_PACK_INFO_VAR(A, x),
+SCF_PACK_INFO_VAR(A, y),
+SCF_PACK_INFO_VARS(A, z, int),
+SCF_PACK_END(A)
+
+typedef struct {
+       SCF_PACK_DEF_VAR(double, d);
+       SCF_PACK_DEF_OBJS(A, as);
+} B;
+
+SCF_PACK_TYPE(B)
+SCF_PACK_INFO_VAR(B, d),
+SCF_PACK_INFO_OBJS(B, as, A),
+SCF_PACK_END(B)
+
+int main()
+{
+       int z0[] = {1, 2, 3, 4};
+       int z1[] = {5, 6};
+       A  a0 = {0x90, 0xff, sizeof(z0) / sizeof(z0[0]), z0};
+       A  a1 = {9, 10, sizeof(z1) / sizeof(z1[0]), z1};
+       A* as[] = {&a0, &a1};
+
+       B  b = {3.14, sizeof(as) / sizeof(as[0]), as};
+       B* p = NULL;
+
+       printf("b: %p, b->as: %p, b->as[0]: %p, b->as[1]: %p\n", &b, b.as, b.as[0], b.as[1]);
+       printf("a0: %p, a1: %p\n", &a0, &a1);
+       printf("z0: %p, z1: %p\n", z0, z1);
+
+       uint8_t* buf = NULL;
+       int      len = 0;
+
+       B_pack(&b, &buf, &len);
+
+       int i;
+       int j;
+       for (i = 0; i < len; i++)
+               printf("i: %d, %#x\n", i, buf[i]);
+#if 1
+       B_unpack(&p, buf, len);
+       printf("p: %p, p->as: %p\n", p, p->as);
+       printf("p->d: %lg, p->n_as: %ld, p->as: %p\n", p->d, p->n_as, p->as);
+
+       for (i = 0; i < p->n_as; i++) {
+               printf("p->as[%d]: %p\n", i, p->as[i]);
+
+               A* a = p->as[i];
+               printf("a->x: %#x, a->y: %#x, a->n_z: %ld,a->z: %p\n", a->x,a->y, a->n_z, a->z);
+
+               for (j = 0; j < a->n_z; j++)
+                       printf("a->z[%d]: %d\n", j, a->z[j]);
+               printf("\n");
+       }
+
+       B_free(p);
+       free(buf);
+#endif
+       return 0;
+}
diff --git a/pack/scf_pack.c b/pack/scf_pack.c
new file mode 100644 (file)
index 0000000..1d440fe
--- /dev/null
@@ -0,0 +1,557 @@
+#include"scf_pack.h"
+
+int __scf_pack_one_index(uint8_t* pack, uint64_t u, int shift)
+{
+       int max  = -1;
+       int bits = 1u << shift;
+       int i;
+       int j;
+       int k;
+
+       j = 0;
+       k = 3;
+       for (i = bits - 1; i >= 0; i--) {
+
+               if (!(u & (1ull << i)))
+                       continue;
+
+               if (-1 == max)
+                       max = i;
+               else
+                       max -= i;
+               scf_logd("max: %d, i: %d, j: %d, k: %d, shift: %d\n", max, i, j, k, shift);
+
+               pack[j] |= max << k;
+
+               if (8 - k < shift) {
+                       pack[++j] = max >> (8 - k);
+                       k = shift - (8 - k);
+               } else
+                       k += shift;
+
+               if (i < 2)
+                       shift  = 1;
+               else if (i < 4)
+                       shift  = 2;
+
+               else if (i < 8)
+                       shift  = 3;
+               else if (i < 16)
+                       shift  = 4;
+
+               else if (i < 32)
+                       shift  = 5;
+               else if (i < 64)
+                       shift  = 6;
+               else {
+                       scf_loge("pack error\n");
+                       return -EINVAL;
+               }
+
+               scf_logd("max: %d, i: %d, j: %d, k: %d, shift: %d\n\n", max, i, j, k, shift);
+
+               max = i;
+       }
+
+       if (8 - k < shift && 0 != max) {
+               pack[++j] = 0;
+               scf_logd("max: %d, i: %d, j: %d, k: %d, shift: %d\n\n", max, i, j, k, shift);
+       }
+
+       return j + 1;
+}
+
+int __scf_pack_byte_map(uint8_t* pack, uint64_t u, int shift)
+{
+       uint8_t* p = (uint8_t*)&u;
+       uint8_t map = 0;
+
+       int bytes = 1u << shift >> 3;
+       int i;
+       int j;
+       int k;
+
+       pack[0] |= 0x4;
+       j = 0;
+       k = 4;
+
+       for (i = 0; i < bytes; i++) {
+               if (p[i])
+                       map |= 1u << i;
+       }
+
+       if (((1u << bytes) - 1) & ~map) {
+               pack[0] |= 0x8;
+               pack[j] |= map << k;
+
+               if (bytes > k) {
+                       pack[++j] = map >> (8 - k);
+                       k = bytes - k;
+               } else
+                       k += bytes;
+       }
+
+       for (i = 0; i < bytes; i++) {
+               if (p[i]) {
+                       pack[++j] = p[i];
+                       scf_logd("bytes: %d, map: %#x, i: %d, j: %d, p[i]: %#x\n", bytes, map, i, j, p[i]);
+               }
+       }
+
+       return j + 1;
+}
+
+int __scf_pack2(uint8_t* pack, uint64_t u, int shift)
+{
+       int sum  = 0;
+       int not  = 0;
+       int bits = 1u << shift;
+       int i;
+
+       for (i = 0; i < bits; i++) {
+               if (u & (1ull << i))
+                       sum++;
+       }
+
+       if (sum > (bits >> 1)) { // bits / 2
+               not = 1;
+               sum = bits - sum;
+               u = ~u;
+       }
+
+       scf_logd("bits: %d, not: %d, u: %#lx, sum: %d\n", bits, not, u, sum);
+
+       pack[0] = not;
+
+       if (u < 64) {
+               pack[0] |= u << 2;
+               return 1;
+       }
+
+       pack[0] |= 0x2;
+
+       if (sum < 4)
+               return __scf_pack_one_index(pack, u, shift);
+       return __scf_pack_byte_map(pack, u, shift);
+}
+
+int __scf_unpack2(void* p, int shift, const uint8_t* buf, int len)
+{
+       int bits = 1u << shift;
+       int max  = -1;
+       int i;
+       int j;
+       int k;
+
+       if (len < 1)
+               return -EINVAL;
+
+       uint64_t u = 0;
+
+       if (!(buf[0] & 0x2)) {
+
+               u = buf[0] >> 2;
+               j = 1;
+
+       } else if (!(buf[0] & 0x4)) {
+               j = 0;
+               k = 3;
+
+               while (1) {
+                       if (j >= len)
+                               return -EINVAL;
+
+                       i = (buf[j] >> k) & ((1u << shift) - 1);
+
+                       if (shift > 8 - k) {
+                               if (++j >= len)
+                                       return -EINVAL;
+
+                               i |= buf[j] << (8 - k);
+                               i &= (1u << shift) - 1;
+                               k  = shift - (8 - k);
+                       } else
+                               k += shift;
+
+                       if (-1 == max)
+                               max = i;
+                       else if (0 == i)
+                               break;
+                       else
+                               max -= i;
+
+                       u |= 1ull << max;
+
+                       if (max < 2)
+                               shift  = 1;
+                       else if (max < 4)
+                               shift  = 2;
+
+                       else if (max < 8)
+                               shift  = 3;
+                       else if (max < 16)
+                               shift  = 4;
+
+                       else if (max < 32)
+                               shift  = 5;
+                       else if (max < 64)
+                               shift  = 6;
+                       else {
+                               scf_loge("unpack error\n");
+                               return -EINVAL;
+                       }
+
+                       scf_logd("max: %d, i: %d, j: %d, k: %d, shift: %d\n\n", max, i, j, k, shift);
+               }
+
+               j++;
+               scf_logd("u: %ld, %#lx\n", u, u);
+
+       } else if (!(buf[0] & 0x8)) {
+               j = 1;
+
+               for (k = 0; k < bits / 8; k++) {
+
+                       if (j >= len)
+                               return -EINVAL;
+
+                       uint64_t u8 = buf[j];
+
+                       u |= u8 << (k << 3);
+
+                       scf_logd("buf[%d]: %#x, u: %#lx, k: %d, bits: %d\n", j, buf[j], u, k, bits);
+                       j++;
+               }
+
+       } else {
+               uint8_t map = buf[0] >> 4;
+
+               if (bits > 32) {
+                       if (1 >= len)
+                               return -EINVAL;
+
+                       map |= buf[1] << 4;
+                       j = 2;
+               } else
+                       j = 1;
+
+               for (k = 0; k < bits / 8; k++) {
+                       if (!(map & (1u << k)))
+                               continue;
+
+                       if (j >= len)
+                               return -EINVAL;
+
+                       uint64_t u8 = buf[j++];
+
+                       u |= u8 << (k << 3);
+
+                       scf_logd("buf[%d]: %#x, u: %#lx, k: %d, map: %#x, bits: %d\n", j, buf[j], u, k, map, bits);
+               }
+       }
+
+       if (buf[0] & 0x1)
+               u = ~u;
+
+       switch (bits) {
+               case 32:
+                       *(uint32_t*)p = u;
+                       break;
+               case 64:
+                       *(uint64_t*)p = u;
+                       break;
+               default:
+                       scf_loge("bits %d Not support!\n", bits);
+                       return -EINVAL;
+                       break;
+       };
+
+       scf_logd("u: %#lx, j: %d, bits: %d\n", u, j, bits);
+       return j;
+}
+
+int __scf_unpack(void* p, int size, const uint8_t* buf, int len)
+{
+       switch (size) {
+               case 1:
+                       if (1 <= len) {
+                               *(uint8_t*)p = buf[0];
+                               return 1;
+                       }
+                       break;
+
+               case 2:
+                       if (2 <= len) {
+                               *(uint16_t*)p = *(uint16_t*)buf;
+                               return 2;
+                       }
+                       break;
+
+               case 4:
+#if 0
+                       if (4 <= len) {
+                               *(uint32_t*)p = *(uint32_t*)buf;
+                               return 4;
+                       }
+#else
+                       return __scf_unpack2(p, 5, buf, len);
+#endif
+                       break;
+
+               case 8:
+#if 0
+                       if (8 <= len) {
+                               *(uint64_t*)p = *(uint64_t*)buf;
+                               return 8;
+                       }
+#else
+                       return __scf_unpack2(p, 6, buf, len);
+#endif
+                       break;
+               default:
+                       scf_loge("data type NOT support!\n");
+                       break;
+       };
+
+       return -EINVAL;
+}
+
+int __scf_pack(void* p, int size, uint8_t** pbuf, int* plen)
+{
+       uint8_t pack[64];
+       int     len = 0;
+
+       switch (size) {
+               case 1:
+                       pack[0] = *(uint8_t*)p;
+                       len = 1;
+                       break;
+               case 2:
+                       *(uint16_t*)pack = *(uint16_t*)p;
+                       len = 2;
+                       break;
+               case 4:
+#if 1
+                       len = __scf_pack2(pack, *(uint32_t*)p, 5);
+                       if (len < 0)
+                               return len;
+#else
+                       *(uint32_t*)pack = *(uint32_t*)p;
+                       len = 4;
+#endif
+                       scf_logd("p: %p, %d, len: %d\n\n", p, *(uint32_t*)p, len);
+                       break;
+               case 8:
+#if 1
+                       len = __scf_pack2(pack, *(uint64_t*)p, 6);
+                       if (len < 0)
+                               return len;
+#else
+                       *(uint64_t*)pack = *(uint64_t*)p;
+                       len = 8;
+#endif
+                       scf_logd("p: %p, %ld, %#lx, %lg, len: %d\n\n", p, *(uint64_t*)p, *(uint64_t*)p, *(double*)p, len);
+                       break;
+               default:
+                       scf_loge("data size '%d' NOT support!\n", size);
+                       return -EINVAL;
+                       break;
+       };
+
+       void* b = realloc(*pbuf, *plen + len);
+       if (!b)
+               return -ENOMEM;
+       *pbuf = b;
+
+       memcpy(*pbuf + *plen, pack, len);
+       *plen += len;
+       return 0;
+}
+
+int scf_pack(void* p, scf_pack_info_t* infos, int n_infos, uint8_t** pbuf, int* plen)
+{
+       if (!p || !infos || n_infos < 1 || !pbuf || !plen)
+               return -EINVAL;
+
+       if (!*pbuf)
+               *plen = 0;
+
+//     printf("\n");
+       scf_logd("p: %p\n", p);
+
+       int i;
+       for (i = 0; i < n_infos; i++) {
+               scf_logd("name: %s, size: %ld, offset: %ld, noffset: %ld, msize: %ld, members: %p, n_members: %ld\n",
+                               infos[i].name, infos[i].size, infos[i].offset, infos[i].noffset, infos[i].msize, infos[i].members, infos[i].n_members);
+
+               if (infos[i].noffset >= 0) {
+
+                       void* a = *(void**)(p + infos[i].offset);
+                       long  n = *(long* )(p + infos[i].noffset);
+                       int   j;
+
+                       scf_logd("a: %p, n: %ld, infos[i].msize: %ld, infos[i].noffset: %ld\n", a, n, infos[i].msize, infos[i].noffset);
+
+                       for (j = 0; j < n; j++) {
+
+                               if (infos[i].members) {
+                                       int ret = scf_pack(*(void**)(a + j * infos[i].msize), infos[i].members, infos[i].n_members, pbuf, plen);
+                                       if (ret < 0) {
+                                               scf_loge("ret: %d\n", ret);
+                                               return ret;
+                                       }
+                               } else {
+                                       int ret = __scf_pack(a + j * infos[i].msize, infos[i].msize, pbuf, plen);
+                                       if (ret < 0) {
+                                               scf_loge("ret: %d\n", ret);
+                                               return ret;
+                                       }
+                               }
+                       }
+
+                       continue;
+               }
+
+               if (infos[i].members) {
+
+                       int ret = scf_pack(*(void**)(p + infos[i].offset), infos[i].members, infos[i].n_members, pbuf, plen);
+                       if (ret < 0) {
+                               scf_loge("ret: %d\n", ret);
+                               return ret;
+                       }
+                       continue;
+               }
+
+               int ret = __scf_pack(p + infos[i].offset, infos[i].size, pbuf, plen);
+               if (ret < 0) {
+                       scf_loge("ret: %d\n", ret);
+                       return ret;
+               }
+
+               scf_logd("size: %ld\n\n", infos[i].size);
+       }
+
+       return 0;
+}
+
+int scf_unpack(void** pp, scf_pack_info_t* infos, int n_infos, const uint8_t* buf, int len)
+{
+       if (!pp || !infos || n_infos < 1 || !buf || len < 1)
+               return -EINVAL;
+
+       int size = infos[n_infos - 1].offset + infos[n_infos - 1].size;
+
+       void* p  = calloc(1, size);
+       if (!p)
+               return -ENOMEM;
+
+       int i;
+       int j;
+       int k = 0;
+
+       for (i = 0; i < n_infos; i++) {
+
+               if (infos[i].noffset >= 0) {
+
+                       long  n = *(long*)(p + infos[i].noffset);
+                       void* a = calloc(n, infos[i].msize);
+                       if (!a)
+                               return -ENOMEM;
+                       *(void**)(p + infos[i].offset) = a;
+
+                       scf_logd("a: %p, n: %ld, infos[i].msize: %ld\n", a, n, infos[i].msize);
+
+                       for (j = 0; j < n; j++) {
+
+                               if (infos[i].members) {
+                                       int ret = scf_unpack((void**)(a + j * infos[i].msize), infos[i].members, infos[i].n_members, buf + k, len - k);
+                                       if (ret < 0) {
+                                               scf_loge("ret: %d\n", ret);
+                                               return ret;
+                                       }
+
+                                       k += ret;
+
+                               } else {
+                                       int ret = __scf_unpack(a + j * infos[i].msize, infos[i].msize, buf + k, len - k);
+                                       if (ret < 0) {
+                                               scf_loge("ret: %d\n", ret);
+                                               return ret;
+                                       }
+
+                                       k += ret;
+                               }
+                       }
+
+                       continue;
+               }
+
+               if (infos[i].members) {
+
+                       int ret = scf_unpack((void**)(p + infos[i].offset), infos[i].members, infos[i].n_members, buf + k, len - k);
+                       if (ret < 0) {
+                               scf_loge("ret: %d\n", ret);
+                               return ret;
+                       }
+
+                       k += ret;
+                       continue;
+               }
+
+               int ret = __scf_unpack(p + infos[i].offset, infos[i].size, buf + k, len - k);
+               if (ret < 0) {
+                       scf_loge("ret: %d\n", ret);
+                       return ret;
+               }
+
+               k += ret;
+       }
+
+       *pp = p;
+       return k;
+}
+
+int scf_unpack_free(void* p, scf_pack_info_t* infos, int n_infos)
+{
+       if (!p || !infos || n_infos < 1)
+               return -EINVAL;
+
+       int i;
+       int j;
+       for (i = 0; i < n_infos; i++) {
+
+               if (infos[i].noffset >= 0) {
+                       long  n = *(long* )(p + infos[i].noffset);
+                       void* a = *(void**)(p + infos[i].offset);
+
+                       scf_logd("a: %p, n: %ld, infos[i].msize: %ld\n", a, n, infos[i].msize);
+
+                       if (infos[i].members) {
+
+                               for (j = 0; j < n; j++) {
+                                       int ret = scf_unpack_free(*(void**)(a + j * infos[i].msize), infos[i].members, infos[i].n_members);
+                                       if (ret < 0) {
+                                               scf_loge("ret: %d\n", ret);
+                                               return ret;
+                                       }
+                               }
+                       }
+
+                       scf_logd("a: %p\n", a);
+                       free(a);
+                       continue;
+               }
+
+               if (infos[i].members) {
+                       int ret = scf_unpack_free(*(void**)(p + infos[i].offset), infos[i].members, infos[i].n_members);
+                       if (ret < 0) {
+                               scf_loge("ret: %d\n", ret);
+                               return ret;
+                       }
+               }
+       }
+
+       scf_logd("p: %p\n", p);
+       free(p);
+       return 0;
+}
diff --git a/pack/scf_pack.h b/pack/scf_pack.h
new file mode 100644 (file)
index 0000000..133497b
--- /dev/null
@@ -0,0 +1,61 @@
+#ifndef SCF_PACK_H
+#define SCF_PACK_H
+
+#include"scf_def.h"
+
+typedef struct scf_pack_info_s  scf_pack_info_t;
+
+struct scf_pack_info_s
+{
+       const char*      name;
+       long             size;
+       long             offset;
+       long             noffset;
+       long             msize;
+       scf_pack_info_t* members;
+       long             n_members;
+};
+
+int scf_pack       (void*  p,  scf_pack_info_t* infos, int n_infos,       uint8_t** pbuf, int* plen);
+int scf_unpack     (void** pp, scf_pack_info_t* infos, int n_infos, const uint8_t*  buf,  int  len);
+int scf_unpack_free(void*  p,  scf_pack_info_t* infos, int n_infos);
+
+#define SCF_PACK_DEF_VAR(type, var)    type  var
+#define SCF_PACK_DEF_VARS(type, vars)  long  n_##vars; type* vars
+
+#define SCF_PACK_DEF_OBJ(type, obj)    type* obj
+#define SCF_PACK_DEF_OBJS(type, objs)  long  n_##objs; type** objs
+
+#define SCF_PACK_N_INFOS(type)         (sizeof(scf_pack_info_##type) / sizeof(scf_pack_info_##type[0]))
+
+#define SCF_PACK_INFO_VAR(type, var)            {#var,  sizeof(((type*)0)->var),   offsetof(type, var), -1, -1, NULL, 0}
+#define SCF_PACK_INFO_OBJ(type, obj, objtype)   {#obj,  sizeof(((type*)0)->obj),   offsetof(type, obj), -1, -1, scf_pack_info_##objtype, SCF_PACK_N_INFOS(objtype)}
+
+#define SCF_PACK_INFO_VARS(type, vars, vtype) \
+       {"n_"#vars, sizeof(((type*)0)->n_##vars), offsetof(type, n_##vars), -1, -1, NULL, 0}, \
+       {#vars,     sizeof(((type*)0)->vars),     offsetof(type, vars),     offsetof(type, n_##vars), sizeof(vtype), NULL, 0}
+
+#define SCF_PACK_INFO_OBJS(type, objs, objtype) \
+       {"n_"#objs, sizeof(((type*)0)->n_##objs), offsetof(type, n_##objs), -1, -1, NULL, 0}, \
+       {#objs,     sizeof(((type*)0)->objs),     offsetof(type, objs),     offsetof(type, n_##objs), sizeof(objtype*), scf_pack_info_##objtype, SCF_PACK_N_INFOS(objtype)}
+
+#define SCF_PACK_TYPE(type) \
+static scf_pack_info_t scf_pack_info_##type[] = {
+
+
+#define SCF_PACK_END(type) \
+}; \
+static int type##_pack(type* p, uint8_t** pbuf, int* plen) \
+{ \
+       return scf_pack(p, scf_pack_info_##type, SCF_PACK_N_INFOS(type), pbuf, plen); \
+} \
+static int type##_unpack(type** pp, uint8_t* buf, int len) \
+{ \
+       return scf_unpack((void**)pp, scf_pack_info_##type, SCF_PACK_N_INFOS(type), buf, len); \
+} \
+static int type##_free(type* p) \
+{ \
+       return scf_unpack_free(p, scf_pack_info_##type, SCF_PACK_N_INFOS(type)); \
+}
+
+#endif
index 87c4c3918d11cf583f9480774c1b0c7f77320cc1..55b1def0cdce3471b7196b3eb26fe0e2d2d573b7 100644 (file)
--- a/scf_def.h
+++ b/scf_def.h
@@ -3,7 +3,6 @@
 
 #include<stdio.h>
 #include<stdint.h>
-#include<math.h>
 #include<stdlib.h>
 #include<stddef.h>
 #include<string.h>
@@ -11,6 +10,8 @@
 #include<errno.h>
 #include<time.h>
 #include<unistd.h>
+#include<limits.h>
+#include<math.h>
 
 #if 1
 #include<sys/time.h>
diff --git a/scf_eda.pb-c.c b/scf_eda.pb-c.c
deleted file mode 100644 (file)
index 8a55620..0000000
+++ /dev/null
@@ -1,1499 +0,0 @@
-/* Generated by the protocol buffer compiler.  DO NOT EDIT! */
-/* Generated from: scf_eda.proto */
-
-/* Do not generate deprecated warnings for self */
-#ifndef PROTOBUF_C__NO_DEPRECATED
-#define PROTOBUF_C__NO_DEPRECATED
-#endif
-
-#include "scf_eda.pb-c.h"
-void   scf_line__init
-                     (ScfLine         *message)
-{
-  static ScfLine init_value = SCF_LINE__INIT;
-  *message = init_value;
-}
-size_t scf_line__get_packed_size
-                     (const ScfLine *message)
-{
-  assert(message->base.descriptor == &scf_line__descriptor);
-  return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
-}
-size_t scf_line__pack
-                     (const ScfLine *message,
-                      uint8_t       *out)
-{
-  assert(message->base.descriptor == &scf_line__descriptor);
-  return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
-}
-size_t scf_line__pack_to_buffer
-                     (const ScfLine *message,
-                      ProtobufCBuffer *buffer)
-{
-  assert(message->base.descriptor == &scf_line__descriptor);
-  return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
-}
-ScfLine *
-       scf_line__unpack
-                     (ProtobufCAllocator  *allocator,
-                      size_t               len,
-                      const uint8_t       *data)
-{
-  return (ScfLine *)
-     protobuf_c_message_unpack (&scf_line__descriptor,
-                                allocator, len, data);
-}
-void   scf_line__free_unpacked
-                     (ScfLine *message,
-                      ProtobufCAllocator *allocator)
-{
-  assert(message->base.descriptor == &scf_line__descriptor);
-  protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
-}
-void   scf_epin__init
-                     (ScfEpin         *message)
-{
-  static ScfEpin init_value = SCF_EPIN__INIT;
-  *message = init_value;
-}
-size_t scf_epin__get_packed_size
-                     (const ScfEpin *message)
-{
-  assert(message->base.descriptor == &scf_epin__descriptor);
-  return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
-}
-size_t scf_epin__pack
-                     (const ScfEpin *message,
-                      uint8_t       *out)
-{
-  assert(message->base.descriptor == &scf_epin__descriptor);
-  return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
-}
-size_t scf_epin__pack_to_buffer
-                     (const ScfEpin *message,
-                      ProtobufCBuffer *buffer)
-{
-  assert(message->base.descriptor == &scf_epin__descriptor);
-  return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
-}
-ScfEpin *
-       scf_epin__unpack
-                     (ProtobufCAllocator  *allocator,
-                      size_t               len,
-                      const uint8_t       *data)
-{
-  return (ScfEpin *)
-     protobuf_c_message_unpack (&scf_epin__descriptor,
-                                allocator, len, data);
-}
-void   scf_epin__free_unpacked
-                     (ScfEpin *message,
-                      ProtobufCAllocator *allocator)
-{
-  assert(message->base.descriptor == &scf_epin__descriptor);
-  protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
-}
-void   scf_econn__init
-                     (ScfEconn         *message)
-{
-  static ScfEconn init_value = SCF_ECONN__INIT;
-  *message = init_value;
-}
-size_t scf_econn__get_packed_size
-                     (const ScfEconn *message)
-{
-  assert(message->base.descriptor == &scf_econn__descriptor);
-  return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
-}
-size_t scf_econn__pack
-                     (const ScfEconn *message,
-                      uint8_t       *out)
-{
-  assert(message->base.descriptor == &scf_econn__descriptor);
-  return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
-}
-size_t scf_econn__pack_to_buffer
-                     (const ScfEconn *message,
-                      ProtobufCBuffer *buffer)
-{
-  assert(message->base.descriptor == &scf_econn__descriptor);
-  return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
-}
-ScfEconn *
-       scf_econn__unpack
-                     (ProtobufCAllocator  *allocator,
-                      size_t               len,
-                      const uint8_t       *data)
-{
-  return (ScfEconn *)
-     protobuf_c_message_unpack (&scf_econn__descriptor,
-                                allocator, len, data);
-}
-void   scf_econn__free_unpacked
-                     (ScfEconn *message,
-                      ProtobufCAllocator *allocator)
-{
-  assert(message->base.descriptor == &scf_econn__descriptor);
-  protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
-}
-void   scf_eline__init
-                     (ScfEline         *message)
-{
-  static ScfEline init_value = SCF_ELINE__INIT;
-  *message = init_value;
-}
-size_t scf_eline__get_packed_size
-                     (const ScfEline *message)
-{
-  assert(message->base.descriptor == &scf_eline__descriptor);
-  return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
-}
-size_t scf_eline__pack
-                     (const ScfEline *message,
-                      uint8_t       *out)
-{
-  assert(message->base.descriptor == &scf_eline__descriptor);
-  return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
-}
-size_t scf_eline__pack_to_buffer
-                     (const ScfEline *message,
-                      ProtobufCBuffer *buffer)
-{
-  assert(message->base.descriptor == &scf_eline__descriptor);
-  return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
-}
-ScfEline *
-       scf_eline__unpack
-                     (ProtobufCAllocator  *allocator,
-                      size_t               len,
-                      const uint8_t       *data)
-{
-  return (ScfEline *)
-     protobuf_c_message_unpack (&scf_eline__descriptor,
-                                allocator, len, data);
-}
-void   scf_eline__free_unpacked
-                     (ScfEline *message,
-                      ProtobufCAllocator *allocator)
-{
-  assert(message->base.descriptor == &scf_eline__descriptor);
-  protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
-}
-void   scf_ecomponent__init
-                     (ScfEcomponent         *message)
-{
-  static ScfEcomponent init_value = SCF_ECOMPONENT__INIT;
-  *message = init_value;
-}
-size_t scf_ecomponent__get_packed_size
-                     (const ScfEcomponent *message)
-{
-  assert(message->base.descriptor == &scf_ecomponent__descriptor);
-  return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
-}
-size_t scf_ecomponent__pack
-                     (const ScfEcomponent *message,
-                      uint8_t       *out)
-{
-  assert(message->base.descriptor == &scf_ecomponent__descriptor);
-  return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
-}
-size_t scf_ecomponent__pack_to_buffer
-                     (const ScfEcomponent *message,
-                      ProtobufCBuffer *buffer)
-{
-  assert(message->base.descriptor == &scf_ecomponent__descriptor);
-  return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
-}
-ScfEcomponent *
-       scf_ecomponent__unpack
-                     (ProtobufCAllocator  *allocator,
-                      size_t               len,
-                      const uint8_t       *data)
-{
-  return (ScfEcomponent *)
-     protobuf_c_message_unpack (&scf_ecomponent__descriptor,
-                                allocator, len, data);
-}
-void   scf_ecomponent__free_unpacked
-                     (ScfEcomponent *message,
-                      ProtobufCAllocator *allocator)
-{
-  assert(message->base.descriptor == &scf_ecomponent__descriptor);
-  protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
-}
-void   scf_efunction__init
-                     (ScfEfunction         *message)
-{
-  static ScfEfunction init_value = SCF_EFUNCTION__INIT;
-  *message = init_value;
-}
-size_t scf_efunction__get_packed_size
-                     (const ScfEfunction *message)
-{
-  assert(message->base.descriptor == &scf_efunction__descriptor);
-  return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
-}
-size_t scf_efunction__pack
-                     (const ScfEfunction *message,
-                      uint8_t       *out)
-{
-  assert(message->base.descriptor == &scf_efunction__descriptor);
-  return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
-}
-size_t scf_efunction__pack_to_buffer
-                     (const ScfEfunction *message,
-                      ProtobufCBuffer *buffer)
-{
-  assert(message->base.descriptor == &scf_efunction__descriptor);
-  return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
-}
-ScfEfunction *
-       scf_efunction__unpack
-                     (ProtobufCAllocator  *allocator,
-                      size_t               len,
-                      const uint8_t       *data)
-{
-  return (ScfEfunction *)
-     protobuf_c_message_unpack (&scf_efunction__descriptor,
-                                allocator, len, data);
-}
-void   scf_efunction__free_unpacked
-                     (ScfEfunction *message,
-                      ProtobufCAllocator *allocator)
-{
-  assert(message->base.descriptor == &scf_efunction__descriptor);
-  protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
-}
-void   scf_eboard__init
-                     (ScfEboard         *message)
-{
-  static ScfEboard init_value = SCF_EBOARD__INIT;
-  *message = init_value;
-}
-size_t scf_eboard__get_packed_size
-                     (const ScfEboard *message)
-{
-  assert(message->base.descriptor == &scf_eboard__descriptor);
-  return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
-}
-size_t scf_eboard__pack
-                     (const ScfEboard *message,
-                      uint8_t       *out)
-{
-  assert(message->base.descriptor == &scf_eboard__descriptor);
-  return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
-}
-size_t scf_eboard__pack_to_buffer
-                     (const ScfEboard *message,
-                      ProtobufCBuffer *buffer)
-{
-  assert(message->base.descriptor == &scf_eboard__descriptor);
-  return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
-}
-ScfEboard *
-       scf_eboard__unpack
-                     (ProtobufCAllocator  *allocator,
-                      size_t               len,
-                      const uint8_t       *data)
-{
-  return (ScfEboard *)
-     protobuf_c_message_unpack (&scf_eboard__descriptor,
-                                allocator, len, data);
-}
-void   scf_eboard__free_unpacked
-                     (ScfEboard *message,
-                      ProtobufCAllocator *allocator)
-{
-  assert(message->base.descriptor == &scf_eboard__descriptor);
-  protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
-}
-static const ProtobufCFieldDescriptor scf_line__field_descriptors[4] =
-{
-  {
-    "x0",
-    1,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_INT32,
-    0,   /* quantifier_offset */
-    offsetof(ScfLine, x0),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "y0",
-    2,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_INT32,
-    0,   /* quantifier_offset */
-    offsetof(ScfLine, y0),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "x1",
-    3,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_INT32,
-    0,   /* quantifier_offset */
-    offsetof(ScfLine, x1),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "y1",
-    4,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_INT32,
-    0,   /* quantifier_offset */
-    offsetof(ScfLine, y1),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-};
-static const unsigned scf_line__field_indices_by_name[] = {
-  0,   /* field[0] = x0 */
-  2,   /* field[2] = x1 */
-  1,   /* field[1] = y0 */
-  3,   /* field[3] = y1 */
-};
-static const ProtobufCIntRange scf_line__number_ranges[1 + 1] =
-{
-  { 1, 0 },
-  { 0, 4 }
-};
-const ProtobufCMessageDescriptor scf_line__descriptor =
-{
-  PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
-  "scf_line",
-  "ScfLine",
-  "ScfLine",
-  "",
-  sizeof(ScfLine),
-  4,
-  scf_line__field_descriptors,
-  scf_line__field_indices_by_name,
-  1,  scf_line__number_ranges,
-  (ProtobufCMessageInit) scf_line__init,
-  NULL,NULL,NULL    /* reserved[123] */
-};
-static const ProtobufCFieldDescriptor scf_epin__field_descriptors[30] =
-{
-  {
-    "id",
-    1,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_UINT64,
-    0,   /* quantifier_offset */
-    offsetof(ScfEpin, id),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "cid",
-    2,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_UINT64,
-    0,   /* quantifier_offset */
-    offsetof(ScfEpin, cid),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "lid",
-    3,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_UINT64,
-    0,   /* quantifier_offset */
-    offsetof(ScfEpin, lid),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "flags",
-    4,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_UINT64,
-    0,   /* quantifier_offset */
-    offsetof(ScfEpin, flags),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "tos",
-    5,
-    PROTOBUF_C_LABEL_REPEATED,
-    PROTOBUF_C_TYPE_UINT64,
-    offsetof(ScfEpin, n_tos),
-    offsetof(ScfEpin, tos),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "c_lid",
-    6,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_UINT64,
-    0,   /* quantifier_offset */
-    offsetof(ScfEpin, c_lid),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "v",
-    7,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_DOUBLE,
-    0,   /* quantifier_offset */
-    offsetof(ScfEpin, v),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "jv",
-    8,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_DOUBLE,
-    0,   /* quantifier_offset */
-    offsetof(ScfEpin, jv),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "a",
-    9,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_DOUBLE,
-    0,   /* quantifier_offset */
-    offsetof(ScfEpin, a),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "ja",
-    10,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_DOUBLE,
-    0,   /* quantifier_offset */
-    offsetof(ScfEpin, ja),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "r",
-    11,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_DOUBLE,
-    0,   /* quantifier_offset */
-    offsetof(ScfEpin, r),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "jr",
-    12,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_DOUBLE,
-    0,   /* quantifier_offset */
-    offsetof(ScfEpin, jr),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "uF",
-    13,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_DOUBLE,
-    0,   /* quantifier_offset */
-    offsetof(ScfEpin, uf),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "uH",
-    14,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_DOUBLE,
-    0,   /* quantifier_offset */
-    offsetof(ScfEpin, uh),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "hfe",
-    15,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_DOUBLE,
-    0,   /* quantifier_offset */
-    offsetof(ScfEpin, hfe),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "dr",
-    16,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_DOUBLE,
-    0,   /* quantifier_offset */
-    offsetof(ScfEpin, dr),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "jdr",
-    17,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_DOUBLE,
-    0,   /* quantifier_offset */
-    offsetof(ScfEpin, jdr),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "sr",
-    18,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_DOUBLE,
-    0,   /* quantifier_offset */
-    offsetof(ScfEpin, sr),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "jsr",
-    19,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_DOUBLE,
-    0,   /* quantifier_offset */
-    offsetof(ScfEpin, jsr),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "pr",
-    20,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_DOUBLE,
-    0,   /* quantifier_offset */
-    offsetof(ScfEpin, pr),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "jpr",
-    21,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_DOUBLE,
-    0,   /* quantifier_offset */
-    offsetof(ScfEpin, jpr),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "path",
-    22,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_UINT64,
-    0,   /* quantifier_offset */
-    offsetof(ScfEpin, path),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "x",
-    23,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_INT32,
-    0,   /* quantifier_offset */
-    offsetof(ScfEpin, x),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "y",
-    24,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_INT32,
-    0,   /* quantifier_offset */
-    offsetof(ScfEpin, y),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "n_diodes",
-    25,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_INT32,
-    0,   /* quantifier_offset */
-    offsetof(ScfEpin, n_diodes),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "l_pos",
-    26,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_INT32,
-    0,   /* quantifier_offset */
-    offsetof(ScfEpin, l_pos),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "vflag",
-    27,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_BOOL,
-    0,   /* quantifier_offset */
-    offsetof(ScfEpin, vflag),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "pflag",
-    28,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_BOOL,
-    0,   /* quantifier_offset */
-    offsetof(ScfEpin, pflag),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "vconst",
-    29,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_BOOL,
-    0,   /* quantifier_offset */
-    offsetof(ScfEpin, vconst),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "aconst",
-    30,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_BOOL,
-    0,   /* quantifier_offset */
-    offsetof(ScfEpin, aconst),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-};
-static const unsigned scf_epin__field_indices_by_name[] = {
-  8,   /* field[8] = a */
-  29,   /* field[29] = aconst */
-  5,   /* field[5] = c_lid */
-  1,   /* field[1] = cid */
-  15,   /* field[15] = dr */
-  3,   /* field[3] = flags */
-  14,   /* field[14] = hfe */
-  0,   /* field[0] = id */
-  9,   /* field[9] = ja */
-  16,   /* field[16] = jdr */
-  20,   /* field[20] = jpr */
-  11,   /* field[11] = jr */
-  18,   /* field[18] = jsr */
-  7,   /* field[7] = jv */
-  25,   /* field[25] = l_pos */
-  2,   /* field[2] = lid */
-  24,   /* field[24] = n_diodes */
-  21,   /* field[21] = path */
-  27,   /* field[27] = pflag */
-  19,   /* field[19] = pr */
-  10,   /* field[10] = r */
-  17,   /* field[17] = sr */
-  4,   /* field[4] = tos */
-  12,   /* field[12] = uF */
-  13,   /* field[13] = uH */
-  6,   /* field[6] = v */
-  28,   /* field[28] = vconst */
-  26,   /* field[26] = vflag */
-  22,   /* field[22] = x */
-  23,   /* field[23] = y */
-};
-static const ProtobufCIntRange scf_epin__number_ranges[1 + 1] =
-{
-  { 1, 0 },
-  { 0, 30 }
-};
-const ProtobufCMessageDescriptor scf_epin__descriptor =
-{
-  PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
-  "scf_epin",
-  "ScfEpin",
-  "ScfEpin",
-  "",
-  sizeof(ScfEpin),
-  30,
-  scf_epin__field_descriptors,
-  scf_epin__field_indices_by_name,
-  1,  scf_epin__number_ranges,
-  (ProtobufCMessageInit) scf_epin__init,
-  NULL,NULL,NULL    /* reserved[123] */
-};
-static const ProtobufCFieldDescriptor scf_econn__field_descriptors[2] =
-{
-  {
-    "lid",
-    1,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_UINT64,
-    0,   /* quantifier_offset */
-    offsetof(ScfEconn, lid),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "cids",
-    2,
-    PROTOBUF_C_LABEL_REPEATED,
-    PROTOBUF_C_TYPE_UINT64,
-    offsetof(ScfEconn, n_cids),
-    offsetof(ScfEconn, cids),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-};
-static const unsigned scf_econn__field_indices_by_name[] = {
-  1,   /* field[1] = cids */
-  0,   /* field[0] = lid */
-};
-static const ProtobufCIntRange scf_econn__number_ranges[1 + 1] =
-{
-  { 1, 0 },
-  { 0, 2 }
-};
-const ProtobufCMessageDescriptor scf_econn__descriptor =
-{
-  PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
-  "scf_econn",
-  "ScfEconn",
-  "ScfEconn",
-  "",
-  sizeof(ScfEconn),
-  2,
-  scf_econn__field_descriptors,
-  scf_econn__field_indices_by_name,
-  1,  scf_econn__number_ranges,
-  (ProtobufCMessageInit) scf_econn__init,
-  NULL,NULL,NULL    /* reserved[123] */
-};
-static const ProtobufCFieldDescriptor scf_eline__field_descriptors[14] =
-{
-  {
-    "id",
-    1,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_UINT64,
-    0,   /* quantifier_offset */
-    offsetof(ScfEline, id),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "pins",
-    2,
-    PROTOBUF_C_LABEL_REPEATED,
-    PROTOBUF_C_TYPE_UINT64,
-    offsetof(ScfEline, n_pins),
-    offsetof(ScfEline, pins),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "c_pins",
-    3,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_UINT64,
-    0,   /* quantifier_offset */
-    offsetof(ScfEline, c_pins),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "flags",
-    4,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_UINT64,
-    0,   /* quantifier_offset */
-    offsetof(ScfEline, flags),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "color",
-    5,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_INT64,
-    0,   /* quantifier_offset */
-    offsetof(ScfEline, color),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "conns",
-    6,
-    PROTOBUF_C_LABEL_REPEATED,
-    PROTOBUF_C_TYPE_MESSAGE,
-    offsetof(ScfEline, n_conns),
-    offsetof(ScfEline, conns),
-    &scf_econn__descriptor,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "lines",
-    7,
-    PROTOBUF_C_LABEL_REPEATED,
-    PROTOBUF_C_TYPE_MESSAGE,
-    offsetof(ScfEline, n_lines),
-    offsetof(ScfEline, lines),
-    &scf_line__descriptor,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "v",
-    8,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_DOUBLE,
-    0,   /* quantifier_offset */
-    offsetof(ScfEline, v),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "jv",
-    9,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_DOUBLE,
-    0,   /* quantifier_offset */
-    offsetof(ScfEline, jv),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "a",
-    10,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_DOUBLE,
-    0,   /* quantifier_offset */
-    offsetof(ScfEline, a),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "ja",
-    11,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_DOUBLE,
-    0,   /* quantifier_offset */
-    offsetof(ScfEline, ja),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "vconst",
-    12,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_BOOL,
-    0,   /* quantifier_offset */
-    offsetof(ScfEline, vconst),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "aconst",
-    13,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_BOOL,
-    0,   /* quantifier_offset */
-    offsetof(ScfEline, aconst),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "vflag",
-    14,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_BOOL,
-    0,   /* quantifier_offset */
-    offsetof(ScfEline, vflag),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-};
-static const unsigned scf_eline__field_indices_by_name[] = {
-  9,   /* field[9] = a */
-  12,   /* field[12] = aconst */
-  2,   /* field[2] = c_pins */
-  4,   /* field[4] = color */
-  5,   /* field[5] = conns */
-  3,   /* field[3] = flags */
-  0,   /* field[0] = id */
-  10,   /* field[10] = ja */
-  8,   /* field[8] = jv */
-  6,   /* field[6] = lines */
-  1,   /* field[1] = pins */
-  7,   /* field[7] = v */
-  11,   /* field[11] = vconst */
-  13,   /* field[13] = vflag */
-};
-static const ProtobufCIntRange scf_eline__number_ranges[1 + 1] =
-{
-  { 1, 0 },
-  { 0, 14 }
-};
-const ProtobufCMessageDescriptor scf_eline__descriptor =
-{
-  PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
-  "scf_eline",
-  "ScfEline",
-  "ScfEline",
-  "",
-  sizeof(ScfEline),
-  14,
-  scf_eline__field_descriptors,
-  scf_eline__field_indices_by_name,
-  1,  scf_eline__number_ranges,
-  (ProtobufCMessageInit) scf_eline__init,
-  NULL,NULL,NULL    /* reserved[123] */
-};
-static const ProtobufCFieldDescriptor scf_ecomponent__field_descriptors[20] =
-{
-  {
-    "id",
-    1,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_UINT64,
-    0,   /* quantifier_offset */
-    offsetof(ScfEcomponent, id),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "type",
-    2,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_UINT64,
-    0,   /* quantifier_offset */
-    offsetof(ScfEcomponent, type),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "model",
-    3,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_UINT64,
-    0,   /* quantifier_offset */
-    offsetof(ScfEcomponent, model),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "pins",
-    4,
-    PROTOBUF_C_LABEL_REPEATED,
-    PROTOBUF_C_TYPE_MESSAGE,
-    offsetof(ScfEcomponent, n_pins),
-    offsetof(ScfEcomponent, pins),
-    &scf_epin__descriptor,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "v",
-    5,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_DOUBLE,
-    0,   /* quantifier_offset */
-    offsetof(ScfEcomponent, v),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "jv",
-    6,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_DOUBLE,
-    0,   /* quantifier_offset */
-    offsetof(ScfEcomponent, jv),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "a",
-    7,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_DOUBLE,
-    0,   /* quantifier_offset */
-    offsetof(ScfEcomponent, a),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "ja",
-    8,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_DOUBLE,
-    0,   /* quantifier_offset */
-    offsetof(ScfEcomponent, ja),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "r",
-    9,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_DOUBLE,
-    0,   /* quantifier_offset */
-    offsetof(ScfEcomponent, r),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "jr",
-    10,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_DOUBLE,
-    0,   /* quantifier_offset */
-    offsetof(ScfEcomponent, jr),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "uF",
-    11,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_DOUBLE,
-    0,   /* quantifier_offset */
-    offsetof(ScfEcomponent, uf),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "uH",
-    12,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_DOUBLE,
-    0,   /* quantifier_offset */
-    offsetof(ScfEcomponent, uh),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "color",
-    13,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_INT64,
-    0,   /* quantifier_offset */
-    offsetof(ScfEcomponent, color),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "status",
-    14,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_INT32,
-    0,   /* quantifier_offset */
-    offsetof(ScfEcomponent, status),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "x",
-    15,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_INT32,
-    0,   /* quantifier_offset */
-    offsetof(ScfEcomponent, x),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "y",
-    16,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_INT32,
-    0,   /* quantifier_offset */
-    offsetof(ScfEcomponent, y),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "w",
-    17,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_INT32,
-    0,   /* quantifier_offset */
-    offsetof(ScfEcomponent, w),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "h",
-    18,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_INT32,
-    0,   /* quantifier_offset */
-    offsetof(ScfEcomponent, h),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "vflag",
-    19,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_BOOL,
-    0,   /* quantifier_offset */
-    offsetof(ScfEcomponent, vflag),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "lock",
-    20,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_BOOL,
-    0,   /* quantifier_offset */
-    offsetof(ScfEcomponent, lock),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-};
-static const unsigned scf_ecomponent__field_indices_by_name[] = {
-  6,   /* field[6] = a */
-  12,   /* field[12] = color */
-  17,   /* field[17] = h */
-  0,   /* field[0] = id */
-  7,   /* field[7] = ja */
-  9,   /* field[9] = jr */
-  5,   /* field[5] = jv */
-  19,   /* field[19] = lock */
-  2,   /* field[2] = model */
-  3,   /* field[3] = pins */
-  8,   /* field[8] = r */
-  13,   /* field[13] = status */
-  1,   /* field[1] = type */
-  10,   /* field[10] = uF */
-  11,   /* field[11] = uH */
-  4,   /* field[4] = v */
-  18,   /* field[18] = vflag */
-  16,   /* field[16] = w */
-  14,   /* field[14] = x */
-  15,   /* field[15] = y */
-};
-static const ProtobufCIntRange scf_ecomponent__number_ranges[1 + 1] =
-{
-  { 1, 0 },
-  { 0, 20 }
-};
-const ProtobufCMessageDescriptor scf_ecomponent__descriptor =
-{
-  PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
-  "scf_ecomponent",
-  "ScfEcomponent",
-  "ScfEcomponent",
-  "",
-  sizeof(ScfEcomponent),
-  20,
-  scf_ecomponent__field_descriptors,
-  scf_ecomponent__field_indices_by_name,
-  1,  scf_ecomponent__number_ranges,
-  (ProtobufCMessageInit) scf_ecomponent__init,
-  NULL,NULL,NULL    /* reserved[123] */
-};
-static const ProtobufCFieldDescriptor scf_efunction__field_descriptors[7] =
-{
-  {
-    "name",
-    1,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_STRING,
-    0,   /* quantifier_offset */
-    offsetof(ScfEfunction, name),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "components",
-    2,
-    PROTOBUF_C_LABEL_REPEATED,
-    PROTOBUF_C_TYPE_MESSAGE,
-    offsetof(ScfEfunction, n_components),
-    offsetof(ScfEfunction, components),
-    &scf_ecomponent__descriptor,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "elines",
-    3,
-    PROTOBUF_C_LABEL_REPEATED,
-    PROTOBUF_C_TYPE_MESSAGE,
-    offsetof(ScfEfunction, n_elines),
-    offsetof(ScfEfunction, elines),
-    &scf_eline__descriptor,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "x",
-    4,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_INT32,
-    0,   /* quantifier_offset */
-    offsetof(ScfEfunction, x),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "y",
-    5,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_INT32,
-    0,   /* quantifier_offset */
-    offsetof(ScfEfunction, y),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "w",
-    6,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_INT32,
-    0,   /* quantifier_offset */
-    offsetof(ScfEfunction, w),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-  {
-    "h",
-    7,
-    PROTOBUF_C_LABEL_REQUIRED,
-    PROTOBUF_C_TYPE_INT32,
-    0,   /* quantifier_offset */
-    offsetof(ScfEfunction, h),
-    NULL,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-};
-static const unsigned scf_efunction__field_indices_by_name[] = {
-  1,   /* field[1] = components */
-  2,   /* field[2] = elines */
-  6,   /* field[6] = h */
-  0,   /* field[0] = name */
-  5,   /* field[5] = w */
-  3,   /* field[3] = x */
-  4,   /* field[4] = y */
-};
-static const ProtobufCIntRange scf_efunction__number_ranges[1 + 1] =
-{
-  { 1, 0 },
-  { 0, 7 }
-};
-const ProtobufCMessageDescriptor scf_efunction__descriptor =
-{
-  PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
-  "scf_efunction",
-  "ScfEfunction",
-  "ScfEfunction",
-  "",
-  sizeof(ScfEfunction),
-  7,
-  scf_efunction__field_descriptors,
-  scf_efunction__field_indices_by_name,
-  1,  scf_efunction__number_ranges,
-  (ProtobufCMessageInit) scf_efunction__init,
-  NULL,NULL,NULL    /* reserved[123] */
-};
-static const ProtobufCFieldDescriptor scf_eboard__field_descriptors[1] =
-{
-  {
-    "functions",
-    1,
-    PROTOBUF_C_LABEL_REPEATED,
-    PROTOBUF_C_TYPE_MESSAGE,
-    offsetof(ScfEboard, n_functions),
-    offsetof(ScfEboard, functions),
-    &scf_efunction__descriptor,
-    NULL,
-    0,             /* flags */
-    0,NULL,NULL    /* reserved1,reserved2, etc */
-  },
-};
-static const unsigned scf_eboard__field_indices_by_name[] = {
-  0,   /* field[0] = functions */
-};
-static const ProtobufCIntRange scf_eboard__number_ranges[1 + 1] =
-{
-  { 1, 0 },
-  { 0, 1 }
-};
-const ProtobufCMessageDescriptor scf_eboard__descriptor =
-{
-  PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
-  "scf_eboard",
-  "ScfEboard",
-  "ScfEboard",
-  "",
-  sizeof(ScfEboard),
-  1,
-  scf_eboard__field_descriptors,
-  scf_eboard__field_indices_by_name,
-  1,  scf_eboard__number_ranges,
-  (ProtobufCMessageInit) scf_eboard__init,
-  NULL,NULL,NULL    /* reserved[123] */
-};
diff --git a/scf_eda.pb-c.h b/scf_eda.pb-c.h
deleted file mode 100644 (file)
index 750c4cc..0000000
+++ /dev/null
@@ -1,355 +0,0 @@
-/* Generated by the protocol buffer compiler.  DO NOT EDIT! */
-/* Generated from: scf_eda.proto */
-
-#ifndef PROTOBUF_C_scf_5feda_2eproto__INCLUDED
-#define PROTOBUF_C_scf_5feda_2eproto__INCLUDED
-
-#include <protobuf-c/protobuf-c.h>
-
-PROTOBUF_C__BEGIN_DECLS
-
-#if PROTOBUF_C_VERSION_NUMBER < 1000000
-# error This file was generated by a newer version of protoc-c which is incompatible with your libprotobuf-c headers. Please update your headers.
-#elif 1002001 < PROTOBUF_C_MIN_COMPILER_VERSION
-# error This file was generated by an older version of protoc-c which is incompatible with your libprotobuf-c headers. Please regenerate this file with a newer version of protoc-c.
-#endif
-
-
-typedef struct _ScfLine ScfLine;
-typedef struct _ScfEpin ScfEpin;
-typedef struct _ScfEconn ScfEconn;
-typedef struct _ScfEline ScfEline;
-typedef struct _ScfEcomponent ScfEcomponent;
-typedef struct _ScfEfunction ScfEfunction;
-typedef struct _ScfEboard ScfEboard;
-
-
-/* --- enums --- */
-
-
-/* --- messages --- */
-
-struct  _ScfLine
-{
-  ProtobufCMessage base;
-  int32_t x0;
-  int32_t y0;
-  int32_t x1;
-  int32_t y1;
-};
-#define SCF_LINE__INIT \
- { PROTOBUF_C_MESSAGE_INIT (&scf_line__descriptor) \
-    , 0, 0, 0, 0 }
-
-
-struct  _ScfEpin
-{
-  ProtobufCMessage base;
-  uint64_t id;
-  uint64_t cid;
-  uint64_t lid;
-  uint64_t flags;
-  size_t n_tos;
-  uint64_t *tos;
-  uint64_t c_lid;
-  double v;
-  double jv;
-  double a;
-  double ja;
-  double r;
-  double jr;
-  double uf;
-  double uh;
-  double hfe;
-  double dr;
-  double jdr;
-  double sr;
-  double jsr;
-  double pr;
-  double jpr;
-  uint64_t path;
-  int32_t x;
-  int32_t y;
-  int32_t n_diodes;
-  int32_t l_pos;
-  protobuf_c_boolean vflag;
-  protobuf_c_boolean pflag;
-  protobuf_c_boolean vconst;
-  protobuf_c_boolean aconst;
-};
-#define SCF_EPIN__INIT \
- { PROTOBUF_C_MESSAGE_INIT (&scf_epin__descriptor) \
-    , 0, 0, 0, 0, 0,NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
-
-
-struct  _ScfEconn
-{
-  ProtobufCMessage base;
-  uint64_t lid;
-  size_t n_cids;
-  uint64_t *cids;
-};
-#define SCF_ECONN__INIT \
- { PROTOBUF_C_MESSAGE_INIT (&scf_econn__descriptor) \
-    , 0, 0,NULL }
-
-
-struct  _ScfEline
-{
-  ProtobufCMessage base;
-  uint64_t id;
-  size_t n_pins;
-  uint64_t *pins;
-  uint64_t c_pins;
-  uint64_t flags;
-  int64_t color;
-  size_t n_conns;
-  ScfEconn **conns;
-  size_t n_lines;
-  ScfLine **lines;
-  double v;
-  double jv;
-  double a;
-  double ja;
-  protobuf_c_boolean vconst;
-  protobuf_c_boolean aconst;
-  protobuf_c_boolean vflag;
-};
-#define SCF_ELINE__INIT \
- { PROTOBUF_C_MESSAGE_INIT (&scf_eline__descriptor) \
-    , 0, 0,NULL, 0, 0, 0, 0,NULL, 0,NULL, 0, 0, 0, 0, 0, 0, 0 }
-
-
-struct  _ScfEcomponent
-{
-  ProtobufCMessage base;
-  uint64_t id;
-  uint64_t type;
-  uint64_t model;
-  size_t n_pins;
-  ScfEpin **pins;
-  double v;
-  double jv;
-  double a;
-  double ja;
-  double r;
-  double jr;
-  double uf;
-  double uh;
-  int64_t color;
-  int32_t status;
-  int32_t x;
-  int32_t y;
-  int32_t w;
-  int32_t h;
-  protobuf_c_boolean vflag;
-  protobuf_c_boolean lock;
-};
-#define SCF_ECOMPONENT__INIT \
- { PROTOBUF_C_MESSAGE_INIT (&scf_ecomponent__descriptor) \
-    , 0, 0, 0, 0,NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
-
-
-struct  _ScfEfunction
-{
-  ProtobufCMessage base;
-  char *name;
-  size_t n_components;
-  ScfEcomponent **components;
-  size_t n_elines;
-  ScfEline **elines;
-  int32_t x;
-  int32_t y;
-  int32_t w;
-  int32_t h;
-};
-#define SCF_EFUNCTION__INIT \
- { PROTOBUF_C_MESSAGE_INIT (&scf_efunction__descriptor) \
-    , NULL, 0,NULL, 0,NULL, 0, 0, 0, 0 }
-
-
-struct  _ScfEboard
-{
-  ProtobufCMessage base;
-  size_t n_functions;
-  ScfEfunction **functions;
-};
-#define SCF_EBOARD__INIT \
- { PROTOBUF_C_MESSAGE_INIT (&scf_eboard__descriptor) \
-    , 0,NULL }
-
-
-/* ScfLine methods */
-void   scf_line__init
-                     (ScfLine         *message);
-size_t scf_line__get_packed_size
-                     (const ScfLine   *message);
-size_t scf_line__pack
-                     (const ScfLine   *message,
-                      uint8_t             *out);
-size_t scf_line__pack_to_buffer
-                     (const ScfLine   *message,
-                      ProtobufCBuffer     *buffer);
-ScfLine *
-       scf_line__unpack
-                     (ProtobufCAllocator  *allocator,
-                      size_t               len,
-                      const uint8_t       *data);
-void   scf_line__free_unpacked
-                     (ScfLine *message,
-                      ProtobufCAllocator *allocator);
-/* ScfEpin methods */
-void   scf_epin__init
-                     (ScfEpin         *message);
-size_t scf_epin__get_packed_size
-                     (const ScfEpin   *message);
-size_t scf_epin__pack
-                     (const ScfEpin   *message,
-                      uint8_t             *out);
-size_t scf_epin__pack_to_buffer
-                     (const ScfEpin   *message,
-                      ProtobufCBuffer     *buffer);
-ScfEpin *
-       scf_epin__unpack
-                     (ProtobufCAllocator  *allocator,
-                      size_t               len,
-                      const uint8_t       *data);
-void   scf_epin__free_unpacked
-                     (ScfEpin *message,
-                      ProtobufCAllocator *allocator);
-/* ScfEconn methods */
-void   scf_econn__init
-                     (ScfEconn         *message);
-size_t scf_econn__get_packed_size
-                     (const ScfEconn   *message);
-size_t scf_econn__pack
-                     (const ScfEconn   *message,
-                      uint8_t             *out);
-size_t scf_econn__pack_to_buffer
-                     (const ScfEconn   *message,
-                      ProtobufCBuffer     *buffer);
-ScfEconn *
-       scf_econn__unpack
-                     (ProtobufCAllocator  *allocator,
-                      size_t               len,
-                      const uint8_t       *data);
-void   scf_econn__free_unpacked
-                     (ScfEconn *message,
-                      ProtobufCAllocator *allocator);
-/* ScfEline methods */
-void   scf_eline__init
-                     (ScfEline         *message);
-size_t scf_eline__get_packed_size
-                     (const ScfEline   *message);
-size_t scf_eline__pack
-                     (const ScfEline   *message,
-                      uint8_t             *out);
-size_t scf_eline__pack_to_buffer
-                     (const ScfEline   *message,
-                      ProtobufCBuffer     *buffer);
-ScfEline *
-       scf_eline__unpack
-                     (ProtobufCAllocator  *allocator,
-                      size_t               len,
-                      const uint8_t       *data);
-void   scf_eline__free_unpacked
-                     (ScfEline *message,
-                      ProtobufCAllocator *allocator);
-/* ScfEcomponent methods */
-void   scf_ecomponent__init
-                     (ScfEcomponent         *message);
-size_t scf_ecomponent__get_packed_size
-                     (const ScfEcomponent   *message);
-size_t scf_ecomponent__pack
-                     (const ScfEcomponent   *message,
-                      uint8_t             *out);
-size_t scf_ecomponent__pack_to_buffer
-                     (const ScfEcomponent   *message,
-                      ProtobufCBuffer     *buffer);
-ScfEcomponent *
-       scf_ecomponent__unpack
-                     (ProtobufCAllocator  *allocator,
-                      size_t               len,
-                      const uint8_t       *data);
-void   scf_ecomponent__free_unpacked
-                     (ScfEcomponent *message,
-                      ProtobufCAllocator *allocator);
-/* ScfEfunction methods */
-void   scf_efunction__init
-                     (ScfEfunction         *message);
-size_t scf_efunction__get_packed_size
-                     (const ScfEfunction   *message);
-size_t scf_efunction__pack
-                     (const ScfEfunction   *message,
-                      uint8_t             *out);
-size_t scf_efunction__pack_to_buffer
-                     (const ScfEfunction   *message,
-                      ProtobufCBuffer     *buffer);
-ScfEfunction *
-       scf_efunction__unpack
-                     (ProtobufCAllocator  *allocator,
-                      size_t               len,
-                      const uint8_t       *data);
-void   scf_efunction__free_unpacked
-                     (ScfEfunction *message,
-                      ProtobufCAllocator *allocator);
-/* ScfEboard methods */
-void   scf_eboard__init
-                     (ScfEboard         *message);
-size_t scf_eboard__get_packed_size
-                     (const ScfEboard   *message);
-size_t scf_eboard__pack
-                     (const ScfEboard   *message,
-                      uint8_t             *out);
-size_t scf_eboard__pack_to_buffer
-                     (const ScfEboard   *message,
-                      ProtobufCBuffer     *buffer);
-ScfEboard *
-       scf_eboard__unpack
-                     (ProtobufCAllocator  *allocator,
-                      size_t               len,
-                      const uint8_t       *data);
-void   scf_eboard__free_unpacked
-                     (ScfEboard *message,
-                      ProtobufCAllocator *allocator);
-/* --- per-message closures --- */
-
-typedef void (*ScfLine_Closure)
-                 (const ScfLine *message,
-                  void *closure_data);
-typedef void (*ScfEpin_Closure)
-                 (const ScfEpin *message,
-                  void *closure_data);
-typedef void (*ScfEconn_Closure)
-                 (const ScfEconn *message,
-                  void *closure_data);
-typedef void (*ScfEline_Closure)
-                 (const ScfEline *message,
-                  void *closure_data);
-typedef void (*ScfEcomponent_Closure)
-                 (const ScfEcomponent *message,
-                  void *closure_data);
-typedef void (*ScfEfunction_Closure)
-                 (const ScfEfunction *message,
-                  void *closure_data);
-typedef void (*ScfEboard_Closure)
-                 (const ScfEboard *message,
-                  void *closure_data);
-
-/* --- services --- */
-
-
-/* --- descriptors --- */
-
-extern const ProtobufCMessageDescriptor scf_line__descriptor;
-extern const ProtobufCMessageDescriptor scf_epin__descriptor;
-extern const ProtobufCMessageDescriptor scf_econn__descriptor;
-extern const ProtobufCMessageDescriptor scf_eline__descriptor;
-extern const ProtobufCMessageDescriptor scf_ecomponent__descriptor;
-extern const ProtobufCMessageDescriptor scf_efunction__descriptor;
-extern const ProtobufCMessageDescriptor scf_eboard__descriptor;
-
-PROTOBUF_C__END_DECLS
-
-
-#endif  /* PROTOBUF_C_scf_5feda_2eproto__INCLUDED */
similarity index 83%
rename from scf_eda_pb.c
rename to scf_eda_pack.c
index 5433001844e246620f9e9e0a2c16c42e94ff2822..12c1e890b8a214be9705adf3e93110e83e6d9165 100644 (file)
@@ -1,5 +1,5 @@
-#include "scf_eda_pb.h"
-#include "scf_def.h"
+#include "scf_eda_pack.h"
+//#include "scf_def.h"
 
 static int component_pins[SCF_EDA_Components_NB] =
 {
@@ -70,11 +70,8 @@ static scf_edata_t* _component_find_data(const uint64_t type, const uint64_t mod
 
 ScfEconn* scf_econn__alloc()
 {
-       ScfEconn* ec = malloc(sizeof(ScfEconn));
-       if (!ec)
-               return NULL;
+       ScfEconn* ec = calloc(1, sizeof(ScfEconn));
 
-       scf_econn__init(ec);
        return ec;
 }
 
@@ -126,23 +123,10 @@ int scf_econn__del_cid(ScfEconn* ec, uint64_t cid)
        return -EINVAL;
 }
 
-void scf_econn__free(ScfEconn* ec)
-{
-       if (ec) {
-               if (ec->cids)
-                       free(ec->cids);
-
-               free(ec);
-       }
-}
-
 ScfEline* scf_eline__alloc()
 {
-       ScfEline* l = malloc(sizeof(ScfEline));
-       if (!l)
-               return NULL;
+       ScfEline* l = calloc(1, sizeof(ScfEline));
 
-       scf_eline__init(l);
        return l;
 }
 
@@ -300,39 +284,10 @@ int scf_eline__del_conn(ScfEline* el, ScfEconn* ec)
        return -EINVAL;
 }
 
-void scf_eline__free(ScfEline* l)
-{
-       if (l) {
-               size_t i;
-
-               if (l->pins)
-                       free(l->pins);
-
-               if (l->conns) {
-                       for (i = 0; i < l->n_conns; i++)
-                               scf_econn__free(l->conns[i]);
-
-                       free(l->conns);
-               }
-
-               if (l->lines) {
-                       for (i = 0; i < l->n_lines; i++)
-                               free(l->lines[i]);
-
-                       free(l->lines);
-               }
-
-               free(l);
-       }
-}
-
 ScfEpin* scf_epin__alloc()
 {
-       ScfEpin* pin = malloc(sizeof(ScfEpin));
-       if (!pin)
-               return NULL;
+       ScfEpin* pin = calloc(1, sizeof(ScfEpin));
 
-       scf_epin__init(pin);
        return pin;
 }
 
@@ -385,31 +340,18 @@ int scf_epin__del_component(ScfEpin* pin, uint64_t cid, uint64_t pid)
        return -EINVAL;
 }
 
-void scf_epin__free(ScfEpin* pin)
-{
-       if (pin) {
-               scf_logd("pin: %p\n", pin);
-
-               if (pin->tos)
-                       free(pin->tos);
-               free(pin);
-       }
-}
-
 ScfEcomponent* scf_ecomponent__alloc(uint64_t type)
 {
        ScfEcomponent* c;
-       scf_edata_t*   ed;
+       scf_edata_t*      ed;
 
        if (type >= SCF_EDA_Components_NB)
                return NULL;
 
-       c = malloc(sizeof(ScfEcomponent));
+       c = calloc(1, sizeof(ScfEcomponent));
        if (!c)
                return NULL;
 
-       scf_ecomponent__init(c);
-
        c->type = type;
 
        ed = _component_find_data(c->type, c->model);
@@ -427,15 +369,15 @@ ScfEcomponent* scf_ecomponent__alloc(uint64_t type)
 
                ScfEpin* pin = scf_epin__alloc();
                if (!pin) {
-                       scf_ecomponent__free(c);
+                       ScfEcomponent_free(c);
                        return NULL;
                }
 
                pin->id = i;
 
                if (scf_ecomponent__add_pin(c, pin) < 0) {
-                       scf_ecomponent__free(c);
-                       scf_epin__free(pin);
+                       ScfEcomponent_free(c);
+                       ScfEpin_free(pin);
                        return NULL;
                }
 
@@ -496,31 +438,13 @@ int scf_ecomponent__del_pin(ScfEcomponent* c, ScfEpin* pin)
        return -EINVAL;
 }
 
-void scf_ecomponent__free(ScfEcomponent* c)
-{
-       if (c) {
-               scf_logd("c: %ld\n", c->id);
-
-               if (c->pins) {
-                       size_t i;
-
-                       for (i = 0; i < c->n_pins; i++)
-                               scf_epin__free(c->pins[i]);
-
-                       free(c->pins);
-               }
-
-               free(c);
-       }
-}
-
 ScfEfunction*  scf_efunction__alloc(const char* name)
 {
-       ScfEfunction* f = malloc(sizeof(ScfEfunction));
+       ScfEfunction* f = calloc(1, sizeof(ScfEfunction));
        if (!f)
                return NULL;
 
-       scf_efunction__init(f);
+       f->n_name = strlen(name) + 1;
 
        f->name = strdup(name);
        if (!f->name) {
@@ -615,32 +539,10 @@ int scf_efunction__del_eline(ScfEfunction* f, ScfEline* el)
        return -EINVAL;
 }
 
-void scf_efunction__free(ScfEfunction* f)
-{
-       if (f) {
-               scf_logd("f: %s\n", f->name);
-
-               if (f->components) {
-                       size_t i;
-
-                       for (i = 0; i < f->n_components; i++)
-                               scf_ecomponent__free(f->components[i]);
-
-                       free(f->components);
-               }
-
-               free(f->name);
-               free(f);
-       }
-}
-
 ScfEboard* scf_eboard__alloc()
 {
-       ScfEboard* b = malloc(sizeof(ScfEboard));
-       if (!b)
-               return NULL;
+       ScfEboard* b = calloc(1, sizeof(ScfEboard));
 
-       scf_eboard__init(b);
        return b;
 }
 
@@ -685,19 +587,3 @@ int scf_eboard__del_function(ScfEboard* b, ScfEfunction* f)
 
        return -EINVAL;
 }
-
-void scf_eboard__free(ScfEboard* b)
-{
-       if (b) {
-               if (b->functions) {
-                       size_t i;
-
-                       for (i = 0; i < b->n_functions; i++)
-                               scf_efunction__free(b->functions[i]);
-
-                       free(b->functions);
-               }
-
-               free(b);
-       }
-}
diff --git a/scf_eda_pack.h b/scf_eda_pack.h
new file mode 100644 (file)
index 0000000..8b3dbd3
--- /dev/null
@@ -0,0 +1,393 @@
+#ifndef SCF_EDA_PACK_H
+#define SCF_EDA_PACK_H
+
+#include "scf_pack.h"
+
+enum {
+       SCF_EDA_None,
+       SCF_EDA_Battery,
+
+       SCF_EDA_Resistor,
+       SCF_EDA_Capacitor,
+       SCF_EDA_Inductor,
+
+       SCF_EDA_Diode,
+       SCF_EDA_NPN,
+       SCF_EDA_PNP,
+
+       SCF_EDA_Components_NB,
+};
+
+#define SCF_EDA_PIN_NONE   0
+#define SCF_EDA_PIN_IN     1
+#define SCF_EDA_PIN_OUT    2
+#define SCF_EDA_PIN_POS    4
+#define SCF_EDA_PIN_NEG    8
+#define SCF_EDA_PIN_CF     16
+#define SCF_EDA_PIN_BORDER 32
+
+#define SCF_EDA_V_INIT   -10001001.0
+#define SCF_EDA_V_MIN    -10000000.0
+#define SCF_EDA_V_MAX     10000000.0
+
+#define SCF_EDA_V_Diode_ON  0.58
+#define SCF_EDA_V_Diode_OFF 0.55
+
+#define SCF_EDA_V_NPN_ON    0.70
+#define SCF_EDA_V_NPN_OFF   0.61
+
+enum {
+       SCF_EDA_Battery_NEG,
+       SCF_EDA_Battery_POS,
+       SCF_EDA_Battery_NB,
+};
+
+enum {
+       SCF_EDA_Diode_NEG,
+       SCF_EDA_Diode_POS,
+       SCF_EDA_Diode_NB,
+};
+
+enum {
+       SCF_EDA_Status_ON,
+       SCF_EDA_Status_OFF,
+       SCF_EDA_Path_OFF,
+       SCF_EDA_Path_TO,
+};
+
+enum {
+       SCF_EDA_NPN_B,
+       SCF_EDA_NPN_E,
+       SCF_EDA_NPN_C,
+       SCF_EDA_NPN_NB,
+};
+
+enum {
+       SCF_EDA_PNP_B,
+       SCF_EDA_PNP_E,
+       SCF_EDA_PNP_C,
+       SCF_EDA_PNP_NB,
+};
+
+typedef struct {
+       uint64_t  type;
+       uint64_t  model;
+       uint64_t  pid;
+
+       double    v;
+       double    a;
+       double    r;
+       double    jr;
+       double    uf;
+       double    uh;
+       double    hfe;
+} scf_edata_t;
+
+typedef struct {
+       SCF_PACK_DEF_VAR(int, x0);
+       SCF_PACK_DEF_VAR(int, y0);
+       SCF_PACK_DEF_VAR(int, x1);
+       SCF_PACK_DEF_VAR(int, y1);
+} ScfLine;
+
+SCF_PACK_TYPE(ScfLine)
+SCF_PACK_INFO_VAR(ScfLine, x0),
+SCF_PACK_INFO_VAR(ScfLine, y0),
+SCF_PACK_INFO_VAR(ScfLine, x1),
+SCF_PACK_INFO_VAR(ScfLine, y1),
+SCF_PACK_END(ScfLine)
+
+typedef struct scf_epin_s        ScfEpin;
+typedef struct scf_ecomponent_s  ScfEcomponent;
+typedef struct scf_efunction_s   ScfEfunction;
+typedef struct scf_eboard_s      ScfEboard;
+
+struct scf_epin_s
+{
+       SCF_PACK_DEF_VAR(uint64_t, id);
+       SCF_PACK_DEF_VAR(uint64_t, cid);
+       SCF_PACK_DEF_VAR(uint64_t, lid);
+       SCF_PACK_DEF_VAR(uint64_t, flags);
+       SCF_PACK_DEF_VARS(uint64_t, tos);
+       SCF_PACK_DEF_VAR(uint64_t, c_lid);
+
+       SCF_PACK_DEF_VAR(double, v);
+       SCF_PACK_DEF_VAR(double, jv);
+       SCF_PACK_DEF_VAR(double, a);
+       SCF_PACK_DEF_VAR(double, ja);
+
+       SCF_PACK_DEF_VAR(double, r);
+       SCF_PACK_DEF_VAR(double, jr);
+       SCF_PACK_DEF_VAR(double, uf);
+       SCF_PACK_DEF_VAR(double, uh);
+       SCF_PACK_DEF_VAR(double, hfe);
+
+       SCF_PACK_DEF_VAR(double, dr);
+       SCF_PACK_DEF_VAR(double, jdr);
+
+       SCF_PACK_DEF_VAR(double, sr);
+       SCF_PACK_DEF_VAR(double, jsr);
+
+       SCF_PACK_DEF_VAR(double, pr);
+       SCF_PACK_DEF_VAR(double, jpr);
+
+       SCF_PACK_DEF_VAR(uint64_t, path);
+
+       SCF_PACK_DEF_VAR(int, x);
+       SCF_PACK_DEF_VAR(int, y);
+
+       SCF_PACK_DEF_VAR(int, n_diodes);
+       SCF_PACK_DEF_VAR(int, l_pos);
+
+       SCF_PACK_DEF_VAR(uint8_t, vflag);
+       SCF_PACK_DEF_VAR(uint8_t, pflag);
+       SCF_PACK_DEF_VAR(uint8_t, vconst);
+       SCF_PACK_DEF_VAR(uint8_t, aconst);
+};
+
+SCF_PACK_TYPE(ScfEpin)
+SCF_PACK_INFO_VAR(ScfEpin, id),
+SCF_PACK_INFO_VAR(ScfEpin, cid),
+SCF_PACK_INFO_VAR(ScfEpin, lid),
+SCF_PACK_INFO_VAR(ScfEpin, flags),
+SCF_PACK_INFO_VARS(ScfEpin, tos, uint64_t),
+SCF_PACK_INFO_VAR(ScfEpin, c_lid),
+
+SCF_PACK_INFO_VAR(ScfEpin, v),
+SCF_PACK_INFO_VAR(ScfEpin, jv),
+SCF_PACK_INFO_VAR(ScfEpin, a),
+SCF_PACK_INFO_VAR(ScfEpin, ja),
+
+SCF_PACK_INFO_VAR(ScfEpin, r),
+SCF_PACK_INFO_VAR(ScfEpin, jr),
+SCF_PACK_INFO_VAR(ScfEpin, uf),
+SCF_PACK_INFO_VAR(ScfEpin, uh),
+SCF_PACK_INFO_VAR(ScfEpin, hfe),
+
+SCF_PACK_INFO_VAR(ScfEpin, dr),
+SCF_PACK_INFO_VAR(ScfEpin, jdr),
+
+SCF_PACK_INFO_VAR(ScfEpin, sr),
+SCF_PACK_INFO_VAR(ScfEpin, jsr),
+
+SCF_PACK_INFO_VAR(ScfEpin, pr),
+SCF_PACK_INFO_VAR(ScfEpin, jpr),
+
+SCF_PACK_INFO_VAR(ScfEpin, path),
+SCF_PACK_INFO_VAR(ScfEpin, x),
+SCF_PACK_INFO_VAR(ScfEpin, y),
+SCF_PACK_INFO_VAR(ScfEpin, n_diodes),
+SCF_PACK_INFO_VAR(ScfEpin, l_pos),
+
+SCF_PACK_INFO_VAR(ScfEpin, vflag),
+SCF_PACK_INFO_VAR(ScfEpin, pflag),
+SCF_PACK_INFO_VAR(ScfEpin, vconst),
+SCF_PACK_INFO_VAR(ScfEpin, aconst),
+SCF_PACK_END(ScfEpin)
+
+typedef struct {
+       SCF_PACK_DEF_VAR(uint64_t, lid);
+       SCF_PACK_DEF_VARS(uint64_t, cids);
+} ScfEconn;
+
+SCF_PACK_TYPE(ScfEconn)
+SCF_PACK_INFO_VAR(ScfEconn, lid),
+SCF_PACK_INFO_VARS(ScfEconn, cids, uint64_t),
+SCF_PACK_END(ScfEconn)
+
+typedef struct {
+       SCF_PACK_DEF_VAR(uint64_t, id);
+       SCF_PACK_DEF_VARS(uint64_t, pins);
+       SCF_PACK_DEF_VAR(uint64_t, c_pins);
+       SCF_PACK_DEF_VAR(uint64_t, flags);
+       SCF_PACK_DEF_VAR(int64_t, color);
+
+       SCF_PACK_DEF_OBJS(ScfEconn, conns);
+       SCF_PACK_DEF_OBJS(ScfLine, lines);
+
+       SCF_PACK_DEF_VAR(double, v);
+       SCF_PACK_DEF_VAR(double, jv);
+       SCF_PACK_DEF_VAR(double, a);
+       SCF_PACK_DEF_VAR(double, ja);
+       SCF_PACK_DEF_VAR(uint8_t, vconst);
+       SCF_PACK_DEF_VAR(uint8_t, aconst);
+       SCF_PACK_DEF_VAR(uint8_t, vflag);
+} ScfEline;
+
+SCF_PACK_TYPE(ScfEline)
+SCF_PACK_INFO_VAR(ScfEline, id),
+SCF_PACK_INFO_VARS(ScfEline, pins, uint64_t),
+SCF_PACK_INFO_VAR(ScfEline, c_pins),
+SCF_PACK_INFO_VAR(ScfEline, flags),
+SCF_PACK_INFO_VAR(ScfEline, color),
+
+SCF_PACK_INFO_OBJS(ScfEline, conns, ScfEconn),
+SCF_PACK_INFO_OBJS(ScfEline, lines, ScfLine),
+
+SCF_PACK_INFO_VAR(ScfEline, v),
+SCF_PACK_INFO_VAR(ScfEline, jv),
+SCF_PACK_INFO_VAR(ScfEline, a),
+SCF_PACK_INFO_VAR(ScfEline, ja),
+SCF_PACK_INFO_VAR(ScfEline, vconst),
+SCF_PACK_INFO_VAR(ScfEline, aconst),
+SCF_PACK_INFO_VAR(ScfEline, vflag),
+SCF_PACK_END(ScfEline)
+
+struct scf_ecomponent_s
+{
+       SCF_PACK_DEF_VAR(uint64_t, id);
+       SCF_PACK_DEF_VAR(uint64_t, type);
+       SCF_PACK_DEF_VAR(uint64_t, model);
+       SCF_PACK_DEF_OBJS(ScfEpin, pins);
+
+       SCF_PACK_DEF_VAR(double, v);
+       SCF_PACK_DEF_VAR(double, jv);
+       SCF_PACK_DEF_VAR(double, a);
+       SCF_PACK_DEF_VAR(double, ja);
+
+       SCF_PACK_DEF_VAR(double, r);
+       SCF_PACK_DEF_VAR(double, jr);
+       SCF_PACK_DEF_VAR(double, uf);
+       SCF_PACK_DEF_VAR(double, uh);
+
+       SCF_PACK_DEF_VAR(int64_t, color);
+       SCF_PACK_DEF_VAR(int, status);
+       SCF_PACK_DEF_VAR(int, x);
+       SCF_PACK_DEF_VAR(int, y);
+       SCF_PACK_DEF_VAR(int, w);
+       SCF_PACK_DEF_VAR(int, h);
+       SCF_PACK_DEF_VAR(uint8_t, vflag);
+       SCF_PACK_DEF_VAR(uint8_t, lock);
+};
+
+SCF_PACK_TYPE(ScfEcomponent)
+SCF_PACK_INFO_VAR(ScfEcomponent, id),
+SCF_PACK_INFO_VAR(ScfEcomponent, type),
+SCF_PACK_INFO_VAR(ScfEcomponent, model),
+SCF_PACK_INFO_OBJS(ScfEcomponent, pins, ScfEpin),
+
+SCF_PACK_INFO_VAR(ScfEcomponent, v),
+SCF_PACK_INFO_VAR(ScfEcomponent, jv),
+SCF_PACK_INFO_VAR(ScfEcomponent, a),
+SCF_PACK_INFO_VAR(ScfEcomponent, ja),
+
+SCF_PACK_INFO_VAR(ScfEcomponent, r),
+SCF_PACK_INFO_VAR(ScfEcomponent, jr),
+SCF_PACK_INFO_VAR(ScfEcomponent, uf),
+SCF_PACK_INFO_VAR(ScfEcomponent, uh),
+
+SCF_PACK_INFO_VAR(ScfEcomponent, color),
+SCF_PACK_INFO_VAR(ScfEcomponent, status),
+SCF_PACK_INFO_VAR(ScfEcomponent, x),
+SCF_PACK_INFO_VAR(ScfEcomponent, y),
+SCF_PACK_INFO_VAR(ScfEcomponent, w),
+SCF_PACK_INFO_VAR(ScfEcomponent, h),
+SCF_PACK_INFO_VAR(ScfEcomponent, vflag),
+SCF_PACK_INFO_VAR(ScfEcomponent, lock),
+SCF_PACK_END(ScfEcomponent)
+
+struct scf_efunction_s
+{
+       SCF_PACK_DEF_VARS(uint8_t, name);
+       SCF_PACK_DEF_OBJS(ScfEcomponent, components);
+       SCF_PACK_DEF_OBJS(ScfEline,      elines);
+       SCF_PACK_DEF_VAR(int, x);
+       SCF_PACK_DEF_VAR(int, y);
+       SCF_PACK_DEF_VAR(int, w);
+       SCF_PACK_DEF_VAR(int, h);
+};
+
+SCF_PACK_TYPE(ScfEfunction)
+SCF_PACK_INFO_VARS(ScfEfunction, name,       uint8_t),
+SCF_PACK_INFO_OBJS(ScfEfunction, components, ScfEcomponent),
+SCF_PACK_INFO_OBJS(ScfEfunction, elines,     ScfEline),
+SCF_PACK_INFO_VAR(ScfEfunction,  x),
+SCF_PACK_INFO_VAR(ScfEfunction,  y),
+SCF_PACK_INFO_VAR(ScfEfunction,  w),
+SCF_PACK_INFO_VAR(ScfEfunction,  h),
+SCF_PACK_END(ScfEfunction)
+
+struct scf_eboard_s
+{
+       SCF_PACK_DEF_OBJS(ScfEfunction, functions);
+};
+
+SCF_PACK_TYPE(ScfEboard)
+SCF_PACK_INFO_OBJS(ScfEboard, functions, ScfEfunction),
+SCF_PACK_END(ScfEboard)
+
+
+ScfEconn*   scf_econn__alloc();
+int            scf_econn__add_cid(ScfEconn* ec, uint64_t  cid);
+int            scf_econn__del_cid(ScfEconn* ec, uint64_t  cid);
+
+ScfEline*      scf_eline__alloc();
+int            scf_eline__add_line(ScfEline* el, ScfLine*  l);
+int            scf_eline__del_line(ScfEline* el, ScfLine*  l);
+
+int            scf_eline__add_pin (ScfEline* el, uint64_t  cid, uint64_t pid);
+int            scf_eline__del_pin (ScfEline* el, uint64_t  cid, uint64_t pid);
+
+int            scf_eline__add_conn(ScfEline* el, ScfEconn* ec);
+int            scf_eline__del_conn(ScfEline* el, ScfEconn* ec);
+
+ScfEpin*       scf_epin__alloc();
+int            scf_epin__add_component(ScfEpin* pin, uint64_t cid, uint64_t pid);
+int            scf_epin__del_component(ScfEpin* pin, uint64_t cid, uint64_t pid);
+
+ScfEcomponent* scf_ecomponent__alloc  (uint64_t type);
+int            scf_ecomponent__add_pin(ScfEcomponent* c, ScfEpin* pin);
+int            scf_ecomponent__del_pin(ScfEcomponent* c, ScfEpin* pin);
+
+ScfEfunction*  scf_efunction__alloc        (const   char* name);
+int            scf_efunction__add_component(ScfEfunction* f, ScfEcomponent* c);
+int            scf_efunction__del_component(ScfEfunction* f, ScfEcomponent* c);
+
+int            scf_efunction__add_eline    (ScfEfunction* f, ScfEline* el);
+int            scf_efunction__del_eline    (ScfEfunction* f, ScfEline* el);
+
+ScfEboard*     scf_eboard__alloc();
+int            scf_eboard__add_function(ScfEboard* b, ScfEfunction* f);
+int            scf_eboard__del_function(ScfEboard* b, ScfEfunction* f);
+
+#define EDA_INST_ADD_COMPONENT(_ef, _c, _type) \
+       do { \
+               _c = scf_ecomponent__alloc(_type); \
+               if (!_c) \
+                       return -ENOMEM; \
+               \
+               (_c)->id = (_ef)->n_components; \
+               \
+               int ret = scf_efunction__add_component(_ef, _c); \
+               if (ret < 0) { \
+                       ScfEcomponent_free(_c); \
+                       _c = NULL; \
+                       return ret; \
+               } \
+               \
+               for (size_t i = 0;  i < (_c)->n_pins; i++) \
+                       (_c)->pins[i]->cid = (_c)->id; \
+       } while (0)
+
+#define EDA_PIN_ADD_COMPONENT(_pin, _cid, _pid) \
+       do { \
+               int ret = scf_epin__add_component((_pin), _cid, _pid); \
+               if (ret < 0) \
+                       return ret; \
+       } while (0)
+
+#define EDA_PIN_ADD_PIN(_c0, _pid0, _c1, _pid1) \
+       do { \
+               int ret = scf_epin__add_component((_c0)->pins[_pid0], (_c1)->id, (_pid1)); \
+               if (ret < 0) \
+                       return ret; \
+               \
+               ret = scf_epin__add_component((_c1)->pins[_pid1], (_c0)->id, (_pid0)); \
+               if (ret < 0) \
+                       return ret; \
+       } while (0)
+
+#define EDA_PIN_ADD_PIN_EF(_ef, _p0, _p1) \
+       EDA_PIN_ADD_PIN((_ef)->components[(_p0)->cid], (_p0)->id, (_ef)->components[(_p1)->cid], (_p1)->id)
+
+#endif
diff --git a/scf_eda_pb.h b/scf_eda_pb.h
deleted file mode 100644 (file)
index 109fa64..0000000
+++ /dev/null
@@ -1,166 +0,0 @@
-#ifndef SCF_EDA_PB_H
-#define SCF_EDA_PB_H
-
-#include "scf_eda.pb-c.h"
-
-enum {
-       SCF_EDA_None,
-       SCF_EDA_Battery,
-
-       SCF_EDA_Resistor,
-       SCF_EDA_Capacitor,
-       SCF_EDA_Inductor,
-
-       SCF_EDA_Diode,
-       SCF_EDA_NPN,
-       SCF_EDA_PNP,
-
-       SCF_EDA_Components_NB,
-};
-
-#define SCF_EDA_PIN_NONE   0
-#define SCF_EDA_PIN_IN     1
-#define SCF_EDA_PIN_OUT    2
-#define SCF_EDA_PIN_POS    4
-#define SCF_EDA_PIN_NEG    8
-#define SCF_EDA_PIN_CF     16
-#define SCF_EDA_PIN_BORDER 32
-
-#define SCF_EDA_V_INIT   -10001001.0
-#define SCF_EDA_V_MIN    -10000000.0
-#define SCF_EDA_V_MAX     10000000.0
-
-#define SCF_EDA_V_Diode_ON  0.58
-#define SCF_EDA_V_Diode_OFF 0.55
-
-#define SCF_EDA_V_NPN_ON    0.70
-#define SCF_EDA_V_NPN_OFF   0.61
-
-enum {
-       SCF_EDA_Battery_NEG,
-       SCF_EDA_Battery_POS,
-       SCF_EDA_Battery_NB,
-};
-
-enum {
-       SCF_EDA_Diode_NEG,
-       SCF_EDA_Diode_POS,
-       SCF_EDA_Diode_NB,
-};
-
-enum {
-       SCF_EDA_Status_ON,
-       SCF_EDA_Status_OFF,
-       SCF_EDA_Path_OFF,
-       SCF_EDA_Path_TO,
-};
-
-enum {
-       SCF_EDA_NPN_B,
-       SCF_EDA_NPN_E,
-       SCF_EDA_NPN_C,
-       SCF_EDA_NPN_NB,
-};
-
-enum {
-       SCF_EDA_PNP_B,
-       SCF_EDA_PNP_E,
-       SCF_EDA_PNP_C,
-       SCF_EDA_PNP_NB,
-};
-
-typedef struct {
-       uint64_t  type;
-       uint64_t  model;
-       uint64_t  pid;
-
-       double    v;
-       double    a;
-       double    r;
-       double    jr;
-       double    uf;
-       double    uh;
-       double    hfe;
-} scf_edata_t;
-
-
-ScfEconn*      scf_econn__alloc();
-int            scf_econn__add_cid(ScfEconn* ec, uint64_t  cid);
-int            scf_econn__del_cid(ScfEconn* ec, uint64_t  cid);
-void           scf_econn__free(ScfEconn* ec);
-
-ScfEline*      scf_eline__alloc();
-int            scf_eline__add_line(ScfEline* el, ScfLine*  l);
-int            scf_eline__del_line(ScfEline* el, ScfLine*  l);
-
-int            scf_eline__add_pin (ScfEline* el, uint64_t  cid, uint64_t pid);
-int            scf_eline__del_pin (ScfEline* el, uint64_t  cid, uint64_t pid);
-
-int            scf_eline__add_conn(ScfEline* el, ScfEconn* ec);
-int            scf_eline__del_conn(ScfEline* el, ScfEconn* ec);
-void           scf_eline__free    (ScfEline* el);
-
-ScfEpin*       scf_epin__alloc();
-int            scf_epin__add_component(ScfEpin* pin, uint64_t cid, uint64_t pid);
-int            scf_epin__del_component(ScfEpin* pin, uint64_t cid, uint64_t pid);
-void           scf_epin__free         (ScfEpin* pin);
-
-ScfEcomponent* scf_ecomponent__alloc  (uint64_t type);
-int            scf_ecomponent__add_pin(ScfEcomponent* c, ScfEpin* pin);
-int            scf_ecomponent__del_pin(ScfEcomponent* c, ScfEpin* pin);
-void           scf_ecomponent__free   (ScfEcomponent* c);
-
-ScfEfunction*  scf_efunction__alloc        (const   char* name);
-int            scf_efunction__add_component(ScfEfunction* f, ScfEcomponent* c);
-int            scf_efunction__del_component(ScfEfunction* f, ScfEcomponent* c);
-
-int            scf_efunction__add_eline    (ScfEfunction* f, ScfEline* el);
-int            scf_efunction__del_eline    (ScfEfunction* f, ScfEline* el);
-void           scf_efunction__free         (ScfEfunction* f);
-
-ScfEboard*     scf_eboard__alloc();
-int            scf_eboard__add_function(ScfEboard* b, ScfEfunction* f);
-int            scf_eboard__del_function(ScfEboard* b, ScfEfunction* f);
-void           scf_eboard__free        (ScfEboard* b);
-
-#define EDA_INST_ADD_COMPONENT(_ef, _c, _type) \
-       do { \
-               _c = scf_ecomponent__alloc(_type); \
-               if (!_c) \
-                       return -ENOMEM; \
-               \
-               (_c)->id = (_ef)->n_components; \
-               \
-               int ret = scf_efunction__add_component(_ef, _c); \
-               if (ret < 0) { \
-                       scf_ecomponent__free(_c); \
-                       _c = NULL; \
-                       return ret; \
-               } \
-               \
-               for (size_t i = 0;  i < (_c)->n_pins; i++) \
-                       (_c)->pins[i]->cid = (_c)->id; \
-       } while (0)
-
-#define EDA_PIN_ADD_COMPONENT(_pin, _cid, _pid) \
-       do { \
-               int ret = scf_epin__add_component((_pin), _cid, _pid); \
-               if (ret < 0) \
-                       return ret; \
-       } while (0)
-
-#define EDA_PIN_ADD_PIN(_c0, _pid0, _c1, _pid1) \
-       do { \
-               int ret = scf_epin__add_component((_c0)->pins[_pid0], (_c1)->id, (_pid1)); \
-               if (ret < 0) \
-                       return ret; \
-               \
-               ret = scf_epin__add_component((_c1)->pins[_pid1], (_c0)->id, (_pid0)); \
-               if (ret < 0) \
-                       return ret; \
-       } while (0)
-
-#define EDA_PIN_ADD_PIN_EF(_ef, _p0, _p1) \
-       EDA_PIN_ADD_PIN((_ef)->components[(_p0)->cid], (_p0)->id, (_ef)->components[(_p1)->cid], (_p1)->id)
-
-#endif
index 5b4369cdaf86042ac2720a9d96bd232357195fb2..e29da74f8493413623fc8b52e22b36c706b3239f 100644 (file)
@@ -2,7 +2,7 @@
 #define SES_CORE_H
 
 #include"scf_vector.h"
-#include"scf_eda_pb.h"
+#include"scf_eda_pack.h"
 
 typedef struct ses_step_s    ses_step_t;
 typedef struct ses_path_s    ses_path_t;
index 21a22442af0078bb7818cde0ff0d55276ea876fa..e3437d17cffe8f79e240c8120c9270bfed15c561 100644 (file)
@@ -223,7 +223,7 @@ int ses_pins_same_line(ScfEfunction* f)
                        el->id = f->n_elines;
 
                        if (scf_efunction__add_eline(f, el) < 0) {
-                               scf_eline__free(el);
+                               ScfEline_free(el);
                                return -ENOMEM;
                        }
 
@@ -275,7 +275,7 @@ next:
 
                if (0 == el->n_pins) {
                        scf_efunction__del_eline(f, el);
-                       scf_eline__free(el);
+                       ScfEline_free(el);
                        continue;
                }
 
@@ -365,7 +365,7 @@ int ses_lines_same_components(ScfEfunction* f)
                                        k1 += 2;
 
                                        if (scf_econn__add_cid(ec, c0) < 0) {
-                                               scf_econn__free(ec);
+                                               ScfEconn_free(ec);
                                                return -ENOMEM;
                                        }
                                }
@@ -377,7 +377,7 @@ int ses_lines_same_components(ScfEfunction* f)
                        ec->lid = el1->id;
 
                        if (scf_eline__add_conn(el0, ec) < 0) {
-                               scf_econn__free(ec);
+                               ScfEconn_free(ec);
                                return -ENOMEM;
                        }
 
@@ -388,7 +388,7 @@ int ses_lines_same_components(ScfEfunction* f)
        }
 
        if (ec) {
-               scf_econn__free(ec);
+               ScfEconn_free(ec);
                ec = NULL;
        }