def METHOD_NAME(tag_id, stream):
    wire_type = tag_id & 0x07
    if wire_type == 0:
        read_bytes = []
        for i in range(10):
            x = stream.read(1)[0]
            read_bytes.append(x)
            if x & 0x80 == 0:
                break
        buffer = bytes(read_bytes)
    elif wire_type == 1:
        buffer = stream.read(8)
    elif wire_type == 2:
        l, b = _read_le_varint(stream)
        available_bytes = stream.read(l)
        if len(available_bytes) < l:
            raise ValueError("Stream too short")
        buffer = b + available_bytes
    elif wire_type == 5:
        buffer = stream.read(4)
    else:
        raise ValueError("Invalid wiretype")
    return buffer