Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Compression - 5] Add Zstd file compression #220

Merged
merged 25 commits into from
Dec 12, 2019

Conversation

piraka9011
Copy link
Contributor

Implement file compression for Zstd with tests.

Signed-off-by: Anas Abou Allaban allabana@amazon.com

Anas Abou Allaban added 3 commits December 2, 2019 19:29
Signed-off-by: Anas Abou Allaban <allabana@amazon.com>
Signed-off-by: Anas Abou Allaban <allabana@amazon.com>
Signed-off-by: Anas Abou Allaban <allabana@amazon.com>
Signed-off-by: Anas Abou Allaban <allabana@amazon.com>
Copy link
Contributor

@zmichaels11 zmichaels11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments

Anas Abou Allaban added 3 commits December 9, 2019 09:16
Signed-off-by: Anas Abou Allaban <allabana@amazon.com>

Add zstd_vendor, use scopes for files

Signed-off-by: Anas Abou Allaban <allabana@amazon.com>
Signed-off-by: Anas Abou Allaban <allabana@amazon.com>

Use u_ptr, scope for files, and findlib for zstd

Signed-off-by: Anas Abou Allaban <allabana@amazon.com>
Signed-off-by: Anas Abou Allaban <allabana@amazon.com>

Wrap file output statement

Signed-off-by: Anas Abou Allaban <allabana@amazon.com>

Constness

Signed-off-by: Anas Abou Allaban <allabana@amazon.com>
@piraka9011
Copy link
Contributor Author

piraka9011 commented Dec 9, 2019

@zmichaels11 @emersonknapp I was unable to go with your suggestions of using a std::string or unique_ptr for holding the compression buffers. I spent yesterday trying to figure out why and it seems that since Zstd is a C library, it’s unable to free the smart pointer even if I pass a custom destructor to the unique_ptr constructor.

@piraka9011
Copy link
Contributor Author

@ros2/aws-oncall - please run this CI job
Gist: https://gist.githubusercontent.com/piraka9011/b6a4a79d7614c122a824d81d813a654f/raw/df4a4c3c0666d16fb4f902c9a8ce5b026111ad9f/ros2.repos
BUILD args: --packages-up-to rosbag2_compression zstd_vendor
TEST args: --packages-select rosbag2_compression zstd_vendor
Job: ci_launcher

@zmichaels11
Copy link
Contributor

zmichaels11 commented Dec 9, 2019

@piraka9011 to make a buffer using unique_ptr, you want:

auto buffer = std::make_unique<char[]>(buffer_size);

@piraka9011
Copy link
Contributor Author

piraka9011 commented Dec 9, 2019

@piraka9011 to make a buffer using unique_ptr, you want:

auto buffer = std::make_unique<char[]>(buffer_size);

Tried that :) In fact, to have support for < C++14, you need:

std::make_unique<char[]>(new char[buffer_size], (Custom dtor..) )

See this SO answer and comment on why.

@zmichaels11
Copy link
Contributor

zmichaels11 commented Dec 9, 2019

Rosbag2 does target C++14, no?

@zmichaels11
Copy link
Contributor

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

@piraka9011 piraka9011 added this to the F milestone Dec 9, 2019
Copy link
Contributor

@zmichaels11 zmichaels11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a bunch of nits

Signed-off-by: Anas Abou Allaban <allabana@amazon.com>
@thomas-moulard
Copy link
Contributor

fopen() + std::vector<uint8_t> is what you want IMHO

Signed-off-by: Anas Abou Allaban <allabana@amazon.com>
@piraka9011
Copy link
Contributor Author

@Karsten1987 @thomas-moulard check it out 😃

Vectors and uint8_t. File handling should work with Windows too, unless I'm missing anything.

Copy link
Collaborator

@Karsten1987 Karsten1987 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks already way better to me

@Karsten1987
Copy link
Collaborator

please make sure to run CI on this.

@piraka9011
Copy link
Contributor Author

piraka9011 commented Dec 11, 2019

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

Signed-off-by: Anas Abou Allaban <allabana@amazon.com>
Signed-off-by: Anas Abou Allaban <allabana@amazon.com>
@piraka9011
Copy link
Contributor Author

piraka9011 commented Dec 11, 2019

New windows build for cppcheck

  • Windows Build Status

@piraka9011
Copy link
Contributor Author

piraka9011 commented Dec 12, 2019

Windows is still unstable since fopen apparently isn't secure on windows.

Proposed solution:

FILE * get_file_pointer(const std::string & uri, const std::string & read_mode)
{
  FILE * fp = nullptr;
#ifdef _WIN32
  fopen_s(&fp, uri.c_str(), read_mode.c_str());
#else
  fp = fopen(uri.c_str(), read_mode.c_str());
#endif
  return fp;
}

or simply

#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS 1
#endif

@Karsten1987
Copy link
Collaborator

Your first proposed solution makes sense to me. We apply a similar pattern already in various things in rcutils.

Signed-off-by: Zachary Michaels <zmichaels11@gmail.com>
Signed-off-by: Zachary Michaels <zmichaels11@gmail.com>
@zmichaels11
Copy link
Contributor

zmichaels11 commented Dec 12, 2019

@Karsten1987 I've applied the suggestions in:

@ros2/aws-oncall Run this CI: #220 (comment)

@piraka9011
Copy link
Contributor Author

piraka9011 commented Dec 12, 2019

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

Signed-off-by: Zachary Michaels <zmichaels11@gmail.com>
@piraka9011 piraka9011 merged commit de2c3ab into ros2:master Dec 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants