jens@0: // jens@0: // BLIPProperties.h jens@0: // MYNetwork jens@0: // jens@0: // Created by Jens Alfke on 5/13/08. jens@0: // Copyright 2008 Jens Alfke. All rights reserved. jens@0: // jens@0: jens@0: #import jens@0: jens@0: jens@0: /** A key/value property store, like a set of MIME or RFC822 headers (but without the weird details). jens@0: It can be written to or read from a block of data; the data is binary, not the textual jens@0: format that MIME uses. */ jens@0: @interface BLIPProperties : NSObject jens@0: jens@0: /** Parse properties from a block of data. jens@0: On success, returns a Properties object and sets *usedLength to the number of bytes of jens@0: data consumed. jens@0: If the data doesn't contain the complete properties, returns nil and sets *usedLength to zero. jens@0: If the properties are syntactically invalid, returns nil and sets *usedLength to a negative number. jens@0: */ jens@0: + (BLIPProperties*) propertiesWithEncodedData: (NSData*)data jens@0: usedLength: (ssize_t*)usedLength; jens@0: jens@0: /** Returns an empty autoreleased instance. */ jens@0: + (BLIPProperties*) properties; jens@0: jens@0: /** Property value lookup. (Case-sensitive, like NSDictionary, but unlike RFC822.) */ jens@0: - (NSString*) valueOfProperty: (NSString*)prop; jens@0: jens@0: /** Returns all the properties/values as a dictionary. */ jens@0: @property (readonly) NSDictionary* allProperties; jens@0: jens@0: /** The number of properties. */ jens@0: @property (readonly) NSUInteger count; jens@0: jens@0: /** The raw data representation of the properties. */ jens@0: @property (readonly) NSData *encodedData; jens@0: jens@0: @end jens@0: jens@0: jens@0: jens@0: /** Mutable subclass of BLIPProperties, used for creating new instances. */ jens@0: @interface BLIPMutableProperties : BLIPProperties jens@0: { jens@26: @private jens@0: NSMutableDictionary *_properties; jens@0: } jens@0: jens@0: /** Initializes a new instance, adding all the key/value pairs from the given NSDictionary. */ jens@0: - (id) initWithDictionary: (NSDictionary*)dict; jens@0: jens@0: /** Sets the value of a property. A nil value is allowed, and removes the property. */ jens@0: - (void) setValue: (NSString*)value ofProperty: (NSString*)prop; jens@0: jens@0: /** Sets the receiver's key/value pairs from the given NSDictionary. jens@0: All previously existing properties are removed first. */ jens@0: - (void) setAllProperties: (NSDictionary*)properties; jens@0: jens@0: @end