How to convert app global state values to human-readable format?

I’m trying to show the values of an application global state in a human-readable format.
If the global state param is of type “Bytes”, Then it can be converted to a human-readable string by doing

EX: atob(“Z29sZGk=”) will return “glodi”

But it is failing, if the value stored is the address or Tx-id.
I know how to decode address and tx-id to actual values, but the problem I’m trying to resolve is how to identify whether the values saved as “Bytes” are a normal string vs address/tx-id?

For javascript you can use something like Buffer.from(thevalue, “base64”) which will give you a Uint8Array representing the 32 byte version of the transaction id. To get the human readable one you can base32 encode it and strip the = padding if present.

Right,

Normal string, Address, tx-id , all of them are stored as bytes in a global state.
To decode to actual values:

Normal string: atob(value.bytes);
Address: sdk.encodeAddress(new Uint8Array(Buffer.from(value.bytes, “base64”)));
tx-id: encode(new Uint8Array(Buffer.from(value.bytes, “base64”))).slice(0, 52);

But here the problem is that all of them are stored as bytes and there is no way to distinguish between normal string vs address vs tx-id.

Right, unless you key them specifically to denote what type they are you’d have no way to know if a given 32 byte array is a txid or account or a generic hash

Got it. thanks, ben.
In my case, it can be any application, so I will not be able to identify based on the keys.
I will provide all the options in the UI and users can toggle between them.