Inserting NULLs into a message....

PaulR

Active Member
Licensed User
Longtime User
Hi

I want to assemble messages for the Open Sound Control (OSC) protocol which requires padding out parts of the message with NULL values.

What would be the best way of doing that?

I assume I want to Dim Message() As Byte, but how to I append NULLs where I want them?

Cheers

Paul
 

PaulR

Active Member
Licensed User
Longtime User
Yes, that makes sense. What would be the syntax for appending values into a Byte? I am doing this...

B4X:
Dim data() As Byte
data = "/foo".0.0.0.0.GetBytes("UTF8")

... but getting a syntax error (works without the zeros).
 
Upvote 0

Jost aus Soest

Active Member
Licensed User
Longtime User
GetBytes works only on strings and results in an byte array.

For example you could do something like this:
B4X:
Dim data() As Byte
data = "/foo....".GetBytes("UTF8")  '<-- "." as placeholder
data(4) = 0
data(5) = 0
data(6) = 0
data(7) = 0

Or you use the chr-function, e. g.:
B4X:
s = "/foo....".Replace(".", Chr(0))
or
B4X:
s = "/foo" & Chr(0) & Chr(0) & Chr(0) & Chr(0)
 
Upvote 0

PaulR

Active Member
Licensed User
Longtime User
Sorry, but how would I go around putting appending a Big Endian 32 bit twos compliment integer or a 32 bit floating point into a string?
 
Upvote 0

rbsoft

Active Member
Licensed User
Longtime User
@Jost

Nice picture. Is that inspired by the "Jäger von Soest", Simplicius Simplicissimus?

Rolf
 
Upvote 0

rbsoft

Active Member
Licensed User
Longtime User
Schickes Outfit!

Rolf
 
Upvote 0

PaulR

Active Member
Licensed User
Longtime User
Hi, sorry to derail the thread. :)

I have two messages, one is....


blah = "^^^1".Replace("^", Chr(0)).Replace("1",Chr(1))

blah = "~~~~".Replace("^", Chr(0)).Replace("~",Chr(255))

The first one when I.....

data = blah.GetBytes("UTF8")

... sends okay (a 1 value), but the second one sends -1010842689 instead of -1 (which is what 0xFFFFFFFF should be).

Any ideas as to what is happening, all I want to do is send FFFFFFFF....

:sign0013:
 
Upvote 0

PaulR

Active Member
Licensed User
Longtime User
Well it turns out that any value above 127 is sent in multiple bytes with UTF-8. 255 is an invalid value.

On a wing I tried GetBytes("ASCII") but it too doesn't send any value about 127, changing any value above that to 63.

I tried GetBytes(""), but it crashes the app.

So my revised question is how do I send byte values greater than 127 via UDP in Basic4Android?

edit: I have also been using the ByteConverter library StringToBytes function that requires stating what encoding will be used. The issue is that I don't want any encoding.

edit2: So my final question is... how do I send raw data via UDP? (I can send raw data, on a byte by byte basis, but want to store the information in a string, for conversion to ASCII values).
 
Last edited:
Upvote 0
Top