⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 netutility.h

📁 调用tuxedo服务的dll库的源代码。其中用到了c++ qt 库4.3。
💻 H
字号:
#if !defined _UTILITY_H
#define _UTILITY_H
#pragma once

 
 class Utility
{

 public: 
   inline static short charsToShort( char achar[])//字节数组到字
   {
	    int j;
		int length=sizeof(achar);
        if(length <= 2)
            j = length;
        else
            j = 2;
        int i = 0;
        for(int k = 0; k < j; k++)
            i = (i << 8) + (achar[k] & 0xff);

        return i;
   }
   inline  static int charsToInt( char achar[])//字节数组到整数
    {
        int j;
		int length=sizeof(achar);
        if(length <= 4)
            j = length;
        else
            j = 4;
        int i = 0;
        for(int k = 0; k < j; k++)
            i = (i << 8) + (achar[k] & 0xff);

        return i;
    }

    inline   static  char* decodeMsgID( char achar[])//消息ID解码
    {
         char* achar1=new  char(20);
        int i;
	     int length=sizeof(achar);
        if(length < 10)
            i = length;
        else
            i = 10;
        for(int j = 0; j < i; j++)
        {
            achar1[j * 2] = (char)((achar[j] >> 4 & 0xf) + 48);
            achar1[j * 2 + 1] = (char)((achar[j] & 0xf) + 48);
        }

        return achar1;
    }

    inline   static  char* intTochars(int i, char* achar0)//整数到字节转换
    {
       
		 Zerochars(achar0,4);
        achar0[3] = ( char)i;
        i >>= 8;
        achar0[2] = i;
        i >>= 8;
        achar0[1] = i;
        i >>= 8;
        achar0[0] = i;
        return achar0;
    }
	inline static  char* shortTochars(short i,  char* achar0 )//字到字节转换
	{
		
		Zerochars(achar0,2);
        achar0[1] = ( char)i;
        i >>= 8;
        achar0[0] = i;
        
        return achar0;
	}
	inline static void exchange(char* chars,int len)
	{
		for(int i=0;i<len/2;i++)
		{   char temp=chars[i];
			chars[i]=chars[len-i-1];
			chars[len-i-1]=temp;
		}
	}
	inline static void Zerochars(char* chars,int len)
	{
		for(int i=0;i<len;i++)
		{
			chars[i]=0;
		}
	}
inline static  int  HToNL(const int value)//等同 ms htonl
{ char theb[4];
  Utility::Zerochars(theb,4);
  int nl=0;
  memcpy(theb,&value,4);
  Utility::exchange(theb,4);
  memcpy(&nl,theb,4);
  
  return nl;


}
inline static int   NToHL(int nl)//等同 ms ntohl
{
  char theb[4];
  Utility::Zerochars(theb,4);
  int hl=0;
  memcpy(theb,&nl,4);
  Utility::exchange(theb,4);
  memcpy(&hl,theb,4);
  
  return hl;

}
 
 };
 #endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -