Comments (4)
CodedInputStream - this implementation "streams" in the official PB (Streaming).
CodedInputStream correctly separates message in byte-stream.
I always use CodedInputStream.
from protobuf-swift.
When you use NSInput/OutputStream, will be used in CodedInput/OutputStream. This is helper methods.
from protobuf-swift.
Perfect !
from protobuf-swift.
The standard way to build up a TPC connection we use:
NSStream.getStreamsToHostWithName(host, port: port, inputStream: &inputStream, outputStream: &outputStream)
Question: how to do that with CodedInputStream and CodedOutputStream streams as NSInputStream and NSOutputStream are privates in your implementation?
(e.g.
private var input:NSInputStream!
private var output:NSOutputStream!
)
Background: normally we use "inputStream!.delegate = ..., inputStream!.scheduleInRunLoop(.mainRunLoop(), forMode: NSDefaultRunLoopMode) ..., func stream(aStream: NSStream, handleEvent eventCode: NSStreamEvent) {... pattern to handle TCP events (like ErrorOccurred, OpenCompleted, HasBytesAvailable, HasSpaceAvailable, etc).
Do I have to use another approach in case of CodedInputStream, CodedOutputStream?
Best Regards,
Péter
more detailed implementation of our standard TCP streams as follows:
func connect(host: String, port: Int) {
self.host = host
self.port = port
NSStream.getStreamsToHostWithName(host, port: port, inputStream: &inputStream, outputStream: &outputStream)
if inputStream != nil && outputStream != nil {
// Set delegate
inputStream!.delegate = self
outputStream!.delegate = self
// Schedule
inputStream!.scheduleInRunLoop(.mainRunLoop(), forMode: NSDefaultRunLoopMode)
outputStream!.scheduleInRunLoop(.mainRunLoop(), forMode: NSDefaultRunLoopMode)
println("Start open()")
// Open!
inputStream!.open()
outputStream!.open()
}
}
// streams event handling:
func stream(aStream: NSStream, handleEvent eventCode: NSStreamEvent) {
if aStream === inputStream {
switch eventCode {
case NSStreamEvent.ErrorOccurred:
println("input: ErrorOccurred: (aStream.streamError?.description)")
break
case NSStreamEvent.EndEncountered:
println("input: EndEncountered")
break
case NSStreamEvent.None:
println("input: None")
break
case NSStreamEvent.OpenCompleted:
println("input: OpenCompleted")
break
case NSStreamEvent.HasBytesAvailable:
println("input: HasBytesAvailable")
// Here you can `read()` from `inputStream`
if ( aStream == inputStream){
var buffer = [UInt8](count: 4096, repeatedValue: 0)
while (inputStream!.hasBytesAvailable){
var len = inputStream!.read(&buffer, maxLength: buffer.count)
// ...
}
}
}
break
case NSStreamEvent.HasSpaceAvailable:
println("input: HasSpaceAvailable")
break
case NSStreamEvent.allZeros:
println("input: allZeros")
break
default:
println("input: default break")
break
}
}
else if aStream === outputStream {
switch eventCode {
case NSStreamEvent.ErrorOccurred:
println("output: ErrorOccurred: \(aStream.streamError?.description)")
break
case NSStreamEvent.EndEncountered:
println("output: OpenCompleted")
break
case NSStreamEvent.None:
println("output: None")
break
case NSStreamEvent.OpenCompleted:
println("output: OpenCompleted")
break
case NSStreamEvent.HasBytesAvailable:
println("output: HasBytesAvailable")
break
case NSStreamEvent.HasSpaceAvailable:
// Here you can write() to `outputStream`
break
case NSStreamEvent.allZeros:
println("output: allZeros")
break
default:
println("output: default break")
break
}
}
}
from protobuf-swift.
Related Issues (20)
- Error in Xcode10 HOT 1
- Build fails with protobuf 3.6.0 HOT 2
- If a number is 0 this property will missing HOT 1
- XCode 10/swift 4.2 compilation errors HOT 3
- Build error on Xcode beta 5 HOT 2
- convert array ro json
- UnsafeRawPointer(&buffer+bufferPos) Ambiguous use of 'init' HOT 4
- configuare.ac
- new function to `delimitedData`
- Build time error HOT 1
- protobuf test program failed to link
- Message Field extensions
- protobuf2.6,swift 3.0 ,version Number
- Question : Codable
- [Question] Use RawValue enum when formatting to JSON
- protocol buffer build.sh error and show “protobuf test program failed to link” HOT 4
- Install failed
- Why the GeneratedMessageProtocol tip error
- Xcode 12.0 BETA 4 HOT 5
- Xcode12 build failure - Generic parameter 'Element' could not be inferred HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from protobuf-swift.