Skip to content

Commit

Permalink
Change TSerializable ==
Browse files Browse the repository at this point in the history
  • Loading branch information
apocolipse committed Jun 12, 2017
1 parent e5f8497 commit 7711f98
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions Sources/TSerializable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ public protocol TSerializable {

/// Write TSerializable instance to Protocol
func write(to proto: TProtocol) throws

}

extension TSerializable {
public static func write(_ value: Self, to proto: TProtocol) throws {
try value.write(to: proto)
}

/// convenience for member access
public var thriftType: TType { return Self.thriftType }
}

public func ==(lhs: TSerializable, rhs: TSerializable) -> Bool {
public func ==<T>(lhs: T, rhs: T) -> Bool where T : TSerializable {
return lhs.hashValue == rhs.hashValue
}

Expand All @@ -52,47 +52,47 @@ public func ==(lhs: TSerializable, rhs: TSerializable) -> Bool {

extension Bool : TSerializable {
public static var thriftType: TType { return .bool }

public static func read(from proto: TProtocol) throws -> Bool {
return try proto.read()
}

public func write(to proto: TProtocol) throws {
try proto.write(self)
}
}

extension Int8 : TSerializable {
public static var thriftType: TType { return .i8 }

public static func read(from proto: TProtocol) throws -> Int8 {
return Int8(try proto.read() as UInt8)
}

public func write(to proto: TProtocol) throws {
try proto.write(UInt8(self))
}
}

extension Int16 : TSerializable {
public static var thriftType: TType { return .i16 }

public static func read(from proto: TProtocol) throws -> Int16 {
return try proto.read()
}

public func write(to proto: TProtocol) throws {
try proto.write(self)
}
}

extension Int32 : TSerializable {
public static var thriftType: TType { return .i32 }

public static func read(from proto: TProtocol) throws -> Int32 {
return try proto.read()
}

public func write(to proto: TProtocol) throws {
try proto.write(self)
}
Expand All @@ -101,35 +101,35 @@ extension Int32 : TSerializable {

extension Int64 : TSerializable {
public static var thriftType: TType { return .i64 }

public static func read(from proto: TProtocol) throws -> Int64 {
return try proto.read()
}

public func write(to proto: TProtocol) throws {
try proto.write(self)
}
}

extension Double : TSerializable {
public static var thriftType: TType { return .double }

public static func read(from proto: TProtocol) throws -> Double {
return try proto.read()
}

public func write(to proto: TProtocol) throws {
try proto.write(self)
}
}

extension String : TSerializable {
public static var thriftType: TType { return .string }

public static func read(from proto: TProtocol) throws -> String {
return try proto.read()
}

public func write(to proto: TProtocol) throws {
try proto.write(self)
}
Expand Down

0 comments on commit 7711f98

Please sign in to comment.