Hi,
I am developing an SMPP (Short Message Peer to Peer) client in PL/SQL (10g) and I do not know how to convert numbers in the format asked by the Protocol Specification (v3.4).
(If anyone is enterested, the specification document can be found here:
Here )
According to the specification, numbers should be represented as "An unsigned value with the defined number of octets (in our case, 4 octets). The octets will always be transmitted MSB first (Big Endian)".
So far, I have found two code examples on the Internet demonstrating this, one in PHP and another in Java.
In the PHP example, the integer numbers are transformed by the "pack" function into unsigned long (always 32 bit, big endian byte order) and then the result is written to the socket. The code where this is done is the following:
$header = pack("NNNN", $v1, $v2, $v3, $v4);
fwrite($this->_socket, $header, 16);
In the java example, the numbers are tranformed into byte arrays using the following code:
int OCTET_MASK = 0xff;
int i = (int) data;
byte[] intBuf = new byte[4];
intBuf[3] = (byte) (i & OCTET_MASK);
intBuf[2] = (byte) ((i >>> 8) & OCTET_MASK);
intBuf[1] = (byte) ((i >>> 16) & OCTET_MASK);
intBuf[0] = (byte) ((i >>> 24) & OCTET_MASK);
They are then concatenated into one byte[] array and then again written to the socket.
Is there a way to achieve this functionality using PL/SQL?
Thank you in advance,
Max