Java 类com.google.protobuf.nano.InvalidProtocolBufferNanoException 实例源码

项目:science-journal    文件:Label.java   
/**
 * Gets the SensorTriggerLabelValue for this label.
 * If changes are made, this needs to be re-set on the Label for them to be saved.
 */
public GoosciSensorTriggerLabelValue.SensorTriggerLabelValue getSensorTriggerLabelValue() {
    if (mLabel.type == GoosciLabel.Label.SENSOR_TRIGGER) {
        try {
            return GoosciSensorTriggerLabelValue.SensorTriggerLabelValue.parseFrom(
                    mLabel.protoData);
        } catch (InvalidProtocolBufferNanoException e) {
            if (Log.isLoggable(TAG, Log.ERROR)) {
                Log.e(TAG, e.getMessage());
            }
        }
    } else {
        throwLabelValueException("SensorTriggerLabelValue", mLabel.type);
    }
    return null;
}
项目:science-journal    文件:EditTriggerFragment.java   
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mSensorId = getArguments().getString(ARG_SENSOR_ID);
    mExperimentId = getArguments().getString(ARG_EXPERIMENT_ID);
    try {
        mSensorLayout = GoosciSensorLayout.SensorLayout.parseFrom(
                getArguments().getByteArray(ARG_SENSOR_LAYOUT));
    } catch (InvalidProtocolBufferNanoException e) {
        if (Log.isLoggable(TAG, Log.ERROR)) {
            Log.e(TAG, "Error parsing the SensorLayout", e);
        }
        mSensorLayout = RecordFragment.defaultLayout(0);
    }
    mSensorLayoutPosition = getArguments().getInt(ARG_LAYOUT_POSITION);
    getDataController().getExperimentById(mExperimentId,
            new LoggingConsumer<Experiment>(TAG, "get experiment") {
                @Override
                public void success(Experiment value) {
                    mExperiment = value;
                    String triggerId = getArguments().getString(ARG_TRIGGER_ID, "");
                    mTriggerToEdit = mExperiment.getSensorTrigger(triggerId);
                    populateView(getView());
                }
            });
}
项目:PainlessMusicPlayer    文件:WearableListenerServiceImpl.java   
@Override
public void onMessageReceived(final MessageEvent messageEvent) {
    super.onMessageReceived(messageEvent);
    switch (messageEvent.getPath()) {
        case DataPaths.Messages.SEARCH_RESULT:
            WearSearchData.Results searchResults = null;
            final byte[] data = messageEvent.getData();
            if (data != null && data.length != 0) {
                try {
                    searchResults = WearSearchData.Results.parseFrom(data);
                } catch (InvalidProtocolBufferNanoException e) {
                    Log.w(TAG, e);
                }
            }
            if (searchResults == null) {
                searchResults = new WearSearchData.Results();
            }
            EventBus.getDefault().post(new EventSearchResults(searchResults));
            break;
    }
}
项目:FMTech    文件:ContentFiltersDialogView.java   
public final void configureView(Bundle paramBundle)
{
  this.mSelections = ContentFiltersUtils.decodeSelections(paramBundle.getString("ContentFiltersDialogView.contentFilterSelections"));
  byte[] arrayOfByte = paramBundle.getByteArray("ContentFiltersDialogView.encodedFilterRange");
  try
  {
    this.mFilterRange = ContentFilters.FilterRange.parseFrom(arrayOfByte);
    this.mListView.setAdapter(new ContentFilterChoiceAdapter(getContext(), this.mSelections, this.mFilterRange));
    this.mListView.setOnItemClickListener(this);
    return;
  }
  catch (InvalidProtocolBufferNanoException localInvalidProtocolBufferNanoException)
  {
    FinskyLog.wtf(localInvalidProtocolBufferNanoException, "Cannot parse FilterRange proto from byte[] in arguments.", new Object[0]);
  }
}
项目:FMTech    文件:InstantPurchaseUtils.java   
public static Document getDocument(PurchaseParams paramPurchaseParams, Cache paramCache)
{
  if (paramPurchaseParams.document != null) {
    return paramPurchaseParams.document;
  }
  Cache.Entry localEntry = paramCache.get("InstantPurchaseDocument-" + paramPurchaseParams.docidStr);
  if ((localEntry == null) || (localEntry.isExpired())) {
    return null;
  }
  try
  {
    byte[] arrayOfByte = localEntry.data;
    Document localDocument = new Document((DocV2)MessageNano.mergeFrom$1ec43da(new DocV2(), arrayOfByte, arrayOfByte.length));
    return localDocument;
  }
  catch (InvalidProtocolBufferNanoException localInvalidProtocolBufferNanoException)
  {
    throw new RuntimeException(localInvalidProtocolBufferNanoException);
  }
}
项目:TurboLauncher    文件:LauncherBackupHelper.java   
/**
 * Read a favorite from the stream.
 *
 * <P>Keys arrive in any order, so screens and containers may not exist yet.
 *
 * @param key identifier for the row
 * @param buffer the serialized proto from the stream, may be larger than dataSize
 * @param dataSize the size of the proto from the stream
 * @param keys keys to mark as clean in the notes for next backup
 */
private void restoreFavorite(Key key, byte[] buffer, int dataSize, ArrayList<Key> keys) {
    if (VERBOSE) Log.v(TAG, "unpacking favorite " + key.id);
    if (DEBUG) Log.d(TAG, "read (" + buffer.length + "): " +
            Base64.encodeToString(buffer, 0, dataSize, Base64.NO_WRAP));

    if (!mRestoreEnabled) {
        if (VERBOSE) Log.v(TAG, "restore not enabled: skipping database mutation");
        return;
    }

    try {
        ContentResolver cr = mContext.getContentResolver();
        ContentValues values = unpackFavorite(buffer, 0, dataSize);
        cr.insert(Favorites.CONTENT_URI, values);
    } catch (InvalidProtocolBufferNanoException e) {
        Log.e(TAG, "failed to decode favorite", e);
    }
}
项目:TurboLauncher    文件:LauncherBackupHelper.java   
/**
 * Read a screen from the stream.
 *
 * <P>Keys arrive in any order, so children of this screen may already exist.
 *
 * @param key identifier for the row
 * @param buffer the serialized proto from the stream, may be larger than dataSize
 * @param dataSize the size of the proto from the stream
 * @param keys keys to mark as clean in the notes for next backup
 */
private void restoreScreen(Key key, byte[] buffer, int dataSize, ArrayList<Key> keys) {
    if (VERBOSE) Log.v(TAG, "unpacking screen " + key.id);
    if (DEBUG) Log.d(TAG, "read (" + buffer.length + "): " +
            Base64.encodeToString(buffer, 0, dataSize, Base64.NO_WRAP));

    if (!mRestoreEnabled) {
        if (VERBOSE) Log.v(TAG, "restore not enabled: skipping database mutation");
        return;
    }

    try {
        ContentResolver cr = mContext.getContentResolver();
        ContentValues values = unpackScreen(buffer, 0, dataSize);
        cr.insert(WorkspaceScreens.CONTENT_URI, values);

    } catch (InvalidProtocolBufferNanoException e) {
        Log.e(TAG, "failed to decode screen", e);
    }
}
项目:science-journal    文件:SensorTrigger.java   
public static SensorTrigger fromBundle(Bundle bundle) {
    try {
        return new SensorTrigger(GoosciSensorTrigger.SensorTrigger.parseFrom(
                bundle.getByteArray(KEY_TRIGGER)));
    } catch (InvalidProtocolBufferNanoException e) {
        if (Log.isLoggable(TAG, Log.ERROR)) {
            Log.e(TAG, "Error parsing SensorTrigger");
        }
        return null;
    }
}
项目:science-journal    文件:Label.java   
protected Label(Parcel in) {
    int serializedSize = in.readInt();
    byte[] serialized = new byte[serializedSize];
    in.readByteArray(serialized);
    try {
        mLabel = GoosciLabel.Label.parseFrom(serialized);
    } catch (InvalidProtocolBufferNanoException ex) {
        if (Log.isLoggable(TAG, Log.ERROR)) {
            Log.e(TAG, "Couldn't parse label storage");
        }
    }
}
项目:science-journal    文件:Label.java   
/**
 * Gets the GoosciTextLabelValue.TextLabelValue for this label.
 * If changes are made, this needs to be re-set on the Label for them to be saved.
 */
