Skip to content

Instantly share code, notes, and snippets.

@mebjas
Last active November 16, 2022 10:02
Show Gist options
  • Save mebjas/f1f23b3e550a3d0290b448e89107122e to your computer and use it in GitHub Desktop.
Save mebjas/f1f23b3e550a3d0290b448e89107122e to your computer and use it in GitHub Desktop.
Updated interface of image library with method to decode Image from string image buffer.
class ImageFactory {
public:
// Decodes the `image_buffer` and returns Image instance.
//
// Suggestion for readers: Use absl::string_view instead of string here.
static std::unique_ptr<Image> FromString(const std::string& image_buffer);
// Creates an instance of 'Image' from the file descriptor 'fd'.
//
// Will return 'nullptr' if it's unable to decode image successfully.
//
// Note for readers: If you can add abseil package to your code base, I
// recommend changing this API to return
// 'absl::StatusOr<std::unique_ptr<Image>>' instead. This will lead to much
// cleaner API and improved error handling.
static std::unique_ptr<Image> FromFd(int fd);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment