Java Code Examples for com.google.protobuf.nano.MessageNano#mergeFrom()
The following examples show how to use
com.google.protobuf.nano.MessageNano#mergeFrom() .
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: StorageDelegate.java From delion with Apache License 2.0 | 5 votes |
/** * Update tab entries based on metadata. * @param metadataBytes Metadata from last time Chrome was alive. * @param entryMap Map to fill with {@link DocumentTabModel.Entry}s about Tabs. * @param recentlyClosedTabIdList List to fill with IDs of recently closed tabs. */ private void updateTabEntriesFromMetadata(byte[] metadataBytes, SparseArray<Entry> entryMap, List<Integer> recentlyClosedTabIdList) { if (metadataBytes != null) { DocumentList list = null; try { list = MessageNano.mergeFrom(new DocumentList(), metadataBytes); } catch (IOException e) { Log.e(TAG, "I/O exception", e); } if (list == null) return; for (int i = 0; i < list.entries.length; i++) { DocumentEntry savedEntry = list.entries[i]; int tabId = savedEntry.tabId; // If the tab ID isn't in the list, it must have been closed after Chrome died. if (entryMap.indexOfKey(tabId) < 0) { recentlyClosedTabIdList.add(tabId); continue; } // Restore information about the Tab. entryMap.get(tabId).canGoBack = savedEntry.canGoBack; } } }
Example 2
Source File: StorageDelegate.java From AndroidChromium with Apache License 2.0 | 5 votes |
/** * Update tab entries based on metadata. * @param metadataBytes Metadata from last time Chrome was alive. * @param entryMap Map to fill with {@link DocumentTabModel.Entry}s about Tabs. * @param recentlyClosedTabIdList List to fill with IDs of recently closed tabs. */ private void updateTabEntriesFromMetadata(byte[] metadataBytes, SparseArray<Entry> entryMap, List<Integer> recentlyClosedTabIdList) { if (metadataBytes != null) { DocumentList list = null; try { list = MessageNano.mergeFrom(new DocumentList(), metadataBytes); } catch (IOException e) { Log.e(TAG, "I/O exception", e); } if (list == null) return; for (int i = 0; i < list.entries.length; i++) { DocumentEntry savedEntry = list.entries[i]; int tabId = savedEntry.tabId; // If the tab ID isn't in the list, it must have been closed after Chrome died. if (entryMap.indexOfKey(tabId) < 0) { recentlyClosedTabIdList.add(tabId); continue; } // Restore information about the Tab. entryMap.get(tabId).canGoBack = savedEntry.canGoBack; } } }
Example 3
Source File: LauncherBackupHelper.java From Trebuchet with GNU General Public License v3.0 | 5 votes |
/** * 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; }
Example 4
Source File: LauncherBackupHelper.java From Trebuchet with GNU General Public License v3.0 | 5 votes |
/** 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; }
Example 5
Source File: ProtoUtils.java From PainlessMusicPlayer with Apache License 2.0 | 5 votes |
@Nullable public static <T extends MessageNano> T readFromFile(@NonNull final Context context, @NonNull final String fileName, @NonNull final T obj) { T message = null; try { final byte[] bytes = FileUtils.readPrivateFile(context, fileName); message = MessageNano.mergeFrom(obj, bytes); } catch (IOException e) { Log.w(TAG, e); } return message; }
Example 6
Source File: ProtoUtilsTest.java From PainlessMusicPlayer with Apache License 2.0 | 5 votes |
@Test public void testToByteArray() throws Exception { final SettingsProto.Settings message = new SettingsProto.Settings(); message.scrobbleEnabled = true; message.theme = 666; final byte[] data = ProtoUtils.toByteArray(message); assertNotNull(data); final SettingsProto.Settings fromBytes = MessageNano.mergeFrom( new SettingsProto.Settings(), data); assertEquals(message.scrobbleEnabled, fromBytes.scrobbleEnabled); assertEquals(message.theme, fromBytes.theme); }
Example 7
Source File: LauncherBackupHelper.java From TurboLauncher with Apache License 2.0 | 5 votes |
/** 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; }
Example 8
Source File: LauncherBackupHelper.java From TurboLauncher with Apache License 2.0 | 5 votes |
/** 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; }
Example 9
Source File: LauncherBackupHelper.java From TurboLauncher with Apache License 2.0 | 5 votes |
/** 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; }
Example 10
Source File: LauncherBackupHelper.java From TurboLauncher with Apache License 2.0 | 5 votes |
/** 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; }
Example 11
Source File: StorageDelegate.java From 365browser with Apache License 2.0 | 5 votes |
/** * Update tab entries based on metadata. * @param metadataBytes Metadata from last time Chrome was alive. * @param entryMap Map to fill with {@link DocumentTabModel.Entry}s about Tabs. * @param recentlyClosedTabIdList List to fill with IDs of recently closed tabs. */ private void updateTabEntriesFromMetadata(byte[] metadataBytes, SparseArray<Entry> entryMap, List<Integer> recentlyClosedTabIdList) { if (metadataBytes != null) { DocumentList list = null; try { list = MessageNano.mergeFrom(new DocumentList(), metadataBytes); } catch (IOException e) { Log.e(TAG, "I/O exception", e); } if (list == null) return; for (int i = 0; i < list.entries.length; i++) { DocumentEntry savedEntry = list.entries[i]; int tabId = savedEntry.tabId; // If the tab ID isn't in the list, it must have been closed after Chrome died. if (entryMap.indexOfKey(tabId) < 0) { recentlyClosedTabIdList.add(tabId); continue; } // Restore information about the Tab. entryMap.get(tabId).canGoBack = savedEntry.canGoBack; } } }
Example 12
Source File: LauncherBackupHelper.java From LB-Launcher with Apache License 2.0 | 5 votes |
/** * 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; }
Example 13
Source File: LauncherBackupHelper.java From LB-Launcher with Apache License 2.0 | 5 votes |
/** 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; }
Example 14
Source File: LauncherBackupHelper.java From TurboLauncher with Apache License 2.0 | 4 votes |
/** Deserialize a Favorite from persistence, after verifying checksum wrapper. */ private ContentValues unpackFavorite(byte[] buffer, int offset, int dataSize) throws InvalidProtocolBufferNanoException { Favorite favorite = new Favorite(); MessageNano.mergeFrom(favorite, readCheckedBytes(buffer, offset, dataSize)); if (VERBOSE) Log.v(TAG, "unpacked favorite " + favorite.itemType + ", " + (TextUtils.isEmpty(favorite.title) ? favorite.id : favorite.title)); ContentValues values = new ContentValues(); values.put(Favorites._ID, favorite.id); values.put(Favorites.SCREEN, favorite.screen); values.put(Favorites.CONTAINER, favorite.container); values.put(Favorites.CELLX, favorite.cellX); values.put(Favorites.CELLY, favorite.cellY); values.put(Favorites.SPANX, favorite.spanX); values.put(Favorites.SPANY, favorite.spanY); values.put(Favorites.ICON_TYPE, favorite.iconType); if (favorite.iconType == Favorites.ICON_TYPE_RESOURCE) { values.put(Favorites.ICON_PACKAGE, favorite.iconPackage); values.put(Favorites.ICON_RESOURCE, favorite.iconResource); } if (favorite.iconType == Favorites.ICON_TYPE_BITMAP) { values.put(Favorites.ICON, favorite.icon); } if (!TextUtils.isEmpty(favorite.title)) { values.put(Favorites.TITLE, favorite.title); } else { values.put(Favorites.TITLE, ""); } if (!TextUtils.isEmpty(favorite.intent)) { values.put(Favorites.INTENT, favorite.intent); } values.put(Favorites.ITEM_TYPE, favorite.itemType); if (favorite.itemType == Favorites.ITEM_TYPE_APPWIDGET) { if (!TextUtils.isEmpty(favorite.appWidgetProvider)) { values.put(Favorites.APPWIDGET_PROVIDER, favorite.appWidgetProvider); } values.put(Favorites.APPWIDGET_ID, favorite.appWidgetId); } // Let LauncherModel know we've been here. values.put(LauncherSettings.Favorites.RESTORED, 1); return values; }