public GoosciTextLabelValue.TextLabelValue getTextLabelValue() {
    if (mLabel.type == GoosciLabel.Label.TEXT) {
        try {
            return GoosciTextLabelValue.TextLabelValue.parseFrom(mLabel.protoData);
        } catch (InvalidProtocolBufferNanoException e) {
            if (Log.isLoggable(TAG, Log.ERROR)) {
                Log.e(TAG, e.getMessage());
            }
        }
    } else {
        throwLabelValueException("TextLabelValue", mLabel.type);
    }
    return null;
}
项目:science-journal    文件:Label.java   
/**
 * Gets the PictureLabelValue for this label.
 * If changes are made, this needs to be re-set on the Label for them to be saved.
 */
public GoosciPictureLabelValue.PictureLabelValue getPictureLabelValue() {
    if (mLabel.type == GoosciLabel.Label.PICTURE) {
        try {
            return GoosciPictureLabelValue.PictureLabelValue.parseFrom(mLabel.protoData);
        } catch (InvalidProtocolBufferNanoException e) {
            if (Log.isLoggable(TAG, Log.ERROR)) {
                Log.e(TAG, e.getMessage());
            }
        }
    } else {
        throwLabelValueException("PictureLabelValue", mLabel.type);
    }
    return null;
}
项目:science-journal    文件:Label.java   
/**
 * Gets the SnapshotLabelValue for this label.
 * If changes are made, this needs to be re-set on the Label for them to be saved.
 */
