Giter Club home page Giter Club logo

objectiveavro's Introduction

ObjectiveAvro

Version Platform

What is ObjectiveAvro?

ObjectiveAvro is a wrapper on Avro-C, following the API conventions of Foundation's NSJSONSerialization class.

But what is this Avro thing?

From Avro Documentation:

Apache Avro™ is a data serialization system.

Avro provides:

  • Rich data structures.
  • A compact, fast, binary data format.
  • A container file, to store persistent data.
  • Remote procedure call (RPC).
  • Simple integration with dynamic languages. Code generation is not required to read or write data files nor to use or implement RPC protocols. Code generation as an optional optimization, only worth implementing for statically typed languages.

Basically, you can serialize data to a fast and compact binary format (which is very handy on a mobile device!). However, there isn't an official API for Objective-C, only C, C++, C#, Java and Python. ObjectiveAvro is the midfield between your Objective-C code and Avro-C.

Usage Examples

Registering schemas

Avro works with schemas. Before using OAVAvroSerialization to serialize objects, you must register the schemas you'll use.

NSString *schema = @"{\"type\":\"record\",\"name\":\"Person\",\"namespace\":\"com.movile.objectiveavro.unittest.v1\",\"fields\":[{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"country\",\"type\":\"string\"},{\"name\":\"age\",\"type\":\"int\"}]}";

OAVAvroSerialization *avro = [[OAVAvroSerialization alloc] init];
NSError *error;
BOOL result = [avro registerSchema:schema error:&error];

Transforming JSON to NSData

NSError *error;
NSDictionary *dict = @{@"name": @"Marcelo Fabri", @"country": @"Brazil", @"age": @20};
NSData *data = [avro dataFromJSONObject:dict forSchemaNamed:@"Person" error:&error];

Transforming NSData to JSON

NSError *error;
NSData *data = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"marcelo" ofType:@"avro"]];
NSData *data = [avro JSONObjectFromData:data forSchemaNamed:@"Person" error:&error];

Requirements

ObjectiveAvro requires Xcode 5, targeting either iOS 6.0 and above, or Mac OS 10.8 Mountain Lion (64-bit with modern Cocoa runtime) and above.

ObjectiveAvro also requires Avro-C, which is automatically imported when using CocoaPods.

Installation

ObjectiveAvro is available through CocoaPods, to install it simply add the following line to your Podfile:

pod "ObjectiveAvro"

Testing

To run the testing project; clone the repo, and run pod install from the Example directory first. You can run the unit tests by pressing CMD + U on Xcode. Tests are done with XCTest and Expecta.

Known limitations

  • Currently, only the following types are supported: string, float, double, int, long, boolean, null, bytes, array, map and record. That means that enum, union and fixed are not currently supported.

Author

Marcelo Fabri, [email protected]

License

ObjectiveAvro is available under the MIT license. See the LICENSE file for more info.

objectiveavro's People

Contributors

jlawton avatar marcelofabri avatar

Watchers

James Cloos avatar Clay Jensen-Reimann avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.