com.squareup.wire.Wire Java Examples

The following examples show how to use com.squareup.wire.Wire. 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: BgReading.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
private static void processFromMessage(BgReadingMessage btm) {
    if ((btm != null) && (btm.uuid != null) && (btm.uuid.length() == 36)) {
        BgReading bg = byUUID(btm.uuid);
        if (bg != null) {
            // we already have this uuid and we don't have a circumstance to update the record, so quick return here
            return;
        }
        if (bg == null) {
            bg = getForPreciseTimestamp(Wire.get(btm.timestamp, BgReadingMessage.DEFAULT_TIMESTAMP), CLOSEST_READING_MS, false);
            if (bg != null) {
                UserError.Log.wtf(TAG, "Error matches a different uuid with the same timestamp: " + bg.uuid + " vs " + btm.uuid + " skipping!");
                return;
            }
            bg = new BgReading();
        }

        bg.timestamp = Wire.get(btm.timestamp, BgReadingMessage.DEFAULT_TIMESTAMP);
        bg.calculated_value = Wire.get(btm.calculated_value, BgReadingMessage.DEFAULT_CALCULATED_VALUE);
        bg.filtered_calculated_value = Wire.get(btm.filtered_calculated_value, BgReadingMessage.DEFAULT_FILTERED_CALCULATED_VALUE);
        bg.calibration_flag = Wire.get(btm.calibration_flag, BgReadingMessage.DEFAULT_CALIBRATION_FLAG);
        bg.raw_calculated = Wire.get(btm.raw_calculated, BgReadingMessage.DEFAULT_RAW_CALCULATED);
        bg.raw_data = Wire.get(btm.raw_data, BgReadingMessage.DEFAULT_RAW_DATA);
        bg.calculated_value_slope = Wire.get(btm.calculated_value_slope, BgReadingMessage.DEFAULT_CALCULATED_VALUE_SLOPE);
        bg.calibration_uuid = btm.calibration_uuid;
        bg.uuid = btm.uuid;
        bg.save();
    } else {
        UserError.Log.wtf(TAG, "processFromMessage uuid is null or invalid");
    }
}
 
Example #2
Source File: BloodTest.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
private static void processFromMessage(BloodTestMessage btm) {
    if ((btm != null) && (btm.uuid != null) && (btm.uuid.length() == 36)) {
        boolean is_new = false;
        BloodTest bt = byUUID(btm.uuid);
        if (bt == null) {
            bt = getForPreciseTimestamp(Wire.get(btm.timestamp, BloodTestMessage.DEFAULT_TIMESTAMP), CLOSEST_READING_MS);
            if (bt != null) {
                UserError.Log.wtf(TAG, "Error matches a different uuid with the same timestamp: " + bt.uuid + " vs " + btm.uuid + " skipping!");
                return;
            }
            bt = new BloodTest();
            is_new = true;
        } else {
            if (bt.state != Wire.get(btm.state, BloodTestMessage.DEFAULT_STATE)) {
                is_new = true;
            }
        }
        bt.timestamp = Wire.get(btm.timestamp, BloodTestMessage.DEFAULT_TIMESTAMP);
        bt.mgdl = Wire.get(btm.mgdl, BloodTestMessage.DEFAULT_MGDL);
        bt.created_timestamp = Wire.get(btm.created_timestamp, BloodTestMessage.DEFAULT_CREATED_TIMESTAMP);
        bt.state = Wire.get(btm.state, BloodTestMessage.DEFAULT_STATE);
        bt.source = Wire.get(btm.source, BloodTestMessage.DEFAULT_SOURCE);
        bt.uuid = btm.uuid;
        bt.saveit(); // de-dupe by uuid
        if (is_new) { // cannot handle updates yet
            if (UploaderQueue.newEntry(is_new ? "insert" : "update", bt) != null) {
                if (JoH.quietratelimit("start-sync-service", 5)) {
                    SyncService.startSyncService(3000); // sync in 3 seconds
                }
            }
        }
    } else {
        UserError.Log.wtf(TAG, "processFromMessage uuid is null or invalid");
    }
}
 
