11/*******************************************************************************
2- * Copyright (c) 2019-2022 Oak Ridge National Laboratory.
2+ * Copyright (c) 2019-2025 Oak Ridge National Laboratory.
33 * All rights reserved. This program and the accompanying materials
44 * are made available under the terms of the Eclipse Public License v1.0
55 * which accompanies this distribution, and is available at
1919import org .epics .pva .data .PVAInt ;
2020import org .epics .pva .data .PVAIntArray ;
2121import org .epics .pva .data .PVALongArray ;
22+ import org .epics .pva .data .PVANumber ;
2223import org .epics .pva .data .PVAShortArray ;
2324import org .epics .pva .data .PVAString ;
2425import org .epics .pva .data .PVAStructure ;
2526import org .epics .pva .data .PVAStructureArray ;
2627import org .epics .pva .data .PVAUnion ;
2728import org .epics .pva .data .PVAny ;
28- import org .epics .pvdata .pv .PVInt ;
2929import org .epics .util .array .ArrayByte ;
3030import org .epics .util .array .ArrayDouble ;
3131import org .epics .util .array .ArrayFloat ;
@@ -104,14 +104,14 @@ public static VType decode(final PVAStructure struct) throws Exception
104104 offsets = new int [n_dims ];
105105 reversed = new boolean [n_dims ];
106106 for (int i = 0 ; i < n_dims ; ++i )
107- {
107+ { // 'size' is mandatory, 'offset' and 'reverse' are optional
108108 final PVAStructure d = dim .get ()[i ];
109109 PVAInt el = d .get ("size" );
110110 dimensions [i ] = el .get ();
111111 el = d .get ("offset" );
112- offsets [i ] = el .get ();
112+ offsets [i ] = el == null ? 0 : el .get ();
113113 final PVABool b = d .get ("reverse" );
114- reversed [i ] = b .get ();
114+ reversed [i ] = b == null ? false : b .get ();
115115 }
116116 }
117117
@@ -127,9 +127,9 @@ public static VType decode(final PVAStructure struct) throws Exception
127127 {
128128 final PVAny color_mode_field = attribute .get ("value" );
129129 final PVAData cm = color_mode_field .get ();
130- if (cm instanceof PVInt )
130+ if (cm instanceof PVANumber n )
131131 {
132- colorMode = (( PVInt ) cm ). get ();
132+ colorMode = n . getNumber (). intValue ();
133133 break ;
134134 }
135135 // else: log warning, or throw exception?
@@ -192,8 +192,16 @@ else if (colorMode <= 4 && colorMode >= 2 && dimensions.length != 3)
192192 }
193193
194194 // Fetch pixel data
195- final PVAUnion value_field = struct .get ("value" );
196- PVAData value = value_field .get ();
195+ // NTNDArray is defined with 'union value',
196+ // but PVXS 'group' demo generates 'any value'
197+ final PVAData value_field = struct .get ("value" );
198+ PVAData value ;
199+ if (value_field instanceof PVAUnion vf )
200+ value = vf .get ();
201+ else if (value_field instanceof PVAny vf )
202+ value = vf .get ();
203+ else
204+ throw new Exception ("NDArray expected with value of type 'union' or 'any', got '" + value_field .getType () + "'" );
197205
198206 // Value might be compressed, which means that a PVAByteArray
199207 // needs to be de-compressed and then converted into the
0 commit comments