Swiftgram/submodules/MtProtoKit/MTTransportSchemeStats.m
Peter 373769682e Add 'submodules/MtProtoKit/' from commit '14ab734b977fd4f1686a2a13415f6a4c9b9fdd6d'
git-subtree-dir: submodules/MtProtoKit
git-subtree-mainline: 3b155750f5a4894ff3dedf1860a37e94e0ea9571
git-subtree-split: 14ab734b977fd4f1686a2a13415f6a4c9b9fdd6d
2019-06-11 18:55:34 +01:00

63 lines
2.5 KiB
Objective-C

#import "MTTransportSchemeStats.h"
#import "MTDatacenterAddress.h"
@implementation MTTransportSchemeStats
- (instancetype)initWithLastFailureTimestamp:(int32_t)lastFailureTimestamp lastResponseTimestamp:(int32_t)lastResponseTimestamp {
self = [super init];
if (self != nil) {
_lastFailureTimestamp = lastFailureTimestamp;
_lastResponseTimestamp = lastResponseTimestamp;
}
return self;
}
- (instancetype)initWithCoder:(NSCoder *)aDecoder {
return [self initWithLastFailureTimestamp:[aDecoder decodeInt32ForKey:@"lastFailureTimestamp"] lastResponseTimestamp:[aDecoder decodeInt32ForKey:@"lastResponseTimestamp"]];
}
- (void)encodeWithCoder:(NSCoder *)aCoder {
[aCoder encodeInt32:_lastFailureTimestamp forKey:@"lastFailureTimestamp"];
[aCoder encodeInt32:_lastResponseTimestamp forKey:@"lastResponseTimestamp"];
}
- (BOOL)isEqual:(id)object {
if (![object isKindOfClass:[MTTransportSchemeStats class]]) {
return false;
}
MTTransportSchemeStats *other = object;
if (_lastFailureTimestamp != other->_lastFailureTimestamp) {
return false;
}
if (_lastResponseTimestamp != other->_lastResponseTimestamp) {
return false;
}
return true;
}
- (instancetype)withUpdatedLastFailureTimestamp:(int32_t)lastFailureTimestamp {
return [[MTTransportSchemeStats alloc] initWithLastFailureTimestamp:lastFailureTimestamp lastResponseTimestamp:_lastResponseTimestamp];
}
- (instancetype)withUpdatedLastResponseTimestamp:(int32_t)lastResponseTimestamp {
return [[MTTransportSchemeStats alloc] initWithLastFailureTimestamp:_lastFailureTimestamp lastResponseTimestamp:lastResponseTimestamp];
}
- (NSString *)description {
return [NSString stringWithFormat:@"lastFailureTimestamp: %d, lastResponseTimestamp:%d", _lastFailureTimestamp, _lastResponseTimestamp];
}
+ (NSString *)formatStats:(NSMutableDictionary<NSNumber *, NSMutableDictionary<MTDatacenterAddress *, MTTransportSchemeStats *> *> *)stats {
NSMutableString *result = [[NSMutableString alloc] init];
[stats enumerateKeysAndObjectsUsingBlock:^(NSNumber *nDatacenterId, NSMutableDictionary<MTDatacenterAddress *, MTTransportSchemeStats *> *values, __unused BOOL *stop) {
[result appendFormat:@"DC%@:\n", nDatacenterId];
[values enumerateKeysAndObjectsUsingBlock:^(MTDatacenterAddress *key, MTTransportSchemeStats *obj, __unused BOOL * stop) {
[result appendFormat:@" %@:%@\n", key, obj];
}];
}];
return result;
}
@end