Example usage for java.util UUID getLeastSignificantBits

List of usage examples for java.util UUID getLeastSignificantBits

Introduction

In this page you can find the example usage for java.util UUID getLeastSignificantBits.

Prototype

public long getLeastSignificantBits() 

Source Link

Document

Returns the least significant 64 bits of this UUID's 128 bit value.

Usage

From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleProtocol.java

@Override
public byte[] encodeAppStart(UUID uuid, boolean start) {
    if (mFwMajor >= 3) {
        final short LENGTH_APPRUNSTATE = 17;
        ByteBuffer buf = ByteBuffer.allocate(LENGTH_PREFIX + LENGTH_APPRUNSTATE);
        buf.order(ByteOrder.BIG_ENDIAN);
        buf.putShort(LENGTH_APPRUNSTATE);
        buf.putShort(ENDPOINT_APPRUNSTATE);
        buf.put(start ? APPRUNSTATE_START : APPRUNSTATE_STOP);
        buf.putLong(uuid.getMostSignificantBits());
        buf.putLong(uuid.getLeastSignificantBits());
        return buf.array();
    } else {//  w  ww . ja v a  2  s.c om
        ArrayList<Pair<Integer, Object>> pairs = new ArrayList<>();
        int param = start ? 1 : 0;
        pairs.add(new Pair<>(1, (Object) param));
        return encodeApplicationMessagePush(ENDPOINT_LAUNCHER, uuid, pairs);
    }
}

From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleProtocol.java

private byte[] encodeTimelinePin(UUID uuid, int timestamp, short duration, int icon_id, String title,
        String subtitle) {//from  w  ww .jav a2  s . c o  m
    final short TIMELINE_PIN_LENGTH = 46;

    icon_id |= 0x80000000;
    byte attributes_count = 2;
    byte actions_count = 0;

    int attributes_length = 10 + title.getBytes().length;
    if (subtitle != null && !subtitle.isEmpty()) {
        attributes_length += 3 + subtitle.getBytes().length;
        attributes_count += 1;
    }

    int pin_length = TIMELINE_PIN_LENGTH + attributes_length;
    ByteBuffer buf = ByteBuffer.allocate(pin_length);

    // pin - 46 bytes
    buf.order(ByteOrder.BIG_ENDIAN);
    buf.putLong(uuid.getMostSignificantBits());
    buf.putLong(uuid.getLeastSignificantBits());
    buf.putLong(0); // parent
    buf.putLong(0);
    buf.order(ByteOrder.LITTLE_ENDIAN);
    buf.putInt(timestamp); // 32-bit timestamp
    buf.putShort(duration);
    buf.put((byte) 0x02); // type (0x02 = pin)
    buf.putShort((short) 0x0001); // flags 0x0001 = ?
    buf.put((byte) 0x01); // layout was (0x02 = pin?), 0x01 needed for subtitle but seems to do no harm if there isn't one

    buf.putShort((short) attributes_length); // total length of all attributes and actions in bytes
    buf.put(attributes_count);
    buf.put(actions_count);

    buf.put((byte) 4); // icon
    buf.putShort((short) 4); // length of int
    buf.putInt(icon_id);
    buf.put((byte) 1); // title
    buf.putShort((short) title.getBytes().length);
    buf.put(title.getBytes());
    if (subtitle != null && !subtitle.isEmpty()) {
        buf.put((byte) 2); //subtitle
        buf.putShort((short) subtitle.getBytes().length);
        buf.put(subtitle.getBytes());
    }

    return encodeBlobdb(uuid, BLOBDB_INSERT, BLOBDB_PIN, buf.array());
}

From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleProtocol.java

@Override
public byte[] encodeAppDelete(UUID uuid) {
    if (mFwMajor >= 3) {
        if (UUID_PEBBLE_HEALTH.equals(uuid)) {
            return encodeActivateHealth(false);
        }/* ww w  . j  av a 2  s .  co  m*/
        if (UUID_WORKOUT.equals(uuid)) {
            return encodeActivateHRM(false);
        }
        if (UUID_WEATHER.equals(uuid)) { //TODO: probably it wasn't present in firmware 3
            return encodeActivateWeather(false);
        }
        return encodeBlobdb(uuid, BLOBDB_DELETE, BLOBDB_APP, null);
    } else {
        final short LENGTH_REMOVEAPP_2X = 17;
        ByteBuffer buf = ByteBuffer.allocate(LENGTH_PREFIX + LENGTH_REMOVEAPP_2X);
        buf.order(ByteOrder.BIG_ENDIAN);
        buf.putShort(LENGTH_REMOVEAPP_2X);
        buf.putShort(ENDPOINT_APPMANAGER);
        buf.put(APPMANAGER_REMOVEAPP);
        buf.putLong(uuid.getMostSignificantBits());
        buf.putLong(uuid.getLeastSignificantBits());
        return buf.array();
    }
}

From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleProtocol.java

byte[] encodeApplicationMessagePush(short endpoint, UUID uuid, ArrayList<Pair<Integer, Object>> pairs) {
    int length = LENGTH_UUID + 3; // UUID + (PUSH + id + length of dict)
    for (Pair<Integer, Object> pair : pairs) {
        if (pair.first == null || pair.second == null)
            continue;
        length += 7; // key + type + length
        if (pair.second instanceof Integer) {
            length += 4;//from w ww .  j  a v a  2  s . c om
        } else if (pair.second instanceof Short) {
            length += 2;
        } else if (pair.second instanceof Byte) {
            length += 1;
        } else if (pair.second instanceof String) {
            length += ((String) pair.second).getBytes().length + 1;
        } else if (pair.second instanceof byte[]) {
            length += ((byte[]) pair.second).length;
        } else {
            LOG.warn("unknown type: " + pair.second.getClass().toString());
        }
    }

    ByteBuffer buf = ByteBuffer.allocate(LENGTH_PREFIX + length);
    buf.order(ByteOrder.BIG_ENDIAN);
    buf.putShort((short) length);
    buf.putShort(endpoint); // 48 or 49
    buf.put(APPLICATIONMESSAGE_PUSH);
    buf.put(++last_id);
    buf.putLong(uuid.getMostSignificantBits());
    buf.putLong(uuid.getLeastSignificantBits());
    buf.put((byte) pairs.size());

    buf.order(ByteOrder.LITTLE_ENDIAN);
    for (Pair<Integer, Object> pair : pairs) {
        if (pair.first == null || pair.second == null)
            continue;
        buf.putInt(pair.first);
        if (pair.second instanceof Integer) {
            buf.put(TYPE_INT);
            buf.putShort((short) 4); // length
            buf.putInt((int) pair.second);
        } else if (pair.second instanceof Short) {
            buf.put(TYPE_INT);
            buf.putShort((short) 2); // length
            buf.putShort((short) pair.second);
        } else if (pair.second instanceof Byte) {
            buf.put(TYPE_INT);
            buf.putShort((short) 1); // length
            buf.put((byte) pair.second);
        } else if (pair.second instanceof String) {
            String str = (String) pair.second;
            buf.put(TYPE_CSTRING);
            buf.putShort((short) (str.getBytes().length + 1));
            buf.put(str.getBytes());
            buf.put((byte) 0);
        } else if (pair.second instanceof byte[]) {
            byte[] bytes = (byte[]) pair.second;
            buf.put(TYPE_BYTEARRAY);
            buf.putShort((short) bytes.length);
            buf.put(bytes);
        }
    }

    return buf.array();
}

From source file:org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl.java

private CompletableFuture<Void> prepareLedgerInfoForOffloaded(long ledgerId, UUID uuid,
        String offloadDriverName, Map<String, String> offloadDriverMetadata) {
    log.info("[{}] Preparing metadata to offload ledger {} with uuid {}", name, ledgerId, uuid);
    return transformLedgerInfo(ledgerId, (oldInfo) -> {
        if (oldInfo.getOffloadContext().hasUidMsb()) {
            UUID oldUuid = new UUID(oldInfo.getOffloadContext().getUidMsb(),
                    oldInfo.getOffloadContext().getUidLsb());
            log.info("[{}] Found previous offload attempt for ledger {}, uuid {}" + ", cleaning up", name,
                    ledgerId, uuid);/*www  . j  a va2s  . c o  m*/
            cleanupOffloaded(ledgerId, oldUuid,
                    OffloadUtils.getOffloadDriverName(oldInfo,
                            config.getLedgerOffloader().getOffloadDriverName()),
                    OffloadUtils.getOffloadDriverMetadata(oldInfo,
                            config.getLedgerOffloader().getOffloadDriverMetadata()),
                    "Previous failed offload");
        }
        LedgerInfo.Builder builder = oldInfo.toBuilder();
        builder.getOffloadContextBuilder().setUidMsb(uuid.getMostSignificantBits())
                .setUidLsb(uuid.getLeastSignificantBits());
        OffloadUtils.setOffloadDriverMetadata(builder, offloadDriverName, offloadDriverMetadata);
        return builder.build();
    }).whenComplete((result, exception) -> {
        if (exception != null) {
            log.warn("[{}] Failed to prepare ledger {} for offload, uuid {}", name, ledgerId, uuid, exception);
        } else {
            log.info("[{}] Metadata prepared for offload of ledger {} with uuid {}", name, ledgerId, uuid);
        }
    });
}