From d5916cbeae0ef4570deda5610871a4dc667c5d04 Mon Sep 17 00:00:00 2001 From: BCG Date: Sat, 29 Jan 2022 10:39:17 -0500 Subject: [PATCH] Added no-op io.Reader implementation to machine.NullSerial --- src/machine/serial.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/machine/serial.go b/src/machine/serial.go index fd02d6ca00..a2449d60fc 100644 --- a/src/machine/serial.go +++ b/src/machine/serial.go @@ -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 +} + +// type check to ensure NullSerial implements interfaces for drivers.UART +var ( + _ io.Reader = NullSerial{} + _ io.Writer = NullSerial{} +)