|
15 | 15 |
|
16 | 16 | import org.eclipse.tracecompass.ctf.parser.CTFParser; |
17 | 17 | import org.eclipse.tracecompass.internal.ctf.core.event.metadata.ICommonTreeParser; |
| 18 | +import org.eclipse.tracecompass.internal.ctf.core.event.metadata.JsonStructureFieldMemberMetadataNode; |
18 | 19 | import org.eclipse.tracecompass.internal.ctf.core.event.metadata.JsonStructureFieldMetadataNode; |
19 | 20 | import org.eclipse.tracecompass.internal.ctf.core.event.metadata.ParseException; |
20 | 21 | import org.eclipse.tracecompass.internal.ctf.core.event.types.ICTFMetadataNode; |
| 22 | +import org.eclipse.tracecompass.internal.ctf.core.utils.JsonMetadataStrings; |
| 23 | + |
| 24 | +import com.google.gson.JsonElement; |
| 25 | +import com.google.gson.JsonObject; |
21 | 26 |
|
22 | 27 | /** |
23 | 28 | * Alignment parser, we define byte-packed types as aligned on the byte size, |
@@ -91,13 +96,35 @@ public Long parse(ICTFMetadataNode tree, ICommonTreeParserParameter param) throw |
91 | 96 | } |
92 | 97 |
|
93 | 98 | return alignment; |
94 | | - } else if (tree instanceof JsonStructureFieldMetadataNode) { |
95 | | - long alignment = ((JsonStructureFieldMetadataNode) tree).getMinimumAlignment(); |
| 99 | + } else if (tree instanceof JsonStructureFieldMetadataNode structTree) { |
| 100 | + long alignment = structTree.getMinimumAlignment(); |
| 101 | + |
96 | 102 | if (!isValidAlignment(alignment)) { |
97 | 103 | throw new ParseException(INVALID_VALUE_FOR_ALIGNMENT + " : " //$NON-NLS-1$ |
98 | 104 | + alignment); |
99 | 105 | } |
100 | 106 | return alignment; |
| 107 | + } else if (tree instanceof JsonStructureFieldMemberMetadataNode structTree) { |
| 108 | + JsonElement fieldClassElement = structTree.getFieldClass(); |
| 109 | + if (fieldClassElement == null || !fieldClassElement.isJsonObject()) { |
| 110 | + throw new ParseException(getClass().getName() + " fieldclass must be a json object."); //$NON-NLS-1$ |
| 111 | + } |
| 112 | + JsonObject fieldclass = fieldClassElement.getAsJsonObject(); |
| 113 | + if (fieldclass.has(JsonMetadataStrings.ALIGNMENT)) { |
| 114 | + JsonElement alignmentElement = fieldclass.get(JsonMetadataStrings.ALIGNMENT); |
| 115 | + if (alignmentElement == null || !alignmentElement.isJsonPrimitive()) { |
| 116 | + throw new ParseException(INVALID_VALUE_FOR_ALIGNMENT + " : " //$NON-NLS-1$ |
| 117 | + + alignmentElement); |
| 118 | + } |
| 119 | + long alignment = alignmentElement.getAsLong(); |
| 120 | + if (!isValidAlignment(alignment)) { |
| 121 | + throw new ParseException(INVALID_VALUE_FOR_ALIGNMENT + " : " //$NON-NLS-1$ |
| 122 | + + alignment); |
| 123 | + } |
| 124 | + return alignment; |
| 125 | + } |
| 126 | + // Return default alignment when not specified |
| 127 | + return 1L; |
101 | 128 | } |
102 | 129 |
|
103 | 130 | throw new ParseException(INVALID_VALUE_FOR_ALIGNMENT); // $NON-NLS-1$ |
|
0 commit comments