Skip to content
This repository has been archived by the owner on Aug 1, 2022. It is now read-only.

api util.codec

Ayhan Rashidov edited this page Sep 27, 2021 · 4 revisions

$.util.codec API

Represents the codec namespace with its fields.

Reference

  • SAP Help

https://help.sap.com/doc/3de842783af24336b6305a3c0223a369/2.0.03/en-US/$.util.codec.html

  • Module

https://github.com/SAP/xsk/tree/main/modules/api/api-xsjs/src/main/resources/META-INF/dirigible/xsk/util/codec

  • Sample usage:
var codec = $.util.codec;
var util = $.util;

var text1 = "dirigible as hex";
var text2 = "dirigible as base64";

//HEX
var encodedHex = codec.encodeHex(text1);
result1 = "'" + text1 + "'" + " encoded to hex is "+ encodedHex;

var decodedHex = codec.decodeHex(encodedHex); 
result2 = "'" + encodedHex + "'" + " decoded to ArrayBuffer is: ["+ decodedHex+"]";

var valueFromHex = util.stringify(decodedHex);
result3 = " Array Buffer stringified is "+"'" + valueFromHex +"'" ;

let resultHex = `\n${result1} `;
resultHex += `\n${result2} `;
resultHex += `\n${result3} `;


//BASE64
var encodedToBase64 = codec.encodeBase64("dirigible as base64");
result4 = "'" + text2 + "'" + " encoded to base64 is "+ encodedToBase64;

var decodedBase64 = codec.decodeBase64(encodedToBase64);
result5 = "'" + encodedToBase64 + "'" + " encoded to ArrayBuffer is "+ decodedBase64;

var valueFromBase64 = util.stringify(decodedBase64);
result6 = " Array Buffer stringified is "+"'" +  valueFromBase64+"'" ;

let resultBase = `\n${result4} `;
resultBase += `\n${result5} `;
resultBase += `\n${result6} `;

$.response.setBody(resultHex + "\n" + resultBase );
  • Methods
Members Description Type
decodeBase64(base64Data) Decodes Base64 data ArrayBuffer
decodeHex(hexData) Decodes hexadecimal data. ArrayBuffer
encodeBase64(data) Encodes data into Base64. String
encodeHex(data) Encodes data into hexadecimal format. String
  • Issues

https://github.com/SAP/xsk/issues/21

  • Unit Tests

https://github.com/SAP/xsk/blob/main/modules/engines/engine-xsjs/src/test/resources/test/xsk/util/codec/codec.xsjs

  • Integration Tests ❌

Wiki icons legend

✅ - Feature implemented and working as supposed.
⚠️ - Feature partially implemented and needs to be finished.
❌ - Feature not implemented yet.

Project

Architecture

Tips & Tricks

Infrastructure

Troubleshooting guide

Clone this wiki locally