0

i am working in ELectronJS app that generate QR code from speceific requirement given by the client,

  • it is mandatory to generate and print QR code encoded in Base64 format with up to 500 characters.
  • The QR code fields shall be encoding in Tag-Length-Value (TLV) format with the tag values specified in the “Tag” column of the adjacent table.
  • The TLV encoding shall be as follows:
    • Tag: the tag value as mentioned above stored in one byte.
    • for tags 1 to 5 : - Length: the length of the byte array resulted from the UTF8 encoding of the field value. The length shall be stored in one byte. - Value: the byte array resulted from the UTF8 encoding of the field value.
    • for tags 6 :
      • Length: length of hash (SHA256 ) is 32 bytes
      • Value: the byte array constituting the value of each field

tags as follows:

  1. name

  2. address

  3. age

  4. salary

  5. yearly tax in percentage

  6. Hash of XML salary report ( i didn't implement this yet in the code )

i am starting experimenting this in nodeJS because using the Buffer module in nodeJS will make converting the strings to Hex values is very easy.

const { Buffer } = require("buffer");

var name = "John"; // tag 1
var address = "88 times Circlem, new Castle"; // tag 2
var age = "42"; // tag 3
var salary = "8500.00"; // tag 4
var tax = "20"; // tag 5

function toHex(name, address, age, salary, tax) {
tag_name = "1";
tag_s = Buffer.from(tag_name).toString("hex");
length_name = name.length.toString();
length_s = Buffer.from(length_name).toString("hex");
buffer_name = Buffer.from(name).toString("hex");

tag_address = "2";
tag_ta = Buffer.from(tag_address).toString("hex");
length_address = address.length.toString();
length_t = Buffer.from(length_address).toString("hex");
buffer_address = Buffer.from(address).toString("hex");

tag_age = "3";
tag_ti = Buffer.from(tag_age).toString("hex");
length_age = age.length.toString();
length_ti = Buffer.from(length_age).toString("hex");
buffer_age = Buffer.from(age).toString("hex");

tag_salary = "4";
tag_to = Buffer.from(tag_salary).toString("hex");
length_salary = salary.length.toString();
length_s = Buffer.from(length_salary).toString("hex");
buffer_salary = Buffer.from(salary).toString("hex");

tag_tax = "5";
tag_t = Buffer.from(tag_tax).toString("hex");
length_tax = tax.length.toString();
length_v = Buffer.from(length_tax).toString("hex");
buffer_tax = Buffer.from(tax).toString("hex");

allstring =
tag_s +
length_s +
buffer_name +
tag_ta +
length_t +
buffer_address +
tag_ti +
length_ti +
buffer_age +
tag_to +
length_s +
buffer_salary +
tag_t +
length_v +
buffer_tax;

allbase64 = Buffer.from(allstring).toString("base64");

console.log(`
tag_name = ${tag_name}
tag_s = ${tag_s}
length_name = ${length_name}
length_s = ${length_s}
buffer_name = ${buffer_name}

tag_address = ${tag_address}
tag_ta = ${tag_ta}
length_address = ${length_address}
length_t = ${length_t}
buffer_address = ${buffer_address}

tag_age = ${tag_age}
tag_ti = ${tag_ti}
length_age = ${length_age}
length_ti = ${length_ti}
buffer_age = ${buffer_age}

tag_salary = ${tag_salary}
tag_to = ${tag_to}
length_salary = ${length_salary}
length_s = ${length_s}
buffer_salary = ${buffer_salary}

tag_tax = ${tag_tax}
tag_t = ${tag_t}
length_tax = ${length_tax}
length_v = ${length_v}
buffer_tax = ${buffer_tax}



allstring = ${allstring}

allbase64 = ${allbase64}
`);
}

toHex(name, address, age, salary, tax);

is this proper implementation for the TLV ... ?? only packing strings into hex using Buffer module then concatenate all these pieces together ??

Maged
  • 11
  • 2
  • 1
    You aren't really asking a specific question here. What problem are you running into? – Joseph Nov 11 '21 at 08:29
  • is this proper implementation for the TLV ... ?? only packing strings into hex using Buffer module then concatenate all these pieces together ?? – Maged Nov 11 '21 at 14:23
  • 1
    "proper implementation" is completely subjective opinion. Questions asking for opinions do no follow the guidelines for SO. – daddygames Nov 11 '21 at 14:26
  • what i mean is this the right way to implement TLV ( converting tags, lengths and values to hex then concatenate them together or this is wrong ? – Maged Nov 12 '21 at 07:19

0 Answers0