|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2009 - 2022 Deutsches Elektronen-Synchroton, |
| 2 | + * Copyright (c) 2009 - 2023 Deutsches Elektronen-Synchroton, |
3 | 3 | * Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
|
4 | 4 | *
|
5 | 5 | * This library is free software; you can redistribute it and/or modify
|
@@ -768,14 +768,26 @@ public void xdrEncodeByteBuffer(ByteBuffer buf) {
|
768 | 768 | * @param buf The buffer from which bytes are to be retrieved.
|
769 | 769 | */
|
770 | 770 | public void xdrEncodeShallowByteBuffer(ByteBuffer buf) {
|
| 771 | + var wrap = new ByteBufferWrapper(buf); |
| 772 | + wrap.allowBufferDispose(true); |
| 773 | + xdrEncodeShallowByteBuffer(wrap); |
| 774 | + } |
| 775 | + |
| 776 | + /** |
| 777 | + * A version of {@link #xdrEncodeShallowByteBuffer(ByteBuffer)} which uses Grizzly {@code buffer}. |
| 778 | + * Note: any change to the {@code buf} will cause unpredicted behavior. |
| 779 | + * |
| 780 | + * @param buf The buffer from which bytes are to be retrieved. |
| 781 | + */ |
| 782 | + public void xdrEncodeShallowByteBuffer(Buffer buf) { |
771 | 783 | int len = buf.remaining();
|
772 | 784 | int padding = (4 - (len & 3)) & 3;
|
773 | 785 | xdrEncodeInt(len);
|
774 | 786 | int ep = _buffer.position() + buf.remaining();
|
775 |
| - var b = new ByteBufferWrapper(buf); |
776 |
| - b.allowBufferDispose(true); |
| 787 | + |
777 | 788 | var composite = BuffersBuffer.create(_memoryManager);
|
778 |
| - composite.append(_buffer.slice(0, _buffer.position())).append(b); |
| 789 | + composite.allowBufferDispose(true); |
| 790 | + composite.append(_buffer.slice(0, _buffer.position())).append(buf); |
779 | 791 | composite.position(ep);
|
780 | 792 | composite.limit(ep);
|
781 | 793 |
|
|
0 commit comments