SerialPassthrough for ESP8266

Hello,
I have an ESP8266 that I am trying to update the firmware on and to do so I need to up date the SerialPassthrough code to work with Mbed OS6 since SerialRaw has been depreciated but I am running into some issues.
The original code it has getc and putc, and I have attempted to update with read and write, but they require an initial size. Does anyone know of a work around here?

Original code:

#include "mbed.h"

RawSerial  pc(USBTX, USBRX);
RawSerial  dev(D1, D0);
DigitalOut led1(LED1);
DigitalOut led4(LED4);

void dev_recv()
{
    led1 = !led1;
    while(dev.readable()) {
        pc.putc(dev.getc());
    }
}

void pc_recv()
{
    led4 = !led4;
    while(pc.readable()) {
        dev.putc(pc.getc());
    }
}

int main()
{
    pc.baud(115200);
    dev.baud(115200);

    pc.attach(&pc_recv, Serial::RxIrq);
    dev.attach(&dev_recv, Serial::RxIrq);

    while(1) {
        sleep();
    }
}

My attempted modification:

#include "mbed.h"


UnbufferedSerial  pc(USBTX, USBRX,115200); //tx,rx
UnbufferedSerial  dev(p28, p27, 115200);    //tx,rx
DigitalOut led1(LED1);
DigitalOut led4(LED4);

void dev_recv()
{
    led1 = !led1;
    while(dev.readable()) 
    {
        pc.write(dev.read());
    }
}

void pc_recv()
{
    led4 = !led4;
    while(pc.readable()) 
    {
        dev.write(pc.read());
    }
}

int main()
{
    pc.baud(115200);
    dev.baud(115200);

    pc.attach(&pc_recv, SerialBase::RxIrq);
    dev.attach(&dev_recv, SerialBase::RxIrq);

    while(1) {
        sleep();
    }
}

Hello,

a good start is the documentation and examples for current API - UnbufferedSerial
Methods read and write return size of processed bytes so you can not use them like this. Also both of them are working with buffer, so you need to use them like below.

void dev_recv()
{
    led1 = !led1;
    while(dev.readable()) 
    {
        char c;
        if (dev.read(&c, 1)) {
           pc.write(&c, 1);
        }
    }
}

BR, Jan