webMethods.io - Convert a number encoded as integer into a number encoded in a binary string

Webmethods.io flowservices

Hi,

I’m trying to convert a number encoded as integer, into a number encoded in a binary string.

For example i make an API call that send me back this type of answer :

{
            "id": "xxxxx",
            "values": [
                {
                    "timestamp": 1693229506870,
                    "value": 11
                }
            ]
}

I want to convert the value 11 which is an integer into 0000000000001011 so that i can then decompose this string into bytes and transforme those bytes back into integer. For this example I will have to take bytes 0 to 12 then 12 to 16 and associate the translate value to a key.

I tried to use stringToStream as the documentation says but i only have an “inputStream” in return that i can’t read. (Not even with the streamToReader).
inputStream

I also tried to use stringToBytes as some people explains on the forum here but i don’t have the result i’m expecting.
stringToBytes

In both case i have an “encoded” input to add. I don’t know what to put in it. I found nothing in the doc that help us with that.

I insiste on the fact that i am on webmethods.io - flowservices so i can’t (or i don’t know how maybe) create a nodejs connector and integrate it to my flowservice (we can only do that on workflows i think).

Thanks in advance !

2 Likes

Hi Kassandra,

same question here as in the referenced thread:
What is your use case for this requirement?
Can you provide some screenshots of the steps you have tried so far, i.e. using pub.string:stringToBytes?
So we can check what is happening here.

As I have never worked with webMethods.io, I might not be able to assist further.
Hopefully, there will be some other members to pick up this thread and continue the analysis with you.

Regards,
Holger

1 Like

Hi Kassandra,

bytes (or better bytes) is an object data type in the pipeline which cannot be displayed in clear text.
Instead of this it is only showing a pointer address where the data is stored in the JVM memory.
Same applies to stream.

I am still no seeing the use case for such transformation.
Can you elaborate on this further, please?

When you really need to do this, you can do it “manually” as it was teached in school/studies:

REPEAT until value equals 0
- divide your value by 2 and append the remainder as an element of a char[].
- set value to the result of the devision without remainder
END REPEAT
get the length of the resulting char array
set the final result to char[] with length "16-length of array" filled with 0 and append the result from the repeat.

Regarding this:

Hopefully, you meant bytes 0 to 7 and 8 to 15, as a byte has always 8 binary digits.
Can you provide us the expected final outcome of your sample above for better understanding, please?

Regards,
Holger

1 Like

Sorry what I meant was from the first character to the 11th and then from the 12th to the last one.

I also tried to do it manually, it was not working but maybe i did something wrong because i just test it again and now it works.

Thanks for the help.

Hi Kassandra,

great, that it seems to be working now.

But I still cannot get the clue what should be the expected outcome of such a transformation and what it should be useful for.

Regards,
Holger