Skip to content

Commit 5caad5b

Browse files
committed
Added a method to read data into a char buffer so that character-based (rather than byte-based) operations don't require a cast. As requested by Tom Igoe. Part of the fix to issue 439.
1 parent a3c7a1b commit 5caad5b

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

libraries/Ethernet/Udp.h

+3
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ class UDP : public Stream {
8080
// Read up to len bytes from the current packet and place them into buffer
8181
// Returns the number of bytes read, or 0 if none are available
8282
virtual int read(unsigned char* buffer, size_t len);
83+
// Read up to len characters from the current packet and place them into buffer
84+
// Returns the number of characters read, or 0 if none are available
85+
virtual int read(char* buffer, size_t len) { return read((unsigned char*)buffer, len); };
8386
// Return the next byte from the current packet without moving on to the next byte
8487
virtual int peek();
8588
virtual void flush(); // Finish reading the current packet

libraries/Ethernet/examples/UDPSendReceiveString/UDPSendReceiveString.pde

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ void loop() {
6262
Serial.println(Udp.remotePort());
6363

6464
// read the packet into packetBufffer
65-
Udp.read((byte*)packetBuffer,UDP_TX_PACKET_MAX_SIZE);
65+
Udp.read(packetBuffer,UDP_TX_PACKET_MAX_SIZE);
6666
Serial.println("Contents:");
6767
Serial.println(packetBuffer);
6868

0 commit comments

Comments
 (0)