import io.github.amadeusitgroup.flamme.runtime.annotations.Flamme;
import io.github.amadeusitgroup.flamme.runtime.annotations.FlammeImpl;
import com.google.protobuf.Any;
import com.google.protobuf.InvalidProtocolBufferException;
import com.google.protobuf.StringValue;
import jakarta.inject.Inject;
@Flamme(serviceName = "greeter", consumes = {}, produces = {})
public interface GreeterService {
Any sayHello(Any payload);
}
@FlammeImpl
class GreeterServiceImpl implements GreeterService {
@Override
public Any sayHello(Any payload) {
try {
StringValue name = payload.unpack(StringValue.class);
return Any.pack(StringValue.of("Hello, " + name.getValue() + "!"));
} catch (InvalidProtocolBufferException e) {
throw new RuntimeException(e);
}
}
}
class GreeterResource {
@Inject
GreeterService greeterService;
String greet() {
Any response = greeterService.sayHello(Any.pack(StringValue.of("World")));
try {
return response.unpack(StringValue.class).getValue();
} catch (InvalidProtocolBufferException e) {
throw new RuntimeException(e);
}
}
}