• So I tried an array of 15 length and it works.
    This version adds another step to do Uint16Array.

    console.log("Add this step to convert Uint16Array to Uint8Array");
    A.C = new Uint8Array(A.C.buffer);
    //the trick
    console.log("apply btoa trick");
    A.C=btoa(A.C);
    console.log("A= ",A);
    

    and

    //the trick in reverse
    console.log("reverse the trick");
    H.C=E.toUint8Array(atob(H.C));
    console.log("H= ",H);
    
    console.log("Convert H.C back to Uint16Array");
    H.C= new Uint16Array(H.C.buffer);
    console.log("H16= ",H);
    

    The output:

    >echo(0);
    Create an object with an Uint16Array
    A=  { "B": 1240,
      "C": new Uint16Array([0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400])
     }
    Stringify the object
    D=  {"B":1240,"C":new Uint16Array([0,100,200,300,400,500,600,700,800,900,1000,1100,1200,1300,1400])}
    Parse it back returns undefined
    F=  undefined
    Add this step to convert Uint16Array to Uint8Array
    apply btoa trick
    A=  { "B": 1240,
      "C": "AABkAMgALAGQAfQBWAK8AiADhAPoA0wEsAQUBXgF"
     }
    stringify
    D=  {"B":1240,"C":"AABkAMgALAGQAfQBWAK8AiADhAPoA0wEsAQUBXgF"}
    Write D to flash
    Read G from flash
    G=  new Uint8Array([123, 34, 66, 34, 58, 49, 50, 52, 48, 44, 34, 67, 34, 58, 34, 65, 65, 66, 107, 65, 77, 103, 65, 76, 65, 71, 81, 65, 102, 81, 66, 87, 65, 75, 56, 65, 105, 65, 68, 104, 65, 80, 111, 65, 48, 119, 69, 115, 65, 81, 85, 66, 88, 103, 70, 34, 125])
    parse G into H
    H=  { "B": 1240,
      "C": "AABkAMgALAGQAfQBWAK8AiADhAPoA0wEsAQUBXgF"
     }
    reverse the trick
    H=  { "B": 1240,
      "C": new Uint8Array([0, 0, 100, 0, 200, 0, 44, 1, 144, 1, 244, 1, 88, 2, 188, 2, 32, 3, 132, 3, 232, 3, 76, 4, 176, 4, 20, 5, 120, 5])
     }
    Convert H.C back to Uint16Array
    H16=  { "B": 1240,
      "C": new Uint16Array([0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400])
     }
    

    Anyone want to try Uint32Array?


    1 Attachment

About