//Write all headers, empty line, and body //TODO: support for live forwarding of chunked encoding. static inline int write_common(HTTP_Message* message, int connection) { //Write headers if(write_headers(message->headers, connection)) return 1; //Write blank line if(write_ref(es_temp("\r\n"), connection)) return 1; //Write body if(write_ref(es_ref(&message->body), connection)) return 1; return 0; }
static inline int write_request_line(HTTP_ReqLine* line, int connection) { if(write_ref(method_name(line->method), connection)) return 1; if(write_ref(es_temp(" "), connection)) return 1; if(line->domain.size) { if(write_ref(es_temp("http://"), connection)) return 1; if(write_ref(es_ref(&line->domain), connection)) return 1; } if(write_str(es_printf("/%.*s HTTP/1.%c\r\n", ES_STRINGPRINT(&line->path), line->http_version), connection)) return 1; return 0; }
void serialize_rec( sbuffer *b, value o ) { b->nrec++; if( b->nrec > 350 ) failure("Serialization stack overflow"); switch( val_type(o) ) { case VAL_NULL: write_char(b,'N'); break; case VAL_BOOL: if( val_bool(o) ) write_char(b,'T'); else write_char(b,'F'); break; case VAL_INT: write_char(b,'i'); write_int(b,val_int(o)); break; case VAL_FLOAT: write_char(b,'f'); write_str(b,sizeof(tfloat),&val_float(o)); break; case VAL_STRING: if( !write_ref(b,o,NULL) ) { write_char(b,'s'); write_int(b,val_strlen(o)); write_str(b,val_strlen(o),val_string(o)); } break; case VAL_OBJECT: { value s; if( !write_ref(b,o,&s) ) { if( s != NULL ) { // reference was not written if( !val_is_function(s) || (val_fun_nargs(s) != 0 && val_fun_nargs(s) != VAR_ARGS) ) failure("Invalid __serialize method"); write_char(b,'x'); serialize_rec(b,((neko_module*)((vfunction*)s)->module)->name); serialize_rec(b,val_ocall0(o,id_serialize)); // put reference back write_ref(b,o,NULL); break; } write_char(b,'o'); val_iter_fields(o,serialize_fields_rec,b); write_int(b,0); o = (value)((vobject*)o)->proto; if( o == NULL ) write_char(b,'z'); else { write_char(b,'p'); serialize_rec(b,o); } } } break; case VAL_ARRAY: if( !write_ref(b,o,NULL) ) { int i; int n = val_array_size(o); write_char(b,'a'); write_int(b,n); for(i=0;i<n;i++) serialize_rec(b,val_array_ptr(o)[i]); } break; case VAL_FUNCTION: if( !write_ref(b,o,NULL) ) { neko_module *m; if( val_tag(o) == VAL_PRIMITIVE ) { // assume that alloc_array(0) return a constant array ptr // we don't want to access custom memory (maybe not a ptr) if( ((vfunction*)o)->env != alloc_array(0) ) failure("Cannot Serialize Primitive with environment"); write_char(b,'p'); write_int(b,((vfunction*)o)->nargs); serialize_rec(b,((vfunction*)o)->module); break; } if( val_tag(o) == VAL_JITFUN ) failure("Cannot Serialize JIT method"); write_char(b,'L'); m = (neko_module*)((vfunction*)o)->module; serialize_rec(b,m->name); write_int(b,(int)((int_val*)((vfunction*)o)->addr - m->code)); write_int(b,((vfunction*)o)->nargs); serialize_rec(b,((vfunction*)o)->env); } break; case VAL_INT32: write_char(b,'I'); write_int(b,val_int32(o)); break; case VAL_ABSTRACT: if( val_is_kind(o,k_hash) ) { int i; vhash *h = val_hdata(o); write_char(b,'h'); write_int(b,h->ncells); write_int(b,h->nitems); for(i=0;i<h->ncells;i++) { hcell *c = h->cells[i]; while( c != NULL ) { write_int(b,c->hkey); serialize_rec(b,c->key); serialize_rec(b,c->val); c = c->next; } } break; } default: failure("Cannot Serialize Abstract"); break; } b->nrec--; }
void UmlFragment::write(FileOut & out, UmlItem * diagram, Q3PtrList<UmlSequenceMessage> & msgs) { WrapperStr oper = name(); if (oper == "ref") write_ref(out, diagram, msgs); else { if ((oper != "alt") && (oper != "opt") && (oper != "loop") && (oper != "break") && (oper != "par") && (oper != "seq") && (oper != "strict") && (oper != "neg") && (oper != "critical") && (oper != "assert") && (oper != "ignore") && (oper != "consider")) oper = ""; else { static int rank = 0; out.indent(); out << "<fragment xmi:type=\"uml:CombinedFragment\""; out.id_prefix(diagram, "COMBINEDFRAGMENT", ++rank); if (! covered.isEmpty()) { out << " covered=\""; UmlClassInstanceReference * lifeline = covered.first(); for (;;) { out.ref_only(diagram, lifeline->lifeline()); lifeline = covered.next(); if (lifeline == 0) break; out << " "; } out << '"'; } out << " interactionOperator=\"" << oper.operator QString() << "\">\n"; out.indent(+1); } const Q3PtrVector<UmlFragmentCompartment> & subs = compartments(); unsigned n = subs.size(); for (unsigned i = 0; i != n; i += 1) subs.at(i)->write(out, diagram, msgs, oper); if (!oper.isEmpty()) { out.indent(-1); out.indent(); out << "</fragment>\n"; } } }
static inline int write_str(String str, int connection) { int result = write_ref(es_ref(&str), connection); es_free(&str); return result; }
void write_object(FILE *file, V obj, HashMap *hm) { int t = getType(obj); union double_or_uint64_t num; ITreeNode *id = NULL; NewString *s = NULL; Stack *st; HashMap *hmv; int8_t n8; uint8_t l8; int32_t n32; uint32_t l32; int64_t n64; uint64_t l64; int i; Bucket *b; char type = t; switch (t) { case T_NUM: if (canBeSmallInt(obj)) type |= TYPE_SHORT; break; case T_IDENT: id = toIdent(obj); if (id->length < 256) type |= TYPE_SHORT; break; case T_STR: s = toNewString(obj); if (s->size < 256) type |= TYPE_SHORT; break; case T_FRAC: if (toNumerator(obj) < 128 && toNumerator(obj) >= -128 && toDenominator(obj) < 256) type |= TYPE_SHORT; break; } fwrite(&type, 1, 1, file); switch (t) { case T_IDENT: if (type & TYPE_SHORT) { l8 = id->length; fwrite(&l8, 1, 1, file); } else { l32 = id->length; l32 = htonl(l32); fwrite(&l32, 4, 1, file); } fwrite(&id->data, id->length, 1, file); break; case T_STR: if (type & TYPE_SHORT) { l8 = s->size; fwrite(&l8, 1, 1, file); } else { l32 = s->size; l32 = htonl(l32); fwrite(&l32, 4, 1, file); } fwrite(s->text, s->size, 1, file); break; case T_NUM: if (type & TYPE_SHORT) { n32 = toInt(obj); n32 = htonl(n32); fwrite(((char*)&n32) + 1, 3, 1, file); } else { num.d = toNumber(obj); num.i = htonll(num.i); fwrite(&num, 8, 1, file); } break; case T_FRAC: if (type & TYPE_SHORT) { n8 = toNumerator(obj); fwrite(&n8, 1, 1, file); l8 = toDenominator(obj); fwrite(&l8, 1, 1, file); } else { n64 = toNumerator(obj); n64 = htonl(n64); fwrite(&n64, 8, 1, file); l64 = toDenominator(obj); l64 = htonl(l64); fwrite(&l64, 8, 1, file); } break; case T_PAIR: write_ref(file, toFirst(obj), hm); write_ref(file, toSecond(obj), hm); break; case T_LIST: st = toStack(obj); l32 = st->used; l32 = htonl(l32); fwrite(&l32, 4, 1, file); for (i = 0; i < st->used; i++) { write_ref(file, st->nodes[i], hm); } break; case T_DICT: hmv = toHashMap(obj); l32 = hmv->used; l32 = htonl(l32); fwrite(&l32, 4, 1, file); if (hmv->map != NULL) { for (i = 0; i < hmv->size; i++) { b = hmv->map[i]; while(b != NULL) { write_ref(file, b->key, hm); write_ref(file, b->value, hm); b = b->next; } } } break; } }