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

Make fields of DataBuf private #1886

Merged
merged 5 commits into from
Sep 9, 2021

Conversation

kevinbackhouse
Copy link
Collaborator

This a refactoring change to tidy the DataBuf class. I made the pData_ and size_ fields private and added a few new methods which you can use to read and write the data.

@codecov
Copy link

codecov bot commented Aug 29, 2021

Codecov Report

Merging #1886 (9ff72e5) into main (cb16324) will increase coverage by 0.06%.
The diff coverage is 64.08%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1886      +/-   ##
==========================================
+ Coverage   60.80%   60.86%   +0.06%     
==========================================
  Files          96       96              
  Lines       18963    19044      +81     
  Branches     9512     9726     +214     
==========================================
+ Hits        11531    11592      +61     
- Misses       5131     5139       +8     
- Partials     2301     2313      +12     
Impacted Files Coverage Δ
src/convert.cpp 53.50% <0.00%> (ø)
src/exiv2.cpp 57.85% <0.00%> (ø)
src/mrwimage.cpp 41.89% <0.00%> (+0.55%) ⬆️
src/orfimage_int.cpp 33.33% <0.00%> (ø)
src/preview.cpp 50.35% <32.35%> (+1.27%) ⬆️
src/exif.cpp 65.90% <33.33%> (ø)
src/rafimage.cpp 20.00% <33.33%> (-0.74%) ⬇️
src/basicio.cpp 48.40% <40.00%> (-0.36%) ⬇️
src/tiffvisitor_int.cpp 76.23% <42.10%> (ø)
src/tags_int.cpp 76.34% <42.85%> (-0.13%) ⬇️
... and 24 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cb16324...9ff72e5. Read the comment docs.

Copy link
Collaborator

@clanmills clanmills left a comment

Choose a reason for hiding this comment

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

I think it's a good idea to change this as part of the new Exiv2/API for v1.00. Several suggestions. It's fine to ignore my suggestions!.

  1. Provide a default offset=0 for c_str() and c_data().
const byte* c_data(size_t offset=0) const;
  1. Is c_data() a good name? Perhaps data(offset=0) if easier on the eye.

  2. It there merit in have having operator = for common assignments, such as:

unit64_t foo = dataBuf(size_t offset = 0,ByteOrder bo = inherit); 
  1. There is a ByteOrder inherit. It's used by the binaryDecoder magic (and discussed in my book).

I'm wondering if we should have a ByteOrder on the DataBuf constructor.

On a read, the default bo=inherit would mean "use the buffer byteOrder used in the DataBuf constructor." We could avoid lots of ugly byteOrder arguments. For example, when you allocated an IFD, you store the byteOrder in the buffer itself and the code proceeds more smoothly. The byte swapping takes place in the buffer and not in the parser.

@kevinbackhouse kevinbackhouse marked this pull request as ready for review August 29, 2021 22:34
@kevinbackhouse
Copy link
Collaborator Author

@clanmills: Thanks, those are good suggestions.

  • I'll add the size_t offset=0 default parameter and do a global search and replace on all the places where I have written .c_data(0). I'll do that in this PR.
  • Do you have a suggestion for the name of the method? I added two methods named data() and c_data(). The latter returns a const pointer. (The vast majority of uses of pData_ are read-only.) Would cdata be a better name?
  • I like the idea of DataBuf having a default byte order as a constructor parameter. I think it will be easier to add that in a separate follow-up PR though.

@kevinbackhouse kevinbackhouse added this to the v1.00 milestone Sep 2, 2021
Copy link
Collaborator

@piponazo piponazo left a comment

Choose a reason for hiding this comment

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

Very nice contribution done here!

I particularly appreciate the following facts:

  • Some reinterpret_cast went away.
  • Calls to memset, memcpy, memcmp are now better encapsulated. (Maybe we can get rid of the inclusion of the cstring header in some places now).

As Robin mentioned it would be nice to try to improve the byteOrdering issue, but I agree that it would be better to handle it in a separate PR (this one is already quite big).

I made a comment about adding additional unit tests for the new code. But it can be also tackled in a separate PR. Actually, I could offer my help for that 😉

}

// Test methods like DataBuf::read_uint32 and DataBuf::write_uint32.
TEST(DataBuf, read_write_endianess)
Copy link
Collaborator

Choose a reason for hiding this comment

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

In this test you are checking the "happy" cases. It would also be good to create additional tests to check what happens on the "non-happy" ones:

  • Offset out of limits
  • passing null pointers
  • etc

@kevinbackhouse kevinbackhouse merged commit e71b99b into Exiv2:main Sep 9, 2021
@kevinbackhouse kevinbackhouse deleted the private-pData branch September 9, 2021 21:21
@clanmills
Copy link
Collaborator

It's great to see this merged. Demoting endian handling to the buffer is a different project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants