BLIP/BLIPProperties.h
changeset 7 5936db2c1987
child 26 cb9cdf247239
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/BLIP/BLIPProperties.h	Sun May 25 13:43:03 2008 -0700
     1.3 @@ -0,0 +1,61 @@
     1.4 +//
     1.5 +//  BLIPProperties.h
     1.6 +//  MYNetwork
     1.7 +//
     1.8 +//  Created by Jens Alfke on 5/13/08.
     1.9 +//  Copyright 2008 Jens Alfke. All rights reserved.
    1.10 +//
    1.11 +
    1.12 +#import <Foundation/Foundation.h>
    1.13 +
    1.14 +
    1.15 +/** A key/value property store, like a set of MIME or RFC822 headers (but without the weird details).
    1.16 +    It can be written to or read from a block of data; the data is binary, not the textual
    1.17 +    format that MIME uses. */
    1.18 +@interface BLIPProperties : NSObject <NSCopying, NSMutableCopying>
    1.19 +
    1.20 +/** Parse properties from a block of data.
    1.21 +    On success, returns a Properties object and sets *usedLength to the number of bytes of
    1.22 +    data consumed.
    1.23 +    If the data doesn't contain the complete properties, returns nil and sets *usedLength to zero.
    1.24 +    If the properties are syntactically invalid, returns nil and sets *usedLength to a negative number.
    1.25 +*/
    1.26 ++ (BLIPProperties*) propertiesWithEncodedData: (NSData*)data
    1.27 +                                   usedLength: (ssize_t*)usedLength;
    1.28 +
    1.29 +/** Returns an empty autoreleased instance. */
    1.30 ++ (BLIPProperties*) properties;
    1.31 +
    1.32 +/** Property value lookup. (Case-sensitive, like NSDictionary, but unlike RFC822.) */
    1.33 +- (NSString*) valueOfProperty: (NSString*)prop;
    1.34 +
    1.35 +/** Returns all the properties/values as a dictionary. */
    1.36 +@property (readonly) NSDictionary* allProperties;
    1.37 +
    1.38 +/** The number of properties. */
    1.39 +@property (readonly) NSUInteger count;
    1.40 +
    1.41 +/** The raw data representation of the properties. */
    1.42 +@property (readonly) NSData *encodedData;
    1.43 +
    1.44 +@end
    1.45 +
    1.46 +
    1.47 +
    1.48 +/** Mutable subclass of BLIPProperties, used for creating new instances. */
    1.49 +@interface BLIPMutableProperties : BLIPProperties
    1.50 +{
    1.51 +    NSMutableDictionary *_properties;
    1.52 +}
    1.53 +
    1.54 +/** Initializes a new instance, adding all the key/value pairs from the given NSDictionary. */
    1.55 +- (id) initWithDictionary: (NSDictionary*)dict;
    1.56 +
    1.57 +/** Sets the value of a property. A nil value is allowed, and removes the property. */
    1.58 +- (void) setValue: (NSString*)value ofProperty: (NSString*)prop;
    1.59 +
    1.60 +/** Sets the receiver's key/value pairs from the given NSDictionary.
    1.61 +    All previously existing properties are removed first. */
    1.62 +- (void) setAllProperties: (NSDictionary*)properties;
    1.63 +
    1.64 +@end
    1.65 \ No newline at end of file