Spicy conditional parsing

Is there an easy way in Spicy to parse something of known size, but then limit the variable to a set amount of bytes?

For example, I have a data_size which is parsed, and then a data field after that. Can be anywhere from 0 to 300.
I want to store the the full data if data_size is <=100, and if it’s over 100, only the first 100 bytes.
I need to be able to have a condition on it also if a parsed value id is not 0.

I was doing this, which works and puts all the bytes over 100 into data2 (which I can throw out for now) but this won’t work if data_size is <100, and I want the data to go into the same variable name if data_size is <=100 or >100.

data:  bytes &size=100 if (self._id !=0 && self.data_size > 99);
data2: bytes &size=self.data_size-100 if (self._id !=0 && self.data_size > 100);

It would be great if I could just do this, but I’m not sure how in spicy:

if (self.data_size < 100 && self.id !=0)
       data:      bytes &size=self.data_size;
else if (self.id !=0)
     data:  bytes &size=100;
     data2: bytes &size=self.data_size-100; # (or decode all this into data and just ignore anything after 100 bytes)
    data:  b"";

To throw away the excess data after extracting it you could use &convert to modify the extracted value (here: truncate the bytes to a maximum size). To truncate you can use bytes::sub which allows you to extract a slice [0, max_size); if max_size is larger than the length of the data all data would be returned.

type X = unit {
    # Leaving out your id check.
    trunc: bytes &eod &convert=$$.sub(0, 100);

Thanks @Benjamin_Bannier for the quick response and help. This works for me.