chrisdutz commented on code in PR #1376:
URL: https://github.com/apache/plc4x/pull/1376#discussion_r1476267349


##########
code-generation/language-java/src/main/java/org/apache/plc4x/language/java/JavaLanguageTemplateHelper.java:
##########
@@ -588,6 +591,81 @@ public String getWriteBufferWriteMethodCall(String 
logicalName, SimpleTypeRefere
         throw new FreemarkerException("Unmapped basetype" + 
simpleTypeReference.getBaseType());
     }
 
+    public boolean isRawByteArray(DiscriminatedComplexTypeDefinition 
currentCase) {
+        Optional<Field> valueFieldOptional = 
currentCase.getFields().stream().filter(field -> field.isNamedField() && 
field.asNamedField().orElseThrow().getName().equals("value")).findFirst();
+        if(valueFieldOptional.isPresent()) {
+            Field valueField = valueFieldOptional.get();
+            if(valueField.isTypedField()) {
+                TypedField typedField = 
valueField.asTypedField().orElseThrow();
+                return typedField.getType().isArrayTypeReference() && 
typedField.getType().asArrayTypeReference().orElseThrow().getElementTypeReference().isByteBased();
+            }
+        }
+        return false;
+    }
+
+    public String getDataIoPropertyValue(PropertyField propertyField) {
+        TypeReference propertyFieldType = propertyField.getType();
+        if(propertyFieldType.isSimpleTypeReference()) {
+            SimpleTypeReference simpleTypeReference = 
propertyFieldType.asSimpleTypeReference().orElseThrow();
+            switch (propertyField.getName()) {
+                case "value":
+                    return "_value.get" + 
getLanguageTypeNameForTypeReference(simpleTypeReference) + "()";
+                case "year":
+                    return "_value.getDate().getYear()";
+                case "month":
+                    return "_value.getDate().getMonthValue()";
+                case "day":
+                case "dayOfMonth":
+                    return "_value.getDate().getDayOfMonth()";
+                case "dayOfWeek":
+                    return "_value.getDate().getDayOfWeek().getValue()";
+                case "hour":
+                    return "_value.getTime().getHour()";
+                case "minutes":
+                    return "_value.getTime().getMinute()";
+                case "seconds":
+                    return "_value.getTime().getSecond()";
+                case "secondsSinceEpoch":
+                    return 
"_value.getDateTime().toEpochSecond(OffsetDateTime.now().getOffset())";
+                case "milliseconds":
+                    return "_value.getDuration().toMillis()";
+                case "millisecondsOfSecond":
+                    return "_value.getTime().get(ChronoField.MILLI_OF_SECOND)";
+                case "millisecondsSinceMidnight":
+                    if(simpleTypeReference.getSizeInBits() <= 63) {
+                        return 
"_value.getTime().getLong(ChronoField.MILLI_OF_DAY)";
+                    } else {
+                        return 
"BigInteger.valueOf(_value.getTime().getLong(ChronoField.MILLI_OF_DAY))";
+                    }
+                case "nanoseconds":
+                    if(simpleTypeReference.getSizeInBits() <= 63) {
+                        return "_value.getDuration().toNanos()";
+                    } else {
+                        return 
"BigInteger.valueOf(_value.getDuration().toNanos())";
+                    }
+                case "nanosecondsSinceMidnight":
+                    if(simpleTypeReference.getSizeInBits() <= 63) {
+                        return 
"_value.getTime().getLong(ChronoField.NANO_OF_DAY)";
+                    } else {
+                        return 
"BigInteger.valueOf(_value.getTime().getLong(ChronoField.NANO_OF_DAY))";
+                    }
+                case "nannosecondsOfSecond":
+                    if(simpleTypeReference.getSizeInBits() <= 63) {
+                        return 
"_value.getTime().getLong(ChronoField.NANO_OF_SECOND)";
+                    } else {
+                        return 
"BigInteger.valueOf(_value.getTime().getLong(ChronoField.NANO_OF_SECOND))";
+                    }
+                case "nanosecondsSinceEpoch":
+                    return 
"BigInteger.valueOf(_value.getDateTime().toEpochSecond(OffsetDateTime.now().getOffset())).multiply(BigInteger.valueOf(1000000000)).add(BigInteger.valueOf(_value.getDateTime().getNano()))";
+            }
+            if("value".equals(propertyField.getName())) {

Review Comment:
   Guess I can remove that ... historic leftover .. if propertyField.getName() 
is "value" I would have left the method in line 612



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@plc4x.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to