Difference between revisions of "Serialise.c"

From Organic Design wiki
 
(use *trie() to point all a nodes names to its index)
Line 1: Line 1:
 
// Process passed "alias1|alias2|alias3..." string (GUID's are just alias's)
 
// Process passed "alias1|alias2|alias3..." string (GUID's are just alias's)
 
// NOTE: GUID-alias is traversed as ASCII not binary - these are external guids
 
// NOTE: GUID-alias is traversed as ASCII not binary - these are external guids
//      - this is using list-space as a dictionary
 
//      - the nodal structure of a number can still be binary
 
// - used by [de]serialise()
 
 
// - returns integer index of subject node
 
// - returns integer index of subject node
 +
// - later: if its a number, convert to a binary-coded-string of \x00's and \x01's
 
int processNodeLink(char *link) {
 
int processNodeLink(char *link) {
int subject = atoi(link); // not like this anymore, passed link is external
+
item subject;
// - split by pipe and for each,
+
char* name;
//  - if its a number, convert to a binary-coded-string of \x00's and \x01's
+
while (name = strchr(link,'|') {
//  - traverse from root through name using chr-as-node-index,
+
*name = 0;
//  - the first iteration creates the subject,
+
subject ? *trie(link) = subject : subject = *trie(link);
//  - subsequent iterations must link their last jump to the existing subject
+
link = name+1;
return subject;
+
}
 +
return subject ? *trie(link) = subject : subject = *trie(link);
 
}
 
}
  

Revision as of 03:30, 9 July 2006

// Process passed "alias1|alias2|alias3..." string (GUID's are just alias's) // NOTE: GUID-alias is traversed as ASCII not binary - these are external guids // - returns integer index of subject node // - later: if its a number, convert to a binary-coded-string of \x00's and \x01's int processNodeLink(char *link) { item subject; char* name; while (name = strchr(link,'|') { *name = 0; subject ? *trie(link) = subject : subject = *trie(link); link = name+1; } return subject ? *trie(link) = subject : subject = *trie(link); }

// Convert a node to text for storage or transport char* serialise(int subject) { char *text; return text; }

// Convert textual represntation of one or more nodes and associations to nodal change int deserialise(char *text) { printf("\nPARSING THE FOLLOWING TEXT:\n--------------------------------------------\n%s\n--------------------------------------------\n\n", text); printf("INFORMATION EXTRACTED:\n--------------------------------------------\n"); int node, subject = 0, key, i, j = 0, linkStart, c; char links[100]; char *link1 = (char*)&links; char *link2 = link1+50; for (i = 0; i < strlen(text); i++) { char *s = text+i; if ((c = (int)s[0]) < 32) j = 1; else switch (j) { case 0: // waiting for next line break; case 1: // starting new line // - if not starting with *[[ then wait for next line if (strncmp(s, "*[[", 3) == 0) { j = 2; linkStart = i; } else j = 0; break; case 2: // processing first link if (strncmp(s, "]]", 2) == 0) { if (strncmp(s, "]]:[[", 5) == 0) { // link1 as an association-key // key = strtoint(...) j = 3; // process link2 next } else { // link1 specifies a change of nodal subject link1 = strncpy(link1, text+linkStart+3, i-linkStart-3); link1[i-linkStart-3] = '\0'; subject = processNodeLink(link1); printf("%d:\n", subject); j = 0; // wait for new line } } break; case 3: // processing second link if (strncmp(s, "]]", 2) == 0) { // process link2 link1 = strncpy(link1, text+linkStart+3, i-linkStart-3); link2 = strchr(link1, '[')+2; link1[i-linkStart-3] = '\0'; link1[i-linkStart-strlen(link2)-8] = '\0'; int key = processNodeLink(link1); int val = processNodeLink(link2); // store in nodal-space // - we use list functions because nodal functions cause change listSetValue(listTraverse(subject,key),val); printf("  %d => %d\n", key, val); j = 0; } break; } //printf("chr:%c,%d\n",s[0],j); } printf("--------------------------------------------\n"); return node; }