public GoosciSnapshotValue.SnapshotLabelValue getSnapshotLabelValue() {
    if (mLabel.type == GoosciLabel.Label.SNAPSHOT) {
        try {
            return GoosciSnapshotValue.SnapshotLabelValue.parseFrom(mLabel.protoData);
        } catch (InvalidProtocolBufferNanoException e) {
            if (Log.isLoggable(TAG, Log.ERROR)) {
                Log.e(TAG, e.getMessage());
            }
        }
    } else {
        throwLabelValueException("SnapshotLabelValue", mLabel.type);
    }
    return null;
}
项目:science-journal    文件:InputDeviceSpec.java   
@Nullable
private InputDevice.InputDeviceConfig parse(byte[] config) {
    try {
        return InputDevice.InputDeviceConfig.parseFrom(config);
    } catch (InvalidProtocolBufferNanoException e) {
        if (Log.isLoggable(TAG, Log.ERROR)) {
            Log.e(TAG, "error parsing config", e);
        }
    }
    return null;
}
项目:science-journal    文件:ScalarInputSpec.java   
@Nullable
private GoosciScalarInput.ScalarInputConfig parse(byte[] config) {
    try {
        return GoosciScalarInput.ScalarInputConfig.parseFrom(config);
    } catch (InvalidProtocolBufferNanoException e) {
        if (Log.isLoggable(TAG, Log.ERROR)) {
            Log.e(TAG, "error parsing config", e);
        }
    }
    return null;
}
项目:science-journal    文件:SimpleMetaDataManager.java   
private static List<GoosciSensorLayout.SensorLayout> getDatabaseExperimentSensorLayouts(
        SQLiteDatabase db, String experimentId) {
    List<GoosciSensorLayout.SensorLayout> layouts = new ArrayList<>();
    Cursor cursor = null;
    try {
        cursor = db.query(Tables.EXPERIMENT_SENSOR_LAYOUT,
                new String[]{ExperimentSensorLayoutColumns.LAYOUT},
                ExperimentSensorLayoutColumns.EXPERIMENT_ID + "=?",
                new String[]{experimentId}, null, null,
                ExperimentSensorLayoutColumns.POSITION + " ASC");
        Set<String> sensorIdsAdded = new HashSet<>();
        while (cursor.moveToNext()) {
            try {
                GoosciSensorLayout.SensorLayout layout =
                        GoosciSensorLayout.SensorLayout.parseFrom(cursor.getBlob(0));
                if (!sensorIdsAdded.contains(layout.sensorId)) {
                    layouts.add(layout);
                }
                sensorIdsAdded.add(layout.sensorId);
            } catch (InvalidProtocolBufferNanoException e) {
                Log.e(TAG, "Couldn't parse layout", e);
            }
        }
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
    return layouts;
}
项目:science-journal    文件:SimpleMetaDataManager.java   
/**
 * Gets a list of SensorTrigger by their experiment ID.
 */
private static List<SensorTrigger> getDatabaseSensorTriggers(SQLiteDatabase db,
        String experimentId) {
    List<SensorTrigger> triggers = new ArrayList<>();
    if (TextUtils.isEmpty(experimentId)) {
        return triggers;
    }

    final String selection = SensorTriggerColumns.EXPERIMENT_ID + "=?";
    String[] selectionArgs = new String[]{experimentId};
    Cursor c = null;
    try {
        c = db.query(Tables.SENSOR_TRIGGERS, new String[]{SensorTriggerColumns.TRIGGER_ID,
                        SensorTriggerColumns.SENSOR_ID,
                        SensorTriggerColumns.LAST_USED_TIMESTAMP_MS,
                        SensorTriggerColumns.TRIGGER_INFORMATION},
                selection, selectionArgs, null, null,
                SensorTriggerColumns.LAST_USED_TIMESTAMP_MS + " DESC");
        if (c == null || !c.moveToFirst()) {
            return triggers;
        }
        while (!c.isAfterLast()) {
            triggers.add(SensorTrigger.fromTrigger(c.getString(0), c.getString(1), c.getLong(2),
                    GoosciSensorTriggerInformation.TriggerInformation.parseFrom(c.getBlob(3))));
            c.moveToNext();
        }
    } catch (InvalidProtocolBufferNanoException e) {
        e.printStackTrace();
    } finally {
        if (c != null) {
            c.close();
        }
    }
    return triggers;
}
项目:science-journal    文件:BleSensorSpec.java   
@VisibleForTesting
public void loadFromConfig(byte[] data) {
    try {
        mConfig = GoosciSensorConfig.BleSensorConfig.parseFrom(data);
    } catch (InvalidProtocolBufferNanoException e) {
        Log.e(TAG, "Could not deserialize config", e);
        throw new IllegalStateException(e);
    }
}
项目:science-journal    文件:SensorCardPresenter.java   
private GoosciSensorLayout.SensorLayout copyLayout(GoosciSensorLayout.SensorLayout layout) {
    try {
        return GoosciSensorLayout.SensorLayout.parseFrom(MessageNano.toByteArray(layout));
    } catch (InvalidProtocolBufferNanoException e) {
        throw new RuntimeException("Should be impossible", e);
    }
}
项目:science-journal    文件:MemoryMetadataManager.java   
private GoosciSensorLayout.SensorLayout[] deepCopy(
        List<GoosciSensorLayout.SensorLayout> original) {
    GoosciSensorLayout.SensorLayout[] copy = new GoosciSensorLayout.SensorLayout[
            original.size()];
    for (int i = 0; i < original.size(); i++) {
        GoosciSensorLayout.SensorLayout layout = original.get(i);
        try {
            byte[] bytes = ExternalSensorSpec.getBytes(layout);
            copy[i] = (GoosciSensorLayout.SensorLayout.parseFrom(bytes));
        } catch (InvalidProtocolBufferNanoException e) {
            throw new RuntimeException(e);
        }
    }
    return copy;
}
项目:SimplOS    文件:LauncherBackupHelper.java   
/** Deserialize a Screen from persistence, after verifying checksum wrapper. */
private ContentValues unpackScreen(byte[] buffer, int dataSize)
        throws InvalidProtocolBufferNanoException {
    Screen screen = unpackProto(new Screen(), buffer, dataSize);
    ContentValues values = new ContentValues();
    values.put(WorkspaceScreens._ID, screen.id);
    values.put(WorkspaceScreens.SCREEN_RANK, screen.rank);
    return values;
}
项目:SimplOS    文件:LauncherBackupHelper.java   
/**
 * Deserialize a proto after verifying checksum wrapper.
 */
private <T extends MessageNano> T unpackProto(T proto, byte[] buffer, int dataSize)
        throws InvalidProtocolBufferNanoException {
    MessageNano.mergeFrom(proto, readCheckedBytes(buffer, dataSize));
    if (DEBUG) Log.d(TAG, "unpacked proto " + proto);
    return proto;
}
项目:SimplOS    文件:LauncherBackupHelper.java   
/** Unwrap a proto message from a CheckedMessage, verifying the checksum. */
private static byte[] readCheckedBytes(byte[] buffer, int dataSize)
        throws InvalidProtocolBufferNanoException {
    CheckedMessage wrapper = new CheckedMessage();
    MessageNano.mergeFrom(wrapper, buffer, 0, dataSize);
    CRC32 checksum = new CRC32();
    checksum.update(wrapper.payload);
    if (wrapper.checksum != checksum.getValue()) {
        throw new InvalidProtocolBufferNanoException("checksum does not match");
    }
    return wrapper.payload;
}
项目:SimplOS    文件:DecoderRing.java   
private static Key decodeKey(byte[] payload, boolean fromLogs) {
    Key key = new Key();
    try {
        String encodedKey = new String(payload);
        if (!fromLogs) {
            byte[] rawKey = DatatypeConverter.parseBase64Binary(encodedKey);
            if (rawKey[0] != 'L' || rawKey[1] != ':') {
                System.err.println(encodedKey + " is not a launcher backup key.");
                return null;
            }
            encodedKey = new String(rawKey, 2, rawKey.length - 2);
        }
        byte[] keyProtoData = DatatypeConverter.parseBase64Binary(encodedKey);
        key = Key.parseFrom(keyProtoData);
    } catch (InvalidProtocolBufferNanoException protoException) {
        System.err.println("failed to extract key from filename: " + protoException);
        return null;
    } catch (IllegalArgumentException base64Exception) {
        System.err.println("failed to extract key from filename: " + base64Exception);
        return null;
    }

    // keys are self-checked
    if (key.checksum != checkKey(key)) {
        System.err.println("key ckecksum failed");
        return null;
    }
    return key;
}
项目:Trebuchet    文件:LauncherBackupHelper.java   
/** Deserialize a Screen from persistence, after verifying checksum wrapper. */
private ContentValues unpackScreen(byte[] buffer, int dataSize)
        throws InvalidProtocolBufferNanoException {
    Screen screen = unpackProto(new Screen(), buffer, dataSize);
    ContentValues values = new ContentValues();
    values.put(WorkspaceScreens._ID, screen.id);
    values.put(WorkspaceScreens.SCREEN_RANK, screen.rank);
    return values;
}
项目:Trebuchet    文件:LauncherBackupHelper.java   
/**
 * Deserialize a proto after verifying checksum wrapper.
 */
private <T extends MessageNano> T unpackProto(T proto, byte[] buffer, int dataSize)
        throws InvalidProtocolBufferNanoException {
    MessageNano.mergeFrom(proto, readCheckedBytes(buffer, dataSize));
    if (DEBUG) Log.d(TAG, "unpacked proto " + proto);
    return proto;
}
项目:Trebuchet    文件:LauncherBackupHelper.java   
/** Unwrap a proto message from a CheckedMessage, verifying the checksum. */
private static byte[] readCheckedBytes(byte[] buffer, int dataSize)
        throws InvalidProtocolBufferNanoException {
    CheckedMessage wrapper = new CheckedMessage();
    MessageNano.mergeFrom(wrapper, buffer, 0, dataSize);
    CRC32 checksum = new CRC32();
    checksum.update(wrapper.payload);
    if (wrapper.checksum != checksum.getValue()) {
        throw new InvalidProtocolBufferNanoException("checksum does not match");
    }
    return wrapper.payload;
}
项目:PainlessMusicPlayer    文件:WearableListenerServiceImpl.java   
private void onMediaItemChanged(@NonNull final DataItem mediaItem) {
    final byte[] data = mediaItem.getData();
    if (data == null) {
        MediaHolder.getInstance(this).setMedia(null);
        return;
    }

    try {
        final WearPlaybackData.Media media = WearPlaybackData.Media.parseFrom(data);
        MediaHolder.getInstance(this).setMedia(media);
    } catch (InvalidProtocolBufferNanoException e) {
        Log.w(TAG, e);
    }
}
项目:PainlessMusicPlayer    文件:WearableListenerServiceImpl.java   
private void onPlaybackStateItemChanged(@NonNull final DataItem stateItem) {
    final byte[] data = stateItem.getData();
    if (data == null) {
        MediaHolder.getInstance(this).setPlaybackState(null);
        return;
    }
    try {
        final WearPlaybackData.PlaybackState s = WearPlaybackData.PlaybackState.parseFrom(data);
        MediaHolder.getInstance(this).setPlaybackState(s);
    } catch (InvalidProtocolBufferNanoException e) {
        Log.w(TAG, e);
    }
}
项目:PainlessMusicPlayer    文件:WearableListenerServiceImpl.java   
private void onPlaybackPositionItemChanged(@NonNull final DataItem positionItem) {
    final byte[] data = positionItem.getData();
    if (data == null) {
        MediaHolder.getInstance(this).setPlaybackPosition(null);
        return;
    }
    try {
        final WearPlaybackData.PlaybackPosition s = WearPlaybackData.PlaybackPosition
                .parseFrom(data);
        MediaHolder.getInstance(this).setPlaybackPosition(s);
    } catch (InvalidProtocolBufferNanoException e) {
        Log.w(TAG, e);
    }
}
项目:PainlessMusicPlayer    文件:WearableListenerServiceImpl.java   
private void onQueueChanged(@NonNull final DataItem stateItem) {
    final byte[] data = stateItem.getData();
    if (data == null) {
        QueueHolder.getInstance(this).setQueue(null);
        return;
    }
    try {
        final WearPlaybackData.Queue p = WearPlaybackData.Queue.parseFrom(data);
        QueueHolder.getInstance(this).setQueue(p);
    } catch (InvalidProtocolBufferNanoException e) {
        Log.w(TAG, e);
    }
}
项目:FMTech    文件:PackageVerificationRequest.java   
protected final Response<PackageVerificationResult> parseNetworkResponse(NetworkResponse paramNetworkResponse)
{
  try
  {
    byte[] arrayOfByte = paramNetworkResponse.data;
    CsdClient.ClientDownloadResponse localClientDownloadResponse = (CsdClient.ClientDownloadResponse)MessageNano.mergeFrom$1ec43da(new CsdClient.ClientDownloadResponse(), arrayOfByte, arrayOfByte.length);
    return Response.success(PackageVerificationResult.fromResponse(localClientDownloadResponse), null);
  }
  catch (InvalidProtocolBufferNanoException localInvalidProtocolBufferNanoException)
  {
    return Response.error(new VolleyError(localInvalidProtocolBufferNanoException));
  }
}
项目:FMTech    文件:UserSettingsCache.java   
private static boolean decodeFromString(String paramString, MessageNano paramMessageNano)
{
  try
  {
    byte[] arrayOfByte = Base64.decode(paramString, 3);
    MessageNano.mergeFrom$1ec43da(paramMessageNano, arrayOfByte, arrayOfByte.length);
    return true;
  }
  catch (InvalidProtocolBufferNanoException localInvalidProtocolBufferNanoException)
  {
    FinskyLog.e(localInvalidProtocolBufferNanoException, "Error parsing string into proto", new Object[0]);
  }
  return false;
}
项目:FMTech    文件:ContentFiltersActivity2.java   
protected final void onResumeFragments()
{
  super.onResumeFragments();
  if (this.mExtraParamsOnConfirmedPin != null) {
    switch (this.mExtraParamsOnConfirmedPin.getInt("ContentFiltersActivity2.onPinSuccess"))
    {
    }
  }
  for (;;)
  {
    this.mExtraParamsOnConfirmedPin = null;
    return;
    applyFilterToggle(true);
    continue;
    applyFilterToggle(false);
    continue;
    byte[] arrayOfByte = this.mExtraParamsOnConfirmedPin.getByteArray("ContentFiltersActivity2.filterRange");
    int i = this.mExtraParamsOnConfirmedPin.getInt("ContentFiltersActivity2.filterRangeIndex");
    try
    {
      onFilterLineClicked(ContentFilters.FilterRange.parseFrom(arrayOfByte), i);
    }
    catch (InvalidProtocolBufferNanoException localInvalidProtocolBufferNanoException)
    {
      FinskyLog.wtf(localInvalidProtocolBufferNanoException, "Cannot parse FilterRange proto from byte[] in arguments.", new Object[0]);
    }
  }
}
项目:TurboLauncher    文件:LauncherBackupHelper.java   
/** Deserialize a Screen from persistence, after verifying checksum wrapper. */
private ContentValues unpackScreen(byte[] buffer, int offset, int dataSize)
        throws InvalidProtocolBufferNanoException {
    Screen screen = new Screen();
    MessageNano.mergeFrom(screen, readCheckedBytes(buffer, offset, dataSize));
    if (VERBOSE) Log.v(TAG, "unpacked screen " + screen.id + "/" + screen.rank);
    ContentValues values = new ContentValues();
    values.put(WorkspaceScreens._ID, screen.id);
    values.put(WorkspaceScreens.SCREEN_RANK, screen.rank);
    return values;
}
项目:TurboLauncher    文件:LauncherBackupHelper.java   
/** Deserialize an icon resource from persistence, after verifying checksum wrapper. */
private static Resource unpackIcon(byte[] buffer, int offset, int dataSize)
        throws InvalidProtocolBufferNanoException {
    Resource res = new Resource();
    MessageNano.mergeFrom(res, readCheckedBytes(buffer, offset, dataSize));
    if (VERBOSE) Log.v(TAG, "unpacked icon " + res.dpi + "/" + res.data.length);
    return res;
}
项目:TurboLauncher    文件:LauncherBackupHelper.java   
/** Deserialize a widget from persistence, after verifying checksum wrapper. */
private Widget unpackWidget(byte[] buffer, int offset, int dataSize)
        throws InvalidProtocolBufferNanoException {
    Widget widget = new Widget();
    MessageNano.mergeFrom(widget, readCheckedBytes(buffer, offset, dataSize));
    if (VERBOSE) Log.v(TAG, "unpacked widget " + widget.provider);
    return widget;
}
项目:TurboLauncher    文件:LauncherBackupHelper.java   
/** Unwrap a proto message from a CheckedMessage, verifying the checksum. */
private static byte[] readCheckedBytes(byte[] buffer, int offset, int dataSize)
        throws InvalidProtocolBufferNanoException {
    CheckedMessage wrapper = new CheckedMessage();
    MessageNano.mergeFrom(wrapper, buffer, offset, dataSize);
    CRC32 checksum = new CRC32();
    checksum.update(wrapper.payload);
    if (wrapper.checksum != checksum.getValue()) {
        throw new InvalidProtocolBufferNanoException("checksum does not match");
    }
    return wrapper.payload;
}
项目:FLauncher    文件:LauncherBackupHelper.java   
/** keys need to be strings, decode and parse. */
private Key backupKeyToKey(String backupKey) throws InvalidBackupException {
    try {
        Key key = Key.parseFrom(Base64.decode(backupKey, Base64.DEFAULT));
        if (key.checksum != checkKey(key)) {
            throw new InvalidBackupException("invalid key read from stream" + backupKey);
        }
        return key;
    } catch (InvalidProtocolBufferNanoException | IllegalArgumentException e) {
        throw new InvalidBackupException(e);
    }
}
项目:FLauncher    文件:LauncherBackupHelper.java   
/** Deserialize a Screen from persistence, after verifying checksum wrapper. */
private ContentValues unpackScreen(byte[] buffer, int dataSize)
        throws InvalidProtocolBufferNanoException {
    Screen screen = unpackProto(new Screen(), buffer, dataSize);
    ContentValues values = new ContentValues();
    values.put(WorkspaceScreens._ID, screen.id);
    values.put(WorkspaceScreens.SCREEN_RANK, screen.rank);
    return values;
}
项目:FLauncher    文件:LauncherBackupHelper.java   
/**
 * Deserialize a proto after verifying checksum wrapper.
 */
private <T extends MessageNano> T unpackProto(T proto, byte[] buffer, int dataSize)
        throws InvalidProtocolBufferNanoException {
    MessageNano.mergeFrom(proto, readCheckedBytes(buffer, dataSize));
    if (DEBUG) Log.d(TAG, "unpacked proto " + proto);
    return proto;
}