From a2eb02ec647a4581c15de4d7ff282ec37e991d27 Mon Sep 17 00:00:00 2001 From: Alex Karpovich Date: Fri, 29 May 2026 22:07:02 +0300 Subject: [PATCH] [*] fix warnings --- LICENSE | 2 +- .../deltix/qsrv/hf/pub/codec/FieldLayout.java | 9 +- .../qsrv/hf/pub/Test_RecordCodecsTime.java | 83 +++++++++++++++++++ 3 files changed, 90 insertions(+), 4 deletions(-) create mode 100644 java/timebase/test/src/test/java/com/epam/deltix/test/qsrv/hf/pub/Test_RecordCodecsTime.java diff --git a/LICENSE b/LICENSE index 40b83f5e..65e30c9f 100644 --- a/LICENSE +++ b/LICENSE @@ -186,7 +186,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright 2023 EPAM Systems, Inc. + Copyright 2026 EPAM Systems, Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/java/timebase/pub/src/main/java/com/epam/deltix/qsrv/hf/pub/codec/FieldLayout.java b/java/timebase/pub/src/main/java/com/epam/deltix/qsrv/hf/pub/codec/FieldLayout.java index f89b2548..186ab094 100644 --- a/java/timebase/pub/src/main/java/com/epam/deltix/qsrv/hf/pub/codec/FieldLayout.java +++ b/java/timebase/pub/src/main/java/com/epam/deltix/qsrv/hf/pub/codec/FieldLayout.java @@ -24,6 +24,7 @@ import com.epam.deltix.qsrv.hf.pub.md.*; import com.epam.deltix.timebase.messages.SchemaElement; import com.epam.deltix.timebase.messages.SchemaIgnore; +import com.epam.deltix.util.annotations.TimestampNs; import com.epam.deltix.util.collections.generated.ObjectArrayList; import com.epam.deltix.util.lang.Util; @@ -217,7 +218,7 @@ private boolean searchPublicProperties (Class cls) throws NoSuchFieldExceptio // setter/getter for the nanoseconds precision has suffix "Ns" try { if (field.getType() instanceof DateTimeDataType && ((DateTimeDataType) field.getType()).hasNanosecondPrecision()) { - if (!method.getName().endsWith(fieldName + "Ns")) + if (method.getAnnotation(TimestampNs.class) == null) method = cls.getMethod(method.getName() + "Ns"); } } catch (NoSuchMethodException e) { @@ -240,8 +241,10 @@ private boolean searchPublicProperties (Class cls) throws NoSuchFieldExceptio if (schemaElement != null && isValidGetterJavaBeanNotation(method, fieldName, isBooleanField)) { // setter/getter for the nanoseconds precision has suffix "Ns" try { - if (field.getType() instanceof DateTimeDataType && ((DateTimeDataType) field.getType()).hasNanosecondPrecision()) - method = cls.getMethod(method.getName() + "Ns"); + if (field.getType() instanceof DateTimeDataType && ((DateTimeDataType) field.getType()).hasNanosecondPrecision()) { + if (method.getAnnotation(TimestampNs.class) == null) + method = cls.getMethod(method.getName() + "Ns"); + } } catch (NoSuchMethodException e) { LOG.warn("Nanosecond getter with name \"" + (method.getName() + "Ns") + "\" is not found in class " + cls); } diff --git a/java/timebase/test/src/test/java/com/epam/deltix/test/qsrv/hf/pub/Test_RecordCodecsTime.java b/java/timebase/test/src/test/java/com/epam/deltix/test/qsrv/hf/pub/Test_RecordCodecsTime.java new file mode 100644 index 00000000..cb3b77a1 --- /dev/null +++ b/java/timebase/test/src/test/java/com/epam/deltix/test/qsrv/hf/pub/Test_RecordCodecsTime.java @@ -0,0 +1,83 @@ +package com.epam.deltix.test.qsrv.hf.pub; + +import com.epam.deltix.qsrv.hf.pub.codec.CodecFactory; +import com.epam.deltix.qsrv.hf.pub.md.Introspector; +import com.epam.deltix.qsrv.hf.pub.md.RecordClassDescriptor; +import com.epam.deltix.timebase.messages.InstrumentMessage; +import com.epam.deltix.timebase.messages.*; +import com.epam.deltix.util.annotations.TimestampNs; +import com.epam.deltix.util.memory.MemoryDataInput; +import com.epam.deltix.util.memory.MemoryDataOutput; +import org.junit.Test; + +import static com.epam.deltix.qsrv.hf.pub.md.Introspector.*; +import static org.junit.Assert.assertEquals; + +public class Test_RecordCodecsTime { + + public static class TestMessage extends InstrumentMessage { + + @TimestampNs + private long customTime; + + public TestMessage() { + } + + @SchemaType(encoding = "NANOSECOND",dataType = SchemaDataType.TIMESTAMP) + @SchemaElement(name="customTime") + @TimestampNs + public long getCustomTime() { + return customTime; + } + + public void setCustomTime(@TimestampNs long customTime) { + this.customTime = customTime; + } + } + + private CodecFactory factory; + + private void setUpComp () { + factory = CodecFactory.newCompiledCachingFactory(); + } + + private void setUpIntp () { + factory = CodecFactory.newInterpretingCachingFactory(); + } + + @Test + public void testInterpretted () throws Exception { + setUpIntp(); + testAllTypeFields(); + } + + @Test + public void testCompiled () throws Exception { + setUpIntp(); + testAllTypeFields(); + } + + private void testAllTypeFields () throws Exception { + //final RecordClassDescriptor rcd = Test_RecordCodecsBase.getRCD(TestMessage.class); + final TestMessage msg = new TestMessage(); + + msg.setCustomTime(123456789L); + TestMessage decoded = (TestMessage)encodeDecode(msg, TestMessage.class); + assertEquals(123456789L, decoded.getCustomTime()); + + } + + private InstrumentMessage encodeDecode(InstrumentMessage msg, Class outClass) throws IntrospectionException { + + RecordClassDescriptor rcd = (RecordClassDescriptor) introspectSingleClass(msg.getClass()); + + MemoryDataOutput out = new MemoryDataOutput(); + factory.createFixedBoundEncoder(cd -> msg.getClass(), rcd).encode(msg, out); + + MemoryDataInput in = new MemoryDataInput(out); + return (InstrumentMessage) factory.createFixedBoundDecoder( + cd -> outClass, rcd).decode(in); + + } + +}