Uploaded image for project: 'CloverDX'
  1. CloverDX
  2. CLO-18043

BSON parsing and serialization functions

    XMLWordPrintable

    Details

    • Type: Story
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: rel-5-6-0
    • Component/s: None
    • Security Level: Users (General product issues)
    • Story Points:
      8
    • QA Testing:
      UNDECIDED
    • Epic Link:
    • Sprint:
      Green Sprint 106, Green Sprint 107, Green Sprint 108

      Description

      Introduce following functions:

      • function byte writeBson(<variant var>|list|map) - It will produce standard BSON. Serializes the passed value (has to be List or Map or variant) into BSON representation (see http://bsonspec.org/spec.html).
      • function byte toBytes(<variant var>|list|map) - It will produce BSON with Clover specific types. It uses “Clover” specific handling of List or “atomic” variant values as these are not directly supported by BSON specification- but should still create valied BSON data.
        variant myvariant;
        myvariant=json2obj('\{"city":"chicago","name":"jon doe","age":"22"}’);
        byte serialized = obj2bson(myvariant);
        printErr(byte2hex(serialized));
        

        Produces following output:

        35000000026369747900080000006368696361676f00026e616d6500080000006a6f6e20646f650002616765000300000032320000
        

        Note: BSON standard does not define (de)serialization of BigDecimal (CTL’s decimal). It is implemented using Clover specific BSON type which would not be compatible with other SW using BSON as an exchange format.

      • function variant parseBson(byte) - deserializes the passed value/bytes into variant object containing List, Map or any of the primitive values. Note: the primitive values are only supported by corresponding obj2bson() function. BSON specification does not support serialization of primitive value only.
        variant myvariant;
        myvariant=bson2obj(hex2byte(“35000000026369747900080000006368696361676f00026e616d6500080000006a6f6e5f646f650002616765000300000032320000”));
        printErr(myvariant);
        

        Produces following output:

        {city=chicago, name=jon_doe, age=22}
        
      • function variant parseBson(byte bson, string key) - deserializes all elements with passed-in key from the BSON/bytes representation into list of variant objects or null if no such key exists in BSON representation.
        variant myvariant;
        myvariant=bson2obj(hex2byte(“35000000026369747900080000006368696361676f00026e616d6500080000006a6f6e5f646f650002616765000300000032320000”),”name”);
        printErr(myvariant);
        

        Produces following output:

        [jon_doe]
        

        Note: The result is an CTL list containing 1 element - a string

        variant obj=json2obj('\{"city":"chicago","name":"jon_doe", "other":{"name":"junior"},"age":"22"}');
        byte byteval=obj2bson(obj);
        printErr(bson2obj(byteval,"name"));
        

        Produces following output:

        [jon_doe, junior]
        

        Note: The result is an CTL list containing 2 element - strings, found in the whole hierarchy of BSON data

        Attachments

          Issue Links

          There are no Sub-Tasks for this issue.

            Activity

              People

              Assignee:
              slamam Martin Slama
              Reporter:
              krivanekm Milan Krivanek
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0 minutes
                  0m
                  Logged:
                  Time Spent - 15 minutes
                  15m