nitingautam / jsmpp

Automatically exported from code.google.com/p/jsmpp
Apache License 2.0
0 stars 0 forks source link

Receiving Long Message #92

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago

Hi,

I am facing an issue in interpreting the optional parameters when receiving 
long message.

Is there any sample code which displays how to read optional parameters?

Original issue reported on code.google.com by diptigar...@gmail.com on 7 Feb 2011 at 4:30

GoogleCodeExporter commented 9 years ago
Hi !

This is what i'm currently using :

    public static byte [] newPayLoad(OptionalParameter [] parameters) {
        byte [] result = null;
        for (OptionalParameter param : parameters) {
            if (param.tag ==Tag.MESSAGE_PAYLOAD.code()) {
                result = getValue(param);
                break;
            }
        }
        return result;
    }

    private static byte[] getValue(OptionalParameter param) {
        byte [] value = param.serialize();
        byte [] result = new byte[value.length -4];
        System.arraycopy(value, 4, result, 0, value.length-4);
        return result;
    }

Take care that not all the optional parameters are treated the same :

    public static int newSarMsgRefNum(OptionalParameter [] parameters) {
        int result = 0;
        for (OptionalParameter param : parameters) {
            if (param.tag ==Tag.SAR_MSG_REF_NUM.code()) {
                byte [] serialize = param.serialize();
                result = OctetUtil.bytesToShort(serialize,4);
                break;
            }
        }
        return result;
    }

or 
    public static int newSarSegmentSeqnum(OptionalParameter [] parameters) {
        int result = 0;
        for (OptionalParameter param : parameters) {
            if (param.tag == Tag.SAR_SEGMENT_SEQNUM.code()) {
                byte [] serialize = param.serialize();
                result = serialize[4];
                break;
            }
        }
        return result;
    }

Probably there's a better way, but that's the way it's working for me.

Original comment by almull...@gmail.com on 7 Mar 2011 at 3:36