示例#1
0
AMEFObject* AMEFDecoder::decodeSinglePacketBInternal(const std::string& buffer, AMEFObject* jDBObject)
{
	char type = (char)buffer[jDBObject->position];
	if(type<AMEFObject::INT_TYPE) // All NULL Types
	{
		jDBObject->setType(type);
		decodeObjectName(buffer, jDBObject);
	}
	else if(type<AMEFObject::BOOLEAN_TYPE) // Integer/Long Types
	{
		jDBObject->setType(type);
		decodeObjectName(buffer, jDBObject);
		if(type==AMEFObject::LONG_INT_TYPE)
		{
			jDBObject->setValue(buffer.substr(jDBObject->position, 8));
			jDBObject->position += 8;
		}
		else
		{
			jDBObject->setValue(buffer.substr(jDBObject->position, 4));
			jDBObject->position += 4;
		}
	}
	else if(type<AMEFObject::DATE_TYPE) //Boolean/Char Types
	{
		jDBObject->setType(type);
		decodeObjectName(buffer, jDBObject);
		jDBObject->pushChar(buffer[jDBObject->position++]);
	}
	else if(type<AMEFObject::OBJECT_TYPE) // String/Double/Date Types
	{
		jDBObject->setType(type);
		decodeObjectName(buffer, jDBObject);
		int lengthm = AMEFObject::charArrayToInt(buffer, jDBObject->position, 3);
		jDBObject->position += 3;
		jDBObject->setValue(buffer.substr(jDBObject->position, lengthm));
		jDBObject->position += lengthm;
	}
	else if(type==AMEFObject::OBJECT_TYPE) // Object Types
	{
		jDBObject->setType(type);
		decodeObjectName(buffer, jDBObject);
		jDBObject->blength = 4 + jDBObject->position + AMEFObject::charArrayToInt(buffer, jDBObject->position, 4);
		jDBObject->position += 4;
		int poslen = AMEFObject::charArrayToInt(buffer, jDBObject->position, 4);
		jDBObject->position += poslen + 4;
		while(jDBObject->position<jDBObject->blength)
		{
			AMEFObject* obj = new AMEFObject;
			obj->position = jDBObject->position;
			decodeSinglePacketBInternal(buffer, obj);
			jDBObject->addPacket(obj);
			jDBObject->position = obj->position;
		}
	}
	return jDBObject;
}
示例#2
0
AMEFObject* AMEFDecoder::decodeSinglePacketB(string buffer,bool ignoreName)
{
    char type = (char)buffer[position];
    AMEFObject *jDBObject = NULL;
    int st, en;
    if(type==AMEFObject::NULL_STRING || type==AMEFObject::NULL_DATE || type==AMEFObject::NULL_NUMBER
            || type==AMEFObject::NULL_BOOL || type==AMEFObject::NULL_CHAR)
    {
        jDBObject = new AMEFObject();
        jDBObject->setType(type);
        if(!ignoreName)
        {
            decodeObjectName(buffer, jDBObject);
        }
        else
            position++;
    }
    else if(type==AMEFObject::STRING_TYPE)
    {
        jDBObject = new AMEFObject();
        jDBObject->setType(type);
        if(!ignoreName)
        {
            decodeObjectName(buffer, jDBObject);
        }
        else
            position++;
        int lengthm = AMEFObject::charArrayToInt(buffer,position,4);
        position += 4;
        string value = buffer.substr(position,lengthm);
        jDBObject->setValue(value);
        position += lengthm;
    }
    else if(type==AMEFObject::STRING_65536_TYPE)
    {
        jDBObject = new AMEFObject();
        jDBObject->setType(type);
        if(!ignoreName)
        {
            decodeObjectName(buffer, jDBObject);
        }
        else
            position++;
        int lengthm = AMEFObject::charArrayToInt(buffer,position,2);
        position += 2;
        string value = buffer.substr(position,lengthm);
        jDBObject->setValue(value);
        position += lengthm;
    }
    else if(type==AMEFObject::STRING_16777216_TYPE)
    {
        jDBObject = new AMEFObject();
        jDBObject->setType(type);
        if(!ignoreName)
        {
            decodeObjectName(buffer, jDBObject);
        }
        else
            position++;
        int lengthm = AMEFObject::charArrayToInt(buffer,position,3);
        position += 3;
        string value = buffer.substr(position,lengthm);
        jDBObject->setValue(value);
        position += lengthm;
    }
    else if(type==AMEFObject::DATE_TYPE || type==AMEFObject::STRING_256_TYPE || type==AMEFObject::DOUBLE_FLOAT_TYPE)
    {
        jDBObject = new AMEFObject();
        jDBObject->setType(type);
        if(!ignoreName)
        {
            decodeObjectName(buffer, jDBObject);
        }
        else
            position++;
        int lengthm = AMEFObject::charArrayToInt(buffer,position,1);
        position++;
        string value = buffer.substr(position,lengthm);
        jDBObject->setValue(value);
        position += lengthm;
    }
    else if(type==AMEFObject::VERY_SMALL_INT_TYPE)
    {
        jDBObject = new AMEFObject();
        jDBObject->setType(type);
        if(!ignoreName)
        {
            decodeObjectName(buffer, jDBObject);
        }
        else
            position++;
        jDBObject->pushChar(buffer[position]);
        position += 1;
    }
    else if(type==AMEFObject::SMALL_INT_TYPE)
    {
        jDBObject = new AMEFObject();
        jDBObject->setType(type);
        if(!ignoreName)
        {
            decodeObjectName(buffer, jDBObject);
        }
        else
            position++;
        jDBObject->pushChar(buffer[position]);
        jDBObject->pushChar(buffer[position+1]);
        position += 2;
    }
    else if(type==AMEFObject::BIG_INT_TYPE)
    {
        jDBObject = new AMEFObject();
        jDBObject->setType(type);
        if(!ignoreName)
        {
            decodeObjectName(buffer, jDBObject);
        }
        else
            position++;
        jDBObject->pushChar(buffer[position]);
        jDBObject->pushChar(buffer[position+1]);
        jDBObject->pushChar(buffer[position+2]);
        position += 3;
    }
    else if(type==AMEFObject::INT_TYPE)
    {
        jDBObject = new AMEFObject();
        jDBObject->setType(type);
        if(!ignoreName)
        {
            decodeObjectName(buffer, jDBObject);
        }
        else
            position++;
        jDBObject->pushChar(buffer[position]);
        jDBObject->pushChar(buffer[position+1]);
        jDBObject->pushChar(buffer[position+2]);
        jDBObject->pushChar(buffer[position+3]);
        position += 4;
    }
    else if(type==AMEFObject::VS_LONG_INT_TYPE)
    {
        jDBObject = new AMEFObject();
        jDBObject->setType(type);
        if(!ignoreName)
        {
            decodeObjectName(buffer, jDBObject);
        }
        else
            position++;
        jDBObject->pushChar(buffer[position]);
        jDBObject->pushChar(buffer[position+1]);
        jDBObject->pushChar(buffer[position+2]);
        jDBObject->pushChar(buffer[position+3]);
        jDBObject->pushChar(buffer[position+4]);
        position += 5;
    }
    else if(type==AMEFObject::S_LONG_INT_TYPE)
    {
        jDBObject = new AMEFObject();
        jDBObject->setType(type);
        if(!ignoreName)
        {
            decodeObjectName(buffer, jDBObject);
        }
        else
            position++;
        jDBObject->pushChar(buffer[position]);
        jDBObject->pushChar(buffer[position+1]);
        jDBObject->pushChar(buffer[position+2]);
        jDBObject->pushChar(buffer[position+3]);
        jDBObject->pushChar(buffer[position+4]);
        jDBObject->pushChar(buffer[position+5]);
        position += 6;
    }
    else if(type==AMEFObject::B_LONG_INT_TYPE)
    {
        jDBObject = new AMEFObject();
        jDBObject->setType(type);
        if(!ignoreName)
        {
            decodeObjectName(buffer, jDBObject);
        }
        else
            position++;
        jDBObject->pushChar(buffer[position]);
        jDBObject->pushChar(buffer[position+1]);
        jDBObject->pushChar(buffer[position+2]);
        jDBObject->pushChar(buffer[position+3]);
        jDBObject->pushChar(buffer[position+4]);
        jDBObject->pushChar(buffer[position+5]);
        jDBObject->pushChar(buffer[position+6]);
        position += 7;
    }
    else if(type==AMEFObject::LONG_INT_TYPE)
    {
        jDBObject = new AMEFObject();
        jDBObject->setType(type);
        if(!ignoreName)
        {
            decodeObjectName(buffer, jDBObject);
        }
        else
            position++;
        jDBObject->pushChar(buffer[position]);
        jDBObject->pushChar(buffer[position+1]);
        jDBObject->pushChar(buffer[position+2]);
        jDBObject->pushChar(buffer[position+3]);
        jDBObject->pushChar(buffer[position+4]);
        jDBObject->pushChar(buffer[position+5]);
        jDBObject->pushChar(buffer[position+6]);
        jDBObject->pushChar(buffer[position+7]);
        position += 8;
    }
    else if(type==AMEFObject::BOOLEAN_TYPE || type==AMEFObject::CHAR_TYPE)
    {
        jDBObject = new AMEFObject();
        jDBObject->setType(type);
        if(!ignoreName)
        {
            decodeObjectName(buffer, jDBObject);
        }
        else
            position++;
        jDBObject->pushChar(buffer[position]);
        position += 1;
    }
    else if(type==AMEFObject::VS_OBJECT_TYPE)
    {
        jDBObject = new AMEFObject();
        jDBObject->setType(type);
        if(!ignoreName)
        {
            decodeObjectName(buffer, jDBObject);
        }
        else
            position++;
        position++;
        while(position<(int)buffer.length())
        {
            AMEFObject *obj = decodeSinglePacketB(buffer,ignoreName);
            jDBObject->addPacket(obj);
        }
    }
    else if(type==AMEFObject::S_OBJECT_TYPE)
    {
        jDBObject = new AMEFObject();
        jDBObject->setType(type);
        if(!ignoreName)
        {
            decodeObjectName(buffer, jDBObject);
        }
        else
            position++;
        position += 2;
        while(position<(int)buffer.length())
        {
            AMEFObject* obj = decodeSinglePacketB(buffer,ignoreName);
            jDBObject->addPacket(obj);
        }
    }
    else if(type==AMEFObject::B_OBJECT_TYPE)
    {
        jDBObject = new AMEFObject();
        jDBObject->setType(type);
        if(!ignoreName)
        {
            decodeObjectName(buffer, jDBObject);
        }
        else
            position++;
        position += 3;
        while(position<(int)buffer.length())
        {
            AMEFObject* obj = decodeSinglePacketB(buffer,ignoreName);
            jDBObject->addPacket(obj);
        }
    }
    else if(type==AMEFObject::OBJECT_TYPE)
    {
        jDBObject = new AMEFObject();
        jDBObject->setType(type);
        if(!ignoreName)
        {
            decodeObjectName(buffer, jDBObject);
        }
        else
            position++;
        position += 4;
        while(position<(int)buffer.length())
        {
            AMEFObject* obj = decodeSinglePacketB(buffer,ignoreName);
            jDBObject->addPacket(obj);
        }
    }
    return jDBObject;
}