Skip to content

Commit

Permalink
xdr: do not flip byte buffer in Xdr#xdrEncodeByteBuffer
Browse files Browse the repository at this point in the history
Motivation:
The most of java API that ByteBuffer consumers use it
without flipping. It make sense to make Xdr#xdrEncodeByteBuffer to
follow that behavior to offer familiar behavior to application
developers.

Modification:
do not flip byte buffer in Xdr#xdrEncodeByteBuffer

Result:
More standard behavior.

Fixes: #62
Acked-by: Paul Millar
Target: master, 3.0
  • Loading branch information
kofemann committed May 7, 2018
1 parent 6aac14c commit fea57b0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,20 @@ org.dcache.xdr.GrizzlyXdrTransport => into org.dcache.oncrpc4j.grizzly.GrizzlyRp

org.dcache.xdr.XdrBuffer is removed. Use org.dcache.oncrpc4j.xdr.Xdr.

### Behavoir change ###

The Xdr#xdrEncodeByteBuffer changed to not flip provided byte buffer. As a result, the Xdr#xdrEncodeByteBuffer
will encode data in the buffer from buffers current position up to the limit:

```
ButeByffer buffer = ...;
Xdr xdr = ...;
buffer.put(...);
buffer.flip();
xdr.xdrEncodeByteBuffer(buffer);
```


Using RPCGEN to generate client and server stubs
------------------------------------------------
Expand Down
7 changes: 6 additions & 1 deletion oncrpc4j-core/src/main/java/org/dcache/oncrpc4j/xdr/Xdr.java
Original file line number Diff line number Diff line change
Expand Up @@ -656,9 +656,14 @@ public void xdrEncodeLong(long value) {
_buffer.putLong(value);
}

/**
* Encodes (aka "serializes") a sequence of bytes from the given buffer
* to this Xdr stream.
*
* @param buf The buffer from which bytes are to be retrieved.
*/
@Override
public void xdrEncodeByteBuffer(ByteBuffer buf) {
buf.flip();
int len = buf.remaining();
int padding = (4 - (len & 3)) & 3;
xdrEncodeInt(len);
Expand Down

0 comments on commit fea57b0

Please sign in to comment.