// This file was automatically generated by protocompiler
// DO NOT EDIT!
// Compiled from SecDbBackupRecoverySet.proto

#import "SecDbBackupMetadataClassKey.h"
#import <ProtocolBuffer/PBConstants.h>
#import <ProtocolBuffer/PBHashUtil.h>
#import <ProtocolBuffer/PBDataReader.h>

#if !__has_feature(objc_arc)
# error This generated file depends on ARC but it is not enabled; turn on ARC, or use 'objc_use_arc' option to generate non-ARC code.
#endif

@implementation SecDbBackupMetadataClassKey

@synthesize keyClass = _keyClass;
- (void)setKeyClass:(int32_t)v
{
    _has.keyClass = YES;
    _keyClass = v;
}
- (void)setHasKeyClass:(BOOL)f
{
    _has.keyClass = f;
}
- (BOOL)hasKeyClass
{
    return _has.keyClass;
}
- (BOOL)hasBackupWrappedMetadataKey
{
    return _backupWrappedMetadataKey != nil;
}
@synthesize backupWrappedMetadataKey = _backupWrappedMetadataKey;

- (NSString *)description
{
    return [NSString stringWithFormat:@"%@ %@", [super description], [self dictionaryRepresentation]];
}

- (NSDictionary *)dictionaryRepresentation
{
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    if (self->_has.keyClass)
    {
        [dict setObject:[NSNumber numberWithInt:self->_keyClass] forKey:@"keyClass"];
    }
    if (self->_backupWrappedMetadataKey)
    {
        [dict setObject:self->_backupWrappedMetadataKey forKey:@"backupWrappedMetadataKey"];
    }
    return dict;
}

BOOL SecDbBackupMetadataClassKeyReadFrom(__unsafe_unretained SecDbBackupMetadataClassKey *self, __unsafe_unretained PBDataReader *reader) {
    while (PBReaderHasMoreData(reader)) {
        uint32_t tag = 0;
        uint8_t aType = 0;

        PBReaderReadTag32AndType(reader, &tag, &aType);

        if (PBReaderHasError(reader))
            break;

        if (aType == TYPE_END_GROUP) {
            break;
        }

        switch (tag) {

            case 1 /* keyClass */:
            {
                self->_has.keyClass = YES;
                self->_keyClass = PBReaderReadInt32(reader);
            }
            break;
            case 2 /* backupWrappedMetadataKey */:
            {
                NSData *new_backupWrappedMetadataKey = PBReaderReadData(reader);
                self->_backupWrappedMetadataKey = new_backupWrappedMetadataKey;
            }
            break;
            default:
                if (!PBReaderSkipValueWithTag(reader, tag, aType))
                    return NO;
                break;
        }
    }
    return !PBReaderHasError(reader);
}

- (BOOL)readFrom:(PBDataReader *)reader
{
    return SecDbBackupMetadataClassKeyReadFrom(self, reader);
}
- (void)writeTo:(PBDataWriter *)writer
{
    /* keyClass */
    {
        if (self->_has.keyClass)
        {
            PBDataWriterWriteInt32Field(writer, self->_keyClass, 1);
        }
    }
    /* backupWrappedMetadataKey */
    {
        if (self->_backupWrappedMetadataKey)
        {
            PBDataWriterWriteDataField(writer, self->_backupWrappedMetadataKey, 2);
        }
    }
}

- (void)copyTo:(SecDbBackupMetadataClassKey *)other
{
    if (self->_has.keyClass)
    {
        other->_keyClass = _keyClass;
        other->_has.keyClass = YES;
    }
    if (_backupWrappedMetadataKey)
    {
        other.backupWrappedMetadataKey = _backupWrappedMetadataKey;
    }
}

- (id)copyWithZone:(NSZone *)zone
{
    SecDbBackupMetadataClassKey *copy = [[[self class] allocWithZone:zone] init];
    if (self->_has.keyClass)
    {
        copy->_keyClass = _keyClass;
        copy->_has.keyClass = YES;
    }
    copy->_backupWrappedMetadataKey = [_backupWrappedMetadataKey copyWithZone:zone];
    return copy;
}

- (BOOL)isEqual:(id)object
{
    SecDbBackupMetadataClassKey *other = (SecDbBackupMetadataClassKey *)object;
    return [other isMemberOfClass:[self class]]
    &&
    ((self->_has.keyClass && other->_has.keyClass && self->_keyClass == other->_keyClass) || (!self->_has.keyClass && !other->_has.keyClass))
    &&
    ((!self->_backupWrappedMetadataKey && !other->_backupWrappedMetadataKey) || [self->_backupWrappedMetadataKey isEqual:other->_backupWrappedMetadataKey])
    ;
}

- (NSUInteger)hash
{
    return 0
    ^
    (self->_has.keyClass ? PBHashInt((NSUInteger)self->_keyClass) : 0)
    ^
    [self->_backupWrappedMetadataKey hash]
    ;
}

- (void)mergeFrom:(SecDbBackupMetadataClassKey *)other
{
    if (other->_has.keyClass)
    {
        self->_keyClass = other->_keyClass;
        self->_has.keyClass = YES;
    }
    if (other->_backupWrappedMetadataKey)
    {
        [self setBackupWrappedMetadataKey:other->_backupWrappedMetadataKey];
    }
}

@end

