Skip to main content

Posts

Showing posts with the label j2objc

Protocol Buffers!

Protocol Buffers are Google’s preferred method of representing and communicating structured data. For most Google projects, protocol buffers are used for data storage or client-server communication. As such, a working protocol buffer solution has been a requirement for J2ObjC from day one. Until recently our solution contained internal dependencies that prevented it’s public release, but now I am very pleased to be able to make our internal solution available to all J2ObjC users. Let’s take a quick look at how protocol buffers are used (for a more in-depth look you can read through the Protocol Buffers Developer Guide ). Suppose my app needs a geographic location, so I would create a geo.proto file with the following declaration: message Location {   optional string name = 1;   optional double latitude = 2;   optional double longitude = 3; } Then I can use the protocol buffer compiler, “protoc”, to generate data types in the languages I need: $ protoc --java_out=src...

cfront: a J2ObjC Inspiration

Developers new to J2ObjC may find its "Java compiles to Objective-C, which compiles to .o files" approach a little strange, but it's based on precedent: cfront . When C++ was first released, no compilers translated C++ sources directly into object files. Instead, the cfront script translated C++ into temporary C files, and then invoked cc to compile them. cfront took similar options as cc, so most C++ developers used it as if it was a true C++ compiler. The cfront script wrapped around a transpiler , though; it was a script very similar to combining the j2objc and j2objcc scripts in J2ObjC. One of cfront 's innovations was name mangling , where C++ type information was embedded into C names. J2ObjC also uses name mangling ( described here ) to support features like packages and Java's method overloading semantics that Objective-C doesn't directly support. For example, the JRE has both java.util.Date and java.sql.Date classes; since C names are all ...