Skip to content

Commit 1d98aaa

Browse files
committed
xdr: introduce argument-less constructor for XdrOpaque
Motivation: To use XdrOpaque as reply from an RPC call we need to create an instance of XdrOpaque without arguments: XdrAble arg = ...; XdrOpaque reply = new XdrOpaque(); clnt.call(0, arg, reply); Modification: introduce argument-less constructor for XdrOpaque Result: XdrOpaque can be used as reply of rpc request. Acked-by: Paul Millar Target: master
1 parent a6981bf commit 1d98aaa

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

oncrpc4j-core/src/main/java/org/dcache/oncrpc4j/xdr/XdrOpaque.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2009 - 2018 Deutsches Elektronen-Synchroton,
2+
* Copyright (c) 2009 - 2019 Deutsches Elektronen-Synchroton,
33
* Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
44
*
55
* This library is free software; you can redistribute it and/or modify
@@ -33,6 +33,9 @@ public class XdrOpaque implements XdrAble {
3333

3434
private byte[] _opaque;
3535

36+
public XdrOpaque() {
37+
}
38+
3639
public XdrOpaque(byte[] opaque) {
3740
_opaque = opaque;
3841
}

oncrpc4j-core/src/test/java/org/dcache/oncrpc4j/xdr/XdrOpaqueTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,24 @@ public void testDecodeWellKnown() throws IOException {
100100
}
101101
}
102102

103+
@Test
104+
public void testDecodeWellKnownStandardConstructor() throws IOException {
105+
106+
byte[] data = new byte[]{
107+
0x0, 0x0, 0x0, 0x08, // size
108+
0x0C, 0x0A, 0x0F, 0x0E, 0x0B, 0x0A, 0x0B, 0x0E // data
109+
};
110+
111+
try ( Xdr xdr = new Xdr(data)) {
112+
xdr.beginDecoding();
113+
114+
XdrOpaque opaque = new XdrOpaque();
115+
opaque.xdrDecode(xdr);
116+
// the data part must match (e.g without size)
117+
assertArrayEquals(Arrays.copyOfRange(data, 4, 12), opaque.getOpaque());
118+
}
119+
}
120+
103121
@Test
104122
public void testEncodeWellKnown() throws IOException {
105123

0 commit comments

Comments
 (0)