Exemplo n.º 1
0
bool OSSerialize::previouslySerialized(const OSMetaClassBase *o)
{
	char temp[16];
	OSString *tagString;

	if (binary) return (binarySerialize(o));

	// look it up
	tagString = (OSString *)tags->getObject((const OSSymbol *) o);

// xx-review: no error checking here for addString calls!
	// does it exist?
	if (tagString) {
		addString("<reference IDREF=\"");
		addString(tagString->getCStringNoCopy());
		addString("\"/>");
		return true;
	}

	// build a tag
	snprintf(temp, sizeof(temp), "%u", tag++);
	tagString = OSString::withCString(temp);

	// add to tag dictionary
        tags->setObject((const OSSymbol *) o, tagString);// XXX check return
	tagString->release();

	return false;
}
Exemplo n.º 2
0
bool OSSerialize::previouslySerialized(const OSMetaClassBase *o)
{
    char temp[16];
    unsigned int tagIdx;

    if (binary) return (binarySerialize(o));

    // look it up
    tagIdx = tags->getNextIndexOfObject(o, 0);

// xx-review: no error checking here for addString calls!
    // does it exist?
    if (tagIdx != -1U) {
        addString("<reference IDREF=\"");
        snprintf(temp, sizeof(temp), "%u", tagIdx);
        addString(temp);
        addString("\"/>");
        return true;
    }

    // add to tag array
    tags->setObject(o);// XXX check return

    return false;
}
Exemplo n.º 3
0
int main( int , char ** )
{
    dash::NodePtr root = createSampleNode();

    dash::NodePtr outRoot = new dash::Node;

    textSerialize( *root, *outRoot );
    TEST( areEqual( root, outRoot ));

    binarySerialize( *root, *outRoot );
    TEST( areEqual( root, outRoot ));

    return EXIT_SUCCESS;
}
Exemplo n.º 4
0
int dash::test::main( int argc, char **argv )
{
    dash::AttributePtr outAttribute = new dash::Attribute;

    dash::AttributePtr intAttribute = new dash::Attribute( 42 );
    textSerialize( *intAttribute, *outAttribute );
    TEST( intAttribute->get<int>() == outAttribute->get<int>( ))
    binarySerialize( *intAttribute, *outAttribute );
    TEST( intAttribute->get<int>() == outAttribute->get<int>( ))

    dash::AttributePtr floatAttribute = new dash::Attribute( 42.f );
    textSerialize( *floatAttribute, *outAttribute );
    TEST( floatAttribute->get<float>() == outAttribute->get<float>( ))

    dash::AttributePtr stringAttribute =
                                     new dash::Attribute( std::string( "bla" ));
    textSerialize( *stringAttribute, *outAttribute );
    TEST( stringAttribute->get<std::string>() ==
          outAttribute->get<std::string>( ))

    dash::AttributePtr uint128Attribute =
                      new dash::Attribute( lunchbox::uint128_t( 12345, 54321 ));
    textSerialize( *uint128Attribute, *outAttribute );
    TEST( uint128Attribute->get<lunchbox::uint128_t>() ==
          outAttribute->get<lunchbox::uint128_t>( ))

    Foo foo = {42, 1.5f, false, "blablub"};
    dash::AttributePtr fooAttribute = new dash::Attribute( foo );
    textSerialize( *fooAttribute, *outAttribute );
    const Foo& outFoo = outAttribute->get<Foo>();
    TEST( foo.i == outFoo.i );
    TEST( foo.f == outFoo.f );
    TEST( foo.b == outFoo.b );
    TEST( foo.s == outFoo.s );

    return EXIT_SUCCESS;
}
Exemplo n.º 5
0
bool OSSerialize::binarySerialize(const OSMetaClassBase *o)
{
    OSDictionary * dict;
    OSArray      * array;
    OSSet        * set;
    OSNumber     * num;
    OSSymbol     * sym;
    OSString     * str;
    OSData       * ldata;
    OSBoolean    * boo;

	unsigned int  tagIdx;
    uint32_t   i, key;
    size_t     len;
    bool       ok;

	tagIdx = tags->getNextIndexOfObject(o, 0);
	// does it exist?
	if (-1U != tagIdx)
	{
		key = (kOSSerializeObject | tagIdx);
		if (endCollection)
		{
			 endCollection = false;
			 key |= kOSSerializeEndCollecton;
		}
		ok = addBinary(&key, sizeof(key));
		return (ok);
	}

	if ((dict = OSDynamicCast(OSDictionary, o)))
	{
		key = (kOSSerializeDictionary | dict->count);
		ok = addBinaryObject(o, key, NULL, 0);
		for (i = 0; ok && (i < dict->count);)
		{
			const OSSymbol        * dictKey;
			const OSMetaClassBase * dictValue;
			const OSMetaClassBase * nvalue = 0;

			dictKey = dict->dictionary[i].key;
			dictValue = dict->dictionary[i].value;
			i++;
			if (editor)
			{
				dictValue = nvalue = (*editor)(editRef, this, dict, dictKey, dictValue);
				if (!dictValue) dictValue = dict;
			}
			ok = binarySerialize(dictKey);
			if (!ok) break;
			endCollection = (i == dict->count);
			ok = binarySerialize(dictValue);
			if (!ok) ok = dictValue->serialize(this);
			if (nvalue) nvalue->release();
//			if (!ok) ok = binarySerialize(kOSBooleanFalse);
		}			
	}
	else if ((array = OSDynamicCast(OSArray, o)))
	{
		key = (kOSSerializeArray | array->count);
		ok = addBinaryObject(o, key, NULL, 0);
		for (i = 0; ok && (i < array->count);)
		{
			i++;
			endCollection = (i == array->count);
			ok = binarySerialize(array->array[i-1]);
			if (!ok) ok = array->array[i-1]->serialize(this);
//			if (!ok) ok = binarySerialize(kOSBooleanFalse);
		}			
	}
	else if ((set = OSDynamicCast(OSSet, o)))
	{
		key = (kOSSerializeSet | set->members->count);
		ok = addBinaryObject(o, key, NULL, 0);
		for (i = 0; ok && (i < set->members->count);)
		{
			i++;
			endCollection = (i == set->members->count);
			ok = binarySerialize(set->members->array[i-1]);
			if (!ok) ok = set->members->array[i-1]->serialize(this);
//			if (!ok) ok = binarySerialize(kOSBooleanFalse);
		}			
	}
	else if ((num = OSDynamicCast(OSNumber, o)))
	{
		key = (kOSSerializeNumber | num->size);
		ok = addBinaryObject(o, key, &num->value, sizeof(num->value));
	}
	else if ((boo = OSDynamicCast(OSBoolean, o)))
	{
		key = (kOSSerializeBoolean | (kOSBooleanTrue == boo));
		ok = addBinaryObject(o, key, NULL, 0);
	}
	else if ((sym = OSDynamicCast(OSSymbol, o)))
	{
		len = (sym->getLength() + 1);
		key = (kOSSerializeSymbol | len);
		ok = addBinaryObject(o, key, sym->getCStringNoCopy(), len);
	}
	else if ((str = OSDynamicCast(OSString, o)))
	{
		len = (str->getLength() + 0);
		key = (kOSSerializeString | len);
		ok = addBinaryObject(o, key, str->getCStringNoCopy(), len);
	}
	else if ((ldata = OSDynamicCast(OSData, o)))
	{
		len = ldata->getLength();
		if (ldata->reserved && ldata->reserved->disableSerialization) len = 0;
		key = (kOSSerializeData | len);
		ok = addBinaryObject(o, key, ldata->getBytesNoCopy(), len);
	}
	else return (false);

    return (ok);
}