Index: src/OFUUID.h ================================================================== --- src/OFUUID.h +++ src/OFUUID.h @@ -12,20 +12,23 @@ * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFObject.h" +#import "OFSerialization.h" OF_ASSUME_NONNULL_BEGIN + +@class OFString; /** * @class OFUUID OFUUID.h ObjFW/OFUUID.h * * @brief A UUID conforming to RFC 4122. */ OF_SUBCLASSING_RESTRICTED -@interface OFUUID: OFObject +@interface OFUUID: OFObject { unsigned char _bytes[16]; } /** Index: src/OFUUID.m ================================================================== --- src/OFUUID.m +++ src/OFUUID.m @@ -16,10 +16,11 @@ #include "config.h" #import "OFUUID.h" #import "OFArray.h" #import "OFString.h" +#import "OFXMLElement.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFOutOfRangeException.h" @@ -141,10 +142,33 @@ @throw e; } return self; } + +- (instancetype)initWithSerialization: (OFXMLElement *)element +{ + void *pool = objc_autoreleasePoolPush(); + OFString *UUIDString; + + @try { + if (![element.name isEqual: self.className] || + ![element.namespace isEqual: OFSerializationNS]) + @throw [OFInvalidArgumentException exception]; + + UUIDString = element.stringValue; + } @catch (id e) { + [self release]; + @throw e; + } + + self = [self initWithUUIDString: UUIDString]; + + objc_autoreleasePoolPop(pool); + + return self; +} - (bool)isEqual: (id)object { OFUUID *UUID; @@ -209,6 +233,20 @@ - (OFString *)description { return self.UUIDString; } + +- (OFXMLElement *)XMLElementBySerializing +{ + void *pool = objc_autoreleasePoolPush(); + OFXMLElement *element = [OFXMLElement elementWithName: self.className + namespace: OFSerializationNS + stringValue: self.UUIDString]; + + [element retain]; + + objc_autoreleasePoolPop(pool); + + return [element autorelease]; +} @end Index: tests/OFSerializationTests.m ================================================================== --- tests/OFSerializationTests.m +++ tests/OFSerializationTests.m @@ -26,10 +26,11 @@ OFMutableDictionary *dict = [OFMutableDictionary dictionary]; OFMutableArray *array = [OFMutableArray array]; OFList *list = [OFList list]; OFData *data; OFString *string; + OFUUID *UUID; [array addObject: @"Qu\"xbar\ntest"]; [array addObject: [OFNumber numberWithInt: 1234]]; [array addObject: [OFNumber numberWithDouble: 1234.5678]]; [array addObject: [OFMutableString stringWithString: @"asd"]]; @@ -52,10 +53,14 @@ data = [OFData dataWithItems: "0123456789:; + + 01234567-89AB-CDEF-FEDC-BA9876543210 + + + uuid + Blub B"la