-
Notifications
You must be signed in to change notification settings - Fork 929
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
machine: add no-op io.Reader implementation to NullSerial #2593
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -1,6 +1,9 @@ | ||||||||
package machine | ||||||||
|
||||||||
import "errors" | ||||||||
import ( | ||||||||
"errors" | ||||||||
"io" | ||||||||
) | ||||||||
|
||||||||
var errNoByte = errors.New("machine: no byte read") | ||||||||
|
||||||||
|
@@ -44,3 +47,14 @@ func (ns NullSerial) Buffered() int { | |||||||
func (ns NullSerial) Write(p []byte) (n int, err error) { | ||||||||
return len(p), nil | ||||||||
} | ||||||||
|
||||||||
// Read is a no-op; always returns that zero bytes were read with no error | ||||||||
func (ns NullSerial) Read(p []byte) (n int, err error) { | ||||||||
return 0, nil | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just wondering, shouldn't it return io.EOF to show that there is nothing to read? As per doc
The same as Lines 32 to 34 in 3458726
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, returning an error seems more correct to me. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you think should return |
||||||||
} | ||||||||
|
||||||||
// type check to ensure NullSerial implements interfaces for drivers.UART | ||||||||
var ( | ||||||||
_ io.Reader = NullSerial{} | ||||||||
_ io.Writer = NullSerial{} | ||||||||
Comment on lines
+56
to
+59
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||||||||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this change intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Importing the
io
package as part of the type check causes a compile error in the smoke test for RP2040 because it defines an internal type calledio
as well. The alternative would have been to importio
with an alias inserial.go
, but I thought it would be better and more appropriate to rename the type for the rp2040 to prevent this problem from happening again in the future.