Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement NEP 2 #17

Merged
merged 5 commits into from
Mar 5, 2016
Merged

Implement NEP 2 #17

merged 5 commits into from
Mar 5, 2016

Conversation

kylef
Copy link
Member

@kylef kylef commented Jan 2, 2016

This is a reference implementation of NEP 2.

@danneu
Copy link

danneu commented Mar 1, 2016

What do you think about changing next to return byte arrays instead of single bytes?

i.e. change this

protocol PayloadType {
  mutating func next() -> UInt8?
}

to

protocol PayloadType {
  mutating func next() -> [UInt8]?
}

Reasoning:

For all responses except for streams, you already have the payload in memory, in which case you have to regress from what was a straight socket dump to a tight loop just for conformance.

Also, (so far in my limited experience with Swift) it seems that you usually end up with byte arrays when working with APIs and system calls to read data. For example, when I was extending NSInputStream to conform to PayloadType, I was getting [UInt8] chunks from the stream at which point emitting individual bytes felt like an unnecessary intermediate step.

Finally, I'll sheepishly admit that I had trouble making the tight loop performant. Maybe it's me (most likely), maybe it's the socket abstraction I am using, but I definitely had a big performance regression compared to just flushing byte arrays to the socket.

What do you think?

kylef added a commit that referenced this pull request Mar 5, 2016
@kylef kylef merged commit 135f99e into master Mar 5, 2016
@kylef kylef deleted the kylef/nep-2 branch March 5, 2016 23:03
@kylef
Copy link
Member Author

kylef commented Mar 5, 2016

@danneu I agree and I've added that change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants