Search in sources :

Example 6 with ByteBuffer

use of org.smpp.util.ByteBuffer in project opensmpp by OpenSmpp.

the class TLVUByte method getValueData.

/**
 * Creates byt buffer containing one unsigned byte.
 * @return the byte buffer with one unsingned byte
 */
protected ByteBuffer getValueData() throws ValueNotSetException {
    ByteBuffer valueBuf = new ByteBuffer();
    valueBuf.appendByte(encodeUnsigned(getValue()));
    return valueBuf;
}
Also used : ByteBuffer(org.smpp.util.ByteBuffer)

Example 7 with ByteBuffer

use of org.smpp.util.ByteBuffer in project opensmpp by OpenSmpp.

the class TLV method getData.

/**
 * Returns the binary TLV created from tag, length and binary data value
 * carried by this TLV.
 */
public ByteBuffer getData() throws ValueNotSetException {
    if (hasValue()) {
        ByteBuffer tlvBuf = new ByteBuffer();
        tlvBuf.appendShort(getTag());
        tlvBuf.appendShort(encodeUnsigned(getLength()));
        tlvBuf.appendBuffer(getValueData());
        return tlvBuf;
    } else {
        return null;
    }
}
Also used : ByteBuffer(org.smpp.util.ByteBuffer)

Example 8 with ByteBuffer

use of org.smpp.util.ByteBuffer in project opensmpp by OpenSmpp.

the class TLV method setData.

/**
 * Overwrites <code>ByteData</code>'s <code>setData</code> and parses
 * tag, length and the binary data value from the buffer. For parsing the
 * data value calls abstract <code>setValueData</code>.
 */
public void setData(ByteBuffer buffer) throws NotEnoughDataInByteBufferException, TLVException {
    short newTag = buffer.removeShort();
    int length = buffer.removeShort();
    ByteBuffer valueBuf = buffer.removeBuffer(length);
    setValueData(valueBuf);
    setTag(newTag);
}
Also used : ByteBuffer(org.smpp.util.ByteBuffer)

Example 9 with ByteBuffer

use of org.smpp.util.ByteBuffer in project opensmpp by OpenSmpp.

the class ByteBufferTest method testAppendByte1.

@Test
public void testAppendByte1() {
    buffer = new ByteBuffer(new byte[] {});
    buffer.appendByte(t_bite);
    assertBufferMatches(t_bite);
}
Also used : ByteBuffer(org.smpp.util.ByteBuffer) Test(org.junit.Test)

Example 10 with ByteBuffer

use of org.smpp.util.ByteBuffer in project opensmpp by OpenSmpp.

the class AddressTest method testGetData.

@Test
public void testGetData() throws Exception {
    for (byte ton : TONS) {
        for (byte npi : NPIS) {
            for (int len = 1; len <= MAX_ADDRESS_LENGTH; len++) {
                String a = address(len);
                address = new Address(ton, npi, a, len + 1);
                ByteBuffer buffer = address.getData();
                assertEquals(ton, buffer.removeByte());
                assertEquals(npi, buffer.removeByte());
                assertEquals(a, buffer.removeCString());
            }
        }
    }
}
Also used : ByteBuffer(org.smpp.util.ByteBuffer) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

ByteBuffer (org.smpp.util.ByteBuffer)21 Test (org.junit.Test)9 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 PDU (org.smpp.pdu.PDU)2 UnknownCommandIdException (org.smpp.pdu.UnknownCommandIdException)2 HeaderIncompleteException (org.smpp.pdu.HeaderIncompleteException)1 MessageIncompleteException (org.smpp.pdu.MessageIncompleteException)1 PDUException (org.smpp.pdu.PDUException)1 NotEnoughDataInByteBufferException (org.smpp.util.NotEnoughDataInByteBufferException)1