File tree Expand file tree Collapse file tree 2 files changed +2
-33
lines changed
Expand file tree Collapse file tree 2 files changed +2
-33
lines changed Original file line number Diff line number Diff line change @@ -46,36 +46,8 @@ class Stderr {
4646
4747class Stdout {
4848 static func print( _ s: String ) { printToFd ( s, fd: 1 ) }
49- static func write( bytes: Data ) {
50- bytes. withUnsafeBytes { ( p: UnsafePointer < UInt8 > ) -> ( ) in
51- _ = _write ( 1 , p, bytes. count)
52- }
53- }
5449}
5550
56- class Stdin {
57- static func readall( ) -> Data ? {
58- let fd : Int32 = 0
59- let buffSize = 1024
60- var buff = [ UInt8] ( )
61- var fragment = [ UInt8] ( repeating: 0 , count: buffSize)
62- while true {
63- let count = read ( fd, & fragment, buffSize)
64- if count < 0 {
65- return nil
66- }
67- if count < buffSize {
68- if count > 0 {
69- buff += fragment [ 0 ..< count]
70- }
71- return Data ( bytes: buff)
72- }
73- buff += fragment
74- }
75- }
76- }
77-
78-
7951func readFileData( filename: String ) throws -> Data {
8052 let url = URL ( fileURLWithPath: filename)
8153 return try Data ( contentsOf: url)
Original file line number Diff line number Diff line change @@ -135,10 +135,7 @@ struct GeneratorPlugin {
135135 }
136136
137137 private func generateFromStdin( ) -> Int32 {
138- guard let requestData = Stdin . readall ( ) else {
139- Stderr . print ( " Failed to read request " )
140- return 1
141- }
138+ let requestData = FileHandle . standardInput. readDataToEndOfFile ( )
142139
143140 // Support for loggin the request. Useful when protoc/protoc-gen-swift are
144141 // being invoked from some build system/script. protoc-gen-swift supports
@@ -263,7 +260,7 @@ struct GeneratorPlugin {
263260 Stderr . print ( " Failure while serializing response: \( e) " )
264261 return false
265262 }
266- Stdout . write ( bytes : serializedResponse)
263+ FileHandle . standardOutput . write ( serializedResponse)
267264 return true
268265 }
269266
You can’t perform that action at this time.
0 commit comments