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

[Java] add an util method for buffer's pretty hex dump #169

Merged
merged 1 commit into from
Apr 26, 2019
Merged

[Java] add an util method for buffer's pretty hex dump #169

merged 1 commit into from
Apr 26, 2019

Conversation

QIvan
Copy link
Contributor

@QIvan QIvan commented Apr 26, 2019

hi! My colleagues had some experiments with Netty and they showed me beautiful logging of byte buffers and I thought that it would be nice to have in aeron for debug purposes.
So I adopted that code for MutableDirectBuffer
results seems like this
for buffer

final UnsafeBuffer buffer = new UnsafeBuffer(new byte[128]);

final int length = buffer.putIntAscii(INDEX, -123);

System.out.println(PrintBufferUtil.prettyHexDump(buffer));

output will be

         +-------------------------------------------------+
         |  0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f |
+--------+-------------------------------------------------+----------------+
|00000000| 00 2d 31 32 33 00 00 00 00 00 00 00 00 00 00 00 |.-123...........|
|00000010| 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
|00000020| 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
|00000030| 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
|00000040| 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
|00000050| 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
|00000060| 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
|00000070| 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
+--------+-------------------------------------------------+----------------+

or for

final byte[] testBytes = "Hello World".getBytes();
final ByteBuffer srcBuffer = ByteBuffer.allocateDirect(testBytes.length);
srcBuffer.put(testBytes).flip();

final UnsafeBuffer srcUnsafeBuffer = new UnsafeBuffer(srcBuffer);

srcUnsafeBuffer.getBytes(0, buffer, INDEX, testBytes.length);

output is

         +-------------------------------------------------+
         |  0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f |
+--------+-------------------------------------------------+----------------+
|00000000| 48 65 6c 6c 6f 20 57 6f 72 6c 64                |Hello World     |
+--------+-------------------------------------------------+----------------+

@QIvan
Copy link
Contributor Author

QIvan commented Apr 26, 2019

oh, right, I also made your build.gradle file a little bit more IDE-friendly.

@QIvan
Copy link
Contributor Author

QIvan commented Apr 26, 2019

about licence, my understanding as well as I noticed that original code is from netty project, i kept the header and your code is under the same Apache 2.0 licence there is no problems here.

@normanmaurer
Copy link

Sounds good to me 👌

Copy link

@normanmaurer normanmaurer 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 you also need to add it it to the notice file (or something similar)

* License for the specific language governing permissions and limitations
* under the License.
*/
package org.agrona;

Choose a reason for hiding this comment

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

I think you also want to add the agrona license header as well

@mjpt777 mjpt777 merged commit 9bddb2e into real-logic:master Apr 26, 2019
mjpt777 added a commit that referenced this pull request Apr 26, 2019
@QIvan
Copy link
Contributor Author

QIvan commented Apr 27, 2019

Sorry i was out of my desc, thank you @mjpt777 for the tidy up and improvements.
thanks everyone for review and merge!

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