Is it possible to directly parse API protobuf files in iOS? - ios

I am making an app that shows the real-time location of local buses. I have an API that returns the .pb (protobuf) file with Vehicle Positions. I am handling proto buffers for the first time and I have no idea why we can't parse them like JSON file.
I saw a library named "Swift-Protobuf", but in its documentation. They are asking to run a command to convert protobuf file into a swift object. But as I am making API calls every minute that returns the protobuf file. How can I run that command every time?
$ protoc --swift_out=. my.proto
I just want to parse those .pb files into a swift object. So that I can use the data on my project.

They are asking to run a command to convert protobuf file into a swift object. But as I am making API calls every minute that returns the protobuf file. How can I run that command every time?
I think you've misunderstood the documentation: you don't need to run protoc --swift_out=. my.proto for every .pb file you receive; you use that command to generate code that knows how to read and write data according to the schema that you define in a .proto file. You can then take that generated code and add it to your iOS project, and after that you can use the code to read and write protobuf data that matches your schema.
I am making an app that shows the real-time location of local buses.
So before you can get started, you're going to need a .proto file that describes the data format used by whoever provides the bus location data, or you'll need whoever provides that data to use SwiftProtobuf or similar to generate a Swift parser for their .proto file.
...I have no idea why we can't parse them like JSON file.
Well, the point of the protobuf format is to be language-agnostic and faster/easier to use than JSON or XML, and one of the design decisions that Google apparently made is to sacrifice human readability for size/speed. So you could write a parser to parse these files just as you would JSON data, but you'd have to learn how the format works. But it's a lot easier to describe the data you're sending and have a program generate the code. One nice aspect of this arrangement is that you can describe the schema once and then generate code that works with that schema for several languages, so you don't have to write code separately for your iOS app, your Android app, and your server.

Related

Parse or convert .pb files under .sonar folder

I'm using sonarqube 5.6.5,everything works well . Now i need to parse the issues.PB file generated under .sonar/batch-report/ folder. i tried using jsonformat but it is not working.
They are "Protobuf" format, which is a format by google for serializing data. You can get started here or find for example a tutorial here on how to use it in Java.
What I don't understand is that your question has a tag "protobuf-net", which github page explains very well how to use it (in .NET).

How to export data as a XES file in rails?

I am working on a application that allows users upload and edit CSV files containing process activity logs.
I am not storing the data in the database.
So far the user can download the data as a new .csv file.
Now I want to convert that data into a XES file (this a special XML format used mainly for process mining in tools such as ProM framework).
I couldn't find any hint on how to do that.
I wonder if there's a rails gem or something.
Thanks in advance
ps.: here is the project code.
A simple method would be imported in Disco and by using this tool, exported in XES format ( I always use this method).
If you don't access to Disco another solution would be used ProM software. There is a plugin for this platform for converting CSV file to XES format ( developed by F. Mannhardt).

Read .las (LiDAR data) in iOS

I am making an app render the cloud points on different layer. For now I am consuming the data as .txt file converted from .las file. My question is: is there a way or lib to directly consume the .las format on iOS device? I searched about the libLAS (http://www.liblas.org/) but don't think it will work.
Thanks
Try LASlib of LAStools. It compiles without dependencies and also reads compressed LAS aka LAZ.
http://github.com/LAStools/LAStools/tree/master/LASlib

iOS know when file has changed

I am downloading a mp4 file with my iOS app, it works fine using
NSData dataWithContentsOfURL
but i need to updated only if the file has been updated,
can I check the file headers? or what is the best way to determine if the file has been updated so I downloaded it again?
Thanks
You can access the metadata using the http HEAD request, as explained in this SO answer. You'll need to create some sort of parser to pick out the information you need, though. Note that this might not work with every server, depending on how it has been set up.
If you have control of the server yourself, I'd recommend using a php script to output the date the file has been last changed, which you would call before downloading the file.
Personally, I prefer placing a manifest file (usually a plist) alongside the file in question, as it can hold even more data, for example metadata for several files, the number of entries in a database and the like. A backdraw of this approach is that you'll need to keep this file up to date, though. But often, that is worth the while.
Lastly, as rckoenes has mentioned, dataWithContentsOfURL is not a very good way to download files, espcially large ones. You really should be using some sort of datamanager class, which manages a NSURLConnection.

How can we write Structures in file?

I am new to IOS programming. I want to write a C style structure into file and retrieve back.
I am able to write string into file after getting Document directory path. But how to write a structure in that file. Can anyone help?
You'd likely be most interested in the NSCoding protocol, as well as the Creating and Extracting Archives and Encoding and Decoding Objects in the Archives and Serialization guide.
Normal C way of I\O operation worked well, however the to write file in particular location we need permission.

Resources