Java Code Examples for javax.bluetooth.DataElement#DATALT

The following examples show how to use javax.bluetooth.DataElement#DATALT . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ServiceRecordImpl.java    From pluotsorbet with GNU General Public License v2.0 5 votes vote down vote up
private DataElement dataElementCopy(DataElement original) {
    if ((original.getDataType() == DataElement.DATSEQ)
            || (original.getDataType() == DataElement.DATALT)) {
        DataElement copy = new DataElement(original.getDataType());
        Enumeration elements = (Enumeration) original.getValue();

        while (elements.hasMoreElements()) {
            copy.addElement(dataElementCopy((DataElement)
                    elements.nextElement()));
        }
        return copy;
    } else {
        return original;
    }
}
 
Example 2
Source File: DataElementSerializer.java    From pluotsorbet with GNU General Public License v2.0 5 votes vote down vote up
public long getDataSize(DataElement data) {
    int type = data.getDataType();
    long size = getPureDataSize(data);
    if ((type == DataElement.NULL) || (type == DataElement.BOOL)
            || (type == DataElement.INT_1) || (type == DataElement.U_INT_1)
            || (type == DataElement.INT_2) || (type == DataElement.U_INT_2)
            || (type == DataElement.INT_4) || (type == DataElement.U_INT_4)
            || (type == DataElement.INT_8) || (type == DataElement.U_INT_8)
            || (type == DataElement.INT_16)
            || (type == DataElement.U_INT_16)
            || (type == DataElement.UUID)) {
        return size + 1;
    } else if ((type == DataElement.DATSEQ)
            || (type == DataElement.DATALT) || (type == DataElement.STRING)
            || (type == DataElement.URL)) {
        if (size <= 0xffL) {
            return size + 2;
        } else if (size <= 0xffffL) {
            return size + 3;
        } else if (size <= 0xffffffffL) {
            return size + 5;
        } else {
            throw new RuntimeException("Data size is too large.");
        }
    } else {
        throw new RuntimeException("Unexpected data type.");
    }
}
 
Example 3
Source File: DataElementSerializer.java    From pluotsorbet with GNU General Public License v2.0 5 votes vote down vote up
public long getPureDataSize(DataElement data) {
    switch (data.getDataType()) {
        case DataElement.NULL:
            return 0;
        case DataElement.BOOL:
        case DataElement.INT_1:
        case DataElement.U_INT_1:
            return 1;
        case DataElement.INT_2:
        case DataElement.U_INT_2:
            return 2;
        case DataElement.INT_4:
        case DataElement.U_INT_4:
            return 4;
        case DataElement.INT_8:
        case DataElement.U_INT_8:
            return 8;
        case DataElement.INT_16:
        case DataElement.U_INT_16:
            return 16;
        case DataElement.DATSEQ:
        case DataElement.DATALT:
            long size = 0;
            Enumeration elements = (Enumeration)data.getValue();
            while (elements.hasMoreElements()) {
                size += getDataSize((DataElement)elements.nextElement());
            }
            return size;
        case DataElement.STRING:
        case DataElement.URL:
            return ((String)data.getValue()).length();
        case DataElement.UUID:
            return 16;
        default:
            throw new RuntimeException("Unknown data type.");
    }
}