mirror of https://github.com/noisymime/Arduino.git
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.
This commit is contained in:
parent
a3c7a1bedd
commit
5caad5bdb4
|
@ -80,6 +80,9 @@ public:
|
||||||
// Read up to len bytes from the current packet and place them into buffer
|
// Read up to len bytes from the current packet and place them into buffer
|
||||||
// Returns the number of bytes read, or 0 if none are available
|
// Returns the number of bytes read, or 0 if none are available
|
||||||
virtual int read(unsigned char* buffer, size_t len);
|
virtual int read(unsigned char* buffer, size_t len);
|
||||||
|
// Read up to len characters from the current packet and place them into buffer
|
||||||
|
// Returns the number of characters read, or 0 if none are available
|
||||||
|
virtual int read(char* buffer, size_t len) { return read((unsigned char*)buffer, len); };
|
||||||
// Return the next byte from the current packet without moving on to the next byte
|
// Return the next byte from the current packet without moving on to the next byte
|
||||||
virtual int peek();
|
virtual int peek();
|
||||||
virtual void flush(); // Finish reading the current packet
|
virtual void flush(); // Finish reading the current packet
|
||||||
|
|
|
@ -62,7 +62,7 @@ void loop() {
|
||||||
Serial.println(Udp.remotePort());
|
Serial.println(Udp.remotePort());
|
||||||
|
|
||||||
// read the packet into packetBufffer
|
// read the packet into packetBufffer
|
||||||
Udp.read((byte*)packetBuffer,UDP_TX_PACKET_MAX_SIZE);
|
Udp.read(packetBuffer,UDP_TX_PACKET_MAX_SIZE);
|
||||||
Serial.println("Contents:");
|
Serial.println("Contents:");
|
||||||
Serial.println(packetBuffer);
|
Serial.println(packetBuffer);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue