Skip to content

Commit

Permalink
Added no-op io.Reader implementation to machine.NullSerial
Browse files Browse the repository at this point in the history
  • Loading branch information
bgould committed Jan 29, 2022
1 parent a7a69d3 commit d5916cb
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/machine/serial.go
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")

Expand Down Expand Up @@ -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
}

// type check to ensure NullSerial implements interfaces for drivers.UART
var (
_ io.Reader = NullSerial{}
_ io.Writer = NullSerial{}
)

0 comments on commit d5916cb

Please sign in to comment.