forked from square/wire
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sample. Also make pom.xml more uniform.
- Loading branch information
1 parent
f61aa88
commit af22aa8
Showing
10 changed files
with
140 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>com.squareup.wire</groupId> | ||
<artifactId>wire</artifactId> | ||
<version>2.0.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>wire-sample</artifactId> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.squareup.wire</groupId> | ||
<artifactId>wire-runtime</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.squareup.okio</groupId> | ||
<artifactId>okio</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>com.squareup.wire</groupId> | ||
<artifactId>wire-maven-plugin</artifactId> | ||
<version>${project.version}</version> | ||
<executions> | ||
<execution> | ||
<phase>generate-sources</phase> | ||
<goals> | ||
<goal>generate-sources</goal> | ||
</goals> | ||
<configuration> | ||
<protoFiles> | ||
<param>squareup/dinosaurs/dinosaur.proto</param> | ||
<param>squareup/geology/period.proto</param> | ||
</protoFiles> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright 2015 Square Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.squareup.dinosaurs; | ||
|
||
import com.squareup.geology.Period; | ||
import java.io.IOException; | ||
import java.util.Arrays; | ||
import okio.ByteString; | ||
|
||
public final class Sample { | ||
public void run() throws IOException { | ||
// Create an immutable value object with the Builder API. | ||
Dinosaur stegosaurus = new Dinosaur.Builder() | ||
.name("Stegosaurus") | ||
.period(Period.JURASSIC) | ||
.length_meters(9.0) | ||
.mass_kilograms(5_000.0) | ||
.picture_urls(Arrays.asList("http://goo.gl/LD5KY5", "http://goo.gl/VYRM67")) | ||
.build(); | ||
|
||
// Encode that value to bytes, and print that as base64. | ||
byte[] stegosaurusEncoded = Dinosaur.ADAPTER.encode(stegosaurus); | ||
System.out.println(ByteString.of(stegosaurusEncoded).base64()); | ||
|
||
// Decode base64 bytes, and decode those bytes as a dinosaur. | ||
ByteString tyrannosaurusEncoded = ByteString.decodeBase64("Cg1UeXJhbm5vc2F1cnVzEmhodHRwOi8vdmln" | ||
+ "bmV0dGUxLndpa2lhLm5vY29va2llLm5ldC9qdXJhc3NpY3BhcmsvaW1hZ2VzLzYvNmEvTGVnbzUuanBnL3Jldmlz" | ||
+ "aW9uL2xhdGVzdD9jYj0yMDE1MDMxOTAxMTIyMRJtaHR0cDovL3ZpZ25ldHRlMy53aWtpYS5ub2Nvb2tpZS5uZXQv" | ||
+ "anVyYXNzaWNwYXJrL2ltYWdlcy81LzUwL1JleHlfcHJlcGFyaW5nX2Zvcl9iYXR0bGVfd2l0aF9JbmRvbWludXNf" | ||
+ "cmV4LmpwZxmamZmZmZkoQCEAAAAAAJC6QCgB"); | ||
Dinosaur tyrannosaurus = Dinosaur.ADAPTER.decode(tyrannosaurusEncoded.toByteArray()); | ||
|
||
// Print both of our dinosaurs. | ||
System.out.println(stegosaurus.name + " is " + stegosaurus.length_meters + " meters long!"); | ||
System.out.println(tyrannosaurus.name + " weighs " + tyrannosaurus.mass_kilograms + " kilos!"); | ||
} | ||
|
||
public static void main(String[] args) throws IOException { | ||
new Sample().run(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
syntax = "proto2"; | ||
|
||
package squareup.dinosaurs; | ||
|
||
option java_package = "com.squareup.dinosaurs"; | ||
|
||
import "squareup/geology/period.proto"; | ||
|
||
message Dinosaur { | ||
/** Common name of this dinosaur, like "Stegosaurus". */ | ||
optional string name = 1; | ||
|
||
/** URLs with images of this dinosaur. */ | ||
repeated string picture_urls = 2; | ||
|
||
optional double length_meters = 3; | ||
optional double mass_kilograms = 4; | ||
optional squareup.geology.Period period = 5; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
syntax = "proto2"; | ||
|
||
package squareup.geology; | ||
|
||
option java_package = "com.squareup.geology"; | ||
|
||
enum Period { | ||
/** 145.5 million years ago — 66.0 million years ago. */ | ||
CRETACEOUS = 1; | ||
|
||
/** 201.3 million years ago — 145.0 million years ago. */ | ||
JURASSIC = 2; | ||
|
||
/** 252.17 million years ago — 201.3 million years ago. */ | ||
TRIASSIC = 3; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters