Respond to CR.

This commit is contained in:
Matthew Chen 2018-08-07 15:29:21 -04:00
parent 1ab0842403
commit 21523ac522
11 changed files with 43 additions and 788 deletions

View file

@ -613,15 +613,16 @@ public func serializedData() throws -> Data {
writer.newline()
# description
writer.add('@objc public override var description: String {')
writer.push_indent()
writer.add('var fields = [String]()')
for field in self.fields():
writer.add('fields.append("%s: \(proto.%s)")' % ( field.name_swift, field.name_swift, ) )
writer.add('return "[" + fields.joined(separator: ", ") + "]"')
writer.pop_indent()
writer.add('}')
writer.newline()
if self.args.add_description:
writer.add('@objc public override var description: String {')
writer.push_indent()
writer.add('var fields = [String]()')
for field in self.fields():
writer.add('fields.append("%s: \(proto.%s)")' % ( field.name_swift, field.name_swift, ) )
writer.add('return "[" + fields.joined(separator: ", ") + "]"')
writer.pop_indent()
writer.add('}')
writer.newline()
writer.pop_context()
@ -735,15 +736,16 @@ public func serializedData() throws -> Data {
writer.newline()
# description
writer.add('@objc public override var description: String {')
writer.push_indent()
writer.add('var fields = [String]()')
for field in self.fields():
writer.add('fields.append("%s: \(proto.%s)")' % ( field.name_swift, field.name_swift, ) )
writer.add('return "[" + fields.joined(separator: ", ") + "]"')
writer.pop_indent()
writer.add('}')
writer.newline()
if self.args.add_description:
writer.add('@objc public override var description: String {')
writer.push_indent()
writer.add('var fields = [String]()')
for field in self.fields():
writer.add('fields.append("%s: \(proto.%s)")' % ( field.name_swift, field.name_swift, ) )
writer.add('return "[" + fields.joined(separator: ", ") + "]"')
writer.pop_indent()
writer.add('}')
writer.newline()
writer.pop_context()
@ -1124,6 +1126,7 @@ if __name__ == "__main__":
parser.add_argument('--proto-prefix', help='name prefix for proto bufs.')
parser.add_argument('--dst-dir', help='path to the destination directory.')
parser.add_argument('--add-log-tag', action='store_true', help='add log tag properties.')
parser.add_argument('--add-description', action='store_true', help='add log tag properties.')
parser.add_argument('--verbose', action='store_true', help='enables verbose logging')
args = parser.parse_args()

View file

@ -54,7 +54,7 @@ import SignalMessaging
owsFail("\(self.logTag) could not serialize sync contacts data")
return
}
dataSource = DataSourceValue.dataSource(withSyncMessageData: messageData)
dataSource = DataSourceValue.dataSource(withSyncMessageData: messageData)
}
guard let attachmentDataSource = dataSource else {

View file

@ -15,7 +15,7 @@ NS_ASSUME_NONNULL_BEGIN
// Returns NO on error.
- (BOOL)writeData:(NSData *)data;
- (BOOL)writeUInt32:(UInt32)value;
- (BOOL)writeVariableLengthUInt32:(UInt32)value;
@end

View file

@ -42,16 +42,28 @@ NS_ASSUME_NONNULL_BEGIN
- (BOOL)writeData:(NSData *)data
{
OWSAssert(data);
NSInteger written = [self.outputStream write:data.bytes maxLength:data.length];
if (written != data.length) {
OWSFail(@"%@ could not write to output stream.", self.logTag);
self.hasError = YES;
return NO;
if (data.length < 1) {
return YES;
}
while (YES) {
NSInteger written = [self.outputStream write:data.bytes maxLength:data.length];
if (written < 1) {
OWSFail(@"%@ could not write to output stream.", self.logTag);
self.hasError = YES;
return NO;
}
if (written < data.length) {
data = [data subdataWithRange:NSMakeRange(written, data.length - written)];
} else {
return YES;
}
}
return YES;
}
- (BOOL)writeUInt32:(UInt32)value
- (BOOL)writeVariableLengthUInt32:(UInt32)value
{
while (YES) {
if (value <= 0x7F) {

View file

@ -96,7 +96,7 @@ disappearingMessagesConfiguration:(nullable OWSDisappearingMessagesConfiguration
}
uint32_t contactDataLength = (uint32_t)contactData.length;
[self writeUInt32:contactDataLength];
[self writeVariableLengthUInt32:contactDataLength];
[self writeData:contactData];
if (avatarPng) {

View file

@ -68,7 +68,7 @@ NS_ASSUME_NONNULL_BEGIN
uint32_t groupDataLength = (uint32_t)groupData.length;
[self writeUInt32:groupDataLength];
[self writeVariableLengthUInt32:groupDataLength];
[self writeData:groupData];
if (avatarPng) {

View file

@ -43,12 +43,6 @@ public enum FingerprintProtoError: Error {
@objc public func buildSerializedData() throws -> Data {
return try FingerprintProtoLogicalFingerprint.parseProto(proto).serializedData()
}
@objc public override var description: String {
var fields = [String]()
fields.append("identityData: \(proto.identityData)")
return "[" + fields.joined(separator: ", ") + "]"
}
}
fileprivate let proto: FingerprintProtos_LogicalFingerprint
@ -94,12 +88,6 @@ public enum FingerprintProtoError: Error {
identityData: identityData)
return result
}
@objc public override var description: String {
var fields = [String]()
fields.append("identityData: \(proto.identityData)")
return "[" + fields.joined(separator: ", ") + "]"
}
}
// MARK: - FingerprintProtoLogicalFingerprints
@ -142,14 +130,6 @@ public enum FingerprintProtoError: Error {
@objc public func buildSerializedData() throws -> Data {
return try FingerprintProtoLogicalFingerprints.parseProto(proto).serializedData()
}
@objc public override var description: String {
var fields = [String]()
fields.append("version: \(proto.version)")
fields.append("localFingerprint: \(proto.localFingerprint)")
fields.append("remoteFingerprint: \(proto.remoteFingerprint)")
return "[" + fields.joined(separator: ", ") + "]"
}
}
fileprivate let proto: FingerprintProtos_LogicalFingerprints
@ -215,12 +195,4 @@ public enum FingerprintProtoError: Error {
remoteFingerprint: remoteFingerprint)
return result
}
@objc public override var description: String {
var fields = [String]()
fields.append("version: \(proto.version)")
fields.append("localFingerprint: \(proto.localFingerprint)")
fields.append("remoteFingerprint: \(proto.remoteFingerprint)")
return "[" + fields.joined(separator: ", ") + "]"
}
}

View file

@ -47,13 +47,6 @@ public enum ProvisioningProtoError: Error {
@objc public func buildSerializedData() throws -> Data {
return try ProvisioningProtoProvisionEnvelope.parseProto(proto).serializedData()
}
@objc public override var description: String {
var fields = [String]()
fields.append("publicKey: \(proto.publicKey)")
fields.append("body: \(proto.body)")
return "[" + fields.joined(separator: ", ") + "]"
}
}
fileprivate let proto: ProvisioningProtos_ProvisionEnvelope
@ -109,13 +102,6 @@ public enum ProvisioningProtoError: Error {
body: body)
return result
}
@objc public override var description: String {
var fields = [String]()
fields.append("publicKey: \(proto.publicKey)")
fields.append("body: \(proto.body)")
return "[" + fields.joined(separator: ", ") + "]"
}
}
// MARK: - ProvisioningProtoProvisionMessage
@ -174,18 +160,6 @@ public enum ProvisioningProtoError: Error {
@objc public func buildSerializedData() throws -> Data {
return try ProvisioningProtoProvisionMessage.parseProto(proto).serializedData()
}
@objc public override var description: String {
var fields = [String]()
fields.append("identityKeyPublic: \(proto.identityKeyPublic)")
fields.append("identityKeyPrivate: \(proto.identityKeyPrivate)")
fields.append("number: \(proto.number)")
fields.append("provisioningCode: \(proto.provisioningCode)")
fields.append("userAgent: \(proto.userAgent)")
fields.append("profileKey: \(proto.profileKey)")
fields.append("readReceipts: \(proto.readReceipts)")
return "[" + fields.joined(separator: ", ") + "]"
}
}
fileprivate let proto: ProvisioningProtos_ProvisionMessage
@ -291,16 +265,4 @@ public enum ProvisioningProtoError: Error {
readReceipts: readReceipts)
return result
}
@objc public override var description: String {
var fields = [String]()
fields.append("identityKeyPublic: \(proto.identityKeyPublic)")
fields.append("identityKeyPrivate: \(proto.identityKeyPrivate)")
fields.append("number: \(proto.number)")
fields.append("provisioningCode: \(proto.provisioningCode)")
fields.append("userAgent: \(proto.userAgent)")
fields.append("profileKey: \(proto.profileKey)")
fields.append("readReceipts: \(proto.readReceipts)")
return "[" + fields.joined(separator: ", ") + "]"
}
}

File diff suppressed because it is too large Load diff

View file

@ -77,13 +77,6 @@ public enum SignalIOSProtoError: Error {
@objc public func buildSerializedData() throws -> Data {
return try SignalIOSProtoBackupSnapshotBackupEntity.parseProto(proto).serializedData()
}
@objc public override var description: String {
var fields = [String]()
fields.append("type: \(proto.type)")
fields.append("entityData: \(proto.entityData)")
return "[" + fields.joined(separator: ", ") + "]"
}
}
fileprivate let proto: IOSProtos_BackupSnapshot.BackupEntity
@ -139,13 +132,6 @@ public enum SignalIOSProtoError: Error {
entityData: entityData)
return result
}
@objc public override var description: String {
var fields = [String]()
fields.append("type: \(proto.type)")
fields.append("entityData: \(proto.entityData)")
return "[" + fields.joined(separator: ", ") + "]"
}
}
// MARK: - SignalIOSProtoBackupSnapshot
@ -186,12 +172,6 @@ public enum SignalIOSProtoError: Error {
@objc public func buildSerializedData() throws -> Data {
return try SignalIOSProtoBackupSnapshot.parseProto(proto).serializedData()
}
@objc public override var description: String {
var fields = [String]()
fields.append("entity: \(proto.entity)")
return "[" + fields.joined(separator: ", ") + "]"
}
}
fileprivate let proto: IOSProtos_BackupSnapshot
@ -235,10 +215,4 @@ public enum SignalIOSProtoError: Error {
entity: entity)
return result
}
@objc public override var description: String {
var fields = [String]()
fields.append("entity: \(proto.entity)")
return "[" + fields.joined(separator: ", ") + "]"
}
}

View file

@ -65,16 +65,6 @@ public enum WebSocketProtoError: Error {
@objc public func buildSerializedData() throws -> Data {
return try WebSocketProtoWebSocketRequestMessage.parseProto(proto).serializedData()
}
@objc public override var description: String {
var fields = [String]()
fields.append("verb: \(proto.verb)")
fields.append("path: \(proto.path)")
fields.append("body: \(proto.body)")
fields.append("headers: \(proto.headers)")
fields.append("requestID: \(proto.requestID)")
return "[" + fields.joined(separator: ", ") + "]"
}
}
fileprivate let proto: WebSocketProtos_WebSocketRequestMessage
@ -154,16 +144,6 @@ public enum WebSocketProtoError: Error {
requestID: requestID)
return result
}
@objc public override var description: String {
var fields = [String]()
fields.append("verb: \(proto.verb)")
fields.append("path: \(proto.path)")
fields.append("body: \(proto.body)")
fields.append("headers: \(proto.headers)")
fields.append("requestID: \(proto.requestID)")
return "[" + fields.joined(separator: ", ") + "]"
}
}
// MARK: - WebSocketProtoWebSocketResponseMessage
@ -220,16 +200,6 @@ public enum WebSocketProtoError: Error {
@objc public func buildSerializedData() throws -> Data {
return try WebSocketProtoWebSocketResponseMessage.parseProto(proto).serializedData()
}
@objc public override var description: String {
var fields = [String]()
fields.append("requestID: \(proto.requestID)")
fields.append("status: \(proto.status)")
fields.append("message: \(proto.message)")
fields.append("headers: \(proto.headers)")
fields.append("body: \(proto.body)")
return "[" + fields.joined(separator: ", ") + "]"
}
}
fileprivate let proto: WebSocketProtos_WebSocketResponseMessage
@ -309,16 +279,6 @@ public enum WebSocketProtoError: Error {
status: status)
return result
}
@objc public override var description: String {
var fields = [String]()
fields.append("requestID: \(proto.requestID)")
fields.append("status: \(proto.status)")
fields.append("message: \(proto.message)")
fields.append("headers: \(proto.headers)")
fields.append("body: \(proto.body)")
return "[" + fields.joined(separator: ", ") + "]"
}
}
// MARK: - WebSocketProtoWebSocketMessage
@ -385,14 +345,6 @@ public enum WebSocketProtoError: Error {
@objc public func buildSerializedData() throws -> Data {
return try WebSocketProtoWebSocketMessage.parseProto(proto).serializedData()
}
@objc public override var description: String {
var fields = [String]()
fields.append("type: \(proto.type)")
fields.append("request: \(proto.request)")
fields.append("response: \(proto.response)")
return "[" + fields.joined(separator: ", ") + "]"
}
}
fileprivate let proto: WebSocketProtos_WebSocketMessage
@ -464,12 +416,4 @@ public enum WebSocketProtoError: Error {
response: response)
return result
}
@objc public override var description: String {
var fields = [String]()
fields.append("type: \(proto.type)")
fields.append("request: \(proto.request)")
fields.append("response: \(proto.response)")
return "[" + fields.joined(separator: ", ") + "]"
}
}