VSerializer


Source link: https://github.com/vaslabs/VSerializer

Deprecated

Please use https://github.com/vaslabs/VSerializerJVM instead.

VSerializer

A library to serialize and deserialize objects with minimum memory usage.

Gradle dependencies

allprojects {

repositories {

 ...
 maven {
 url "https://jitpack.io" 
}

}
 
}
dependencies {

  compile 'com.github.vaslabs:VSerializer:2.3.1' 
}

Example - Simple object

VSerializer vSerializer = new AlphabeticalSerializer();
 TestUtils.AllEncapsulatedData allEncapsulatedData = new TestUtils.AllEncapsulatedData();
 allEncapsulatedData.a = -1L; allEncapsulatedData.b = 1; allEncapsulatedData.c = 127; allEncapsulatedData.d = -32768; allEncapsulatedData.e = true; allEncapsulatedData.f = 'h';  byte[] data = vSerializer.serialize(allEncapsulatedData);
  TestUtils.AllEncapsulatedData recoveredData =
vSerializer.deserialise(data, TestUtils.AllEncapsulatedData.class);

#Example - List

List<TestUtils.EncapsulatedData> encapsulatedDataList = initList(...);
 byte[] data = vSerializer.serialize(encapsulatedDataList);
 List<TestUtils.EncapsulatedData> recoveredList =
vSerializer.deserialise(data, List.class, TestUtils.EncapsulatedData.class);

Motivation

Memory on Android is precious. Every application should be using the minimum available memory both volatile and persistent. However, the complexity of doing such a thing is too much for the average developer that wants to ship the application as fast as possible. The aim of this library is to automate the whole process and replace ideally the default serialization mechanism.

That can achieve:

  • Lazy compression and decompression on the fly to keep volatile memory usage low for objects that are not used frequently (e.g. cached objects with low hit/miss ratio).
  • Occupying less persistent memory when saving objects on disk.

How does it work?

This project is under development and very young. However, you can use it if you are curious or you want to be a step ahead by following the examples in the unit test classes.

Advantages

  • A lot less memory usage when serializing objects compared to JVM or json.
  • Faster processing for serialization/deserialization
  • Extensible: will be able to easily encrypt and decrypt your serialized objects
  • Out of the box deep cloning.

Disadvantages

  • Less forgiving for changed classes. A mechanism to manage changes will be in place but since the meta data for the classes won't be carried over it will never be the same as the defaults.
  • Does not maintain the object graph meaning that a cyclic data structure will not be possible to be serialized (The new version provides an experimental serializer that can serialize circular data structures. Use with care as it's still in beta.)
  • Loses polymorphism capabilities as it needs the exact class passed to deserialised methods in order to construct the object correctly
  • Reflection slows it down.

Example

circularDS = new CircularDS();
 circularDS.pointsTo = circularDS; circularDS.justANumber = 5; VSerializer vSerializer = new ReferenceSensitiveAlphabeticalSerializer();
 byte[] data = vSerializer.serialize(circularDS);
 CircularDS recoveredCircularDS = vSerializer.deserialise(data, CircularDS.class);

Use case

  • Any data structure that matches a timestamp with other primitive values would be highly optimised in terms of space when saving the data using this approach. You can save millions of key/value pairs for data like timestamp/location history graph.
  • Short lived cache data are in less danger to cause problems when you do class changes. You can benefit by reducing the memory usage in your caching mechanism and not worry much about versioning problems.

Resources

Create useful .gitignore files for your project.

adk-toolkit exposes an AdkManager to manage UsbManager and UsbAccessory. In this way you don't need to fully understand some background concept about how ADK works but, as soon as possible, you should read ADK official documentation.

Robojava is a Gradle plugin that allows simple integration of Robolectric into Android Studio. This plugin works by creating a stub java project. This allows extending it with powerful plugins that are compatible with gradle java projects, but not with gradle android projects, like Gradle Cobertura Plugin for example.

CircleIndicator is a lightweight viewpager indicator like in nexus 5 launcher.

IntentLogger allows to dump intent content into logcat.

Droidcon 2013 Gradle workshop is an example project. It shows how to write Unit and Integration tests.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes