How to handle fields with different usages in the GenericPackager?

437 Views Asked by At

I have a several fields that change their definitions based on what usage of that field is being used.

For example, F48 is defined as:

Variable Length, 1-byte binary + 255 bytes, variable by usage, max 256 bytes

It's simple enough handling one usage at a time, for example usage A is defined in spec and my packager:

Variable length, 1-byte binary + 255 bytes, EBCDIC, max 256 bytes
<isofield
  id="48"
  length="255"
  name="ADITIONAL DATA - PRIVATE"
  class="org.jpos.iso.IFB_LLHECHAR"/>

But another usage may be defined as

variable length, 1-byte binary + 4 N, 4-bit BCD

Or

variable length, 1-byte binary + 143 AN, EBCDIC

And so on. I'm not quite sure how to handle multiple usages of the same field in my generic packager.

I've thought about using isofieldpackager to treat it like subfields, and then depending on the usage I need I just use that subfield.

For example, with usage A, I tried

<isofieldpackager
      id="48"
      length="255"
      name="F48 ADDITIONAL DATA - PRIVATE"
      emitBitmap="false"
      firstField="0"
      class="org.jpos.iso.IFB_LLHBINARY"
      packager="org.jpos.iso.packager.GenericSubFieldPackager">
<isofield
        id="0"
        length="255"
        name="ADITIONAL DATA - PRIVATE"
        class="org.jpos.iso.IFB_LLHECHAR"/>
</isofieldpackager>

and then setting the field as isoMSG.set("48.0", "This is my data"), which seems to work for the most part, but there is some unreadable data being prefixed to that field when it reaches my acquiring process.

Thanks for any help, if you need more info let me know

2

There are 2 best solutions below

2
On BEST ANSWER

At the channel level, if you have a way to figure out the usage, you can use the dynamic packager support. So basically, you create different packages, and the channel decides which one to use at runtime.

But the easiest way is to handle it as an opaque binary field, and then handle the differences on your higher level code.

0
On

So apr has the correct answer. I took me more time than I'd like to admit to understand it, but from what I understand is you have to take the bytes of a String and then run that through your interpreter, prefixer, etc.

private static byte[] calcBytes(String s) throws ISOException {
    byte[] bytes = s.getBytes();
    EbcdicInterpreter.INSTANCE.interpret(s,bytes,0);
    return bytes;

Then in your Generic Packager, it has to be a (opaque) binary class

<isofield
  id="48"
  length="255"
  name="ADITIONAL DATA - PRIVATE"
  class="org.jpos.iso.IFB_LLHBINARY"/>

Reason for binary is because its interpreter doesn't change your bytes again after you had manually interpreted like above method. Since every usage for this field for me has 1-byte binary length, that is why class I used is IFB_LLH

Just thought I'd add this here for anyone else struggling to understand what to do with "opaque binary field"