Kotlin Data Classes support in Protobuf - kotlin

I am implementing protobuf recently in our kotlin project.
I am receiving the binary data and deserialising it to Proto object using the proto file.
But I would like have that converted to data class.
I could not find any supporting information about how to do this.
Is it possible to get data class from binary data or from deserialized proto object??

One solution might be to use pb-and-k which has the kotlin code generator and will generate data classes for you based off of the .proto files

If you have know the structure of the data and can write your data classes upfront, you might want to have a look at kotlinx.serialization. It is an official Kotlin project and supports protobuf out-of-the-box.

Related

In Kotlin How to read and parse json file

I am new to Kotlin and trying to understand how I can read and parse the .json file.
Say, I have a file Test.json with some json array and need to read the array and stored the content in mutable list.
I tried searching the blog but could not find the answer.
Thanks in advance.
It depends, if you know the format of the JSON file maps to one of your Kotlin classes then you could use a library such as Jackson, Gson, Klaxon or Moshi to convert the contents of the file to an instance of this class.
Alternatively you could manually parse the JSON using Java's JSONObjects and work through the nested map of JsonObjects/Values.
I personally use this Klaxon library to parse json file and use in in my android application.
which I think will do your work.
Add dependncy to your gradle.build file
compile 'com.beust:klaxon:0.30'

Jax-rs convert to object Mule

I am using RAML for design api.
Then I convert raml to jaxrs and get java classes (https://github.com/mulesoft-labs/raml-for-jax-rs ).
It gives two classes: interface and *impl classes.
Then I Import them into my project In Anypoint Studio. I want to use them.
But JsonToObject Transfer cannot use convert classes.
org.mule.api.transformer.TransformerMessagingException: Failed to transform from "json" to "classImpl".
I try use without interface classes. It work correct.
How to use interface and *impl Classes for convert json to Object?
I solved the problem. 1. RAML need to convert using jackson 2. In Anypoint need to deserialize from the json to the object by ObjectMapper
You should make sure your classImp support JSON binding using Jackson annotations. See the related Mule documentation on JSON Support for details.

convert an object to JSON in objective c

I work in tool theos projects and i want convert an object into JSON.
I need a easy to use library with examples for converting NSObjects to JSON and back again
I check a lot of question like this but i can't use them.
I use JSONModel library but i have a lot of errors.
Anybody body have a good tutorial or a sample code to convert NSObject to JSON?
I don't have any idea whether I can created a json or not.
How can I fix this?
Look at my library - https://github.com/DimasSup/BaseMangedObjectModel
With it you can serialize/deserialize any your class. aslo can save it to SQLite database if needed. Also there are NetworkHelper class which help you send/receive your classes from remote server.

XText using type information from an external EMF Model

I'm looking into using XText to make an extenstion DSL to a language that I use daily and has some obvious shortcomings (AS3, through FlashBuilder).
I have a grammar and code generation system working, where the below declaration generates a value class, with constructor, class level vars and getters etc.
class Person (name: String, age: int)
This is fine, but I would like the have the types defined in the flash player library and also the types that I define in users projects available in my extension DSL. In the code above both String and int come from the native flash library.
I presume that Flash Builder uses the EMF core internally to represent both any included libs (swcs) and any types I define in my projects. If this is the case, my question is:
How can I access the EMF model of FLash Builder?
If there is no EMF model then I presume I would have to parse the library.swc myself and the source code of my projects.
Is the Xtend language intended to preform these sort of native filesystem tasks?
Thanks
Let us asume the Flash Builder comes with an EMF based metamodel. then the "thing" you have to do is to implement a IResourceServiceProvider. I have blogged on doing the very same stuff for uml models: http://christiandietrich.wordpress.com/2011/07/17/xtext-2-0-and-uml/
and no: xtend is a modern style programming language that compiles to Java and has nice Templating support.

Using Objective-C Metadata to Generate Class Dependency Graph

This guy came up with a pretty neat tool to generate a class dependency graph - however, it relies on parsing your source code and looking for #import directives.
http://seriot.ch/blog.php?article=20110124
https://github.com/nst/objc_dep/blob/master/objc-dep.py
This is neat, but I have a number of problems with this. Not least of which is it doesn't take into account imports of imports nor prefix headers nor whether-or-not the class(es) in the file referenced by the import are actually being used.
I'd like to do something more akin to class-dump and examine the Objective-C metadata stored in the Mach-O file to generate an in-memory representation of the class dependencies.
I'd rather not do this from scratch, so I'm wondering:
Has it already been done?
Is there an open-source library which would provide me with the foundational tools I need to extract this information (a library which examines the Mach-O file and creates a façade of the Objective-C information contained within - such that I could iterate over all of the classes, their methods, properties, ivars, etc and scan for references to other classes) I figure class-dump's source would be a good place to start.
If you have experience in this sort of thing, is what I'm trying to accomplish feasible?
What roadblocks will I need to overcome?
Has it already been done?
Not that I know of.
Is there an open-source library which would provide me with the
foundational tools I need to extract this information?
At the core of class-dump is libMachObjC which does exatly what you want, i.e. parse all classes/methods/ivars and more. The API is very clean, it should be very easy to use.
If you have experience in this sort of thing, is what I'm trying to
accomplish feasible?
Unfortunately, no because some classes don't declare the real class but use id instead. For example, here is the information that can be extracted from a class-dump of UIKit:
#interface UITableView : UIScrollView <NSCoding>
{
int _style;
id <UITableViewDataSource> _dataSource;
id _rowData;
...
The _rowData ivar type information is id but if you check at runtime you will see that _rowData is an instance of the UITableViewRowData class. This information is not present in the Mach-O binary so you have no way to find the relation between UITableView and UITableViewRowData. The same applies for method parameters.
Here's a solution that relies on information in mach.o files, and generates graph dependency based on that information: https://github.com/PaulTaykalo/objc-dependency-visualizer
Has it already been done?
yes - but i can't recommend a good public implementation
Is there an open-source library which would provide me with the foundational tools I need to extract this information (a library which examines the Mach-O file and creates a façade of the Objective-C information contained within - such that I could iterate over all of the classes, their methods, properties, ivars, etc and scan for references to other classes) I figure class-dump's source would be a good place to start.
most use cases would benefit by using the objc runtime facilities objc/... rather than examining the binary.
If you have experience in this sort of thing, is what I'm trying to accomplish feasible?
yes. i've done something similar using the objc runtime.
What roadblocks will I need to overcome?
that depends largely on the level of detail you want... implementation time if you find no such implementation, but i figure you will find a few options if you google the more esoteric functions in the objc runtime; perhaps you would find one in an (open) language binding or bridge?
if you do end up writing one yourself, you can get registered objc classes using objc_getClassList, then access the properties/information you want from there.