Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Reading serialized objects
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Reading serialized objects



Hi. Basically I'm sending information over STDOUT from a Cocoa app to a Carbon tool.
In the Cocoa app, I serialize an NSDictionary, then find it's data size, send that size to the tool, and then send the actual data, like this:

// inFile = a file handle to STDIN of the child (tool) process

    NSData *configData = [NSArchiver archivedDataWithRootObject:anNSDictionary];
    unsigned configDataSize = [configData length];
    [inFile writeData:[NSData dataWithBytes:&configDataSize length:sizeof( unsigned )]];
    [inFile writeData:configData];


Now on the other side, I can capture the SIZE of the dictionary, but reading the dictionary itself using only C and the Carbon APIs is proving difficult. Here is what I am doing (which works, but uses NSFileHandle and NSData):

        unsigned sizeOfDict = 0;
        if( read(0, &sizeOfDict, sizeof(unsigned)) != sizeof(unsigned) )
        {
            printf("Error reading sizeOfDict\n");
            return -1;
        }

        NSFileHandle *fh = [NSFileHandle fileHandleWithStandardInput];
        NSData *dictData = [fh readDataOfLength:sizeOfDict];
        NSDictionary *dict = [NSUnarchiver unarchiveObjectWithData:dictData];
        
        CFDictionaryRef parametersDict;
        parametersDict = (CFDictionaryRef)dict;

        // now I have my dictionary.


How can I read this NSDictionary/CFDictionary into my tool using only C and Carbon APIs? Thank you. :)
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Carbon-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.