Example #3
Source File: BgReading.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
private static void processFromMessage(BgReadingMessage btm) {
    if ((btm != null) && (btm.uuid != null) && (btm.uuid.length() == 36)) {
        BgReading bg = byUUID(btm.uuid);
        if (bg != null) {
            // we already have this uuid and we don't have a circumstance to update the record, so quick return here
            return;
        }
        if (bg == null) {
            bg = getForPreciseTimestamp(Wire.get(btm.timestamp, BgReadingMessage.DEFAULT_TIMESTAMP), CLOSEST_READING_MS, false);
            if (bg != null) {
                UserError.Log.wtf(TAG, "Error matches a different uuid with the same timestamp: " + bg.uuid + " vs " + btm.uuid + " skipping!");
                return;
            }
            bg = new BgReading();
        }

        bg.timestamp = Wire.get(btm.timestamp, BgReadingMessage.DEFAULT_TIMESTAMP);
        bg.calculated_value = Wire.get(btm.calculated_value, BgReadingMessage.DEFAULT_CALCULATED_VALUE);
        bg.filtered_calculated_value = Wire.get(btm.filtered_calculated_value, BgReadingMessage.DEFAULT_FILTERED_CALCULATED_VALUE);
        bg.calibration_flag = Wire.get(btm.calibration_flag, BgReadingMessage.DEFAULT_CALIBRATION_FLAG);
        bg.raw_calculated = Wire.get(btm.raw_calculated, BgReadingMessage.DEFAULT_RAW_CALCULATED);
        bg.raw_data = Wire.get(btm.raw_data, BgReadingMessage.DEFAULT_RAW_DATA);
        bg.calculated_value_slope = Wire.get(btm.calculated_value_slope, BgReadingMessage.DEFAULT_CALCULATED_VALUE_SLOPE);
        bg.calibration_uuid = btm.calibration_uuid;
        bg.uuid = btm.uuid;
        bg.save();
    } else {
        UserError.Log.wtf(TAG, "processFromMessage uuid is null or invalid");
    }
}
 
Example #4
Source File: BgReading.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
private static void processFromMessage(BgReadingMessage btm) {
    if ((btm != null) && (btm.uuid != null) && (btm.uuid.length() == 36)) {
        BgReading bg = byUUID(btm.uuid);
        if (bg != null) {
            // we already have this uuid and we don't have a circumstance to update the record, so quick return here
            return;
        }
        if (bg == null) {
            bg = getForPreciseTimestamp(Wire.get(btm.timestamp, BgReadingMessage.DEFAULT_TIMESTAMP), CLOSEST_READING_MS, false);
            if (bg != null) {
                UserError.Log.wtf(TAG, "Error matches a different uuid with the same timestamp: " + bg.uuid + " vs " + btm.uuid + " skipping!");
                return;
            }
            bg = new BgReading();
        }

        bg.timestamp = Wire.get(btm.timestamp, BgReadingMessage.DEFAULT_TIMESTAMP);
        bg.calculated_value = Wire.get(btm.calculated_value, BgReadingMessage.DEFAULT_CALCULATED_VALUE);
        bg.filtered_calculated_value = Wire.get(btm.filtered_calculated_value, BgReadingMessage.DEFAULT_FILTERED_CALCULATED_VALUE);
        bg.calibration_flag = Wire.get(btm.calibration_flag, BgReadingMessage.DEFAULT_CALIBRATION_FLAG);
        bg.raw_calculated = Wire.get(btm.raw_calculated, BgReadingMessage.DEFAULT_RAW_CALCULATED);
        bg.raw_data = Wire.get(btm.raw_data, BgReadingMessage.DEFAULT_RAW_DATA);
        bg.calculated_value_slope = Wire.get(btm.calculated_value_slope, BgReadingMessage.DEFAULT_CALCULATED_VALUE_SLOPE);
        bg.calibration_uuid = btm.calibration_uuid;
        bg.uuid = btm.uuid;
        bg.save();
    } else {
        UserError.Log.wtf(TAG, "processFromMessage uuid is null or invalid");
    }
}
 
Example #5
Source File: BloodTest.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
private static void processFromMessage(BloodTestMessage btm) {
    if ((btm != null) && (btm.uuid != null) && (btm.uuid.length() == 36)) {
        boolean is_new = false;
        BloodTest bt = byUUID(btm.uuid);
        if (bt == null) {
            bt = getForPreciseTimestamp(Wire.get(btm.timestamp, BloodTestMessage.DEFAULT_TIMESTAMP), CLOSEST_READING_MS);
            if (bt != null) {
                UserError.Log.wtf(TAG, "Error matches a different uuid with the same timestamp: " + bt.uuid + " vs " + btm.uuid + " skipping!");
                return;
            }
            bt = new BloodTest();
            is_new = true;
        } else {
            if (bt.state != Wire.get(btm.state, BloodTestMessage.DEFAULT_STATE)) {
                is_new = true;
            }
        }
        bt.timestamp = Wire.get(btm.timestamp, BloodTestMessage.DEFAULT_TIMESTAMP);
        bt.mgdl = Wire.get(btm.mgdl, BloodTestMessage.DEFAULT_MGDL);
        bt.created_timestamp = Wire.get(btm.created_timestamp, BloodTestMessage.DEFAULT_CREATED_TIMESTAMP);
        bt.state = Wire.get(btm.state, BloodTestMessage.DEFAULT_STATE);
        bt.source = Wire.get(btm.source, BloodTestMessage.DEFAULT_SOURCE);
        bt.uuid = btm.uuid;
        bt.saveit(); // de-dupe by uuid
        if (is_new) { // cannot handle updates yet
            if (UploaderQueue.newEntry(is_new ? "insert" : "update", bt) != null) {
                if (JoH.quietratelimit("start-sync-service", 5)) {
                    SyncService.startSyncService(3000); // sync in 3 seconds
                }
            }
        }
    } else {
        UserError.Log.wtf(TAG, "processFromMessage uuid is null or invalid");
    }
}
 
Example #6
Source File: BgReading.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
private static void processFromMessage(BgReadingMessage btm) {
    if ((btm != null) && (btm.uuid != null) && (btm.uuid.length() == 36)) {
        BgReading bg = byUUID(btm.uuid);
        if (bg != null) {
            // we already have this uuid and we don't have a circumstance to update the record, so quick return here
            return;
        }
        if (bg == null) {
            bg = getForPreciseTimestamp(Wire.get(btm.timestamp, BgReadingMessage.DEFAULT_TIMESTAMP), CLOSEST_READING_MS, false);
            if (bg != null) {
                UserError.Log.wtf(TAG, "Error matches a different uuid with the same timestamp: " + bg.uuid + " vs " + btm.uuid + " skipping!");
                return;
            }
            bg = new BgReading();
        }

        bg.timestamp = Wire.get(btm.timestamp, BgReadingMessage.DEFAULT_TIMESTAMP);
        bg.calculated_value = Wire.get(btm.calculated_value, BgReadingMessage.DEFAULT_CALCULATED_VALUE);
        bg.filtered_calculated_value = Wire.get(btm.filtered_calculated_value, BgReadingMessage.DEFAULT_FILTERED_CALCULATED_VALUE);
        bg.calibration_flag = Wire.get(btm.calibration_flag, BgReadingMessage.DEFAULT_CALIBRATION_FLAG);
        bg.raw_calculated = Wire.get(btm.raw_calculated, BgReadingMessage.DEFAULT_RAW_CALCULATED);
        bg.raw_data = Wire.get(btm.raw_data, BgReadingMessage.DEFAULT_RAW_DATA);
        bg.calculated_value_slope = Wire.get(btm.calculated_value_slope, BgReadingMessage.DEFAULT_CALCULATED_VALUE_SLOPE);
        bg.calibration_uuid = btm.calibration_uuid;
        bg.uuid = btm.uuid;
        bg.save();
    } else {
        UserError.Log.wtf(TAG, "processFromMessage uuid is null or invalid");
    }
}
 
Example #7
Source File: DataBundleUtil.java    From android_external_GmsLib with Apache License 2.0 5 votes vote down vote up
public static DataMap readDataMap(byte[] bytes, List<Asset> assets) {
    try {
        return readDataMap(new Wire().parseFrom(bytes, DataBundle.class), assets);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
Example #8
Source File: McsInputStream.java    From android_packages_apps_GmsCore with Apache License 2.0 5 votes vote down vote up
private static Message read(int mcsTag, byte[] bytes, int len) throws IOException {
    Wire wire = new Wire();
    try {
        switch (mcsTag) {
            case MCS_HEARTBEAT_PING_TAG:
                return wire.parseFrom(bytes, 0, len, HeartbeatPing.class);
            case MCS_HEARTBEAT_ACK_TAG:
                return wire.parseFrom(bytes, 0, len, HeartbeatAck.class);
            case MCS_LOGIN_REQUEST_TAG:
                return wire.parseFrom(bytes, 0, len, LoginRequest.class);
            case MCS_LOGIN_RESPONSE_TAG:
                return wire.parseFrom(bytes, 0, len, LoginResponse.class);
            case MCS_CLOSE_TAG:
                return wire.parseFrom(bytes, 0, len, Close.class);
            case MCS_IQ_STANZA_TAG:
                return wire.parseFrom(bytes, 0, len, IqStanza.class);
            case MCS_DATA_MESSAGE_STANZA_TAG:
                return wire.parseFrom(bytes, 0, len, DataMessageStanza.class);
            default:
                Log.w(TAG, "Unknown tag: " + mcsTag);
                return null;
        }
    } catch (IllegalStateException e) {
        Log.w(TAG, "Error parsing tag: "+mcsTag, e);
        return null;
    }
}