wire - Clean, lightweight protocol buffers for Android.

  •        0

Using Wire in your application------------------------------The `wire-runtime` package contains runtime support libraries that must be included in applicationsthat use Wire-generated code.Download [the latest runtime .jar][dl_runtime] or depend via Maven:```xml com.squareup.wire wire-runtime VERSION```or Gradle:```groovycompile 'com.squareup.wire:wire-runtime:VERSION'```where `VERSION` is replaced by an actual version number such as `1.5.0`.How Wire works--------------The Wire compiler generates a Java class for each message or enum defined in a `.proto file`specified on the command line. Each message class has an associated Builder class that may be usedto construct an instance manually:```java MyMessage msg = new MyMessage.Builder().some_int_field(123).build();```Note that field names are not converted to camel case.Wire messages contain a `public final` field for each field of the protocol buffer message.Each field is annotated with a `@ProtoField` annotation containing the field metadata requiredby the Wire runtime.Numeric and boolean values are stored using boxed primitive types (e.g., Integer or Long).If a field is unset, its value is `null`. Wire does not generate methods such as `getXXX()`,`hasXXX()`, `setXXX(`), etc. Repeated fields are stored as Lists of values.A field `some_field` has a constant `DEFAULT_SOME_FIELD` containing the default value for thatfield. A convenience method `Wire.get` allows substitution of a default value for `null`:```java// Equivalent to:// x = msg.some_field != null ? msg.some_field : MyMessage.DEFAULT_SOME_FIELDint x = Wire.get(msg.some_field, MyMessage.DEFAULT_SOME_FIELD);```Builders contain a `public` field for each field of the protocol buffer message, as well asa method with the same name that sets the given value and returns the Builder instance forchaining.You can serialize a message by calling its `write` or `toByteArray` methods:```javabyte[] serializedMsg = msg.toByteArray();```To parse messages from their serialized representations, use the `Wire` class. Typically youwill want to create a singleton instance of `Wire` for use throughout your application.```javaWire wire = new Wire();MyMessage newMsg = wire.parseFrom(serializedMsg, MyMessage.class);int x = newMsg.some_int_field; // 123```To use protocol buffer extensions, pass the classes that define the extensions youwish to use as arguments to the `Wire` constructor:```java// Assume MessageWithExtensions contains a message SomeMessage that defines// an extension field some_extension to the MyMessage message.Wire wire = new Wire(Ext_SomeMessage.class);MyMessage msg = new MyMessage.Builder() .setExtension(Ext_SomeMessage.some_extension, 3) .build();int x = msg.getExtension(Ext_SomeMessage.some_extension); // 3```Unsupported-----------Wire does not support: * Groups - they are skipped when parsing binary input dataWire supports custom options on messages and fields. Other custom options are ignored. Use the`--no_options` flag to omit option information from the generated code. [dl_runtime]: http://repository.sonatype.org/service/local/artifact/maven/redirect?r=central-proxy&g=com.squareup.wire&a=wire-runtime&v=LATEST [dl_compiler]: http://repository.sonatype.org/service/local/artifact/maven/redirect?r=central-proxy&g=com.squareup.wire&a=wire-compiler&v=LATEST&c=jar-with-dependencies




comments powered by Disqus

Related Projects

Worldomusic - World'O'Music - GPS-based generative music on Arduino

World'O'Music - GPS-based generative music on Arduino This is a device which plays a tune generated from its position. It plays a different tune, roughly, for every square foot of the planet, and the tune generation is written so that over small movements the tune changes smoothly. Here is is on its first day out, at Chapter in Cardiff: And here's what's inside: This project is derived from the Pisan-O-Matic: http://code.google.com/p/pisanomatic/ and the GPS-A-Min: http://jarkman.co.uk/catalog/r