Feature #369

restinout json/UBF remap

Added by Madars Vitolins 7 months ago. Updated 5 months ago.

Status:NewStart date:01/04/2019
Priority:NormalDue date:
Assignee:-% Done:

0%

Category:-
Target version:-

Description

We shall provide buffer remap server that could be called by restin/out to convert format before server calls and when generating responses.

For UBF/JSON mappings we could create new C/PS binary which would perform two way mappings with help of Parson for following json descriptor:

#!/usr/bin/pscript

 a <- {
    //Single field
    "a": {"_ubf":"T_A_FLD[0]", "_opt":"y", "_min":"-1", "_max":"100", "_lenmin":"1", "_lenmax":"5"},

    //Single sub-object
    "b": 
        {
            "username" : {"_ubf":"T_FIRST_NAME[0]", "_opt":"y"},
            "lastname" : {"_ubf":"T_LAST_NAME[0]", "_opt":"n"}
        },

    //Array with singles
    "c": {
            "_minocc":"5",
        "_array": [{"_ubf":"T_C_FLD"}]
         },

    //Array with objects
    "d": {
        "_minocc":"5",
        "_maxocc":"10",
        "_array": [
                {
                    "test": {"_ubf":"C_TEST"},
                    "field2": {"_ubf":"C_FIELD"},
                    //sub field
                    "sub_obj": {
                        "car" : {"_ubf":"T_CAR", "_opt":"y"},
                        "model" : {"_ubf":"T_MODEL", "_opt":"n"}
                    },
                    //sub array
                    "sub_array_of_obj": {
                        "_array": [
                                {
                                    "car" : {"_ubf":"T_CAR", "_opt":"y"},
                                    "model" : {"_ubf":"T_MODEL", "_opt":"n"}
                                }
                            ]
                    },
                }
            ]
        }
      };

/*

We could use PS as Abstract Sytax tree, before loading/compiling the number
like field IDs shall be resolved.
_minocc shall generate reject if missing
_maxocc shall tell until which step to process.

each UBF field occurrence shall be counted on further...

Valid json for above:

{
    "a": "hello world",
    "b": 
        {
            "username" : "John",
            "lastname" : "Doe" 
        },
    "c": ["A", "B", "C", "D", "E"],
    "d": 
        [
            {
                "test": "hello",
                "field2": "world",
                "sub_obj":
                    {
                        "car":"Volvo",
                        "mode":"S80" 
                    },
                "sub_array_of_obj":
                    [
                        {
                            "car":"Volvo",
                            "mode":"S80" 
                        },
                        {
                            "car":"Volvo",
                            "mode":"S60" 
                        }
                    ]
            },
            {
                "test": "hello2",
                "field2": "world2",
                "sub_obj":
                    {
                        "car":"Volvo2",
                        "mode":"S802" 
                    },
                "sub_array_of_obj":
                    [
                        {
                            "car":"Volvo2",
                            "mode":"S802" 
                        },
                        {
                            "car":"Volvo2",
                            "mode":"S602" 
                        }
                    ]
            }
        ]
}

*/

History

#1 Updated by Madars Vitolins 6 months ago

  • Tracker changed from Bug to Feature

#2 Updated by Madars Vitolins 6 months ago

Other option would be to describe the mapping with Squirel script classes and then drive them recursively for build and parse:

mapping could look like:


class Transaction
{
    </ field = "C_RRN", min=12, max=12 /> 
    rrn;

    </ field = "C_AMOUNT", min=12, max=12/> 
    amount;

    </ field = "C_CURRCODE", min=3, max=3/> 
    currcode;
}

class User
{
    </ field = "C_FIRSTNAME", min=1, max=32/> 
    firstname;

    </ field = "C_USERNAME", min=1, max=32/> 
    username;

    Transaction [] tran;
}

class Account
{
    </ field = "C_ACCNUM", min=1, max=28> 
    accnum;

    Transaction [] tran;
}

When parsed in, the buffer could contain:

# Top level class
EX_CLASS     User
C_FIRSTNAME    JIM
C_USERNAME    MORRISON
C_RRN        123456789012
C_RRN        123456789013
C_RRN        123456789014
C_AMOUNT    1.111
C_AMOUNT    1.112
C_AMOUNT    1.113
C_CURRCODE    643
C_CURRCODE    643
C_CURRCODE    643

When responding, we may respond with other object projection, for example
EX_CLASS     Transaction
# and send only response data (single tran):

C_RRN        123456789012
C_AMOUNT    1.111
C_CURRCODE    643

{
    "ex_class":"User",
    "firstname":"JIM",
    "username":"MORRISON" 
    "tran": [
            {
                "rrn":"123456789012",
                "amount":"1.111",
                "currcode":"643" 
            }
            ,
            {
                "rrn":"123456789013",
                "amount":"1.133",
                "currcode":"643" 
            }
            ,
            {
                "rrn":"123456789014",
                "amount":"1.144",
                "currcode":"643" 
            }
        ]
}

#3 Updated by Madars Vitolins 5 months ago

sub-Object occurrence:

</ occ_field="C_ACCTYPE" occ_value="1" /> 
Transaction tran;

Also available in: Atom PDF