From d1507756a5b8367853e238a8be6ca857efb546b6 Mon Sep 17 00:00:00 2001 From: canonical Date: Sat, 28 Sep 2024 20:59:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0writeObjectWithCodec?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...FieldBinaryCodec_{wordType.name}.java.xgen | 4 +- .../nop/record/codec/IFieldBinaryCodec.java | 10 +- .../nop/record/codec/IFieldBinaryDecoder.java | 11 + .../nop/record/codec/IFieldBinaryEncoder.java | 11 + .../io/nop/record/codec/IFieldTextCodec.java | 7 +- .../nop/record/codec/IFieldTextDecoder.java | 7 + .../nop/record/codec/IFieldTextEncoder.java | 7 + .../codec/_gen/FieldBinaryCodec_f4be.java | 4 +- .../codec/_gen/FieldBinaryCodec_f4le.java | 4 +- .../codec/_gen/FieldBinaryCodec_f8be.java | 4 +- .../codec/_gen/FieldBinaryCodec_f8le.java | 4 +- .../codec/_gen/FieldBinaryCodec_s1.java | 4 +- .../codec/_gen/FieldBinaryCodec_s2be.java | 4 +- .../codec/_gen/FieldBinaryCodec_s2le.java | 4 +- .../codec/_gen/FieldBinaryCodec_s4be.java | 4 +- .../codec/_gen/FieldBinaryCodec_s4le.java | 4 +- .../codec/_gen/FieldBinaryCodec_s8be.java | 4 +- .../codec/_gen/FieldBinaryCodec_s8le.java | 4 +- .../codec/_gen/FieldBinaryCodec_u1.java | 4 +- .../codec/_gen/FieldBinaryCodec_u2be.java | 4 +- .../codec/_gen/FieldBinaryCodec_u2le.java | 4 +- .../codec/_gen/FieldBinaryCodec_u4be.java | 4 +- .../codec/_gen/FieldBinaryCodec_u4le.java | 4 +- .../codec/_gen/FieldBinaryCodec_u8be.java | 4 +- .../codec/_gen/FieldBinaryCodec_u8le.java | 4 +- .../record/codec/impl/BeanBinaryCodec.java | 6 +- .../codec/impl/CountArrayBinaryCodec.java | 8 +- .../codec/impl/DynCountArrayBinaryCodec.java | 51 ++++ .../codec/impl/DynLVFieldBinaryCodec.java | 47 +++ .../record/codec/impl/LVFieldBinaryCodec.java | 7 +- .../model/_gen/_RecordAggregateFieldMeta.java | 88 +----- .../record/model/_gen/_RecordFieldMeta.java | 124 +------- .../record/model/_gen/_RecordFieldSwitch.java | 34 +-- .../model/_gen/_RecordFileBodyMeta.java | 46 +-- .../record/model/_gen/_RecordFileMeta.java | 134 ++++----- .../record/model/_gen/_RecordObjectMeta.java | 128 +++----- .../model/_gen/_RecordSimpleFieldMeta.java | 282 ++++++------------ .../AbstractModelBasedRecordOutput.java | 22 +- .../ModelBasedBinaryRecordOutput.java | 16 +- .../resource/ModelBasedTextRecordOutput.java | 17 +- 40 files changed, 475 insertions(+), 664 deletions(-) create mode 100644 nop-record/src/main/java/io/nop/record/codec/IFieldBinaryDecoder.java create mode 100644 nop-record/src/main/java/io/nop/record/codec/IFieldBinaryEncoder.java create mode 100644 nop-record/src/main/java/io/nop/record/codec/IFieldTextDecoder.java create mode 100644 nop-record/src/main/java/io/nop/record/codec/IFieldTextEncoder.java create mode 100644 nop-record/src/main/java/io/nop/record/codec/impl/DynCountArrayBinaryCodec.java create mode 100644 nop-record/src/main/java/io/nop/record/codec/impl/DynLVFieldBinaryCodec.java diff --git a/nop-record/precompile/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_{wordType.name}.java.xgen b/nop-record/precompile/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_{wordType.name}.java.xgen index 4844e44b4..f725de37d 100644 --- a/nop-record/precompile/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_{wordType.name}.java.xgen +++ b/nop-record/precompile/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_{wordType.name}.java.xgen @@ -2,6 +2,7 @@ package io.nop.record.codec._gen; import io.nop.record.codec.IFieldBinaryCodec; +import io.nop.record.codec.IFieldBinaryEncoder; import io.nop.record.codec.IFieldCodecContext; import io.nop.record.input.IRecordBinaryInput; import io.nop.record.output.IRecordBinaryOutput; @@ -15,7 +16,8 @@ public class FieldBinaryCodec_${wordType.name} implements IFieldBinaryCodec{ return input.read${wordType.name.$capitalize()}(); } - public void encode(IRecordBinaryOutput output, Object value, int length, Charset charset, IFieldCodecContext context){ + public void encode(IRecordBinaryOutput output, Object value, int length, Charset charset, + IFieldCodecContext context, IFieldBinaryEncoder bodyEncoder){ if(value == null){ output.write${wordType.name.$capitalize()}(${wordType.obj.defaultValueInitializer}); }else{ diff --git a/nop-record/src/main/java/io/nop/record/codec/IFieldBinaryCodec.java b/nop-record/src/main/java/io/nop/record/codec/IFieldBinaryCodec.java index 2d0df2bb8..c093f2206 100644 --- a/nop-record/src/main/java/io/nop/record/codec/IFieldBinaryCodec.java +++ b/nop-record/src/main/java/io/nop/record/codec/IFieldBinaryCodec.java @@ -7,13 +7,5 @@ */ package io.nop.record.codec; -import io.nop.record.input.IRecordBinaryInput; -import io.nop.record.output.IRecordBinaryOutput; - -import java.nio.charset.Charset; - -public interface IFieldBinaryCodec { - Object decode(IRecordBinaryInput input, int length, Charset charset, IFieldCodecContext context); - - void encode(IRecordBinaryOutput output, Object value, int length, Charset charset, IFieldCodecContext context); +public interface IFieldBinaryCodec extends IFieldBinaryEncoder, IFieldBinaryDecoder { } \ No newline at end of file diff --git a/nop-record/src/main/java/io/nop/record/codec/IFieldBinaryDecoder.java b/nop-record/src/main/java/io/nop/record/codec/IFieldBinaryDecoder.java new file mode 100644 index 000000000..2aa67bf6c --- /dev/null +++ b/nop-record/src/main/java/io/nop/record/codec/IFieldBinaryDecoder.java @@ -0,0 +1,11 @@ +package io.nop.record.codec; + +import io.nop.record.input.IRecordBinaryInput; + +import java.nio.charset.Charset; + +public interface IFieldBinaryDecoder { + + Object decode(IRecordBinaryInput input, int length, Charset charset, IFieldCodecContext context); + +} diff --git a/nop-record/src/main/java/io/nop/record/codec/IFieldBinaryEncoder.java b/nop-record/src/main/java/io/nop/record/codec/IFieldBinaryEncoder.java new file mode 100644 index 000000000..c922ce3b8 --- /dev/null +++ b/nop-record/src/main/java/io/nop/record/codec/IFieldBinaryEncoder.java @@ -0,0 +1,11 @@ +package io.nop.record.codec; + +import io.nop.record.output.IRecordBinaryOutput; + +import java.nio.charset.Charset; + +public interface IFieldBinaryEncoder { + + void encode(IRecordBinaryOutput output, Object value, int length, Charset charset, + IFieldCodecContext context, IFieldBinaryEncoder bodyEncoder); +} diff --git a/nop-record/src/main/java/io/nop/record/codec/IFieldTextCodec.java b/nop-record/src/main/java/io/nop/record/codec/IFieldTextCodec.java index a733e18c6..41509a954 100644 --- a/nop-record/src/main/java/io/nop/record/codec/IFieldTextCodec.java +++ b/nop-record/src/main/java/io/nop/record/codec/IFieldTextCodec.java @@ -7,11 +7,6 @@ */ package io.nop.record.codec; -import io.nop.record.input.IRecordTextInput; -import io.nop.record.output.IRecordTextOutput; +public interface IFieldTextCodec extends IFieldTextEncoder, IFieldTextDecoder { -public interface IFieldTextCodec { - Object decode(IRecordTextInput input, int length, IFieldCodecContext context); - - void encode(IRecordTextOutput output, Object value, int length, IFieldCodecContext context); } \ No newline at end of file diff --git a/nop-record/src/main/java/io/nop/record/codec/IFieldTextDecoder.java b/nop-record/src/main/java/io/nop/record/codec/IFieldTextDecoder.java new file mode 100644 index 000000000..7db34263b --- /dev/null +++ b/nop-record/src/main/java/io/nop/record/codec/IFieldTextDecoder.java @@ -0,0 +1,7 @@ +package io.nop.record.codec; + +import io.nop.record.input.IRecordTextInput; + +public interface IFieldTextDecoder { + Object decode(IRecordTextInput input, int length, IFieldCodecContext context); +} diff --git a/nop-record/src/main/java/io/nop/record/codec/IFieldTextEncoder.java b/nop-record/src/main/java/io/nop/record/codec/IFieldTextEncoder.java new file mode 100644 index 000000000..4f00769c9 --- /dev/null +++ b/nop-record/src/main/java/io/nop/record/codec/IFieldTextEncoder.java @@ -0,0 +1,7 @@ +package io.nop.record.codec; + +import io.nop.record.output.IRecordTextOutput; + +public interface IFieldTextEncoder { + void encode(IRecordTextOutput output, Object value, int length, IFieldCodecContext context, IFieldTextEncoder bodyEncoder); +} diff --git a/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_f4be.java b/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_f4be.java index ac12b5792..976e3d0f4 100644 --- a/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_f4be.java +++ b/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_f4be.java @@ -2,6 +2,7 @@ package io.nop.record.codec._gen; import io.nop.record.codec.IFieldBinaryCodec; +import io.nop.record.codec.IFieldBinaryEncoder; import io.nop.record.codec.IFieldCodecContext; import io.nop.record.input.IRecordBinaryInput; import io.nop.record.output.IRecordBinaryOutput; @@ -15,7 +16,8 @@ public Object decode(IRecordBinaryInput input, int length, Charset charset, IFie return input.readF4be(); } - public void encode(IRecordBinaryOutput output, Object value, int length, Charset charset, IFieldCodecContext context){ + public void encode(IRecordBinaryOutput output, Object value, int length, Charset charset, + IFieldCodecContext context, IFieldBinaryEncoder bodyEncoder){ if(value == null){ output.writeF4be(0.0f); }else{ diff --git a/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_f4le.java b/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_f4le.java index af6c25014..dfa290868 100644 --- a/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_f4le.java +++ b/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_f4le.java @@ -2,6 +2,7 @@ package io.nop.record.codec._gen; import io.nop.record.codec.IFieldBinaryCodec; +import io.nop.record.codec.IFieldBinaryEncoder; import io.nop.record.codec.IFieldCodecContext; import io.nop.record.input.IRecordBinaryInput; import io.nop.record.output.IRecordBinaryOutput; @@ -15,7 +16,8 @@ public Object decode(IRecordBinaryInput input, int length, Charset charset, IFie return input.readF4le(); } - public void encode(IRecordBinaryOutput output, Object value, int length, Charset charset, IFieldCodecContext context){ + public void encode(IRecordBinaryOutput output, Object value, int length, Charset charset, + IFieldCodecContext context, IFieldBinaryEncoder bodyEncoder){ if(value == null){ output.writeF4le(0.0f); }else{ diff --git a/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_f8be.java b/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_f8be.java index 79f722247..6efb9eb52 100644 --- a/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_f8be.java +++ b/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_f8be.java @@ -2,6 +2,7 @@ package io.nop.record.codec._gen; import io.nop.record.codec.IFieldBinaryCodec; +import io.nop.record.codec.IFieldBinaryEncoder; import io.nop.record.codec.IFieldCodecContext; import io.nop.record.input.IRecordBinaryInput; import io.nop.record.output.IRecordBinaryOutput; @@ -15,7 +16,8 @@ public Object decode(IRecordBinaryInput input, int length, Charset charset, IFie return input.readF8be(); } - public void encode(IRecordBinaryOutput output, Object value, int length, Charset charset, IFieldCodecContext context){ + public void encode(IRecordBinaryOutput output, Object value, int length, Charset charset, + IFieldCodecContext context, IFieldBinaryEncoder bodyEncoder){ if(value == null){ output.writeF8be(0.0); }else{ diff --git a/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_f8le.java b/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_f8le.java index 64d9f877e..c0858c8f6 100644 --- a/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_f8le.java +++ b/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_f8le.java @@ -2,6 +2,7 @@ package io.nop.record.codec._gen; import io.nop.record.codec.IFieldBinaryCodec; +import io.nop.record.codec.IFieldBinaryEncoder; import io.nop.record.codec.IFieldCodecContext; import io.nop.record.input.IRecordBinaryInput; import io.nop.record.output.IRecordBinaryOutput; @@ -15,7 +16,8 @@ public Object decode(IRecordBinaryInput input, int length, Charset charset, IFie return input.readF8le(); } - public void encode(IRecordBinaryOutput output, Object value, int length, Charset charset, IFieldCodecContext context){ + public void encode(IRecordBinaryOutput output, Object value, int length, Charset charset, + IFieldCodecContext context, IFieldBinaryEncoder bodyEncoder){ if(value == null){ output.writeF8le(0.0); }else{ diff --git a/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_s1.java b/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_s1.java index 97d3fc0de..7939f9ef9 100644 --- a/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_s1.java +++ b/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_s1.java @@ -2,6 +2,7 @@ package io.nop.record.codec._gen; import io.nop.record.codec.IFieldBinaryCodec; +import io.nop.record.codec.IFieldBinaryEncoder; import io.nop.record.codec.IFieldCodecContext; import io.nop.record.input.IRecordBinaryInput; import io.nop.record.output.IRecordBinaryOutput; @@ -15,7 +16,8 @@ public Object decode(IRecordBinaryInput input, int length, Charset charset, IFie return input.readS1(); } - public void encode(IRecordBinaryOutput output, Object value, int length, Charset charset, IFieldCodecContext context){ + public void encode(IRecordBinaryOutput output, Object value, int length, Charset charset, + IFieldCodecContext context, IFieldBinaryEncoder bodyEncoder){ if(value == null){ output.writeS1((byte) 0); }else{ diff --git a/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_s2be.java b/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_s2be.java index 04ff9e1bc..320c84ba9 100644 --- a/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_s2be.java +++ b/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_s2be.java @@ -2,6 +2,7 @@ package io.nop.record.codec._gen; import io.nop.record.codec.IFieldBinaryCodec; +import io.nop.record.codec.IFieldBinaryEncoder; import io.nop.record.codec.IFieldCodecContext; import io.nop.record.input.IRecordBinaryInput; import io.nop.record.output.IRecordBinaryOutput; @@ -15,7 +16,8 @@ public Object decode(IRecordBinaryInput input, int length, Charset charset, IFie return input.readS2be(); } - public void encode(IRecordBinaryOutput output, Object value, int length, Charset charset, IFieldCodecContext context){ + public void encode(IRecordBinaryOutput output, Object value, int length, Charset charset, + IFieldCodecContext context, IFieldBinaryEncoder bodyEncoder){ if(value == null){ output.writeS2be((short) 0); }else{ diff --git a/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_s2le.java b/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_s2le.java index 532a0e55d..92bde1953 100644 --- a/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_s2le.java +++ b/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_s2le.java @@ -2,6 +2,7 @@ package io.nop.record.codec._gen; import io.nop.record.codec.IFieldBinaryCodec; +import io.nop.record.codec.IFieldBinaryEncoder; import io.nop.record.codec.IFieldCodecContext; import io.nop.record.input.IRecordBinaryInput; import io.nop.record.output.IRecordBinaryOutput; @@ -15,7 +16,8 @@ public Object decode(IRecordBinaryInput input, int length, Charset charset, IFie return input.readS2le(); } - public void encode(IRecordBinaryOutput output, Object value, int length, Charset charset, IFieldCodecContext context){ + public void encode(IRecordBinaryOutput output, Object value, int length, Charset charset, + IFieldCodecContext context, IFieldBinaryEncoder bodyEncoder){ if(value == null){ output.writeS2le((short) 0); }else{ diff --git a/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_s4be.java b/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_s4be.java index aa7a421ba..52c7efb5c 100644 --- a/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_s4be.java +++ b/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_s4be.java @@ -2,6 +2,7 @@ package io.nop.record.codec._gen; import io.nop.record.codec.IFieldBinaryCodec; +import io.nop.record.codec.IFieldBinaryEncoder; import io.nop.record.codec.IFieldCodecContext; import io.nop.record.input.IRecordBinaryInput; import io.nop.record.output.IRecordBinaryOutput; @@ -15,7 +16,8 @@ public Object decode(IRecordBinaryInput input, int length, Charset charset, IFie return input.readS4be(); } - public void encode(IRecordBinaryOutput output, Object value, int length, Charset charset, IFieldCodecContext context){ + public void encode(IRecordBinaryOutput output, Object value, int length, Charset charset, + IFieldCodecContext context, IFieldBinaryEncoder bodyEncoder){ if(value == null){ output.writeS4be(0); }else{ diff --git a/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_s4le.java b/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_s4le.java index 2a887667e..5c802715f 100644 --- a/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_s4le.java +++ b/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_s4le.java @@ -2,6 +2,7 @@ package io.nop.record.codec._gen; import io.nop.record.codec.IFieldBinaryCodec; +import io.nop.record.codec.IFieldBinaryEncoder; import io.nop.record.codec.IFieldCodecContext; import io.nop.record.input.IRecordBinaryInput; import io.nop.record.output.IRecordBinaryOutput; @@ -15,7 +16,8 @@ public Object decode(IRecordBinaryInput input, int length, Charset charset, IFie return input.readS4le(); } - public void encode(IRecordBinaryOutput output, Object value, int length, Charset charset, IFieldCodecContext context){ + public void encode(IRecordBinaryOutput output, Object value, int length, Charset charset, + IFieldCodecContext context, IFieldBinaryEncoder bodyEncoder){ if(value == null){ output.writeS4le(0); }else{ diff --git a/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_s8be.java b/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_s8be.java index 01b81c9fc..1d4ae0fed 100644 --- a/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_s8be.java +++ b/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_s8be.java @@ -2,6 +2,7 @@ package io.nop.record.codec._gen; import io.nop.record.codec.IFieldBinaryCodec; +import io.nop.record.codec.IFieldBinaryEncoder; import io.nop.record.codec.IFieldCodecContext; import io.nop.record.input.IRecordBinaryInput; import io.nop.record.output.IRecordBinaryOutput; @@ -15,7 +16,8 @@ public Object decode(IRecordBinaryInput input, int length, Charset charset, IFie return input.readS8be(); } - public void encode(IRecordBinaryOutput output, Object value, int length, Charset charset, IFieldCodecContext context){ + public void encode(IRecordBinaryOutput output, Object value, int length, Charset charset, + IFieldCodecContext context, IFieldBinaryEncoder bodyEncoder){ if(value == null){ output.writeS8be(0L); }else{ diff --git a/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_s8le.java b/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_s8le.java index 7740d40f4..26ce31bd2 100644 --- a/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_s8le.java +++ b/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_s8le.java @@ -2,6 +2,7 @@ package io.nop.record.codec._gen; import io.nop.record.codec.IFieldBinaryCodec; +import io.nop.record.codec.IFieldBinaryEncoder; import io.nop.record.codec.IFieldCodecContext; import io.nop.record.input.IRecordBinaryInput; import io.nop.record.output.IRecordBinaryOutput; @@ -15,7 +16,8 @@ public Object decode(IRecordBinaryInput input, int length, Charset charset, IFie return input.readS8le(); } - public void encode(IRecordBinaryOutput output, Object value, int length, Charset charset, IFieldCodecContext context){ + public void encode(IRecordBinaryOutput output, Object value, int length, Charset charset, + IFieldCodecContext context, IFieldBinaryEncoder bodyEncoder){ if(value == null){ output.writeS8le(0L); }else{ diff --git a/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_u1.java b/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_u1.java index 8122a87c7..b93007fb6 100644 --- a/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_u1.java +++ b/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_u1.java @@ -2,6 +2,7 @@ package io.nop.record.codec._gen; import io.nop.record.codec.IFieldBinaryCodec; +import io.nop.record.codec.IFieldBinaryEncoder; import io.nop.record.codec.IFieldCodecContext; import io.nop.record.input.IRecordBinaryInput; import io.nop.record.output.IRecordBinaryOutput; @@ -15,7 +16,8 @@ public Object decode(IRecordBinaryInput input, int length, Charset charset, IFie return input.readU1(); } - public void encode(IRecordBinaryOutput output, Object value, int length, Charset charset, IFieldCodecContext context){ + public void encode(IRecordBinaryOutput output, Object value, int length, Charset charset, + IFieldCodecContext context, IFieldBinaryEncoder bodyEncoder){ if(value == null){ output.writeU1((short) 0); }else{ diff --git a/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_u2be.java b/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_u2be.java index 158cf20e8..e8720b30d 100644 --- a/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_u2be.java +++ b/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_u2be.java @@ -2,6 +2,7 @@ package io.nop.record.codec._gen; import io.nop.record.codec.IFieldBinaryCodec; +import io.nop.record.codec.IFieldBinaryEncoder; import io.nop.record.codec.IFieldCodecContext; import io.nop.record.input.IRecordBinaryInput; import io.nop.record.output.IRecordBinaryOutput; @@ -15,7 +16,8 @@ public Object decode(IRecordBinaryInput input, int length, Charset charset, IFie return input.readU2be(); } - public void encode(IRecordBinaryOutput output, Object value, int length, Charset charset, IFieldCodecContext context){ + public void encode(IRecordBinaryOutput output, Object value, int length, Charset charset, + IFieldCodecContext context, IFieldBinaryEncoder bodyEncoder){ if(value == null){ output.writeU2be(0); }else{ diff --git a/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_u2le.java b/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_u2le.java index 568ed53ef..d25d9078b 100644 --- a/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_u2le.java +++ b/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_u2le.java @@ -2,6 +2,7 @@ package io.nop.record.codec._gen; import io.nop.record.codec.IFieldBinaryCodec; +import io.nop.record.codec.IFieldBinaryEncoder; import io.nop.record.codec.IFieldCodecContext; import io.nop.record.input.IRecordBinaryInput; import io.nop.record.output.IRecordBinaryOutput; @@ -15,7 +16,8 @@ public Object decode(IRecordBinaryInput input, int length, Charset charset, IFie return input.readU2le(); } - public void encode(IRecordBinaryOutput output, Object value, int length, Charset charset, IFieldCodecContext context){ + public void encode(IRecordBinaryOutput output, Object value, int length, Charset charset, + IFieldCodecContext context, IFieldBinaryEncoder bodyEncoder){ if(value == null){ output.writeU2le(0); }else{ diff --git a/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_u4be.java b/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_u4be.java index 93865064b..821ffdfc4 100644 --- a/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_u4be.java +++ b/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_u4be.java @@ -2,6 +2,7 @@ package io.nop.record.codec._gen; import io.nop.record.codec.IFieldBinaryCodec; +import io.nop.record.codec.IFieldBinaryEncoder; import io.nop.record.codec.IFieldCodecContext; import io.nop.record.input.IRecordBinaryInput; import io.nop.record.output.IRecordBinaryOutput; @@ -15,7 +16,8 @@ public Object decode(IRecordBinaryInput input, int length, Charset charset, IFie return input.readU4be(); } - public void encode(IRecordBinaryOutput output, Object value, int length, Charset charset, IFieldCodecContext context){ + public void encode(IRecordBinaryOutput output, Object value, int length, Charset charset, + IFieldCodecContext context, IFieldBinaryEncoder bodyEncoder){ if(value == null){ output.writeU4be(0L); }else{ diff --git a/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_u4le.java b/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_u4le.java index c8edf7404..5aaa4d6c1 100644 --- a/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_u4le.java +++ b/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_u4le.java @@ -2,6 +2,7 @@ package io.nop.record.codec._gen; import io.nop.record.codec.IFieldBinaryCodec; +import io.nop.record.codec.IFieldBinaryEncoder; import io.nop.record.codec.IFieldCodecContext; import io.nop.record.input.IRecordBinaryInput; import io.nop.record.output.IRecordBinaryOutput; @@ -15,7 +16,8 @@ public Object decode(IRecordBinaryInput input, int length, Charset charset, IFie return input.readU4le(); } - public void encode(IRecordBinaryOutput output, Object value, int length, Charset charset, IFieldCodecContext context){ + public void encode(IRecordBinaryOutput output, Object value, int length, Charset charset, + IFieldCodecContext context, IFieldBinaryEncoder bodyEncoder){ if(value == null){ output.writeU4le(0L); }else{ diff --git a/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_u8be.java b/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_u8be.java index 6b180abfc..321edb2d4 100644 --- a/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_u8be.java +++ b/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_u8be.java @@ -2,6 +2,7 @@ package io.nop.record.codec._gen; import io.nop.record.codec.IFieldBinaryCodec; +import io.nop.record.codec.IFieldBinaryEncoder; import io.nop.record.codec.IFieldCodecContext; import io.nop.record.input.IRecordBinaryInput; import io.nop.record.output.IRecordBinaryOutput; @@ -15,7 +16,8 @@ public Object decode(IRecordBinaryInput input, int length, Charset charset, IFie return input.readU8be(); } - public void encode(IRecordBinaryOutput output, Object value, int length, Charset charset, IFieldCodecContext context){ + public void encode(IRecordBinaryOutput output, Object value, int length, Charset charset, + IFieldCodecContext context, IFieldBinaryEncoder bodyEncoder){ if(value == null){ output.writeU8be(0L); }else{ diff --git a/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_u8le.java b/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_u8le.java index 01b7b0b58..12be4e74c 100644 --- a/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_u8le.java +++ b/nop-record/src/main/java/io/nop/record/codec/_gen/FieldBinaryCodec_u8le.java @@ -2,6 +2,7 @@ package io.nop.record.codec._gen; import io.nop.record.codec.IFieldBinaryCodec; +import io.nop.record.codec.IFieldBinaryEncoder; import io.nop.record.codec.IFieldCodecContext; import io.nop.record.input.IRecordBinaryInput; import io.nop.record.output.IRecordBinaryOutput; @@ -15,7 +16,8 @@ public Object decode(IRecordBinaryInput input, int length, Charset charset, IFie return input.readU8le(); } - public void encode(IRecordBinaryOutput output, Object value, int length, Charset charset, IFieldCodecContext context){ + public void encode(IRecordBinaryOutput output, Object value, int length, Charset charset, + IFieldCodecContext context, IFieldBinaryEncoder bodyEncoder){ if(value == null){ output.writeU8le(0L); }else{ diff --git a/nop-record/src/main/java/io/nop/record/codec/impl/BeanBinaryCodec.java b/nop-record/src/main/java/io/nop/record/codec/impl/BeanBinaryCodec.java index 8069d483f..0986853a1 100644 --- a/nop-record/src/main/java/io/nop/record/codec/impl/BeanBinaryCodec.java +++ b/nop-record/src/main/java/io/nop/record/codec/impl/BeanBinaryCodec.java @@ -5,6 +5,7 @@ import io.nop.core.reflect.IPropertySetter; import io.nop.core.reflect.bean.IBeanConstructor; import io.nop.record.codec.IFieldBinaryCodec; +import io.nop.record.codec.IFieldBinaryEncoder; import io.nop.record.codec.IFieldCodecContext; import io.nop.record.input.IRecordBinaryInput; import io.nop.record.output.IRecordBinaryOutput; @@ -54,10 +55,11 @@ public Object decode(IRecordBinaryInput input, int length, Charset charset, IFie } @Override - public void encode(IRecordBinaryOutput output, Object bean, int length, Charset charset, IFieldCodecContext context) { + public void encode(IRecordBinaryOutput output, Object bean, int length, Charset charset, + IFieldCodecContext context, IFieldBinaryEncoder bodyEncoder) { for (PropCodec prop : props) { Object value = prop.getter.getProperty(bean, prop.name, DisabledEvalScope.INSTANCE); - prop.codec.encode(output, value, prop.length, prop.charset, context); + prop.codec.encode(output, value, prop.length, prop.charset, context, null); } } } diff --git a/nop-record/src/main/java/io/nop/record/codec/impl/CountArrayBinaryCodec.java b/nop-record/src/main/java/io/nop/record/codec/impl/CountArrayBinaryCodec.java index 2b01a379c..14431f3c5 100644 --- a/nop-record/src/main/java/io/nop/record/codec/impl/CountArrayBinaryCodec.java +++ b/nop-record/src/main/java/io/nop/record/codec/impl/CountArrayBinaryCodec.java @@ -1,6 +1,7 @@ package io.nop.record.codec.impl; import io.nop.record.codec.IFieldBinaryCodec; +import io.nop.record.codec.IFieldBinaryEncoder; import io.nop.record.codec.IFieldCodecContext; import io.nop.record.input.IRecordBinaryInput; import io.nop.record.output.IRecordBinaryOutput; @@ -38,14 +39,15 @@ public Object decode(IRecordBinaryInput input, int length, Charset charset, IFie } @Override - public void encode(IRecordBinaryOutput output, Object value, int length, Charset charset, IFieldCodecContext context) { + public void encode(IRecordBinaryOutput output, Object value, int length, Charset charset, + IFieldCodecContext context, IFieldBinaryEncoder bodyEncoder) { Collection list = (Collection) value; if (list == null) list = Collections.emptyList(); - countCodec.encode(output, list.size(), -1, charset, context); + countCodec.encode(output, list.size(), -1, charset, context, null); for (Object item : list) { - itemCodec.encode(output, item, itemLength, charset, context); + itemCodec.encode(output, item, itemLength, charset, context, null); } } } diff --git a/nop-record/src/main/java/io/nop/record/codec/impl/DynCountArrayBinaryCodec.java b/nop-record/src/main/java/io/nop/record/codec/impl/DynCountArrayBinaryCodec.java new file mode 100644 index 000000000..8d67a44f7 --- /dev/null +++ b/nop-record/src/main/java/io/nop/record/codec/impl/DynCountArrayBinaryCodec.java @@ -0,0 +1,51 @@ +package io.nop.record.codec.impl; + +import io.nop.record.codec.IFieldBinaryCodec; +import io.nop.record.codec.IFieldBinaryEncoder; +import io.nop.record.codec.IFieldCodecContext; +import io.nop.record.input.IRecordBinaryInput; +import io.nop.record.output.IRecordBinaryOutput; + +import java.nio.charset.Charset; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +public class DynCountArrayBinaryCodec implements IFieldBinaryCodec { + private final IFieldBinaryCodec countCodec; + + private final int itemLength; + + public DynCountArrayBinaryCodec(IFieldBinaryCodec countCodec, int itemLength) { + this.countCodec = countCodec; + this.itemLength = itemLength; + } + + @Override + public Object decode(IRecordBinaryInput input, int length, Charset charset, IFieldCodecContext context) { + int count = (Integer) countCodec.decode(input, length, charset, context); + + IRecordBinaryInput arrayInput = input.subInput(length); + + List ret = new ArrayList<>(count); + for (int i = 0; i < count; i++) { + Object item = null; // itemCodec.decode(arrayInput, itemLength, charset, context); + ret.add(item); + } + return ret; + } + + @Override + public void encode(IRecordBinaryOutput output, Object value, int length, Charset charset, + IFieldCodecContext context, IFieldBinaryEncoder bodyEncoder) { + Collection list = (Collection) value; + if (list == null) + list = Collections.emptyList(); + + countCodec.encode(output, list.size(), -1, charset, context, null); + for (Object item : list) { + bodyEncoder.encode(output, item, itemLength, charset, context, null); + } + } +} diff --git a/nop-record/src/main/java/io/nop/record/codec/impl/DynLVFieldBinaryCodec.java b/nop-record/src/main/java/io/nop/record/codec/impl/DynLVFieldBinaryCodec.java new file mode 100644 index 000000000..72013d72c --- /dev/null +++ b/nop-record/src/main/java/io/nop/record/codec/impl/DynLVFieldBinaryCodec.java @@ -0,0 +1,47 @@ +package io.nop.record.codec.impl; + +import io.nop.api.core.exceptions.NopException; +import io.nop.record.codec.IFieldBinaryCodec; +import io.nop.record.codec.IFieldBinaryEncoder; +import io.nop.record.codec.IFieldCodecContext; +import io.nop.record.input.IRecordBinaryInput; +import io.nop.record.output.IRecordBinaryOutput; + +import java.nio.charset.Charset; +import java.util.function.Function; + +import static io.nop.record.RecordErrors.ARG_LENGTH; +import static io.nop.record.RecordErrors.ARG_MAX_LENGTH; +import static io.nop.record.RecordErrors.ERR_RECORD_DECODE_LENGTH_IS_TOO_LONG; + +public class DynLVFieldBinaryCodec implements IFieldBinaryCodec { + private final IFieldBinaryCodec lengthCodec; + private final Function lengthGetter; + + public DynLVFieldBinaryCodec(IFieldBinaryCodec lengthCodec, Function lengthGetter) { + this.lengthCodec = lengthCodec; + this.lengthGetter = lengthGetter; + } + + @Override + public Object decode(IRecordBinaryInput input, int length, Charset charset, IFieldCodecContext context) { + int len = (Integer) lengthCodec.decode(input, length, charset, context); + if (len <= 0) { + return null; + } + + if (length > 0 && len >= length) { + throw new NopException(ERR_RECORD_DECODE_LENGTH_IS_TOO_LONG) + .param(ARG_LENGTH, len).param(ARG_MAX_LENGTH, length); + } + return null; + } + + @Override + public void encode(IRecordBinaryOutput output, Object value, int length, Charset charset, IFieldCodecContext context, IFieldBinaryEncoder bodyEncoder) { + int len = lengthGetter.apply(value); + lengthCodec.encode(output, len, length, charset, context, null); + if (len > 0) + bodyEncoder.encode(output, value, len, charset, context, null); + } +} diff --git a/nop-record/src/main/java/io/nop/record/codec/impl/LVFieldBinaryCodec.java b/nop-record/src/main/java/io/nop/record/codec/impl/LVFieldBinaryCodec.java index 3a308a504..9dfaa8974 100644 --- a/nop-record/src/main/java/io/nop/record/codec/impl/LVFieldBinaryCodec.java +++ b/nop-record/src/main/java/io/nop/record/codec/impl/LVFieldBinaryCodec.java @@ -2,6 +2,7 @@ import io.nop.api.core.exceptions.NopException; import io.nop.record.codec.IFieldBinaryCodec; +import io.nop.record.codec.IFieldBinaryEncoder; import io.nop.record.codec.IFieldCodecContext; import io.nop.record.input.IRecordBinaryInput; import io.nop.record.output.IRecordBinaryOutput; @@ -40,10 +41,10 @@ public Object decode(IRecordBinaryInput input, int length, Charset charset, IFie } @Override - public void encode(IRecordBinaryOutput output, Object value, int length, Charset charset, IFieldCodecContext context) { + public void encode(IRecordBinaryOutput output, Object value, int length, Charset charset, IFieldCodecContext context, IFieldBinaryEncoder bodyEncoder) { int len = lengthGetter.apply(value); - lengthCodec.encode(output, len, length, charset, context); + lengthCodec.encode(output, len, length, charset, context, null); if (len > 0) - valueCodec.encode(output, value, len, charset, context); + valueCodec.encode(output, value, len, charset, context, bodyEncoder); } } diff --git a/nop-record/src/main/java/io/nop/record/model/_gen/_RecordAggregateFieldMeta.java b/nop-record/src/main/java/io/nop/record/model/_gen/_RecordAggregateFieldMeta.java index b2edbc6ac..62bc78cf4 100644 --- a/nop-record/src/main/java/io/nop/record/model/_gen/_RecordAggregateFieldMeta.java +++ b/nop-record/src/main/java/io/nop/record/model/_gen/_RecordAggregateFieldMeta.java @@ -10,11 +10,11 @@ // tell cpd to start ignoring code - CPD-OFF /** * generate from /nop/schema/record/record-file.xdef

- * + * 定长记录的定义 */ @SuppressWarnings({"PMD.UselessOverridingMethod","PMD.UnusedLocalVariable", "PMD.UnnecessaryFullyQualifiedName","PMD.EmptyControlStatement","java:S116","java:S101","java:S1128","java:S1161"}) -public abstract class _RecordAggregateFieldMeta extends io.nop.core.resource.component.AbstractComponentModel { +public abstract class _RecordAggregateFieldMeta extends io.nop.record.model.RecordSimpleFieldMeta { /** * @@ -23,27 +23,6 @@ public abstract class _RecordAggregateFieldMeta extends io.nop.core.resource.com */ private java.lang.String _aggFunc ; - /** - * - * xml name: name - * - */ - private java.lang.String _name ; - - /** - * - * xml name: prop - * - */ - private java.lang.String _prop ; - - /** - * - * xml name: valueExpr - * - */ - private io.nop.core.lang.eval.IEvalFunction _valueExpr ; - /** * * xml name: aggFunc @@ -63,63 +42,6 @@ public void setAggFunc(java.lang.String value){ } - /** - * - * xml name: name - * - */ - - public java.lang.String getName(){ - return _name; - } - - - public void setName(java.lang.String value){ - checkAllowChange(); - - this._name = value; - - } - - - /** - * - * xml name: prop - * - */ - - public java.lang.String getProp(){ - return _prop; - } - - - public void setProp(java.lang.String value){ - checkAllowChange(); - - this._prop = value; - - } - - - /** - * - * xml name: valueExpr - * - */ - - public io.nop.core.lang.eval.IEvalFunction getValueExpr(){ - return _valueExpr; - } - - - public void setValueExpr(io.nop.core.lang.eval.IEvalFunction value){ - checkAllowChange(); - - this._valueExpr = value; - - } - - @Override public void freeze(boolean cascade){ @@ -136,9 +58,6 @@ protected void outputJson(IJsonHandler out){ super.outputJson(out); out.putNotNull("aggFunc",this.getAggFunc()); - out.putNotNull("name",this.getName()); - out.putNotNull("prop",this.getProp()); - out.putNotNull("valueExpr",this.getValueExpr()); } public RecordAggregateFieldMeta cloneInstance(){ @@ -151,9 +70,6 @@ protected void copyTo(RecordAggregateFieldMeta instance){ super.copyTo(instance); instance.setAggFunc(this.getAggFunc()); - instance.setName(this.getName()); - instance.setProp(this.getProp()); - instance.setValueExpr(this.getValueExpr()); } protected RecordAggregateFieldMeta newInstance(){ diff --git a/nop-record/src/main/java/io/nop/record/model/_gen/_RecordFieldMeta.java b/nop-record/src/main/java/io/nop/record/model/_gen/_RecordFieldMeta.java index f21a076aa..8f17be7e1 100644 --- a/nop-record/src/main/java/io/nop/record/model/_gen/_RecordFieldMeta.java +++ b/nop-record/src/main/java/io/nop/record/model/_gen/_RecordFieldMeta.java @@ -16,20 +16,6 @@ "PMD.UnnecessaryFullyQualifiedName","PMD.EmptyControlStatement","java:S116","java:S101","java:S1128","java:S1161"}) public abstract class _RecordFieldMeta extends io.nop.record.model.RecordSimpleFieldMeta { - /** - * - * xml name: afterRead - * 在所有子字段都读取到之后执行 - */ - private io.nop.core.lang.eval.IEvalFunction _afterRead ; - - /** - * - * xml name: afterWrite - * - */ - private io.nop.core.lang.eval.IEvalFunction _afterWrite ; - /** * * xml name: fields @@ -42,21 +28,14 @@ public abstract class _RecordFieldMeta extends io.nop.record.model.RecordSimpleF * xml name: repeatExpr * 返回字段的循环次数 */ - private io.nop.core.lang.eval.IEvalFunction _repeatExpr ; - - /** - * - * xml name: repeatKind - * - */ - private io.nop.record.model.FieldRepeatKind _repeatKind ; + private io.nop.core.lang.eval.IEvalAction _repeatExpr ; /** * * xml name: repeatUntil * 返回字段循环的终止条件 */ - private io.nop.core.lang.eval.IEvalFunction _repeatUntil ; + private io.nop.core.lang.eval.IEvalAction _repeatUntil ; /** * @@ -65,51 +44,6 @@ public abstract class _RecordFieldMeta extends io.nop.record.model.RecordSimpleF */ private io.nop.record.model.RecordFieldSwitch _switch ; - /** - * - * xml name: template - * 文本输出时使用template更加直观 - */ - private java.lang.String _template ; - - /** - * - * xml name: afterRead - * 在所有子字段都读取到之后执行 - */ - - public io.nop.core.lang.eval.IEvalFunction getAfterRead(){ - return _afterRead; - } - - - public void setAfterRead(io.nop.core.lang.eval.IEvalFunction value){ - checkAllowChange(); - - this._afterRead = value; - - } - - - /** - * - * xml name: afterWrite - * - */ - - public io.nop.core.lang.eval.IEvalFunction getAfterWrite(){ - return _afterWrite; - } - - - public void setAfterWrite(io.nop.core.lang.eval.IEvalFunction value){ - checkAllowChange(); - - this._afterWrite = value; - - } - - /** * * xml name: fields @@ -161,12 +95,12 @@ public boolean hasFields(){ * 返回字段的循环次数 */ - public io.nop.core.lang.eval.IEvalFunction getRepeatExpr(){ + public io.nop.core.lang.eval.IEvalAction getRepeatExpr(){ return _repeatExpr; } - public void setRepeatExpr(io.nop.core.lang.eval.IEvalFunction value){ + public void setRepeatExpr(io.nop.core.lang.eval.IEvalAction value){ checkAllowChange(); this._repeatExpr = value; @@ -174,37 +108,18 @@ public void setRepeatExpr(io.nop.core.lang.eval.IEvalFunction value){ } - /** - * - * xml name: repeatKind - * - */ - - public io.nop.record.model.FieldRepeatKind getRepeatKind(){ - return _repeatKind; - } - - - public void setRepeatKind(io.nop.record.model.FieldRepeatKind value){ - checkAllowChange(); - - this._repeatKind = value; - - } - - /** * * xml name: repeatUntil * 返回字段循环的终止条件 */ - public io.nop.core.lang.eval.IEvalFunction getRepeatUntil(){ + public io.nop.core.lang.eval.IEvalAction getRepeatUntil(){ return _repeatUntil; } - public void setRepeatUntil(io.nop.core.lang.eval.IEvalFunction value){ + public void setRepeatUntil(io.nop.core.lang.eval.IEvalAction value){ checkAllowChange(); this._repeatUntil = value; @@ -231,25 +146,6 @@ public void setSwitch(io.nop.record.model.RecordFieldSwitch value){ } - /** - * - * xml name: template - * 文本输出时使用template更加直观 - */ - - public java.lang.String getTemplate(){ - return _template; - } - - - public void setTemplate(java.lang.String value){ - checkAllowChange(); - - this._template = value; - - } - - @Override public void freeze(boolean cascade){ @@ -269,14 +165,10 @@ public void freeze(boolean cascade){ protected void outputJson(IJsonHandler out){ super.outputJson(out); - out.putNotNull("afterRead",this.getAfterRead()); - out.putNotNull("afterWrite",this.getAfterWrite()); out.putNotNull("fields",this.getFields()); out.putNotNull("repeatExpr",this.getRepeatExpr()); - out.putNotNull("repeatKind",this.getRepeatKind()); out.putNotNull("repeatUntil",this.getRepeatUntil()); out.putNotNull("switch",this.getSwitch()); - out.putNotNull("template",this.getTemplate()); } public RecordFieldMeta cloneInstance(){ @@ -288,14 +180,10 @@ public RecordFieldMeta cloneInstance(){ protected void copyTo(RecordFieldMeta instance){ super.copyTo(instance); - instance.setAfterRead(this.getAfterRead()); - instance.setAfterWrite(this.getAfterWrite()); instance.setFields(this.getFields()); instance.setRepeatExpr(this.getRepeatExpr()); - instance.setRepeatKind(this.getRepeatKind()); instance.setRepeatUntil(this.getRepeatUntil()); instance.setSwitch(this.getSwitch()); - instance.setTemplate(this.getTemplate()); } protected RecordFieldMeta newInstance(){ diff --git a/nop-record/src/main/java/io/nop/record/model/_gen/_RecordFieldSwitch.java b/nop-record/src/main/java/io/nop/record/model/_gen/_RecordFieldSwitch.java index 216501b7b..0b0403716 100644 --- a/nop-record/src/main/java/io/nop/record/model/_gen/_RecordFieldSwitch.java +++ b/nop-record/src/main/java/io/nop/record/model/_gen/_RecordFieldSwitch.java @@ -35,14 +35,7 @@ public abstract class _RecordFieldSwitch extends io.nop.core.resource.component. * xml name: on * 类型判断表达式 */ - private io.nop.core.lang.eval.IEvalFunction _on ; - - /** - * - * xml name: onField - * 如果指定了onField,则输出时根据从record[onField]上获取到case类型,然后再映射到type类型,从根对象的types集合中再获取具体定义 - */ - private java.lang.String _onField ; + private io.nop.core.lang.eval.IEvalAction _on ; /** * @@ -114,12 +107,12 @@ public void setDefault(java.lang.String value){ * 类型判断表达式 */ - public io.nop.core.lang.eval.IEvalFunction getOn(){ + public io.nop.core.lang.eval.IEvalAction getOn(){ return _on; } - public void setOn(io.nop.core.lang.eval.IEvalFunction value){ + public void setOn(io.nop.core.lang.eval.IEvalAction value){ checkAllowChange(); this._on = value; @@ -127,25 +120,6 @@ public void setOn(io.nop.core.lang.eval.IEvalFunction value){ } - /** - * - * xml name: onField - * 如果指定了onField,则输出时根据从record[onField]上获取到case类型,然后再映射到type类型,从根对象的types集合中再获取具体定义 - */ - - public java.lang.String getOnField(){ - return _onField; - } - - - public void setOnField(java.lang.String value){ - checkAllowChange(); - - this._onField = value; - - } - - @Override public void freeze(boolean cascade){ @@ -166,7 +140,6 @@ protected void outputJson(IJsonHandler out){ out.putNotNull("cases",this.getCases()); out.putNotNull("default",this.getDefault()); out.putNotNull("on",this.getOn()); - out.putNotNull("onField",this.getOnField()); } public RecordFieldSwitch cloneInstance(){ @@ -181,7 +154,6 @@ protected void copyTo(RecordFieldSwitch instance){ instance.setCases(this.getCases()); instance.setDefault(this.getDefault()); instance.setOn(this.getOn()); - instance.setOnField(this.getOnField()); } protected RecordFieldSwitch newInstance(){ diff --git a/nop-record/src/main/java/io/nop/record/model/_gen/_RecordFileBodyMeta.java b/nop-record/src/main/java/io/nop/record/model/_gen/_RecordFileBodyMeta.java index cb066c1c4..5df099dee 100644 --- a/nop-record/src/main/java/io/nop/record/model/_gen/_RecordFileBodyMeta.java +++ b/nop-record/src/main/java/io/nop/record/model/_gen/_RecordFileBodyMeta.java @@ -18,59 +18,59 @@ public abstract class _RecordFileBodyMeta extends io.nop.record.model.RecordObje /** * - * xml name: repeatExpr - * 返回body行的循环次数 + * xml name: repeat + * */ - private io.nop.core.lang.eval.IEvalFunction _repeatExpr ; + private io.nop.record.model.FieldRepeatKind _repeat ; /** * - * xml name: repeatKind - * + * xml name: repeatExpr + * 返回body行的循环次数 */ - private io.nop.record.model.FieldRepeatKind _repeatKind ; + private io.nop.core.lang.eval.IEvalAction _repeatExpr ; /** * * xml name: repeatUntil * 返回body行循环的终止条件 */ - private io.nop.core.lang.eval.IEvalFunction _repeatUntil ; + private io.nop.core.lang.eval.IEvalAction _repeatUntil ; /** * - * xml name: repeatExpr - * 返回body行的循环次数 + * xml name: repeat + * */ - public io.nop.core.lang.eval.IEvalFunction getRepeatExpr(){ - return _repeatExpr; + public io.nop.record.model.FieldRepeatKind getRepeat(){ + return _repeat; } - public void setRepeatExpr(io.nop.core.lang.eval.IEvalFunction value){ + public void setRepeat(io.nop.record.model.FieldRepeatKind value){ checkAllowChange(); - this._repeatExpr = value; + this._repeat = value; } /** * - * xml name: repeatKind - * + * xml name: repeatExpr + * 返回body行的循环次数 */ - public io.nop.record.model.FieldRepeatKind getRepeatKind(){ - return _repeatKind; + public io.nop.core.lang.eval.IEvalAction getRepeatExpr(){ + return _repeatExpr; } - public void setRepeatKind(io.nop.record.model.FieldRepeatKind value){ + public void setRepeatExpr(io.nop.core.lang.eval.IEvalAction value){ checkAllowChange(); - this._repeatKind = value; + this._repeatExpr = value; } @@ -81,12 +81,12 @@ public void setRepeatKind(io.nop.record.model.FieldRepeatKind value){ * 返回body行循环的终止条件 */ - public io.nop.core.lang.eval.IEvalFunction getRepeatUntil(){ + public io.nop.core.lang.eval.IEvalAction getRepeatUntil(){ return _repeatUntil; } - public void setRepeatUntil(io.nop.core.lang.eval.IEvalFunction value){ + public void setRepeatUntil(io.nop.core.lang.eval.IEvalAction value){ checkAllowChange(); this._repeatUntil = value; @@ -109,8 +109,8 @@ public void freeze(boolean cascade){ protected void outputJson(IJsonHandler out){ super.outputJson(out); + out.putNotNull("repeat",this.getRepeat()); out.putNotNull("repeatExpr",this.getRepeatExpr()); - out.putNotNull("repeatKind",this.getRepeatKind()); out.putNotNull("repeatUntil",this.getRepeatUntil()); } @@ -123,8 +123,8 @@ public RecordFileBodyMeta cloneInstance(){ protected void copyTo(RecordFileBodyMeta instance){ super.copyTo(instance); + instance.setRepeat(this.getRepeat()); instance.setRepeatExpr(this.getRepeatExpr()); - instance.setRepeatKind(this.getRepeatKind()); instance.setRepeatUntil(this.getRepeatUntil()); } diff --git a/nop-record/src/main/java/io/nop/record/model/_gen/_RecordFileMeta.java b/nop-record/src/main/java/io/nop/record/model/_gen/_RecordFileMeta.java index 9f56aeb5c..90e48bb7d 100644 --- a/nop-record/src/main/java/io/nop/record/model/_gen/_RecordFileMeta.java +++ b/nop-record/src/main/java/io/nop/record/model/_gen/_RecordFileMeta.java @@ -16,13 +16,6 @@ "PMD.UnnecessaryFullyQualifiedName","PMD.EmptyControlStatement","java:S116","java:S101","java:S1128","java:S1161"}) public abstract class _RecordFileMeta extends io.nop.core.resource.component.AbstractComponentModel { - /** - * - * xml name: aggregates - * - */ - private KeyedList _aggregates = KeyedList.emptyList(); - /** * * xml name: binary @@ -88,10 +81,10 @@ public abstract class _RecordFileMeta extends io.nop.core.resource.component.Abs /** * - * xml name: pagination - * 分页生成,每页包含指定条目数,并且有可能会具有页头和页尾 + * xml name: headerTemplate + * 定长文件的header和footer采用文本模板模式更加直观 */ - private io.nop.record.model.RecordPaginationMeta _pagination ; + private java.lang.String _headerTemplate ; /** * @@ -100,6 +93,13 @@ public abstract class _RecordFileMeta extends io.nop.core.resource.component.Abs */ private KeyedList _params = KeyedList.emptyList(); + /** + * + * xml name: subGroup + * + */ + private io.nop.record.model.RecordSubGroupMeta _subGroup ; + /** * * xml name: trailer @@ -109,55 +109,17 @@ public abstract class _RecordFileMeta extends io.nop.core.resource.component.Abs /** * - * xml name: types + * xml name: trailerTemplate * */ - private KeyedList _types = KeyedList.emptyList(); + private java.lang.String _trailerTemplate ; /** - * - * xml name: aggregates * + * xml name: types + * */ - - public java.util.List getAggregates(){ - return _aggregates; - } - - - public void setAggregates(java.util.List value){ - checkAllowChange(); - - this._aggregates = KeyedList.fromList(value, io.nop.record.model.RecordAggregateFieldMeta::getName); - - } - - - public io.nop.record.model.RecordAggregateFieldMeta getAggregate(String name){ - return this._aggregates.getByKey(name); - } - - public boolean hasAggregate(String name){ - return this._aggregates.containsKey(name); - } - - public void addAggregate(io.nop.record.model.RecordAggregateFieldMeta item) { - checkAllowChange(); - java.util.List list = this.getAggregates(); - if (list == null || list.isEmpty()) { - list = new KeyedList<>(io.nop.record.model.RecordAggregateFieldMeta::getName); - setAggregates(list); - } - list.add(item); - } - - public java.util.Set keySet_aggregates(){ - return this._aggregates.keySet(); - } - - public boolean hasAggregates(){ - return !this._aggregates.isEmpty(); - } + private KeyedList _types = KeyedList.emptyList(); /** * @@ -358,19 +320,19 @@ public void setHeader(io.nop.record.model.RecordObjectMeta value){ /** * - * xml name: pagination - * 分页生成,每页包含指定条目数,并且有可能会具有页头和页尾 + * xml name: headerTemplate + * 定长文件的header和footer采用文本模板模式更加直观 */ - public io.nop.record.model.RecordPaginationMeta getPagination(){ - return _pagination; + public java.lang.String getHeaderTemplate(){ + return _headerTemplate; } - public void setPagination(io.nop.record.model.RecordPaginationMeta value){ + public void setHeaderTemplate(java.lang.String value){ checkAllowChange(); - this._pagination = value; + this._headerTemplate = value; } @@ -420,6 +382,25 @@ public boolean hasParams(){ return !this._params.isEmpty(); } + /** + * + * xml name: subGroup + * + */ + + public io.nop.record.model.RecordSubGroupMeta getSubGroup(){ + return _subGroup; + } + + + public void setSubGroup(io.nop.record.model.RecordSubGroupMeta value){ + checkAllowChange(); + + this._subGroup = value; + + } + + /** * * xml name: trailer @@ -439,6 +420,25 @@ public void setTrailer(io.nop.record.model.RecordObjectMeta value){ } + /** + * + * xml name: trailerTemplate + * + */ + + public java.lang.String getTrailerTemplate(){ + return _trailerTemplate; + } + + + public void setTrailerTemplate(java.lang.String value){ + checkAllowChange(); + + this._trailerTemplate = value; + + } + + /** * * xml name: types @@ -492,18 +492,16 @@ public void freeze(boolean cascade){ if(cascade){ //NOPMD - suppressed EmptyControlStatement - Auto Gen Code - this._aggregates = io.nop.api.core.util.FreezeHelper.deepFreeze(this._aggregates); - this._body = io.nop.api.core.util.FreezeHelper.deepFreeze(this._body); this._enums = io.nop.api.core.util.FreezeHelper.deepFreeze(this._enums); this._header = io.nop.api.core.util.FreezeHelper.deepFreeze(this._header); - this._pagination = io.nop.api.core.util.FreezeHelper.deepFreeze(this._pagination); - this._params = io.nop.api.core.util.FreezeHelper.deepFreeze(this._params); + this._subGroup = io.nop.api.core.util.FreezeHelper.deepFreeze(this._subGroup); + this._trailer = io.nop.api.core.util.FreezeHelper.deepFreeze(this._trailer); this._types = io.nop.api.core.util.FreezeHelper.deepFreeze(this._types); @@ -515,7 +513,6 @@ public void freeze(boolean cascade){ protected void outputJson(IJsonHandler out){ super.outputJson(out); - out.putNotNull("aggregates",this.getAggregates()); out.putNotNull("binary",this.isBinary()); out.putNotNull("bitEndian",this.getBitEndian()); out.putNotNull("body",this.getBody()); @@ -525,9 +522,11 @@ protected void outputJson(IJsonHandler out){ out.putNotNull("endian",this.getEndian()); out.putNotNull("enums",this.getEnums()); out.putNotNull("header",this.getHeader()); - out.putNotNull("pagination",this.getPagination()); + out.putNotNull("headerTemplate",this.getHeaderTemplate()); out.putNotNull("params",this.getParams()); + out.putNotNull("subGroup",this.getSubGroup()); out.putNotNull("trailer",this.getTrailer()); + out.putNotNull("trailerTemplate",this.getTrailerTemplate()); out.putNotNull("types",this.getTypes()); } @@ -540,7 +539,6 @@ public RecordFileMeta cloneInstance(){ protected void copyTo(RecordFileMeta instance){ super.copyTo(instance); - instance.setAggregates(this.getAggregates()); instance.setBinary(this.isBinary()); instance.setBitEndian(this.getBitEndian()); instance.setBody(this.getBody()); @@ -550,9 +548,11 @@ protected void copyTo(RecordFileMeta instance){ instance.setEndian(this.getEndian()); instance.setEnums(this.getEnums()); instance.setHeader(this.getHeader()); - instance.setPagination(this.getPagination()); + instance.setHeaderTemplate(this.getHeaderTemplate()); instance.setParams(this.getParams()); + instance.setSubGroup(this.getSubGroup()); instance.setTrailer(this.getTrailer()); + instance.setTrailerTemplate(this.getTrailerTemplate()); instance.setTypes(this.getTypes()); } diff --git a/nop-record/src/main/java/io/nop/record/model/_gen/_RecordObjectMeta.java b/nop-record/src/main/java/io/nop/record/model/_gen/_RecordObjectMeta.java index 9e4d28540..54881589a 100644 --- a/nop-record/src/main/java/io/nop/record/model/_gen/_RecordObjectMeta.java +++ b/nop-record/src/main/java/io/nop/record/model/_gen/_RecordObjectMeta.java @@ -18,32 +18,18 @@ public abstract class _RecordObjectMeta extends io.nop.core.resource.component.A /** * - * xml name: afterRead - * 在所有子字段都读取到之后执行 - */ - private io.nop.core.lang.eval.IEvalFunction _afterRead ; - - /** - * - * xml name: afterWrite + * xml name: computed-field * */ - private io.nop.core.lang.eval.IEvalFunction _afterWrite ; + private KeyedList _computedFields = KeyedList.emptyList(); /** * - * xml name: fields - * + * xml name: field + * 定长记录的定义 */ private KeyedList _fields = KeyedList.emptyList(); - /** - * - * xml name: ifExpr - * - */ - private io.nop.core.lang.eval.IEvalFunction _ifExpr ; - /** * * xml name: param @@ -51,13 +37,6 @@ public abstract class _RecordObjectMeta extends io.nop.core.resource.component.A */ private KeyedList _params = KeyedList.emptyList(); - /** - * - * xml name: template - * - */ - private java.lang.String _template ; - /** * * xml name: type @@ -67,46 +46,53 @@ public abstract class _RecordObjectMeta extends io.nop.core.resource.component.A /** * - * xml name: afterRead - * 在所有子字段都读取到之后执行 + * xml name: computed-field + * */ - public io.nop.core.lang.eval.IEvalFunction getAfterRead(){ - return _afterRead; + public java.util.List getComputedFields(){ + return _computedFields; } - public void setAfterRead(io.nop.core.lang.eval.IEvalFunction value){ + public void setComputedFields(java.util.List value){ checkAllowChange(); - this._afterRead = value; + this._computedFields = KeyedList.fromList(value, io.nop.record.model.RecordComputedFieldMeta::getName); } - /** - * - * xml name: afterWrite - * - */ - - public io.nop.core.lang.eval.IEvalFunction getAfterWrite(){ - return _afterWrite; + public io.nop.record.model.RecordComputedFieldMeta getComputedField(String name){ + return this._computedFields.getByKey(name); } - - public void setAfterWrite(io.nop.core.lang.eval.IEvalFunction value){ + public boolean hasComputedField(String name){ + return this._computedFields.containsKey(name); + } + + public void addComputedField(io.nop.record.model.RecordComputedFieldMeta item) { checkAllowChange(); - - this._afterWrite = value; - + java.util.List list = this.getComputedFields(); + if (list == null || list.isEmpty()) { + list = new KeyedList<>(io.nop.record.model.RecordComputedFieldMeta::getName); + setComputedFields(list); + } + list.add(item); + } + + public java.util.Set keySet_computedFields(){ + return this._computedFields.keySet(); } + public boolean hasComputedFields(){ + return !this._computedFields.isEmpty(); + } /** * - * xml name: fields - * + * xml name: field + * 定长记录的定义 */ public java.util.List getFields(){ @@ -148,25 +134,6 @@ public boolean hasFields(){ return !this._fields.isEmpty(); } - /** - * - * xml name: ifExpr - * - */ - - public io.nop.core.lang.eval.IEvalFunction getIfExpr(){ - return _ifExpr; - } - - - public void setIfExpr(io.nop.core.lang.eval.IEvalFunction value){ - checkAllowChange(); - - this._ifExpr = value; - - } - - /** * * xml name: param @@ -212,25 +179,6 @@ public boolean hasParams(){ return !this._params.isEmpty(); } - /** - * - * xml name: template - * - */ - - public java.lang.String getTemplate(){ - return _template; - } - - - public void setTemplate(java.lang.String value){ - checkAllowChange(); - - this._template = value; - - } - - /** * * xml name: type @@ -258,6 +206,8 @@ public void freeze(boolean cascade){ if(cascade){ //NOPMD - suppressed EmptyControlStatement - Auto Gen Code + this._computedFields = io.nop.api.core.util.FreezeHelper.deepFreeze(this._computedFields); + this._fields = io.nop.api.core.util.FreezeHelper.deepFreeze(this._fields); this._params = io.nop.api.core.util.FreezeHelper.deepFreeze(this._params); @@ -269,12 +219,9 @@ public void freeze(boolean cascade){ protected void outputJson(IJsonHandler out){ super.outputJson(out); - out.putNotNull("afterRead",this.getAfterRead()); - out.putNotNull("afterWrite",this.getAfterWrite()); + out.putNotNull("computedFields",this.getComputedFields()); out.putNotNull("fields",this.getFields()); - out.putNotNull("ifExpr",this.getIfExpr()); out.putNotNull("params",this.getParams()); - out.putNotNull("template",this.getTemplate()); out.putNotNull("type",this.getType()); } @@ -287,12 +234,9 @@ public RecordObjectMeta cloneInstance(){ protected void copyTo(RecordObjectMeta instance){ super.copyTo(instance); - instance.setAfterRead(this.getAfterRead()); - instance.setAfterWrite(this.getAfterWrite()); + instance.setComputedFields(this.getComputedFields()); instance.setFields(this.getFields()); - instance.setIfExpr(this.getIfExpr()); instance.setParams(this.getParams()); - instance.setTemplate(this.getTemplate()); instance.setType(this.getType()); } diff --git a/nop-record/src/main/java/io/nop/record/model/_gen/_RecordSimpleFieldMeta.java b/nop-record/src/main/java/io/nop/record/model/_gen/_RecordSimpleFieldMeta.java index 7f555226d..2ba7d6d17 100644 --- a/nop-record/src/main/java/io/nop/record/model/_gen/_RecordSimpleFieldMeta.java +++ b/nop-record/src/main/java/io/nop/record/model/_gen/_RecordSimpleFieldMeta.java @@ -25,31 +25,31 @@ public abstract class _RecordSimpleFieldMeta extends io.nop.core.resource.compon /** * - * xml name: charset - * + * xml name: content + * 如果非空,则表示字段为固定内容。当输出字段到数据文件中时直接使用该内容输出 */ - private java.lang.String _charset ; + private io.nop.commons.bytes.ByteString _content ; /** * - * xml name: codec + * xml name: doc * */ - private java.lang.String _codec ; + private java.lang.String _doc ; /** * - * xml name: content - * 如果非空,则表示字段为固定内容。当输出字段到数据文件中时直接使用该内容输出 + * xml name: encoder + * */ - private io.nop.commons.bytes.ByteString _content ; + private java.lang.String _encoder ; /** * - * xml name: doc + * xml name: encoding * */ - private java.lang.String _doc ; + private java.lang.String _encoding ; /** * @@ -86,19 +86,12 @@ public abstract class _RecordSimpleFieldMeta extends io.nop.core.resource.compon */ private java.lang.Boolean _excludeMin ; - /** - * - * xml name: exportExpr - * 输出时不从实体上获取,根据表达式计算得到输出值 - */ - private io.nop.core.lang.eval.IEvalFunction _exportExpr ; - /** * * xml name: ifExpr * 当表达式返回false时,此字段将被跳过,不会被处理 */ - private io.nop.core.lang.eval.IEvalFunction _ifExpr ; + private io.nop.core.lang.eval.IEvalPredicate _ifExpr ; /** * @@ -138,9 +131,9 @@ public abstract class _RecordSimpleFieldMeta extends io.nop.core.resource.compon /** * * xml name: lengthExpr - * 动态确定字段长度。在表达式中record指向父结构,_root指向根结构。 + * 动态确定字段长度。在表达式中_parent指向父结构,_root指向根结构。其他变量指向兄弟字段 */ - private io.nop.core.lang.eval.IEvalFunction _lengthExpr ; + private io.nop.core.lang.eval.IEvalAction _lengthExpr ; /** * @@ -180,7 +173,7 @@ public abstract class _RecordSimpleFieldMeta extends io.nop.core.resource.compon /** * * xml name: name - * 对应解析得到的属性名。如果指定了prop,则以prop为准 + * 对应解析得到的属性名 */ private java.lang.String _name ; @@ -207,31 +200,10 @@ public abstract class _RecordSimpleFieldMeta extends io.nop.core.resource.compon /** * - * xml name: prop - * 如果设置了此属性,则这个prop才是实际对应的属性名 - */ - private java.lang.String _prop ; - - /** - * - * xml name: skipWhenRead - * 当读取记录时忽略此字段,此字段可能仅用于输出 - */ - private boolean _skipWhenRead = false; - - /** - * - * xml name: skipWhenWrite - * - */ - private boolean _skipWhenWrite = false; - - /** - * - * xml name: skipWriteWhenEmpty + * xml name: repeat * */ - private boolean _skipWriteWhenEmpty = false; + private io.nop.record.model.FieldRepeatKind _repeat ; /** * @@ -254,13 +226,6 @@ public abstract class _RecordSimpleFieldMeta extends io.nop.core.resource.compon */ private boolean _tillEnd = false; - /** - * - * xml name: transformInExpr - * 解析时对已经解析到的value进行转换 - */ - private io.nop.core.lang.eval.IEvalFunction _transformInExpr ; - /** * * xml name: trim @@ -278,10 +243,17 @@ public abstract class _RecordSimpleFieldMeta extends io.nop.core.resource.compon /** * * xml name: virtual - * 虚拟字段,不解析到java bean中。当它具有fields子字段时可以起到分组作用。fields子字段会作为父对象的字段 + * 虚拟字段,不解析到java bean中 */ private boolean _virtual = false; + /** + * + * xml name: wrapper + * + */ + private boolean _wrapper = false; + /** * * xml name: absoluteOffset @@ -303,76 +275,76 @@ public void setAbsoluteOffset(boolean value){ /** * - * xml name: charset - * + * xml name: content + * 如果非空,则表示字段为固定内容。当输出字段到数据文件中时直接使用该内容输出 */ - public java.lang.String getCharset(){ - return _charset; + public io.nop.commons.bytes.ByteString getContent(){ + return _content; } - public void setCharset(java.lang.String value){ + public void setContent(io.nop.commons.bytes.ByteString value){ checkAllowChange(); - this._charset = value; + this._content = value; } /** * - * xml name: codec + * xml name: doc * */ - public java.lang.String getCodec(){ - return _codec; + public java.lang.String getDoc(){ + return _doc; } - public void setCodec(java.lang.String value){ + public void setDoc(java.lang.String value){ checkAllowChange(); - this._codec = value; + this._doc = value; } /** * - * xml name: content - * 如果非空,则表示字段为固定内容。当输出字段到数据文件中时直接使用该内容输出 + * xml name: encoder + * */ - public io.nop.commons.bytes.ByteString getContent(){ - return _content; + public java.lang.String getEncoder(){ + return _encoder; } - public void setContent(io.nop.commons.bytes.ByteString value){ + public void setEncoder(java.lang.String value){ checkAllowChange(); - this._content = value; + this._encoder = value; } /** * - * xml name: doc + * xml name: encoding * */ - public java.lang.String getDoc(){ - return _doc; + public java.lang.String getEncoding(){ + return _encoding; } - public void setDoc(java.lang.String value){ + public void setEncoding(java.lang.String value){ checkAllowChange(); - this._doc = value; + this._encoding = value; } @@ -472,37 +444,18 @@ public void setExcludeMin(java.lang.Boolean value){ } - /** - * - * xml name: exportExpr - * 输出时不从实体上获取,根据表达式计算得到输出值 - */ - - public io.nop.core.lang.eval.IEvalFunction getExportExpr(){ - return _exportExpr; - } - - - public void setExportExpr(io.nop.core.lang.eval.IEvalFunction value){ - checkAllowChange(); - - this._exportExpr = value; - - } - - /** * * xml name: ifExpr * 当表达式返回false时,此字段将被跳过,不会被处理 */ - public io.nop.core.lang.eval.IEvalFunction getIfExpr(){ + public io.nop.core.lang.eval.IEvalPredicate getIfExpr(){ return _ifExpr; } - public void setIfExpr(io.nop.core.lang.eval.IEvalFunction value){ + public void setIfExpr(io.nop.core.lang.eval.IEvalPredicate value){ checkAllowChange(); this._ifExpr = value; @@ -608,15 +561,15 @@ public void setLength(int value){ /** * * xml name: lengthExpr - * 动态确定字段长度。在表达式中record指向父结构,_root指向根结构。 + * 动态确定字段长度。在表达式中_parent指向父结构,_root指向根结构。其他变量指向兄弟字段 */ - public io.nop.core.lang.eval.IEvalFunction getLengthExpr(){ + public io.nop.core.lang.eval.IEvalAction getLengthExpr(){ return _lengthExpr; } - public void setLengthExpr(io.nop.core.lang.eval.IEvalFunction value){ + public void setLengthExpr(io.nop.core.lang.eval.IEvalAction value){ checkAllowChange(); this._lengthExpr = value; @@ -722,7 +675,7 @@ public void setMinLength(java.lang.Integer value){ /** * * xml name: name - * 对应解析得到的属性名。如果指定了prop,则以prop为准 + * 对应解析得到的属性名 */ public java.lang.String getName(){ @@ -797,76 +750,19 @@ public void setPattern(java.lang.String value){ /** * - * xml name: prop - * 如果设置了此属性,则这个prop才是实际对应的属性名 - */ - - public java.lang.String getProp(){ - return _prop; - } - - - public void setProp(java.lang.String value){ - checkAllowChange(); - - this._prop = value; - - } - - - /** - * - * xml name: skipWhenRead - * 当读取记录时忽略此字段,此字段可能仅用于输出 - */ - - public boolean isSkipWhenRead(){ - return _skipWhenRead; - } - - - public void setSkipWhenRead(boolean value){ - checkAllowChange(); - - this._skipWhenRead = value; - - } - - - /** - * - * xml name: skipWhenWrite + * xml name: repeat * */ - public boolean isSkipWhenWrite(){ - return _skipWhenWrite; + public io.nop.record.model.FieldRepeatKind getRepeat(){ + return _repeat; } - public void setSkipWhenWrite(boolean value){ + public void setRepeat(io.nop.record.model.FieldRepeatKind value){ checkAllowChange(); - this._skipWhenWrite = value; - - } - - - /** - * - * xml name: skipWriteWhenEmpty - * - */ - - public boolean isSkipWriteWhenEmpty(){ - return _skipWriteWhenEmpty; - } - - - public void setSkipWriteWhenEmpty(boolean value){ - checkAllowChange(); - - this._skipWriteWhenEmpty = value; + this._repeat = value; } @@ -928,25 +824,6 @@ public void setTillEnd(boolean value){ } - /** - * - * xml name: transformInExpr - * 解析时对已经解析到的value进行转换 - */ - - public io.nop.core.lang.eval.IEvalFunction getTransformInExpr(){ - return _transformInExpr; - } - - - public void setTransformInExpr(io.nop.core.lang.eval.IEvalFunction value){ - checkAllowChange(); - - this._transformInExpr = value; - - } - - /** * * xml name: trim @@ -988,7 +865,7 @@ public void setType(java.lang.String value){ /** * * xml name: virtual - * 虚拟字段,不解析到java bean中。当它具有fields子字段时可以起到分组作用。fields子字段会作为父对象的字段 + * 虚拟字段,不解析到java bean中 */ public boolean isVirtual(){ @@ -1004,6 +881,25 @@ public void setVirtual(boolean value){ } + /** + * + * xml name: wrapper + * + */ + + public boolean isWrapper(){ + return _wrapper; + } + + + public void setWrapper(boolean value){ + checkAllowChange(); + + this._wrapper = value; + + } + + @Override public void freeze(boolean cascade){ @@ -1020,16 +916,15 @@ protected void outputJson(IJsonHandler out){ super.outputJson(out); out.putNotNull("absoluteOffset",this.isAbsoluteOffset()); - out.putNotNull("charset",this.getCharset()); - out.putNotNull("codec",this.getCodec()); out.putNotNull("content",this.getContent()); out.putNotNull("doc",this.getDoc()); + out.putNotNull("encoder",this.getEncoder()); + out.putNotNull("encoding",this.getEncoding()); out.putNotNull("endian",this.getEndian()); out.putNotNull("enum",this.getEnum()); out.putNotNull("eosError",this.isEosError()); out.putNotNull("excludeMax",this.getExcludeMax()); out.putNotNull("excludeMin",this.getExcludeMin()); - out.putNotNull("exportExpr",this.getExportExpr()); out.putNotNull("ifExpr",this.getIfExpr()); out.putNotNull("includeTerminator",this.isIncludeTerminator()); out.putNotNull("label",this.getLabel()); @@ -1046,17 +941,14 @@ protected void outputJson(IJsonHandler out){ out.putNotNull("offset",this.getOffset()); out.putNotNull("padding",this.getPadding()); out.putNotNull("pattern",this.getPattern()); - out.putNotNull("prop",this.getProp()); - out.putNotNull("skipWhenRead",this.isSkipWhenRead()); - out.putNotNull("skipWhenWrite",this.isSkipWhenWrite()); - out.putNotNull("skipWriteWhenEmpty",this.isSkipWriteWhenEmpty()); + out.putNotNull("repeat",this.getRepeat()); out.putNotNull("stdDomain",this.getStdDomain()); out.putNotNull("terminator",this.getTerminator()); out.putNotNull("tillEnd",this.isTillEnd()); - out.putNotNull("transformInExpr",this.getTransformInExpr()); out.putNotNull("trim",this.isTrim()); out.putNotNull("type",this.getType()); out.putNotNull("virtual",this.isVirtual()); + out.putNotNull("wrapper",this.isWrapper()); } public RecordSimpleFieldMeta cloneInstance(){ @@ -1069,16 +961,15 @@ protected void copyTo(RecordSimpleFieldMeta instance){ super.copyTo(instance); instance.setAbsoluteOffset(this.isAbsoluteOffset()); - instance.setCharset(this.getCharset()); - instance.setCodec(this.getCodec()); instance.setContent(this.getContent()); instance.setDoc(this.getDoc()); + instance.setEncoder(this.getEncoder()); + instance.setEncoding(this.getEncoding()); instance.setEndian(this.getEndian()); instance.setEnum(this.getEnum()); instance.setEosError(this.isEosError()); instance.setExcludeMax(this.getExcludeMax()); instance.setExcludeMin(this.getExcludeMin()); - instance.setExportExpr(this.getExportExpr()); instance.setIfExpr(this.getIfExpr()); instance.setIncludeTerminator(this.isIncludeTerminator()); instance.setLabel(this.getLabel()); @@ -1095,17 +986,14 @@ protected void copyTo(RecordSimpleFieldMeta instance){ instance.setOffset(this.getOffset()); instance.setPadding(this.getPadding()); instance.setPattern(this.getPattern()); - instance.setProp(this.getProp()); - instance.setSkipWhenRead(this.isSkipWhenRead()); - instance.setSkipWhenWrite(this.isSkipWhenWrite()); - instance.setSkipWriteWhenEmpty(this.isSkipWriteWhenEmpty()); + instance.setRepeat(this.getRepeat()); instance.setStdDomain(this.getStdDomain()); instance.setTerminator(this.getTerminator()); instance.setTillEnd(this.isTillEnd()); - instance.setTransformInExpr(this.getTransformInExpr()); instance.setTrim(this.isTrim()); instance.setType(this.getType()); instance.setVirtual(this.isVirtual()); + instance.setWrapper(this.isWrapper()); } protected RecordSimpleFieldMeta newInstance(){ diff --git a/nop-record/src/main/java/io/nop/record/resource/AbstractModelBasedRecordOutput.java b/nop-record/src/main/java/io/nop/record/resource/AbstractModelBasedRecordOutput.java index 235861561..48f4bbf64 100644 --- a/nop-record/src/main/java/io/nop/record/resource/AbstractModelBasedRecordOutput.java +++ b/nop-record/src/main/java/io/nop/record/resource/AbstractModelBasedRecordOutput.java @@ -190,16 +190,24 @@ protected void writeField(Output out, RecordFieldMeta field, Object record) thro writeOffset(out, field.getOffset()); } - if (record instanceof Collection) { - Collection c = (Collection) record; - for (Object o : c) { - writeSwitch(out, field, o); - } + if (field.getCodec() != null && isUseBodyEncoder(field)) { + writeObjectWithCodec(out, field, record); } else { - writeSwitch(out, field, record); + if (record instanceof Collection) { + Collection c = (Collection) record; + for (Object o : c) { + writeSwitch(out, field, o); + } + } else { + writeSwitch(out, field, record); + } } } + protected boolean isUseBodyEncoder(RecordFieldMeta field) { + return field.getSwitch() != null || field.hasFields(); + } + boolean runIfExpr(IEvalFunction expr, Object record, String name) { if (expr == null) return true; @@ -289,6 +297,8 @@ protected void writeTemplateOrFields(Output out, IRecordFieldsMeta fields, Chars } } + abstract protected void writeObjectWithCodec(Output out, RecordFieldMeta field, Object record) throws IOException; + abstract protected void writeOffset(Output out, int offset) throws IOException; abstract protected void writeString(Output out, String str, Charset charset) throws IOException; diff --git a/nop-record/src/main/java/io/nop/record/resource/ModelBasedBinaryRecordOutput.java b/nop-record/src/main/java/io/nop/record/resource/ModelBasedBinaryRecordOutput.java index 65457fd6d..75da98006 100644 --- a/nop-record/src/main/java/io/nop/record/resource/ModelBasedBinaryRecordOutput.java +++ b/nop-record/src/main/java/io/nop/record/resource/ModelBasedBinaryRecordOutput.java @@ -7,6 +7,7 @@ */ package io.nop.record.resource; +import io.nop.api.core.exceptions.NopException; import io.nop.commons.aggregator.CompositeAggregatorProvider; import io.nop.commons.aggregator.IAggregatorProvider; import io.nop.commons.bytes.ByteString; @@ -36,6 +37,19 @@ public ModelBasedBinaryRecordOutput(IRecordBinaryOutput out, RecordFileMeta file this(out, fileMeta, new DefaultFieldCodecContext(), FieldCodecRegistry.DEFAULT, CompositeAggregatorProvider.defaultProvider()); } + @Override + protected void writeObjectWithCodec(IRecordBinaryOutput out, RecordFieldMeta field, Object record) throws IOException { + IFieldBinaryCodec encoder = resolveBinaryCodec(field, registry); + encoder.encode(out, record, field.getLength(), field.getCharsetObj(), context, + (output, value, length, charset, ctx, bodyEncoder) -> { + try { + writeSwitch(output, field, value); + } catch (Exception e) { + throw NopException.adapt(e); + } + }); + } + @Override protected void writeOffset(IRecordBinaryOutput out, int offset) throws IOException { for (int i = 0; i < offset; i++) { @@ -55,7 +69,7 @@ protected void writeField0(IRecordBinaryOutput out, RecordFieldMeta field, Objec if (encoder != null) { context.enterField(field.getName()); try { - encoder.encode(out, value, field.getLength(), field.getCharsetObj(), context); + encoder.encode(out, value, field.getLength(), field.getCharsetObj(), context, null); } finally { context.leaveField(field.getName()); } diff --git a/nop-record/src/main/java/io/nop/record/resource/ModelBasedTextRecordOutput.java b/nop-record/src/main/java/io/nop/record/resource/ModelBasedTextRecordOutput.java index 973e769d1..85466cd36 100644 --- a/nop-record/src/main/java/io/nop/record/resource/ModelBasedTextRecordOutput.java +++ b/nop-record/src/main/java/io/nop/record/resource/ModelBasedTextRecordOutput.java @@ -7,6 +7,7 @@ */ package io.nop.record.resource; +import io.nop.api.core.exceptions.NopException; import io.nop.commons.aggregator.CompositeAggregatorProvider; import io.nop.commons.aggregator.IAggregatorProvider; import io.nop.commons.bytes.ByteString; @@ -37,6 +38,20 @@ public ModelBasedTextRecordOutput(IRecordTextOutput out, RecordFileMeta fileMeta this(out, fileMeta, new DefaultFieldCodecContext(), FieldCodecRegistry.DEFAULT, CompositeAggregatorProvider.defaultProvider()); } + @Override + protected void writeObjectWithCodec(IRecordTextOutput out, RecordFieldMeta field, Object record) throws IOException { + IFieldTextCodec encoder = resolveTextCodec(field, registry); + encoder.encode(out, record, field.getLength(), context, + (output, value, length, ctx, bodyEncoder) -> { + try { + writeSwitch(output, field, value); + } catch (Exception e) { + throw NopException.adapt(e); + } + }); + } + + @Override protected void writeOffset(IRecordTextOutput out, int offset) throws IOException { for (int i = 0; i < offset; i++) { @@ -56,7 +71,7 @@ protected void writeField0(IRecordTextOutput out, RecordFieldMeta field, Object if (encoder != null) { context.enterField(field.getName()); try { - encoder.encode(out, value, field.getLength(), context); + encoder.encode(out, value, field.getLength(), context, null); } finally { context.leaveField(field.getName()); }