bool PokerMsgHandler::DecodeData(const void* pData, int nLength) { const char* pBytes = (const char*)pData; for (int i = 0; i < nLength; ++i) { m_vMessageData.push_back(pBytes[i]); } if (m_vMessageData.size() <= 0) return false; // decode the message StreamReader reader(&m_vMessageData[0], m_vMessageData.size()); short nSize = 0; if (!reader.Read(&nSize, sizeof(nSize))) return false; if (nSize < (int)m_vMessageData.size()) return false; short nType = 0; if (!reader.Read(&nType, sizeof(nType))) return false; // dispatch the message (nMsgId, &m_vMessageData[0], nSize) CallHandler(nType, &m_vMessageData[0], nSize); LOGD("receive message: type %d, size:%d", nType, nSize); m_vMessageData.erase(m_vMessageData.begin(), m_vMessageData.begin()+nSize); return true; }
void SerialParser(void) { while (Serial.available()) { SerIn = '@'; SerIn = Serial.read(); // debugging CODE // Serial.print(' '); // Serial.print(SerIn); if ((SerIn >= 65) && (SerIn <= 90)) { // if ASCII 'A' - 'Z' VarHandlerChar = SerIn; for (PosN = 0; PosN < 9; PosN++) { // clean up VarN[PosN] = 0; // reset Var array } PosN = -1; } if (SerIn == 45) { VarSign = -1; } if ((SerIn >= 48) && (SerIn <= 57)) { // if ASCII numeric '0' - '9' VarN[PosN] = VarN[PosN] * 10 + (SerIn - 48); } if (SerIn == ' ') { // if ASCII " " detected if (PosN > -1) { VarN[PosN] = VarSign * VarN[PosN]; // assign sign VarSign = 1; } PosN++; } if (SerIn == 33 || SerIn == 10 || SerIn == 13) { // '!' or CR or LF ends all this spooky things ... VarN[PosN] = VarSign * VarN[PosN]; // assign sign VarSign = 1; CallHandler(); // Call funktion by first Char } // IfEND CR spooky things } }
/* ParsePrint - handle the 'PRINT' statement */ static void ParsePrint(ParseContext *c) { int needNewline = VMTRUE; ParseTreeNode *expr; Token tkn; while ((tkn = GetToken(c)) != T_EOL) { switch (tkn) { case ',': needNewline = VMFALSE; CallHandler(c, "printTab", NULL); break; case ';': needNewline = VMFALSE; break; default: needNewline = VMTRUE; SaveToken(c, tkn); expr = ParseExpr(c); switch (expr->nodeType) { case NodeTypeStringLit: CallHandler(c, "printStr", expr); break; default: CallHandler(c, "printInt", expr); break; } break; } } if (needNewline) CallHandler(c, "printNL", NULL); else CallHandler(c, "printFlush", NULL); }
static int BuildSymTab (TYPE_DESC *desc, DDD_OBJ obj, char *copy, SYMTAB_ENTRY *theSymTab) { ELEM_DESC *theElem; int e, actSym; /*STAT_RESET4;*/ /* reset local portion of SymTab */ actSym = 0; /* prepare map of structure elements */ theElem = desc->element; /* loop over all pointers inside of object obj */ for(e=0; e<desc->nElements; e++, theElem++) { if (theElem->type==EL_OBJPTR) { TYPE_DESC *refdesc; int l; int rt_on_the_fly = (EDESC_REFTYPE(theElem)==DDD_TYPE_BY_HANDLER); /* determine reftype of this elem */ if (! rt_on_the_fly) { /* we know the reftype of this element in advance */ refdesc = &theTypeDefs[EDESC_REFTYPE(theElem)]; } /* else: determine reftype on the fly by calling handler */ /* loop over single pointer array */ #if defined(C_FRONTEND) || defined(CPP_FRONTEND) for(l=0; l<theElem->size; l+=sizeof(void *)) { /* get address of outside reference */ DDD_OBJ *ref = (DDD_OBJ *)(copy+theElem->offset+l); #else for(l=0; l<theElem->size; l+=sizeof(DDD_OBJ)) { /* F77TODO: DDD_OBJ* must be replaced by local objindex */ /* get the index of the referenced object */ DDD_OBJ *ref = (DDD_OBJ *)(copy+theElem->msgoffset); #endif /* create symbol table entry */ if (*ref!=NULL) { DDD_HDR refhdr; if (rt_on_the_fly) { DDD_TYPE rt; /* determine reftype on the fly by calling handler */ assert(obj!=NULL); /* we need a real object here */ rt = theElem->reftypeHandler(obj, *ref); if (rt>=MAX_TYPEDESC) { DDD_PrintError('E', 6520, "invalid referenced DDD_TYPE " "returned by handler"); HARD_EXIT; } refdesc = &theTypeDefs[rt]; } /* get header of referenced object */ refhdr = OBJ2HDR(*ref,refdesc); /* remember the GID of the referenced object */ theSymTab[actSym].gid = OBJ_GID(refhdr); /* remember the address of the reference (in obj-copy) */ theSymTab[actSym].adr.ref = ref; actSym++; } } } } /*STAT_INCTIMER4(33);*/ /* return SymTab increment */ return(actSym); } /****************************************************************************/ /* */ /* Function: GetDepData */ /* */ /* Purpose: fill object-dependent data into message. an appl. routine */ /* will be called to fill in the data actually. pointers are */ /* localized and the message SymTab is actualized. */ /* */ /* Input: data: portion of message buffer reserved for dependent data */ /* desc: descriptor of object */ /* obj: current ddd-object */ /* theSymTab: actual portion of message SymTab */ /* xi: single xferinfo for current ddd-object */ /* */ /* Output: number of new entries into SymTab */ /* */ /****************************************************************************/ static int GetDepData (char *data, TYPE_DESC *desc, DDD_OBJ obj, SYMTAB_ENTRY *theSymTab, XICopyObj *xi) { XFERADDDATA *xa; TYPE_DESC *descDep; char *chunk, *adr, **table1, *next_chunk; int chunks, i, actSym, *table2; if (xi->addLen==0) return(0); chunks = 0; actSym = 0; /* first entry will be number of dependency chunks */ chunk = data + CEIL(sizeof(int)); /* loop through whole dependency data descriptor */ for(xa=xi->add; xa!=NULL; xa=xa->next) { /* first entries of chunk are addCnt and addTyp */ ((int *)chunk)[0] = xa->addCnt; ((DDD_TYPE *)chunk)[1] = xa->addTyp; if (xa->sizes==NULL) { chunk += CEIL(sizeof(int)+sizeof(DDD_TYPE)); /* then all records should be gathered via handler */ if (desc->handlerXFERGATHER) { #if defined(C_FRONTEND) || defined(F_FRONTEND) desc->handlerXFERGATHER(_FADR obj, _FADR xa->addCnt, _FADR xa->addTyp, (void *)chunk); #endif #ifdef CPP_FRONTEND CallHandler(desc,XFERGATHER) (HParam(obj) xa->addCnt, xa->addTyp, (void *)chunk); #endif } if (xa->addTyp<DDD_USER_DATA || xa->addTyp>DDD_USER_DATA_MAX) { /* insert pointers into symtab */ descDep = &theTypeDefs[xa->addTyp]; for(i=0; i<xa->addCnt; i++) { actSym += BuildSymTab(descDep, NULL, chunk, &(theSymTab[actSym])); chunk += CEIL(descDep->size); } } else { /* no regular type -> send byte stream with length addCnt */ chunk += CEIL(xa->addCnt); } } else { /* var-sized AddData items */ ((int *)chunk)[0] *= -1; chunk += CEIL(sizeof(int)+sizeof(DDD_TYPE)); /* create pointer array inside message */ table1 = (char **)chunk; chunk += CEIL(sizeof(int)*xa->addCnt); for(i=0, adr=chunk; i<xa->addCnt; i++) { table1[i] = adr; adr += CEIL(xa->sizes[i]); } next_chunk = adr; /* then all records should be gathered via handler */ if (desc->handlerXFERGATHERX) { #if defined(C_FRONTEND) || defined(F_FRONTEND) desc->handlerXFERGATHERX(_FADR obj, _FADR xa->addCnt, _FADR xa->addTyp, table1); #endif #ifdef CPP_FRONTEND CallHandler(desc,XFERGATHERX) (HParam(obj) xa->addCnt, xa->addTyp, table1); #endif } /* convert pointer table into offset table */ table2 = (int *)table1; descDep = &theTypeDefs[xa->addTyp]; adr = chunk; for(i=0; i<xa->addCnt; i++) { /* insert pointers into symtab */ if (xa->addTyp<DDD_USER_DATA || xa->addTyp>DDD_USER_DATA_MAX) { actSym += BuildSymTab(descDep, NULL, table1[i], &(theSymTab[actSym])); } table2[i] = (int)(table1[i]-adr); } chunk = next_chunk; } /* count chunks */ chunks++; } /* remember number of chunks at the beginning of the deplist */ ((int *)data)[0] = chunks; return(actSym); }