Exemple #1
0
 void endOfAttributes (bool selfClosing) {
     if (m_dumpTable) {
         encodeChar (0);
         if (selfClosing) {
             encodeChar (0); // double 0 because close will not be called
         }
     }
 }
Exemple #2
0
 void initDone () {
     m_dumpTable = true;
     encodeChar ('B');
     encodeChar ('M');
     encodeChar ('L');
     encodeChar ('1');
     dumpTable ();
 }
Exemple #3
0
 void encodeSize (int size) {
     if (size > 255) {
         int n = size / 255;
         encodeChar (255);
         encodeChar (n);
         size -= 255*n;
     }
     encodeChar (size);
 }
Exemple #4
0
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
std::string generateEventID(int year, uint64_t x, const std::string &prefix,
                            const string &pattern, std::string &textBlock, uint64_t *width) {
	string evtID;
	textBlock = "";

	for ( size_t i = 0; i < pattern.size(); ++i ) {
		if ( pattern[i] != '%' )
			evtID += pattern[i];
		else {
			++i;
			int len = 0;
			while ( i < pattern.size() ) {
				if ( pattern[i] >= '0' && pattern[i] <= '9' ) {
					len *= 10;
					len += int(pattern[i] - '0');
					++i;
					continue;
				}
				else if ( pattern[i] == '%' ) {
					evtID += pattern[i];
				}
				else if ( pattern[i] == 'c' ) {
					textBlock = encodeChar(x, len, width);
					evtID += textBlock;
				}
				else if ( pattern[i] == 'C' ) {
					textBlock = makeUpper(encodeChar(x, len, width));
					evtID += textBlock;
				}
				else if ( pattern[i] == 'd' ) {
					textBlock = encodeInt(x, len, width);
					evtID += textBlock;
				}
				else if ( pattern[i] == 'x' ) {
					textBlock = encodeHex(x, len, width);
					evtID += textBlock;
				}
				else if ( pattern[i] == 'X' ) {
					textBlock = makeUpper(encodeHex(x, len, width));
					evtID += textBlock;
				}
				else if ( pattern[i] == 'Y' )
					evtID += toString(year);
				else if ( pattern[i] == 'p' )
					evtID += prefix;
				else
					return "";

				break;
			}
		}
	}

	return evtID;
}
Exemple #5
0
void CBC_EdifactEncoder::Encode(CBC_EncoderContext& context, int32_t& e) {
  CFX_WideString buffer;
  while (context.hasMoreCharacters()) {
    FX_WCHAR c = context.getCurrentChar();
    encodeChar(c, buffer, e);
    if (e != BCExceptionNO) {
      return;
    }
    context.m_pos++;
    int32_t count = buffer.GetLength();
    if (count >= 4) {
      context.writeCodewords(encodeToCodewords(buffer, 0, e));
      if (e != BCExceptionNO) {
        return;
      }
      buffer.Delete(0, 4);
      int32_t newMode = CBC_HighLevelEncoder::lookAheadTest(
          context.m_msg, context.m_pos, getEncodingMode());
      if (newMode != getEncodingMode()) {
        context.signalEncoderChange(ASCII_ENCODATION);
        break;
      }
    }
  }
  buffer += (FX_WCHAR)31;
  handleEOD(context, buffer, e);
}
void MainWidget::bytesWritten(){
	if (timer->isActive()) timer->stop();
	pProgressDialog->hide();
	delete pProgressDialog;
	printf("bytesWritten()\n");
	int i = socket.bytesAvailable();
	char *c = (char*)malloc(i*4);
	printf("bytesAvailable=%i\n",socket.bytesAvailable());
	socket.readBlock( c, i );
	QString answer = QString(QString::fromUtf8(c));
	//printf("Answer = \n[Start]\n%s\n[End]\n",c);
#if ALT_TRANSLATE
	QString s1 = answer;
#else
	int i1 = answer.find("[[[\"",0,true);
	int i2 = answer.find("\",\"",0,true);

	QString s1 = answer.mid(i1+4,i2-(i1+4));
#endif

	s1 = encodeChar(s1); // TODO: and this
	
	MultiLine->setText(s1);
	answer = QString();
	s1 = QString();
	free(c);
	socket.close();
}
Exemple #7
0
 void open (char * t, bool selfClosing) {
     int id = getTagId (t); // create the entry if necessary
     if (m_dumpTable) {
         encodeChar (selfClosing ? 2 : 1);
         encodeSize (id);
     }
 }
Exemple #8
0
 void encodeString (char * s) {
     int l = strlen (s) + 1;
     if (l > 1) {
         ensure (l);
         memcpy (m_buff+m_buffPos, s, l);
         m_buffPos += l;
     } else {
         encodeChar (0);
     }
 }
void Thermal::encode(buffer* b)
{
	ENCODE_PREAMBLE
	SpinOperation::encode(b);
	char version = 0;
	encodeChar(version, b);
	
	encodeDouble(temperature, b);
	
	scale->encode(b);
}
int32_t CBC_C40Encoder::backtrackOneCharacter(CBC_EncoderContext& context,
                                              CFX_WideString& buffer,
                                              CFX_WideString& removed,
                                              int32_t lastCharSize,
                                              int32_t& e) {
  int32_t count = buffer.GetLength();
  buffer.Delete(count - lastCharSize, count);
  context.m_pos--;
  FX_WCHAR c = context.getCurrentChar();
  lastCharSize = encodeChar(c, removed, e);
  BC_EXCEPTION_CHECK_ReturnValue(e, -1);
  context.resetSymbolInfo();
  return lastCharSize;
}
void CBC_C40Encoder::Encode(CBC_EncoderContext& context, int32_t& e) {
  CFX_WideString buffer;
  while (context.hasMoreCharacters()) {
    FX_WCHAR c = context.getCurrentChar();
    context.m_pos++;
    int32_t lastCharSize = encodeChar(c, buffer, e);
    if (e != BCExceptionNO) {
      return;
    }
    int32_t unwritten = (buffer.GetLength() / 3) * 2;
    int32_t curCodewordCount = context.getCodewordCount() + unwritten;
    context.updateSymbolInfo(curCodewordCount, e);
    if (e != BCExceptionNO) {
      return;
    }
    int32_t available = context.m_symbolInfo->m_dataCapacity - curCodewordCount;
    if (!context.hasMoreCharacters()) {
      CFX_WideString removed;
      if ((buffer.GetLength() % 3) == 2) {
        if (available < 2 || available > 2) {
          lastCharSize =
              backtrackOneCharacter(context, buffer, removed, lastCharSize, e);
          if (e != BCExceptionNO) {
            return;
          }
        }
      }
      while ((buffer.GetLength() % 3) == 1 &&
             ((lastCharSize <= 3 && available != 1) || lastCharSize > 3)) {
        lastCharSize =
            backtrackOneCharacter(context, buffer, removed, lastCharSize, e);
        if (e != BCExceptionNO) {
          return;
        }
      }
      break;
    }
    int32_t count = buffer.GetLength();
    if ((count % 3) == 0) {
      int32_t newMode = CBC_HighLevelEncoder::lookAheadTest(
          context.m_msg, context.m_pos, getEncodingMode());
      if (newMode != getEncodingMode()) {
        context.signalEncoderChange(newMode);
        break;
      }
    }
  }
  handleEOD(context, buffer, e);
}
// codifica un messaggio in binario e lo pone in un array
int* encode(char* message) {
	int length=(int)strlen(message);
	int* encoded = (int*)calloc(8*length,sizeof(int));
	int i,j;
	int pos=0;
	int* single_char=(int*)calloc(8,sizeof(int));
	for (i=0;i<length;i++) {
		single_char=encodeChar(message[i]);
		for(j=0;j<8;j++) 
			encoded[j+pos]=single_char[j];
		pos= pos+8; // per ricordare la posizione corrente nell'array finale  
	}
	return encoded;

}
int32_t CBC_C40Encoder::encodeChar(FX_WCHAR c, CFX_WideString& sb, int32_t& e) {
  if (c == ' ') {
    sb += (FX_WCHAR)'\3';
    return 1;
  } else if ((c >= '0') && (c <= '9')) {
    sb += (FX_WCHAR)(c - 48 + 4);
    return 1;
  } else if ((c >= 'A') && (c <= 'Z')) {
    sb += (FX_WCHAR)(c - 65 + 14);
    return 1;
  } else if ((c >= '\0') && (c <= 0x1f)) {
    sb += (FX_WCHAR)'\0';
    sb += c;
    return 2;
  } else if ((c >= '!') && (c <= '/')) {
    sb += (FX_WCHAR)'\1';
    sb += (FX_WCHAR)(c - 33);
    return 2;
  } else if ((c >= ':') && (c <= '@')) {
    sb += (FX_WCHAR)'\1';
    sb += (FX_WCHAR)(c - 58 + 15);
    return 2;
  } else if ((c >= '[') && (c <= '_')) {
    sb += (FX_WCHAR)'\1';
    sb += (FX_WCHAR)(c - 91 + 22);
    return 2;
  } else if ((c >= 60) && (c <= 0x7f)) {
    sb += (FX_WCHAR)'\2';
    sb += (FX_WCHAR)(c - 96);
    return 2;
  } else if (c >= 80) {
    sb += (FX_WCHAR)'\1';
    sb += (FX_WCHAR)0x001e;
    int32_t len = 2;
    len += encodeChar((c - 128), sb, e);
    BC_EXCEPTION_CHECK_ReturnValue(e, 0);
    return len;
  } else {
    e = BCExceptionIllegalArgument;
    return 0;
  }
}
void CBC_X12Encoder::Encode(CBC_EncoderContext& context, int32_t& e) {
  CFX_WideString buffer;
  while (context.hasMoreCharacters()) {
    FX_WCHAR c = context.getCurrentChar();
    context.m_pos++;
    encodeChar(c, buffer, e);
    if (e != BCExceptionNO) {
      return;
    }
    int32_t count = buffer.GetLength();
    if ((count % 3) == 0) {
      writeNextTriplet(context, buffer);
      int32_t newMode = CBC_HighLevelEncoder::lookAheadTest(
          context.m_msg, context.m_pos, getEncodingMode());
      if (newMode != getEncodingMode()) {
        context.signalEncoderChange(newMode);
        break;
      }
    }
  }
  handleEOD(context, buffer, e);
}
void ShortRange::encode(buffer* b)
{
    ENCODE_PREAMBLE
	SpinOperation::encode(b);
    char version = 0;
    encodeChar(version, b);
	
    encodeInteger(pbc[0], b);
    encodeInteger(pbc[1], b);
    encodeInteger(pbc[2], b);
	
    encodeInteger(num, b);
	
    for(int i=0; i<num; i++)
    {
	encodeInteger(pathways[i].fromsite, b);
	encodeInteger(pathways[i].tosite, b);
	encodeDouble(pathways[i].strength, b);
	for(int j=0; j<9; j++)
	    encodeDouble(pathways[i].matrix[j], b);
	encodeDouble(pathways[i].sig_dot_sig_pow, b);
		    
    }
}
Exemple #16
0
void CBC_PDF417::encodeLowLevel(CFX_WideString fullCodewords,
                                int32_t c,
                                int32_t r,
                                int32_t errorCorrectionLevel,
                                CBC_BarcodeMatrix* logic) {
  int32_t idx = 0;
  for (int32_t y = 0; y < r; y++) {
    int32_t cluster = y % 3;
    logic->startRow();
    encodeChar(START_PATTERN, 17, logic->getCurrentRow());
    int32_t left;
    int32_t right;
    if (cluster == 0) {
      left = (30 * (y / 3)) + ((r - 1) / 3);
      right = (30 * (y / 3)) + (c - 1);
    } else if (cluster == 1) {
      left = (30 * (y / 3)) + (errorCorrectionLevel * 3) + ((r - 1) % 3);
      right = (30 * (y / 3)) + ((r - 1) / 3);
    } else {
      left = (30 * (y / 3)) + (c - 1);
      right = (30 * (y / 3)) + (errorCorrectionLevel * 3) + ((r - 1) % 3);
    }
    int32_t pattern = CODEWORD_TABLE[cluster][left];
    encodeChar(pattern, 17, logic->getCurrentRow());
    for (int32_t x = 0; x < c; x++) {
      pattern = CODEWORD_TABLE[cluster][fullCodewords.GetAt(idx)];
      encodeChar(pattern, 17, logic->getCurrentRow());
      idx++;
    }
    if (m_compact) {
      encodeChar(STOP_PATTERN, 1, logic->getCurrentRow());
    } else {
      pattern = CODEWORD_TABLE[cluster][right];
      encodeChar(pattern, 17, logic->getCurrentRow());
      encodeChar(STOP_PATTERN, 18, logic->getCurrentRow());
    }
  }
}
uint32_t MamaRecordedMessageCodec::encodeField(char*& buffer, MamaMsgField& mmf)
{

	uint32_t r = 0;

	mamaFieldType mft = mmf.getType();
	// These modifications will be applied regardless of data type
	mama_fid_t mff = mmf.getFid();

	memcpy(buffer, &mff, 2);
	buffer += 2;
	memcpy(buffer, &mft, 4);
	buffer += 4;
	r += 6;

	switch(mft)
	{
	case MAMA_FIELD_TYPE_BOOL:
		r += encodeBool(buffer, mmf);
		break;
	case MAMA_FIELD_TYPE_CHAR:
		r += encodeChar(buffer, mmf);
		break;
	case MAMA_FIELD_TYPE_I8:
		r += encodeI8(buffer, mmf);
		break;
	case MAMA_FIELD_TYPE_U8:
		r += encodeU8(buffer, mmf);
		break;
	case MAMA_FIELD_TYPE_I16:
		r += encodeI16(buffer, mmf);
		break;
	case MAMA_FIELD_TYPE_U16:
		r += encodeU16(buffer, mmf);
		break;
	case MAMA_FIELD_TYPE_I32:
		r += encodeI32(buffer, mmf);
		break;
	case MAMA_FIELD_TYPE_U32:
		r += encodeU32(buffer, mmf);
		break;
	case MAMA_FIELD_TYPE_I64:
		r += encodeI64(buffer, mmf);
		break;
	case MAMA_FIELD_TYPE_U64:
		r += encodeU64(buffer, mmf);
		break;
	case MAMA_FIELD_TYPE_F32:
		r += encodeF32(buffer, mmf);
		break;
	case MAMA_FIELD_TYPE_F64:
		r += encodeF64(buffer, mmf);
		break;
	case MAMA_FIELD_TYPE_TIME:
		r += encodeTime(buffer, mmf);
		break;
	case MAMA_FIELD_TYPE_PRICE:
		r += encodePrice(buffer, mmf);
		break;
	case MAMA_FIELD_TYPE_STRING:
		r += encodeString(buffer, mmf);
		break;
	case MAMA_FIELD_TYPE_VECTOR_STRING:
		r += encodeVectorString(buffer, mmf);
		break;
	case MAMA_FIELD_TYPE_VECTOR_I32:
		r += encodeVectorI32(buffer, mmf);
		break;
	case MAMA_FIELD_TYPE_VECTOR_F64:
		r += encodeVectorF64(buffer, mmf);
		break;
	case MAMA_FIELD_TYPE_MSG:
		r += encodeMsgField(buffer, mmf);
		break;
	case MAMA_FIELD_TYPE_VECTOR_MSG:
		r += encodeVectorMsg(buffer, mmf);
		break;
	default:
		break;
	}
	return r;
}
void Magnetostatics2D::encode(buffer* b)
{
	LongRange2D::encode(b);
	char version = 0;
	encodeChar(version, b);
}
Exemple #19
0
 void close (char * t) {
     if (m_dumpTable) {
         encodeChar (0);
     }
 }
Exemple #20
0
 void setLeave (char * l) {
     if (m_dumpTable) {
         encodeChar (3);
         encodeString (l);
     }
 }