├── .gitignore ├── .idea ├── artifacts │ └── protoc_as3_jar.xml ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── flexCompiler.xml ├── inspectionProfiles │ ├── Project_Default.xml │ └── profiles_settings.xml ├── misc.xml ├── modules.xml ├── uiDesigner.xml └── vcs.xml ├── protobuf-as3 ├── protobuf-as3.iml └── src │ └── com │ └── google │ └── protobuf │ ├── CodedInputStream.as │ ├── CodedOutputStream.as │ ├── Enum.as │ ├── FieldDescriptorType.as │ ├── Int64.as │ ├── InvalidProtocolBufferException.as │ ├── MapEntry.as │ ├── Message.as │ ├── MessageUtil.as │ └── WireFormat.as ├── protobuf-java ├── protobuf-java.iml └── src │ └── com │ └── google │ └── protobuf │ ├── AbstractMessage.java │ ├── AbstractMessageLite.java │ ├── AbstractParser.java │ ├── AbstractProtobufList.java │ ├── BlockingRpcChannel.java │ ├── BlockingService.java │ ├── BooleanArrayList.java │ ├── ByteBufferWriter.java │ ├── ByteOutput.java │ ├── ByteString.java │ ├── CodedInputStream.java │ ├── CodedOutputStream.java │ ├── DescriptorProtos.java │ ├── Descriptors.java │ ├── DoubleArrayList.java │ ├── DynamicMessage.java │ ├── ExperimentalApi.java │ ├── Extension.java │ ├── ExtensionLite.java │ ├── ExtensionRegistry.java │ ├── ExtensionRegistryLite.java │ ├── FieldSet.java │ ├── FloatArrayList.java │ ├── GeneratedMessage.java │ ├── GeneratedMessageLite.java │ ├── IntArrayList.java │ ├── Internal.java │ ├── InvalidProtocolBufferException.java │ ├── LazyField.java │ ├── LazyFieldLite.java │ ├── LazyStringArrayList.java │ ├── LazyStringList.java │ ├── LongArrayList.java │ ├── MapEntry.java │ ├── MapEntryLite.java │ ├── MapField.java │ ├── MapFieldLite.java │ ├── Message.java │ ├── MessageLite.java │ ├── MessageLiteOrBuilder.java │ ├── MessageLiteToString.java │ ├── MessageOrBuilder.java │ ├── MessageReflection.java │ ├── MutabilityOracle.java │ ├── NioByteString.java │ ├── Parser.java │ ├── ProtobufArrayList.java │ ├── ProtocolMessageEnum.java │ ├── ProtocolStringList.java │ ├── RepeatedFieldBuilder.java │ ├── RopeByteString.java │ ├── RpcCallback.java │ ├── RpcChannel.java │ ├── RpcController.java │ ├── RpcUtil.java │ ├── Service.java │ ├── ServiceException.java │ ├── SingleFieldBuilder.java │ ├── SmallSortedMap.java │ ├── TextFormat.java │ ├── TextFormatEscaper.java │ ├── TextFormatParseInfoTree.java │ ├── TextFormatParseLocation.java │ ├── UninitializedMessageException.java │ ├── UnknownFieldSet.java │ ├── UnknownFieldSetLite.java │ ├── UnmodifiableLazyStringList.java │ ├── UnsafeByteOperations.java │ ├── Utf8.java │ ├── WireFormat.java │ └── compiler │ └── PluginProtos.java ├── protoc-as3 ├── protoc-as3.iml └── src │ ├── META-INF │ └── MANIFEST.MF │ └── com │ └── google │ └── protobuf │ └── compiler │ └── as3 │ ├── CodeGenerator.java │ ├── EnumGenerator.java │ ├── FieldGenerator.java │ ├── IGenerator.java │ ├── MapGenerator.java │ ├── MessageGenerator.java │ ├── Printer.java │ └── Util.java ├── test-as3 ├── src │ ├── Main.as │ └── test │ │ ├── Battle$Player$SkillEntry.as │ │ ├── Battle$Player.as │ │ ├── Battle$Skill.as │ │ ├── Battle.as │ │ ├── Element$Type.as │ │ ├── Element.as │ │ └── Response.as └── test-as3.iml ├── test-java ├── src │ ├── Main.java │ └── test │ │ ├── Battle.java │ │ ├── BattleOrBuilder.java │ │ ├── Element.java │ │ ├── ElementDef.java │ │ ├── ElementOrBuilder.java │ │ └── Response.java └── test-java.iml └── tools ├── build_macosx_linux.sh ├── build_win.bat ├── google └── protobuf │ ├── any.proto │ ├── api.proto │ ├── compiler │ └── plugin.proto │ ├── descriptor.proto │ ├── duration.proto │ ├── empty.proto │ ├── field_mask.proto │ ├── source_context.proto │ ├── struct.proto │ ├── timestamp.proto │ ├── type.proto │ └── wrappers.proto ├── protobuf.test ├── protoc-as3 ├── protoc-as3.bat ├── protoc-as3.jar ├── protoc.exe └── protos └── element.proto /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/workspace.xml 2 | .idea/dictionaries/ 3 | out/ -------------------------------------------------------------------------------- /.idea/artifacts/protoc_as3_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | $PROJECT_DIR$/tools 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/flexCompiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 13 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 60 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /protobuf-as3/protobuf-as3.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /protobuf-as3/src/com/google/protobuf/Enum.as: -------------------------------------------------------------------------------- 1 | package com.google.protobuf { 2 | public class Enum { 3 | private var _value:int; 4 | private var _name:String; 5 | 6 | public function Enum(name:String, value:int) { 7 | _name = name; 8 | _value = value; 9 | } 10 | 11 | public function get value():int { 12 | return _value; 13 | } 14 | 15 | public function get name():String { 16 | return _name; 17 | } 18 | 19 | public function toString():String { 20 | return "(name=" + _name + ", value=" + value + ")"; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /protobuf-as3/src/com/google/protobuf/FieldDescriptorType.as: -------------------------------------------------------------------------------- 1 | package com.google.protobuf { 2 | public class FieldDescriptorType { 3 | public static const DOUBLE:int = 0; 4 | public static const FLOAT:int = 1; 5 | public static const INT32:int = 2; 6 | public static const INT64:int = 3; 7 | public static const UINT32:int = 4; 8 | public static const UINT64:int = 5; 9 | public static const SINT32:int = 6; 10 | public static const SINT64:int = 7; 11 | public static const FIXED32:int = 8; 12 | public static const FIXED64:int = 9; 13 | public static const SFIXED32:int = 10; 14 | public static const SFIXED64:int = 11; 15 | public static const BOOL:int = 12; 16 | public static const STRING:int = 13; 17 | public static const BYTES:int = 14; 18 | public static const ENUM:int = 15; 19 | public static const MESSAGE:int = 16; 20 | public static const MAP:int = 17; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /protobuf-as3/src/com/google/protobuf/Int64.as: -------------------------------------------------------------------------------- 1 | package com.google.protobuf { 2 | public class Int64 { 3 | private var _high:int; 4 | private var _low:uint; 5 | 6 | public function Int64(high:int = 0, low:uint = 0) { 7 | _high = high; 8 | _low = low; 9 | } 10 | 11 | public function get low():uint { 12 | return _low; 13 | } 14 | 15 | public function set low(value:uint):void { 16 | _low = value; 17 | } 18 | 19 | public function get high():int { 20 | return _high; 21 | } 22 | 23 | public function set high(value:int):void { 24 | _high = value; 25 | } 26 | 27 | public function isZero():Boolean { 28 | return _high == 0 && _low == 0; 29 | } 30 | 31 | public function toString():String { 32 | var high:String = "00000000" + uint(_high).toString(16); 33 | var low:String = "00000000" + uint(_low).toString(16); 34 | 35 | return "0x" + high.substr(high.length - 8) + low.substr(low.length - 8); 36 | } 37 | 38 | public function equal(other:Int64):Boolean { 39 | return other._high == _high && other._low == _low; 40 | } 41 | 42 | public function shiftRight(bit:int):Int64 { 43 | var high:int = _high; 44 | var low:uint = _low; 45 | 46 | if (bit >= 64) { 47 | high = 0; 48 | low = 0; 49 | } else if (bit >= 32) { 50 | bit -= 32; 51 | low = high >>> bit; 52 | high = 0; 53 | } else if (bit > 0) { 54 | low >>>= bit; 55 | low |= (high & ((1 << bit) - 1)) << (32 - bit); 56 | high >>>= bit; 57 | } 58 | 59 | return new Int64(high, low); 60 | } 61 | 62 | public function shiftLeft(bit:int):Int64 { 63 | var high:int = _high; 64 | var low:uint = _low; 65 | 66 | if (bit >= 64) { 67 | high = 0; 68 | low = 0; 69 | } else if (bit >= 32) { 70 | bit -= 32; 71 | high = low << bit; 72 | low = 0; 73 | } else if (bit > 0) { 74 | high <<= bit; 75 | high |= low >>> (32 - bit); 76 | low <<= bit; 77 | } 78 | 79 | return new Int64(high, low); 80 | } 81 | 82 | public function xor(other:Int64):Int64 { 83 | return new Int64(_high ^ other._high, _low ^ other.low); 84 | } 85 | 86 | public function and(other:Int64):Int64 { 87 | return new Int64(_high & other._high, _low & other.low); 88 | } 89 | 90 | public function or(other:Int64):Int64 { 91 | return new Int64(_high | other._high, _low | other.low); 92 | } 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /protobuf-as3/src/com/google/protobuf/InvalidProtocolBufferException.as: -------------------------------------------------------------------------------- 1 | package com.google.protobuf { 2 | import flash.errors.IOError; 3 | 4 | public class InvalidProtocolBufferException extends IOError { 5 | 6 | public function InvalidProtocolBufferException(description:String) { 7 | super(description); 8 | } 9 | 10 | internal static function truncatedMessage():InvalidProtocolBufferException { 11 | return new InvalidProtocolBufferException( 12 | "While parsing a protocol message, the input ended unexpectedly " + 13 | "in the middle of a field. This could mean either than the " + 14 | "input has been truncated or that an embedded message " + 15 | "misreported its own length."); 16 | } 17 | 18 | internal static function negativeSize():InvalidProtocolBufferException { 19 | return new InvalidProtocolBufferException( 20 | "CodedInputStream encountered an embedded string or message " + 21 | "which claimed to have negative size."); 22 | } 23 | 24 | internal static function malformedVarint():InvalidProtocolBufferException { 25 | return new InvalidProtocolBufferException( 26 | "CodedInputStream encountered a malformed varint."); 27 | } 28 | 29 | internal static function invalidTag():InvalidProtocolBufferException { 30 | return new InvalidProtocolBufferException( 31 | "Protocol message contained an invalid tag (zero)."); 32 | } 33 | 34 | internal static function invalidEndTag():InvalidProtocolBufferException { 35 | return new InvalidProtocolBufferException( 36 | "Protocol message end-group tag did not match expected tag."); 37 | } 38 | 39 | internal static function invalidWireType():InvalidProtocolBufferException { 40 | return new InvalidProtocolBufferException( 41 | "Protocol message tag had invalid wire type."); 42 | } 43 | 44 | internal static function recursionLimitExceeded():InvalidProtocolBufferException { 45 | return new InvalidProtocolBufferException( 46 | "Protocol message had too many levels of nesting. May be malicious. " + 47 | "Use CodedInputStream.setRecursionLimit() to increase the depth limit."); 48 | } 49 | 50 | internal static function sizeLimitExceeded():InvalidProtocolBufferException { 51 | return new InvalidProtocolBufferException( 52 | "Protocol message was too large. May be malicious. " + 53 | "Use CodedInputStream.setSizeLimit() to increase the size limit."); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /protobuf-as3/src/com/google/protobuf/MapEntry.as: -------------------------------------------------------------------------------- 1 | package com.google.protobuf { 2 | public class MapEntry { 3 | private var _key:*; 4 | private var _value:*; 5 | public function MapEntry(key:*, value:*) { 6 | _key = key; 7 | _value = value; 8 | } 9 | 10 | public function get key():* { 11 | return _key; 12 | } 13 | 14 | public function set key(value:*):void { 15 | _key = value; 16 | } 17 | 18 | public function get value():* { 19 | return _value; 20 | } 21 | 22 | public function set value(value:*):void { 23 | _value = value; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /protobuf-as3/src/com/google/protobuf/Message.as: -------------------------------------------------------------------------------- 1 | package com.google.protobuf { 2 | import flash.utils.ByteArray; 3 | import flash.utils.Dictionary; 4 | 5 | public class Message { 6 | public function Message() { 7 | } 8 | 9 | public function writeTo(output:CodedOutputStream):void { 10 | } 11 | 12 | public function readFrom(input:CodedInputStream):void { 13 | } 14 | 15 | public static function toByteArray(message:Message):ByteArray { 16 | var bytes:ByteArray = new ByteArray(); 17 | message.writeTo(new CodedOutputStream(bytes)); 18 | return bytes; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /protobuf-as3/src/com/google/protobuf/MessageUtil.as: -------------------------------------------------------------------------------- 1 | package com.google.protobuf { 2 | 3 | import flash.utils.ByteArray; 4 | 5 | public class MessageUtil { 6 | public static function clone(message:Message):* { 7 | var bytes:ByteArray = new ByteArray(); 8 | message.writeTo(new CodedOutputStream(bytes)); 9 | 10 | var newMsg:Message = new message['constructor'](); 11 | bytes.position = 0; 12 | newMsg.readFrom(new CodedInputStream(bytes)); 13 | return newMsg; 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /protobuf-as3/src/com/google/protobuf/WireFormat.as: -------------------------------------------------------------------------------- 1 | package com.google.protobuf { 2 | public class WireFormat { 3 | public static const WIRETYPE_VARINT:int = 0; 4 | public static const WIRETYPE_FIXED64:int = 1; 5 | public static const WIRETYPE_LENGTH_DELIMITED:int = 2; 6 | public static const WIRETYPE_START_GROUP:int = 3; 7 | public static const WIRETYPE_END_GROUP:int = 4; 8 | public static const WIRETYPE_FIXED32:int = 5; 9 | 10 | internal static const TAG_TYPE_BITS:int = 3; 11 | internal static const TAG_TYPE_MASK:int = (1 << TAG_TYPE_BITS) - 1; 12 | 13 | public static function getTagWireType(tag:int):int { 14 | return tag & TAG_TYPE_MASK; 15 | } 16 | 17 | public static function getTagFieldNumber(tag:int):int { 18 | return tag >> TAG_TYPE_BITS; 19 | } 20 | 21 | internal static function makeTag(fieldNumber:int, wireType:int):int { 22 | return (fieldNumber << TAG_TYPE_BITS) | wireType; 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /protobuf-java/protobuf-java.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /protobuf-java/src/com/google/protobuf/AbstractProtobufList.java: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | package com.google.protobuf; 32 | 33 | import com.google.protobuf.Internal.ProtobufList; 34 | 35 | import java.util.AbstractList; 36 | import java.util.Collection; 37 | 38 | /** 39 | * An abstract implementation of {@link ProtobufList} which manages mutability semantics. All mutate 40 | * methods are check if the list is mutable before proceeding. Subclasses must invoke 41 | * {@link #ensureIsMutable()} manually when overriding those methods. 42 | */ 43 | abstract class AbstractProtobufList extends AbstractList implements ProtobufList { 44 | 45 | /** 46 | * Whether or not this list is modifiable. 47 | */ 48 | private boolean isMutable; 49 | 50 | /** 51 | * Constructs a mutable list by default. 52 | */ 53 | AbstractProtobufList() { 54 | isMutable = true; 55 | } 56 | 57 | @Override 58 | public boolean add(E e) { 59 | ensureIsMutable(); 60 | return super.add(e); 61 | } 62 | 63 | @Override 64 | public void add(int index, E element) { 65 | ensureIsMutable(); 66 | super.add(index, element); 67 | } 68 | 69 | @Override 70 | public boolean addAll(Collection c) { 71 | ensureIsMutable(); 72 | return super.addAll(c); 73 | } 74 | 75 | @Override 76 | public boolean addAll(int index, Collection c) { 77 | ensureIsMutable(); 78 | return super.addAll(index, c); 79 | } 80 | 81 | @Override 82 | public void clear() { 83 | ensureIsMutable(); 84 | super.clear(); 85 | } 86 | 87 | @Override 88 | public boolean isModifiable() { 89 | return isMutable; 90 | } 91 | 92 | @Override 93 | public final void makeImmutable() { 94 | isMutable = false; 95 | } 96 | 97 | @Override 98 | public E remove(int index) { 99 | ensureIsMutable(); 100 | return super.remove(index); 101 | } 102 | 103 | @Override 104 | public boolean remove(Object o) { 105 | ensureIsMutable(); 106 | return super.remove(o); 107 | } 108 | 109 | @Override 110 | public boolean removeAll(Collection c) { 111 | ensureIsMutable(); 112 | return super.removeAll(c); 113 | } 114 | 115 | @Override 116 | public boolean retainAll(Collection c) { 117 | ensureIsMutable(); 118 | return super.retainAll(c); 119 | } 120 | 121 | @Override 122 | public E set(int index, E element) { 123 | ensureIsMutable(); 124 | return super.set(index, element); 125 | } 126 | 127 | /** 128 | * Throws an {@link UnsupportedOperationException} if the list is immutable. Subclasses are 129 | * responsible for invoking this method on mutate operations. 130 | */ 131 | protected void ensureIsMutable() { 132 | if (!isMutable) { 133 | throw new UnsupportedOperationException(); 134 | } 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /protobuf-java/src/com/google/protobuf/BlockingRpcChannel.java: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | package com.google.protobuf; 32 | 33 | /** 34 | *

Abstract interface for a blocking RPC channel. {@code BlockingRpcChannel} 35 | * is the blocking equivalent to {@link RpcChannel}. 36 | * 37 | * @author kenton@google.com Kenton Varda 38 | * @author cpovirk@google.com Chris Povirk 39 | */ 40 | public interface BlockingRpcChannel { 41 | /** 42 | * Call the given method of the remote service and blocks until it returns. 43 | * {@code callBlockingMethod()} is the blocking equivalent to 44 | * {@link RpcChannel#callMethod}. 45 | */ 46 | Message callBlockingMethod( 47 | Descriptors.MethodDescriptor method, 48 | RpcController controller, 49 | Message request, 50 | Message responsePrototype) throws ServiceException; 51 | } 52 | -------------------------------------------------------------------------------- /protobuf-java/src/com/google/protobuf/BlockingService.java: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | package com.google.protobuf; 32 | 33 | /** 34 | * Blocking equivalent to {@link Service}. 35 | * 36 | * @author kenton@google.com Kenton Varda 37 | * @author cpovirk@google.com Chris Povirk 38 | */ 39 | public interface BlockingService { 40 | /** 41 | * Equivalent to {@link Service#getDescriptorForType}. 42 | */ 43 | Descriptors.ServiceDescriptor getDescriptorForType(); 44 | 45 | /** 46 | * Equivalent to {@link Service#callMethod}, except that 47 | * {@code callBlockingMethod()} returns the result of the RPC or throws a 48 | * {@link ServiceException} if there is a failure, rather than passing the 49 | * information to a callback. 50 | */ 51 | Message callBlockingMethod(Descriptors.MethodDescriptor method, 52 | RpcController controller, 53 | Message request) throws ServiceException; 54 | 55 | /** 56 | * Equivalent to {@link Service#getRequestPrototype}. 57 | */ 58 | Message getRequestPrototype(Descriptors.MethodDescriptor method); 59 | 60 | /** 61 | * Equivalent to {@link Service#getResponsePrototype}. 62 | */ 63 | Message getResponsePrototype(Descriptors.MethodDescriptor method); 64 | } 65 | -------------------------------------------------------------------------------- /protobuf-java/src/com/google/protobuf/ByteBufferWriter.java: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | package com.google.protobuf; 32 | 33 | import static java.lang.Math.max; 34 | import static java.lang.Math.min; 35 | 36 | import java.io.FileOutputStream; 37 | import java.io.IOException; 38 | import java.io.OutputStream; 39 | import java.lang.ref.SoftReference; 40 | import java.nio.ByteBuffer; 41 | 42 | /** 43 | * Utility class to provide efficient writing of {@link ByteBuffer}s to {@link OutputStream}s. 44 | */ 45 | final class ByteBufferWriter { 46 | private ByteBufferWriter() {} 47 | 48 | /** 49 | * Minimum size for a cached buffer. This prevents us from allocating buffers that are too 50 | * small to be easily reused. 51 | */ 52 | // TODO(nathanmittler): tune this property or allow configuration? 53 | private static final int MIN_CACHED_BUFFER_SIZE = 1024; 54 | 55 | /** 56 | * Maximum size for a cached buffer. If a larger buffer is required, it will be allocated 57 | * but not cached. 58 | */ 59 | // TODO(nathanmittler): tune this property or allow configuration? 60 | private static final int MAX_CACHED_BUFFER_SIZE = 16 * 1024; 61 | 62 | /** 63 | * The fraction of the requested buffer size under which the buffer will be reallocated. 64 | */ 65 | // TODO(nathanmittler): tune this property or allow configuration? 66 | private static final float BUFFER_REALLOCATION_THRESHOLD = 0.5f; 67 | 68 | /** 69 | * Keeping a soft reference to a thread-local buffer. This buffer is used for writing a 70 | * {@link ByteBuffer} to an {@link OutputStream} when no zero-copy alternative was available. 71 | * Using a "soft" reference since VMs may keep this reference around longer than "weak" 72 | * (e.g. HotSpot will maintain soft references until memory pressure warrants collection). 73 | */ 74 | private static final ThreadLocal> BUFFER = 75 | new ThreadLocal>(); 76 | 77 | /** 78 | * For testing purposes only. Clears the cached buffer to force a new allocation on the next 79 | * invocation. 80 | */ 81 | static void clearCachedBuffer() { 82 | BUFFER.set(null); 83 | } 84 | 85 | /** 86 | * Writes the remaining content of the buffer to the given stream. The buffer {@code position} 87 | * will remain unchanged by this method. 88 | */ 89 | static void write(ByteBuffer buffer, OutputStream output) throws IOException { 90 | final int initialPos = buffer.position(); 91 | try { 92 | if (buffer.hasArray()) { 93 | // Optimized write for array-backed buffers. 94 | // Note that we're taking the risk that a malicious OutputStream could modify the array. 95 | output.write(buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.remaining()); 96 | } else if (output instanceof FileOutputStream) { 97 | // Use a channel to write out the ByteBuffer. This will automatically empty the buffer. 98 | ((FileOutputStream) output).getChannel().write(buffer); 99 | } else { 100 | // Read all of the data from the buffer to an array. 101 | // TODO(nathanmittler): Consider performance improvements for other "known" stream types. 102 | final byte[] array = getOrCreateBuffer(buffer.remaining()); 103 | while (buffer.hasRemaining()) { 104 | int length = min(buffer.remaining(), array.length); 105 | buffer.get(array, 0, length); 106 | output.write(array, 0, length); 107 | } 108 | } 109 | } finally { 110 | // Restore the initial position. 111 | buffer.position(initialPos); 112 | } 113 | } 114 | 115 | private static byte[] getOrCreateBuffer(int requestedSize) { 116 | requestedSize = max(requestedSize, MIN_CACHED_BUFFER_SIZE); 117 | 118 | byte[] buffer = getBuffer(); 119 | // Only allocate if we need to. 120 | if (buffer == null || needToReallocate(requestedSize, buffer.length)) { 121 | buffer = new byte[requestedSize]; 122 | 123 | // Only cache the buffer if it's not too big. 124 | if (requestedSize <= MAX_CACHED_BUFFER_SIZE) { 125 | setBuffer(buffer); 126 | } 127 | } 128 | return buffer; 129 | } 130 | 131 | private static boolean needToReallocate(int requestedSize, int bufferLength) { 132 | // First check against just the requested length to avoid the multiply. 133 | return bufferLength < requestedSize 134 | && bufferLength < requestedSize * BUFFER_REALLOCATION_THRESHOLD; 135 | } 136 | 137 | private static byte[] getBuffer() { 138 | SoftReference sr = BUFFER.get(); 139 | return sr == null ? null : sr.get(); 140 | } 141 | 142 | private static void setBuffer(byte[] value) { 143 | BUFFER.set(new SoftReference(value)); 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /protobuf-java/src/com/google/protobuf/ByteOutput.java: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | package com.google.protobuf; 32 | 33 | import java.io.IOException; 34 | import java.nio.ByteBuffer; 35 | 36 | /** 37 | * An output target for raw bytes. This interface provides semantics that support two types of 38 | * writing: 39 | * 40 | *

Traditional write operations: 41 | * (as defined by {@link java.io.OutputStream}) where the target method is responsible for either 42 | * copying the data or completing the write before returning from the method call. 43 | * 44 | *

Lazy write operations: where the caller guarantees that it will never modify the 45 | * provided buffer and it can therefore be considered immutable. The target method is free to 46 | * maintain a reference to the buffer beyond the scope of the method call (e.g. until the write 47 | * operation completes). 48 | */ 49 | @ExperimentalApi 50 | public abstract class ByteOutput { 51 | /** 52 | * Writes a single byte. 53 | * 54 | * @param value the byte to be written 55 | * @throws IOException thrown if an error occurred while writing 56 | */ 57 | public abstract void write(byte value) throws IOException; 58 | 59 | /** 60 | * Writes a sequence of bytes. The {@link ByteOutput} must copy {@code value} if it will 61 | * not be processed prior to the return of this method call, since {@code value} may be 62 | * reused/altered by the caller. 63 | * 64 | *

NOTE: This method MUST NOT modify the {@code value}. Doing so is a 65 | * programming error and will lead to data corruption which will be difficult to debug. 66 | * 67 | * @param value the bytes to be written 68 | * @param offset the offset of the start of the writable range 69 | * @param length the number of bytes to write starting from {@code offset} 70 | * @throws IOException thrown if an error occurred while writing 71 | */ 72 | public abstract void write(byte[] value, int offset, int length) throws IOException; 73 | 74 | /** 75 | * Writes a sequence of bytes. The {@link ByteOutput} is free to retain a reference to the value 76 | * beyond the scope of this method call (e.g. write later) since it is considered immutable and is 77 | * guaranteed not to change by the caller. 78 | * 79 | *

NOTE: This method MUST NOT modify the {@code value}. Doing so is a 80 | * programming error and will lead to data corruption which will be difficult to debug. 81 | * 82 | * @param value the bytes to be written 83 | * @param offset the offset of the start of the writable range 84 | * @param length the number of bytes to write starting from {@code offset} 85 | * @throws IOException thrown if an error occurred while writing 86 | */ 87 | public abstract void writeLazy(byte[] value, int offset, int length) throws IOException; 88 | 89 | /** 90 | * Writes a sequence of bytes. The {@link ByteOutput} must copy {@code value} if it will 91 | * not be processed prior to the return of this method call, since {@code value} may be 92 | * reused/altered by the caller. 93 | * 94 | *

NOTE: This method MUST NOT modify the {@code value}. Doing so is a 95 | * programming error and will lead to data corruption which will be difficult to debug. 96 | * 97 | * @param value the bytes to be written. Upon returning from this call, the {@code position} of 98 | * this buffer will be set to the {@code limit} 99 | * @throws IOException thrown if an error occurred while writing 100 | */ 101 | public abstract void write(ByteBuffer value) throws IOException; 102 | 103 | /** 104 | * Writes a sequence of bytes. The {@link ByteOutput} is free to retain a reference to the value 105 | * beyond the scope of this method call (e.g. write later) since it is considered immutable and is 106 | * guaranteed not to change by the caller. 107 | * 108 | *

NOTE: This method MUST NOT modify the {@code value}. Doing so is a 109 | * programming error and will lead to data corruption which will be difficult to debug. 110 | * 111 | * @param value the bytes to be written. Upon returning from this call, the {@code position} of 112 | * this buffer will be set to the {@code limit} 113 | * @throws IOException thrown if an error occurred while writing 114 | */ 115 | public abstract void writeLazy(ByteBuffer value) throws IOException; 116 | } 117 | -------------------------------------------------------------------------------- /protobuf-java/src/com/google/protobuf/ExperimentalApi.java: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | package com.google.protobuf; 32 | 33 | import java.lang.annotation.Documented; 34 | import java.lang.annotation.ElementType; 35 | import java.lang.annotation.Retention; 36 | import java.lang.annotation.RetentionPolicy; 37 | import java.lang.annotation.Target; 38 | 39 | /** 40 | * Indicates a public API that can change at any time, and has no guarantee of API stability and 41 | * backward-compatibility. 42 | * 43 | *

Usage guidelines: 44 | *

    45 | *
  1. This annotation is used only on public API. Internal interfaces should not use it.
  2. 46 | *
  3. This annotation should only be added to new APIs. Adding it to an existing API is 47 | * considered API-breaking.
  4. 48 | *
  5. Removing this annotation from an API gives it stable status.
  6. 49 | *
50 | */ 51 | @Retention(RetentionPolicy.SOURCE) 52 | @Target({ 53 | ElementType.ANNOTATION_TYPE, 54 | ElementType.CONSTRUCTOR, 55 | ElementType.FIELD, 56 | ElementType.METHOD, 57 | ElementType.PACKAGE, 58 | ElementType.TYPE}) 59 | @Documented 60 | public @interface ExperimentalApi { 61 | /** 62 | * Context information such as links to discussion thread, tracking issue etc. 63 | */ 64 | String value() default ""; 65 | } 66 | 67 | -------------------------------------------------------------------------------- /protobuf-java/src/com/google/protobuf/Extension.java: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | package com.google.protobuf; 32 | 33 | /** 34 | * Interface that generated extensions implement. 35 | * 36 | * @author liujisi@google.com (Jisi Liu) 37 | */ 38 | public abstract class Extension 39 | extends ExtensionLite { 40 | 41 | /** Returns the descriptor of the extension. */ 42 | public abstract Descriptors.FieldDescriptor getDescriptor(); 43 | 44 | /** Returns whether or not this extension is a Lite Extension. */ 45 | final boolean isLite() { 46 | return false; 47 | } 48 | 49 | // All the methods below are extension implementation details. 50 | 51 | /** 52 | * The API type that the extension is used for. 53 | */ 54 | protected enum ExtensionType { 55 | IMMUTABLE, 56 | MUTABLE, 57 | PROTO1, 58 | } 59 | 60 | protected ExtensionType getExtensionType() { 61 | // TODO(liujisi): make this abstract after we fix proto1. 62 | return ExtensionType.IMMUTABLE; 63 | } 64 | 65 | /** 66 | * Type of a message extension. 67 | */ 68 | public enum MessageType { 69 | PROTO1, 70 | PROTO2, 71 | } 72 | 73 | /** 74 | * If the extension is a message extension (i.e., getLiteType() == MESSAGE), 75 | * returns the type of the message, otherwise undefined. 76 | */ 77 | public MessageType getMessageType() { 78 | return MessageType.PROTO2; 79 | } 80 | 81 | protected abstract Object fromReflectionType(Object value); 82 | protected abstract Object singularFromReflectionType(Object value); 83 | protected abstract Object toReflectionType(Object value); 84 | protected abstract Object singularToReflectionType(Object value); 85 | } 86 | -------------------------------------------------------------------------------- /protobuf-java/src/com/google/protobuf/ExtensionLite.java: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | package com.google.protobuf; 32 | 33 | /** 34 | * Lite interface that generated extensions implement. 35 | *

36 | * Methods are for use by generated code only. You can hold a reference to 37 | * extensions using this type name. 38 | */ 39 | public abstract class ExtensionLite { 40 | 41 | /** Returns the field number of the extension. */ 42 | public abstract int getNumber(); 43 | 44 | /** Returns the type of the field. */ 45 | public abstract WireFormat.FieldType getLiteType(); 46 | 47 | /** Returns whether it is a repeated field. */ 48 | public abstract boolean isRepeated(); 49 | 50 | /** Returns the default value of the extension field. */ 51 | public abstract Type getDefaultValue(); 52 | 53 | /** 54 | * Returns the default instance of the extension field, if it's a message 55 | * extension. 56 | */ 57 | public abstract MessageLite getMessageDefaultInstance(); 58 | 59 | /** Returns whether or not this extension is a Lite Extension. */ 60 | boolean isLite() { 61 | return true; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /protobuf-java/src/com/google/protobuf/InvalidProtocolBufferException.java: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | package com.google.protobuf; 32 | 33 | import java.io.IOException; 34 | 35 | /** 36 | * Thrown when a protocol message being parsed is invalid in some way, 37 | * e.g. it contains a malformed varint or a negative byte length. 38 | * 39 | * @author kenton@google.com Kenton Varda 40 | */ 41 | public class InvalidProtocolBufferException extends IOException { 42 | private static final long serialVersionUID = -1616151763072450476L; 43 | private MessageLite unfinishedMessage = null; 44 | 45 | public InvalidProtocolBufferException(final String description) { 46 | super(description); 47 | } 48 | 49 | public InvalidProtocolBufferException(IOException e) { 50 | super(e.getMessage(), e); 51 | } 52 | 53 | /** 54 | * Attaches an unfinished message to the exception to support best-effort 55 | * parsing in {@code Parser} interface. 56 | * 57 | * @return this 58 | */ 59 | public InvalidProtocolBufferException setUnfinishedMessage( 60 | MessageLite unfinishedMessage) { 61 | this.unfinishedMessage = unfinishedMessage; 62 | return this; 63 | } 64 | 65 | /** 66 | * Returns the unfinished message attached to the exception, or null if 67 | * no message is attached. 68 | */ 69 | public MessageLite getUnfinishedMessage() { 70 | return unfinishedMessage; 71 | } 72 | 73 | /** 74 | * Unwraps the underlying {@link IOException} if this exception was caused by an I/O 75 | * problem. Otherwise, returns {@code this}. 76 | */ 77 | public IOException unwrapIOException() { 78 | return getCause() instanceof IOException ? (IOException) getCause() : this; 79 | } 80 | 81 | static InvalidProtocolBufferException truncatedMessage() { 82 | return new InvalidProtocolBufferException( 83 | "While parsing a protocol message, the input ended unexpectedly " + 84 | "in the middle of a field. This could mean either that the " + 85 | "input has been truncated or that an embedded message " + 86 | "misreported its own length."); 87 | } 88 | 89 | static InvalidProtocolBufferException negativeSize() { 90 | return new InvalidProtocolBufferException( 91 | "CodedInputStream encountered an embedded string or message " + 92 | "which claimed to have negative size."); 93 | } 94 | 95 | static InvalidProtocolBufferException malformedVarint() { 96 | return new InvalidProtocolBufferException( 97 | "CodedInputStream encountered a malformed varint."); 98 | } 99 | 100 | static InvalidProtocolBufferException invalidTag() { 101 | return new InvalidProtocolBufferException( 102 | "Protocol message contained an invalid tag (zero)."); 103 | } 104 | 105 | static InvalidProtocolBufferException invalidEndTag() { 106 | return new InvalidProtocolBufferException( 107 | "Protocol message end-group tag did not match expected tag."); 108 | } 109 | 110 | static InvalidProtocolBufferException invalidWireType() { 111 | return new InvalidProtocolBufferException( 112 | "Protocol message tag had invalid wire type."); 113 | } 114 | 115 | static InvalidProtocolBufferException recursionLimitExceeded() { 116 | return new InvalidProtocolBufferException( 117 | "Protocol message had too many levels of nesting. May be malicious. " + 118 | "Use CodedInputStream.setRecursionLimit() to increase the depth limit."); 119 | } 120 | 121 | static InvalidProtocolBufferException sizeLimitExceeded() { 122 | return new InvalidProtocolBufferException( 123 | "Protocol message was too large. May be malicious. " + 124 | "Use CodedInputStream.setSizeLimit() to increase the size limit."); 125 | } 126 | 127 | static InvalidProtocolBufferException parseFailure() { 128 | return new InvalidProtocolBufferException("Failed to parse the message."); 129 | } 130 | 131 | static InvalidProtocolBufferException invalidUtf8() { 132 | return new InvalidProtocolBufferException("Protocol message had invalid UTF-8."); 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /protobuf-java/src/com/google/protobuf/LazyField.java: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | package com.google.protobuf; 32 | 33 | import java.util.Iterator; 34 | import java.util.Map.Entry; 35 | 36 | /** 37 | * LazyField encapsulates the logic of lazily parsing message fields. It stores 38 | * the message in a ByteString initially and then parse it on-demand. 39 | * 40 | * Most of key methods are implemented in {@link LazyFieldLite} but this class 41 | * can contain default instance of the message to provide {@code hashCode()}, 42 | * {@code euqals()} and {@code toString()}. 43 | * 44 | * @author xiangl@google.com (Xiang Li) 45 | */ 46 | public class LazyField extends LazyFieldLite { 47 | 48 | /** 49 | * Carry a message's default instance which is used by {@code hashCode()}, {@code euqals()} and 50 | * {@code toString()}. 51 | */ 52 | private final MessageLite defaultInstance; 53 | 54 | public LazyField(MessageLite defaultInstance, 55 | ExtensionRegistryLite extensionRegistry, ByteString bytes) { 56 | super(extensionRegistry, bytes); 57 | 58 | this.defaultInstance = defaultInstance; 59 | } 60 | 61 | @Override 62 | public boolean containsDefaultInstance() { 63 | return super.containsDefaultInstance() || value == defaultInstance; 64 | } 65 | 66 | public MessageLite getValue() { 67 | return getValue(defaultInstance); 68 | } 69 | 70 | @Override 71 | public int hashCode() { 72 | return getValue().hashCode(); 73 | } 74 | 75 | @Override 76 | public boolean equals(Object obj) { 77 | return getValue().equals(obj); 78 | } 79 | 80 | @Override 81 | public String toString() { 82 | return getValue().toString(); 83 | } 84 | 85 | // ==================================================== 86 | 87 | /** 88 | * LazyEntry and LazyIterator are used to encapsulate the LazyField, when 89 | * users iterate all fields from FieldSet. 90 | */ 91 | static class LazyEntry implements Entry { 92 | private Entry entry; 93 | 94 | private LazyEntry(Entry entry) { 95 | this.entry = entry; 96 | } 97 | 98 | // @Override 99 | public K getKey() { 100 | return entry.getKey(); 101 | } 102 | 103 | // @Override 104 | public Object getValue() { 105 | LazyField field = entry.getValue(); 106 | if (field == null) { 107 | return null; 108 | } 109 | return field.getValue(); 110 | } 111 | 112 | public LazyField getField() { 113 | return entry.getValue(); 114 | } 115 | 116 | // @Override 117 | public Object setValue(Object value) { 118 | if (!(value instanceof MessageLite)) { 119 | throw new IllegalArgumentException( 120 | "LazyField now only used for MessageSet, " 121 | + "and the value of MessageSet must be an instance of MessageLite"); 122 | } 123 | return entry.getValue().setValue((MessageLite) value); 124 | } 125 | } 126 | 127 | static class LazyIterator implements Iterator> { 128 | private Iterator> iterator; 129 | 130 | public LazyIterator(Iterator> iterator) { 131 | this.iterator = iterator; 132 | } 133 | 134 | // @Override 135 | public boolean hasNext() { 136 | return iterator.hasNext(); 137 | } 138 | 139 | @SuppressWarnings("unchecked") 140 | // @Override 141 | public Entry next() { 142 | Entry entry = iterator.next(); 143 | if (entry.getValue() instanceof LazyField) { 144 | return new LazyEntry((Entry) entry); 145 | } 146 | return (Entry) entry; 147 | } 148 | 149 | // @Override 150 | public void remove() { 151 | iterator.remove(); 152 | } 153 | } 154 | } 155 | -------------------------------------------------------------------------------- /protobuf-java/src/com/google/protobuf/LazyStringList.java: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | package com.google.protobuf; 32 | 33 | import java.util.Collection; 34 | import java.util.List; 35 | 36 | /** 37 | * An interface extending {@code List} that also provides access to the 38 | * items of the list as UTF8-encoded ByteString or byte[] objects. This is 39 | * used by the protocol buffer implementation to support lazily converting bytes 40 | * parsed over the wire to String objects until needed and also increases the 41 | * efficiency of serialization if the String was never requested as the 42 | * ByteString or byte[] is already cached. The ByteString methods are used in 43 | * immutable API only and byte[] methods used in mutable API only for they use 44 | * different representations for string/bytes fields. 45 | * 46 | * @author jonp@google.com (Jon Perlow) 47 | */ 48 | public interface LazyStringList extends ProtocolStringList { 49 | 50 | /** 51 | * Returns the element at the specified position in this list as a ByteString. 52 | * 53 | * @param index index of the element to return 54 | * @return the element at the specified position in this list 55 | * @throws IndexOutOfBoundsException if the index is out of range 56 | * ({@code index < 0 || index >= size()}) 57 | */ 58 | ByteString getByteString(int index); 59 | 60 | /** 61 | * Returns the element at the specified position in this list as an Object 62 | * that will either be a String or a ByteString. 63 | * 64 | * @param index index of the element to return 65 | * @return the element at the specified position in this list 66 | * @throws IndexOutOfBoundsException if the index is out of range 67 | * ({@code index < 0 || index >= size()}) 68 | */ 69 | Object getRaw(int index); 70 | 71 | /** 72 | * Returns the element at the specified position in this list as byte[]. 73 | * 74 | * @param index index of the element to return 75 | * @return the element at the specified position in this list 76 | * @throws IndexOutOfBoundsException if the index is out of range 77 | * ({@code index < 0 || index >= size()}) 78 | */ 79 | byte[] getByteArray(int index); 80 | 81 | /** 82 | * Appends the specified element to the end of this list (optional 83 | * operation). 84 | * 85 | * @param element element to be appended to this list 86 | * @throws UnsupportedOperationException if the add operation 87 | * is not supported by this list 88 | */ 89 | void add(ByteString element); 90 | 91 | /** 92 | * Appends the specified element to the end of this list (optional 93 | * operation). 94 | * 95 | * @param element element to be appended to this list 96 | * @throws UnsupportedOperationException if the add operation 97 | * is not supported by this list 98 | */ 99 | void add(byte[] element); 100 | 101 | /** 102 | * Replaces the element at the specified position in this list with the 103 | * specified element (optional operation). 104 | * 105 | * @param index index of the element to replace 106 | * @param element the element to be stored at the specified position 107 | * @throws UnsupportedOperationException if the set operation 108 | * is not supported by this list 109 | * IndexOutOfBoundsException if the index is out of range 110 | * ({@code index < 0 || index >= size()}) 111 | */ 112 | void set(int index, ByteString element); 113 | 114 | /** 115 | * Replaces the element at the specified position in this list with the 116 | * specified element (optional operation). 117 | * 118 | * @param index index of the element to replace 119 | * @param element the element to be stored at the specified position 120 | * @throws UnsupportedOperationException if the set operation 121 | * is not supported by this list 122 | * IndexOutOfBoundsException if the index is out of range 123 | * ({@code index < 0 || index >= size()}) 124 | */ 125 | void set(int index, byte[] element); 126 | 127 | /** 128 | * Appends all elements in the specified ByteString collection to the end of 129 | * this list. 130 | * 131 | * @param c collection whose elements are to be added to this list 132 | * @return true if this list changed as a result of the call 133 | * @throws UnsupportedOperationException if the addAllByteString 134 | * operation is not supported by this list 135 | */ 136 | boolean addAllByteString(Collection c); 137 | 138 | /** 139 | * Appends all elements in the specified byte[] collection to the end of 140 | * this list. 141 | * 142 | * @param c collection whose elements are to be added to this list 143 | * @return true if this list changed as a result of the call 144 | * @throws UnsupportedOperationException if the addAllByteArray 145 | * operation is not supported by this list 146 | */ 147 | boolean addAllByteArray(Collection c); 148 | 149 | /** 150 | * Returns an unmodifiable List of the underlying elements, each of which is 151 | * either a {@code String} or its equivalent UTF-8 encoded {@code ByteString} 152 | * or byte[]. It is an error for the caller to modify the returned 153 | * List, and attempting to do so will result in an 154 | * {@link UnsupportedOperationException}. 155 | */ 156 | List getUnderlyingElements(); 157 | 158 | /** 159 | * Merges all elements from another LazyStringList into this one. This method 160 | * differs from {@link #addAll(Collection)} on that underlying byte arrays are 161 | * copied instead of reference shared. Immutable API doesn't need to use this 162 | * method as byte[] is not used there at all. 163 | */ 164 | void mergeFrom(LazyStringList other); 165 | 166 | /** 167 | * Returns a mutable view of this list. Changes to the view will be made into 168 | * the original list. This method is used in mutable API only. 169 | */ 170 | List asByteArrayList(); 171 | 172 | /** Returns an unmodifiable view of the list. */ 173 | LazyStringList getUnmodifiableView(); 174 | } 175 | -------------------------------------------------------------------------------- /protobuf-java/src/com/google/protobuf/MessageLiteOrBuilder.java: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | package com.google.protobuf; 32 | 33 | /** 34 | * Base interface for methods common to {@link MessageLite} 35 | * and {@link MessageLite.Builder} to provide type equivalency. 36 | * 37 | * @author jonp@google.com (Jon Perlow) 38 | */ 39 | public interface MessageLiteOrBuilder { 40 | /** 41 | * Get an instance of the type with no fields set. Because no fields are set, 42 | * all getters for singular fields will return default values and repeated 43 | * fields will appear empty. 44 | * This may or may not be a singleton. This differs from the 45 | * {@code getDefaultInstance()} method of generated message classes in that 46 | * this method is an abstract method of the {@code MessageLite} interface 47 | * whereas {@code getDefaultInstance()} is a static method of a specific 48 | * class. They return the same thing. 49 | */ 50 | MessageLite getDefaultInstanceForType(); 51 | 52 | /** 53 | * Returns true if all required fields in the message and all embedded 54 | * messages are set, false otherwise. 55 | * 56 | *

See also: {@link MessageOrBuilder#getInitializationErrorString()} 57 | */ 58 | boolean isInitialized(); 59 | 60 | } 61 | -------------------------------------------------------------------------------- /protobuf-java/src/com/google/protobuf/MessageOrBuilder.java: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | package com.google.protobuf; 32 | 33 | import java.util.List; 34 | import java.util.Map; 35 | 36 | /** 37 | * Base interface for methods common to {@link Message} and 38 | * {@link Message.Builder} to provide type equivalency. 39 | * 40 | * @author jonp@google.com (Jon Perlow) 41 | */ 42 | public interface MessageOrBuilder extends MessageLiteOrBuilder { 43 | 44 | // (From MessageLite, re-declared here only for return type covariance.) 45 | //@Override (Java 1.6 override semantics, but we must support 1.5) 46 | Message getDefaultInstanceForType(); 47 | 48 | /** 49 | * Returns a list of field paths (e.g. "foo.bar.baz") of required fields 50 | * which are not set in this message. You should call 51 | * {@link MessageLiteOrBuilder#isInitialized()} first to check if there 52 | * are any missing fields, as that method is likely to be much faster 53 | * than this one even when the message is fully-initialized. 54 | */ 55 | List findInitializationErrors(); 56 | 57 | /** 58 | * Returns a comma-delimited list of required fields which are not set 59 | * in this message object. You should call 60 | * {@link MessageLiteOrBuilder#isInitialized()} first to check if there 61 | * are any missing fields, as that method is likely to be much faster 62 | * than this one even when the message is fully-initialized. 63 | */ 64 | String getInitializationErrorString(); 65 | 66 | /** 67 | * Get the message's type's descriptor. This differs from the 68 | * {@code getDescriptor()} method of generated message classes in that 69 | * this method is an abstract method of the {@code Message} interface 70 | * whereas {@code getDescriptor()} is a static method of a specific class. 71 | * They return the same thing. 72 | */ 73 | Descriptors.Descriptor getDescriptorForType(); 74 | 75 | /** 76 | * Returns a collection of all the fields in this message which are set 77 | * and their corresponding values. A singular ("required" or "optional") 78 | * field is set iff hasField() returns true for that field. A "repeated" 79 | * field is set iff getRepeatedFieldCount() is greater than zero. The 80 | * values are exactly what would be returned by calling 81 | * {@link #getField(Descriptors.FieldDescriptor)} for each field. The map 82 | * is guaranteed to be a sorted map, so iterating over it will return fields 83 | * in order by field number. 84 | *
85 | * If this is for a builder, the returned map may or may not reflect future 86 | * changes to the builder. Either way, the returned map is itself 87 | * unmodifiable. 88 | */ 89 | Map getAllFields(); 90 | 91 | /** 92 | * Returns true if the given oneof is set. 93 | * @throws IllegalArgumentException if 94 | * {@code oneof.getContainingType() != getDescriptorForType()}. 95 | */ 96 | boolean hasOneof(Descriptors.OneofDescriptor oneof); 97 | 98 | /** 99 | * Obtains the FieldDescriptor if the given oneof is set. Returns null 100 | * if no field is set. 101 | */ 102 | Descriptors.FieldDescriptor getOneofFieldDescriptor( 103 | Descriptors.OneofDescriptor oneof); 104 | 105 | /** 106 | * Returns true if the given field is set. This is exactly equivalent to 107 | * calling the generated "has" accessor method corresponding to the field. 108 | * @throws IllegalArgumentException The field is a repeated field, or 109 | * {@code field.getContainingType() != getDescriptorForType()}. 110 | */ 111 | boolean hasField(Descriptors.FieldDescriptor field); 112 | 113 | /** 114 | * Obtains the value of the given field, or the default value if it is 115 | * not set. For primitive fields, the boxed primitive value is returned. 116 | * For enum fields, the EnumValueDescriptor for the value is returned. For 117 | * embedded message fields, the sub-message is returned. For repeated 118 | * fields, a java.util.List is returned. 119 | */ 120 | Object getField(Descriptors.FieldDescriptor field); 121 | 122 | /** 123 | * Gets the number of elements of a repeated field. This is exactly 124 | * equivalent to calling the generated "Count" accessor method corresponding 125 | * to the field. 126 | * @throws IllegalArgumentException The field is not a repeated field, or 127 | * {@code field.getContainingType() != getDescriptorForType()}. 128 | */ 129 | int getRepeatedFieldCount(Descriptors.FieldDescriptor field); 130 | 131 | /** 132 | * Gets an element of a repeated field. For primitive fields, the boxed 133 | * primitive value is returned. For enum fields, the EnumValueDescriptor 134 | * for the value is returned. For embedded message fields, the sub-message 135 | * is returned. 136 | * @throws IllegalArgumentException The field is not a repeated field, or 137 | * {@code field.getContainingType() != getDescriptorForType()}. 138 | */ 139 | Object getRepeatedField(Descriptors.FieldDescriptor field, int index); 140 | 141 | /** Get the {@link UnknownFieldSet} for this message. */ 142 | UnknownFieldSet getUnknownFields(); 143 | } 144 | -------------------------------------------------------------------------------- /protobuf-java/src/com/google/protobuf/MutabilityOracle.java: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | package com.google.protobuf; 32 | 33 | /** 34 | * Verifies that an object is mutable, throwing if not. 35 | */ 36 | interface MutabilityOracle { 37 | static final MutabilityOracle IMMUTABLE = new MutabilityOracle() { 38 | @Override 39 | public void ensureMutable() { 40 | throw new UnsupportedOperationException(); 41 | } 42 | }; 43 | 44 | /** 45 | * Throws an {@link UnsupportedOperationException} if not mutable. 46 | */ 47 | void ensureMutable(); 48 | } 49 | -------------------------------------------------------------------------------- /protobuf-java/src/com/google/protobuf/ProtobufArrayList.java: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | package com.google.protobuf; 32 | 33 | import com.google.protobuf.Internal.ProtobufList; 34 | 35 | import java.util.ArrayList; 36 | import java.util.List; 37 | 38 | /** 39 | * Implements {@link ProtobufList} for non-primitive and {@link String} types. 40 | */ 41 | class ProtobufArrayList extends AbstractProtobufList { 42 | 43 | private static final ProtobufArrayList EMPTY_LIST = new ProtobufArrayList(); 44 | static { 45 | EMPTY_LIST.makeImmutable(); 46 | } 47 | 48 | @SuppressWarnings("unchecked") // Guaranteed safe by runtime. 49 | public static ProtobufArrayList emptyList() { 50 | return (ProtobufArrayList) EMPTY_LIST; 51 | } 52 | 53 | private final List list; 54 | 55 | ProtobufArrayList() { 56 | list = new ArrayList(); 57 | } 58 | 59 | ProtobufArrayList(List toCopy) { 60 | list = new ArrayList(toCopy); 61 | } 62 | 63 | ProtobufArrayList(int capacity) { 64 | list = new ArrayList(capacity); 65 | } 66 | 67 | @Override 68 | public void add(int index, E element) { 69 | ensureIsMutable(); 70 | list.add(index, element); 71 | modCount++; 72 | } 73 | 74 | @Override 75 | public E get(int index) { 76 | return list.get(index); 77 | } 78 | 79 | @Override 80 | public E remove(int index) { 81 | ensureIsMutable(); 82 | E toReturn = list.remove(index); 83 | modCount++; 84 | return toReturn; 85 | } 86 | 87 | @Override 88 | public E set(int index, E element) { 89 | ensureIsMutable(); 90 | E toReturn = list.set(index, element); 91 | modCount++; 92 | return toReturn; 93 | } 94 | 95 | @Override 96 | public int size() { 97 | return list.size(); 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /protobuf-java/src/com/google/protobuf/ProtocolMessageEnum.java: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | package com.google.protobuf; 32 | 33 | import com.google.protobuf.Descriptors.EnumDescriptor; 34 | import com.google.protobuf.Descriptors.EnumValueDescriptor; 35 | 36 | /** 37 | * Interface of useful methods added to all enums generated by the protocol 38 | * compiler. 39 | */ 40 | public interface ProtocolMessageEnum extends Internal.EnumLite { 41 | 42 | /** 43 | * Return the value's numeric value as defined in the .proto file. 44 | */ 45 | int getNumber(); 46 | 47 | /** 48 | * Return the value's descriptor, which contains information such as 49 | * value name, number, and type. 50 | */ 51 | EnumValueDescriptor getValueDescriptor(); 52 | 53 | /** 54 | * Return the enum type's descriptor, which contains information 55 | * about each defined value, etc. 56 | */ 57 | EnumDescriptor getDescriptorForType(); 58 | } 59 | -------------------------------------------------------------------------------- /protobuf-java/src/com/google/protobuf/ProtocolStringList.java: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | package com.google.protobuf; 32 | 33 | import java.util.List; 34 | 35 | /** 36 | * An interface extending {@code List} used for repeated string fields 37 | * to provide optional access to the data as a list of ByteStrings. The 38 | * underlying implementation stores values as either ByteStrings or Strings 39 | * (see {@link LazyStringArrayList}) depending on how the value was initialized 40 | * or last read, and it is often more efficient to deal with lists of 41 | * ByteStrings when handling protos that have been deserialized from bytes. 42 | */ 43 | public interface ProtocolStringList extends List { 44 | 45 | /** Returns a view of the data as a list of ByteStrings. */ 46 | List asByteStringList(); 47 | 48 | } 49 | -------------------------------------------------------------------------------- /protobuf-java/src/com/google/protobuf/RpcCallback.java: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | package com.google.protobuf; 32 | 33 | /** 34 | * Interface for an RPC callback, normally called when an RPC completes. 35 | * {@code ParameterType} is normally the method's response message type. 36 | * 37 | *

Starting with version 2.3.0, RPC implementations should not try to build 38 | * on this, but should instead provide code generator plugins which generate 39 | * code specific to the particular RPC implementation. This way the generated 40 | * code can be more appropriate for the implementation in use and can avoid 41 | * unnecessary layers of indirection. 42 | * 43 | * @author kenton@google.com Kenton Varda 44 | */ 45 | public interface RpcCallback { 46 | void run(ParameterType parameter); 47 | } 48 | -------------------------------------------------------------------------------- /protobuf-java/src/com/google/protobuf/RpcChannel.java: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | package com.google.protobuf; 32 | 33 | /** 34 | *

Abstract interface for an RPC channel. An {@code RpcChannel} represents a 35 | * communication line to a {@link Service} which can be used to call that 36 | * {@link Service}'s methods. The {@link Service} may be running on another 37 | * machine. Normally, you should not call an {@code RpcChannel} directly, but 38 | * instead construct a stub {@link Service} wrapping it. Example: 39 | * 40 | *

41 |  *   RpcChannel channel = rpcImpl.newChannel("remotehost.example.com:1234");
42 |  *   RpcController controller = rpcImpl.newController();
43 |  *   MyService service = MyService.newStub(channel);
44 |  *   service.myMethod(controller, request, callback);
45 |  * 
46 | * 47 | *

Starting with version 2.3.0, RPC implementations should not try to build 48 | * on this, but should instead provide code generator plugins which generate 49 | * code specific to the particular RPC implementation. This way the generated 50 | * code can be more appropriate for the implementation in use and can avoid 51 | * unnecessary layers of indirection. 52 | * 53 | * @author kenton@google.com Kenton Varda 54 | */ 55 | public interface RpcChannel { 56 | /** 57 | * Call the given method of the remote service. This method is similar to 58 | * {@code Service.callMethod()} with one important difference: the caller 59 | * decides the types of the {@code Message} objects, not the callee. The 60 | * request may be of any type as long as 61 | * {@code request.getDescriptor() == method.getInputType()}. 62 | * The response passed to the callback will be of the same type as 63 | * {@code responsePrototype} (which must have 64 | * {@code getDescriptor() == method.getOutputType()}). 65 | */ 66 | void callMethod(Descriptors.MethodDescriptor method, 67 | RpcController controller, 68 | Message request, 69 | Message responsePrototype, 70 | RpcCallback done); 71 | } 72 | -------------------------------------------------------------------------------- /protobuf-java/src/com/google/protobuf/RpcController.java: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | package com.google.protobuf; 32 | 33 | /** 34 | *

An {@code RpcController} mediates a single method call. The primary 35 | * purpose of the controller is to provide a way to manipulate settings 36 | * specific to the RPC implementation and to find out about RPC-level errors. 37 | * 38 | *

Starting with version 2.3.0, RPC implementations should not try to build 39 | * on this, but should instead provide code generator plugins which generate 40 | * code specific to the particular RPC implementation. This way the generated 41 | * code can be more appropriate for the implementation in use and can avoid 42 | * unnecessary layers of indirection. 43 | * 44 | *

The methods provided by the {@code RpcController} interface are intended 45 | * to be a "least common denominator" set of features which we expect all 46 | * implementations to support. Specific implementations may provide more 47 | * advanced features (e.g. deadline propagation). 48 | * 49 | * @author kenton@google.com Kenton Varda 50 | */ 51 | public interface RpcController { 52 | // ----------------------------------------------------------------- 53 | // These calls may be made from the client side only. Their results 54 | // are undefined on the server side (may throw RuntimeExceptions). 55 | 56 | /** 57 | * Resets the RpcController to its initial state so that it may be reused in 58 | * a new call. This can be called from the client side only. It must not 59 | * be called while an RPC is in progress. 60 | */ 61 | void reset(); 62 | 63 | /** 64 | * After a call has finished, returns true if the call failed. The possible 65 | * reasons for failure depend on the RPC implementation. {@code failed()} 66 | * most only be called on the client side, and must not be called before a 67 | * call has finished. 68 | */ 69 | boolean failed(); 70 | 71 | /** 72 | * If {@code failed()} is {@code true}, returns a human-readable description 73 | * of the error. 74 | */ 75 | String errorText(); 76 | 77 | /** 78 | * Advises the RPC system that the caller desires that the RPC call be 79 | * canceled. The RPC system may cancel it immediately, may wait awhile and 80 | * then cancel it, or may not even cancel the call at all. If the call is 81 | * canceled, the "done" callback will still be called and the RpcController 82 | * will indicate that the call failed at that time. 83 | */ 84 | void startCancel(); 85 | 86 | // ----------------------------------------------------------------- 87 | // These calls may be made from the server side only. Their results 88 | // are undefined on the client side (may throw RuntimeExceptions). 89 | 90 | /** 91 | * Causes {@code failed()} to return true on the client side. {@code reason} 92 | * will be incorporated into the message returned by {@code errorText()}. 93 | * If you find you need to return machine-readable information about 94 | * failures, you should incorporate it into your response protocol buffer 95 | * and should NOT call {@code setFailed()}. 96 | */ 97 | void setFailed(String reason); 98 | 99 | /** 100 | * If {@code true}, indicates that the client canceled the RPC, so the server 101 | * may as well give up on replying to it. This method must be called on the 102 | * server side only. The server should still call the final "done" callback. 103 | */ 104 | boolean isCanceled(); 105 | 106 | /** 107 | * Asks that the given callback be called when the RPC is canceled. The 108 | * parameter passed to the callback will always be {@code null}. The 109 | * callback will always be called exactly once. If the RPC completes without 110 | * being canceled, the callback will be called after completion. If the RPC 111 | * has already been canceled when NotifyOnCancel() is called, the callback 112 | * will be called immediately. 113 | * 114 | *

{@code notifyOnCancel()} must be called no more than once per request. 115 | * It must be called on the server side only. 116 | */ 117 | void notifyOnCancel(RpcCallback callback); 118 | } 119 | -------------------------------------------------------------------------------- /protobuf-java/src/com/google/protobuf/RpcUtil.java: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | package com.google.protobuf; 32 | 33 | /** 34 | * Grab-bag of utility functions useful when dealing with RPCs. 35 | * 36 | * @author kenton@google.com Kenton Varda 37 | */ 38 | public final class RpcUtil { 39 | private RpcUtil() {} 40 | 41 | /** 42 | * Take an {@code RpcCallback} and convert it to an 43 | * {@code RpcCallback} accepting a specific message type. This is always 44 | * type-safe (parameter type contravariance). 45 | */ 46 | @SuppressWarnings("unchecked") 47 | public static RpcCallback 48 | specializeCallback(final RpcCallback originalCallback) { 49 | return (RpcCallback)originalCallback; 50 | // The above cast works, but only due to technical details of the Java 51 | // implementation. A more theoretically correct -- but less efficient -- 52 | // implementation would be as follows: 53 | // return new RpcCallback() { 54 | // public void run(Type parameter) { 55 | // originalCallback.run(parameter); 56 | // } 57 | // }; 58 | } 59 | 60 | /** 61 | * Take an {@code RpcCallback} accepting a specific message type and convert 62 | * it to an {@code RpcCallback}. The generalized callback will 63 | * accept any message object which has the same descriptor, and will convert 64 | * it to the correct class before calling the original callback. However, 65 | * if the generalized callback is given a message with a different descriptor, 66 | * an exception will be thrown. 67 | */ 68 | public static 69 | RpcCallback generalizeCallback( 70 | final RpcCallback originalCallback, 71 | final Class originalClass, 72 | final Type defaultInstance) { 73 | return new RpcCallback() { 74 | public void run(final Message parameter) { 75 | Type typedParameter; 76 | try { 77 | typedParameter = originalClass.cast(parameter); 78 | } catch (ClassCastException ignored) { 79 | typedParameter = copyAsType(defaultInstance, parameter); 80 | } 81 | originalCallback.run(typedParameter); 82 | } 83 | }; 84 | } 85 | 86 | /** 87 | * Creates a new message of type "Type" which is a copy of "source". "source" 88 | * must have the same descriptor but may be a different class (e.g. 89 | * DynamicMessage). 90 | */ 91 | @SuppressWarnings("unchecked") 92 | private static Type copyAsType( 93 | final Type typeDefaultInstance, final Message source) { 94 | return (Type) typeDefaultInstance 95 | .newBuilderForType().mergeFrom(source).build(); 96 | } 97 | 98 | /** 99 | * Creates a callback which can only be called once. This may be useful for 100 | * security, when passing a callback to untrusted code: most callbacks do 101 | * not expect to be called more than once, so doing so may expose bugs if it 102 | * is not prevented. 103 | */ 104 | public static 105 | RpcCallback newOneTimeCallback( 106 | final RpcCallback originalCallback) { 107 | return new RpcCallback() { 108 | private boolean alreadyCalled = false; 109 | 110 | public void run(final ParameterType parameter) { 111 | synchronized(this) { 112 | if (alreadyCalled) { 113 | throw new AlreadyCalledException(); 114 | } 115 | alreadyCalled = true; 116 | } 117 | 118 | originalCallback.run(parameter); 119 | } 120 | }; 121 | } 122 | 123 | /** 124 | * Exception thrown when a one-time callback is called more than once. 125 | */ 126 | public static final class AlreadyCalledException extends RuntimeException { 127 | private static final long serialVersionUID = 5469741279507848266L; 128 | 129 | public AlreadyCalledException() { 130 | super("This RpcCallback was already called and cannot be called " + 131 | "multiple times."); 132 | } 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /protobuf-java/src/com/google/protobuf/Service.java: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | package com.google.protobuf; 32 | 33 | /** 34 | * Abstract base interface for protocol-buffer-based RPC services. Services 35 | * themselves are abstract classes (implemented either by servers or as 36 | * stubs), but they subclass this base interface. The methods of this 37 | * interface can be used to call the methods of the service without knowing 38 | * its exact type at compile time (analogous to the Message interface). 39 | * 40 | *

Starting with version 2.3.0, RPC implementations should not try to build 41 | * on this, but should instead provide code generator plugins which generate 42 | * code specific to the particular RPC implementation. This way the generated 43 | * code can be more appropriate for the implementation in use and can avoid 44 | * unnecessary layers of indirection. 45 | * 46 | * @author kenton@google.com Kenton Varda 47 | */ 48 | public interface Service { 49 | /** 50 | * Get the {@code ServiceDescriptor} describing this service and its methods. 51 | */ 52 | Descriptors.ServiceDescriptor getDescriptorForType(); 53 | 54 | /** 55 | *

Call a method of the service specified by MethodDescriptor. This is 56 | * normally implemented as a simple {@code switch()} that calls the standard 57 | * definitions of the service's methods. 58 | * 59 | *

Preconditions: 60 | *

    61 | *
  • {@code method.getService() == getDescriptorForType()} 62 | *
  • {@code request} is of the exact same class as the object returned by 63 | * {@code getRequestPrototype(method)}. 64 | *
  • {@code controller} is of the correct type for the RPC implementation 65 | * being used by this Service. For stubs, the "correct type" depends 66 | * on the RpcChannel which the stub is using. Server-side Service 67 | * implementations are expected to accept whatever type of 68 | * {@code RpcController} the server-side RPC implementation uses. 69 | *
70 | * 71 | *

Postconditions: 72 | *

    73 | *
  • {@code done} will be called when the method is complete. This may be 74 | * before {@code callMethod()} returns or it may be at some point in 75 | * the future. 76 | *
  • The parameter to {@code done} is the response. It must be of the 77 | * exact same type as would be returned by 78 | * {@code getResponsePrototype(method)}. 79 | *
  • If the RPC failed, the parameter to {@code done} will be 80 | * {@code null}. Further details about the failure can be found by 81 | * querying {@code controller}. 82 | *
83 | */ 84 | void callMethod(Descriptors.MethodDescriptor method, 85 | RpcController controller, 86 | Message request, 87 | RpcCallback done); 88 | 89 | /** 90 | *

{@code callMethod()} requires that the request passed in is of a 91 | * particular subclass of {@code Message}. {@code getRequestPrototype()} 92 | * gets the default instances of this type for a given method. You can then 93 | * call {@code Message.newBuilderForType()} on this instance to 94 | * construct a builder to build an object which you can then pass to 95 | * {@code callMethod()}. 96 | * 97 | *

Example: 98 | *

 99 |    *   MethodDescriptor method =
100 |    *     service.getDescriptorForType().findMethodByName("Foo");
101 |    *   Message request =
102 |    *     stub.getRequestPrototype(method).newBuilderForType()
103 |    *         .mergeFrom(input).build();
104 |    *   service.callMethod(method, request, callback);
105 |    * 
106 | */ 107 | Message getRequestPrototype(Descriptors.MethodDescriptor method); 108 | 109 | /** 110 | * Like {@code getRequestPrototype()}, but gets a prototype of the response 111 | * message. {@code getResponsePrototype()} is generally not needed because 112 | * the {@code Service} implementation constructs the response message itself, 113 | * but it may be useful in some cases to know ahead of time what type of 114 | * object will be returned. 115 | */ 116 | Message getResponsePrototype(Descriptors.MethodDescriptor method); 117 | } 118 | -------------------------------------------------------------------------------- /protobuf-java/src/com/google/protobuf/ServiceException.java: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | package com.google.protobuf; 32 | 33 | /** 34 | * Thrown by blocking RPC methods when a failure occurs. 35 | * 36 | * @author cpovirk@google.com (Chris Povirk) 37 | */ 38 | public class ServiceException extends Exception { 39 | private static final long serialVersionUID = -1219262335729891920L; 40 | 41 | public ServiceException(final String message) { 42 | super(message); 43 | } 44 | 45 | public ServiceException(final Throwable cause) { 46 | super(cause); 47 | } 48 | 49 | public ServiceException(final String message, final Throwable cause) { 50 | super(message, cause); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /protobuf-java/src/com/google/protobuf/TextFormatEscaper.java: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | package com.google.protobuf; 32 | 33 | /** 34 | * Provide text format escaping support for proto2 instances. 35 | */ 36 | final class TextFormatEscaper { 37 | private TextFormatEscaper() {} 38 | 39 | private interface ByteSequence { 40 | int size(); 41 | byte byteAt(int offset); 42 | } 43 | 44 | /** 45 | * Escapes bytes in the format used in protocol buffer text format, which 46 | * is the same as the format used for C string literals. All bytes 47 | * that are not printable 7-bit ASCII characters are escaped, as well as 48 | * backslash, single-quote, and double-quote characters. Characters for 49 | * which no defined short-hand escape sequence is defined will be escaped 50 | * using 3-digit octal sequences. 51 | */ 52 | static String escapeBytes(final ByteSequence input) { 53 | final StringBuilder builder = new StringBuilder(input.size()); 54 | for (int i = 0; i < input.size(); i++) { 55 | final byte b = input.byteAt(i); 56 | switch (b) { 57 | // Java does not recognize \a or \v, apparently. 58 | case 0x07: builder.append("\\a"); break; 59 | case '\b': builder.append("\\b"); break; 60 | case '\f': builder.append("\\f"); break; 61 | case '\n': builder.append("\\n"); break; 62 | case '\r': builder.append("\\r"); break; 63 | case '\t': builder.append("\\t"); break; 64 | case 0x0b: builder.append("\\v"); break; 65 | case '\\': builder.append("\\\\"); break; 66 | case '\'': builder.append("\\\'"); break; 67 | case '"' : builder.append("\\\""); break; 68 | default: 69 | // Only ASCII characters between 0x20 (space) and 0x7e (tilde) are 70 | // printable. Other byte values must be escaped. 71 | if (b >= 0x20 && b <= 0x7e) { 72 | builder.append((char) b); 73 | } else { 74 | builder.append('\\'); 75 | builder.append((char) ('0' + ((b >>> 6) & 3))); 76 | builder.append((char) ('0' + ((b >>> 3) & 7))); 77 | builder.append((char) ('0' + (b & 7))); 78 | } 79 | break; 80 | } 81 | } 82 | return builder.toString(); 83 | } 84 | 85 | /** 86 | * Escapes bytes in the format used in protocol buffer text format, which 87 | * is the same as the format used for C string literals. All bytes 88 | * that are not printable 7-bit ASCII characters are escaped, as well as 89 | * backslash, single-quote, and double-quote characters. Characters for 90 | * which no defined short-hand escape sequence is defined will be escaped 91 | * using 3-digit octal sequences. 92 | */ 93 | static String escapeBytes(final ByteString input) { 94 | return escapeBytes(new ByteSequence() { 95 | @Override 96 | public int size() { 97 | return input.size(); 98 | } 99 | @Override 100 | public byte byteAt(int offset) { 101 | return input.byteAt(offset); 102 | } 103 | }); 104 | } 105 | 106 | /** 107 | * Like {@link #escapeBytes(ByteString)}, but used for byte array. 108 | */ 109 | static String escapeBytes(final byte[] input) { 110 | return escapeBytes(new ByteSequence() { 111 | @Override 112 | public int size() { 113 | return input.length; 114 | } 115 | @Override 116 | public byte byteAt(int offset) { 117 | return input[offset]; 118 | } 119 | }); 120 | } 121 | 122 | /** 123 | * Like {@link #escapeBytes(ByteString)}, but escapes a text string. 124 | * Non-ASCII characters are first encoded as UTF-8, then each byte is escaped 125 | * individually as a 3-digit octal escape. Yes, it's weird. 126 | */ 127 | static String escapeText(final String input) { 128 | return escapeBytes(ByteString.copyFromUtf8(input)); 129 | } 130 | 131 | /** 132 | * Escape double quotes and backslashes in a String for unicode output of a message. 133 | */ 134 | static String escapeDoubleQuotesAndBackslashes(final String input) { 135 | return input.replace("\\", "\\\\").replace("\"", "\\\""); 136 | } 137 | } 138 | -------------------------------------------------------------------------------- /protobuf-java/src/com/google/protobuf/TextFormatParseLocation.java: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | package com.google.protobuf; 32 | 33 | import java.util.Arrays; 34 | 35 | /** 36 | * A location in the source code. 37 | * 38 | *

A location is the starting line number and starting column number. 39 | */ 40 | public final class TextFormatParseLocation { 41 | 42 | /** 43 | * The empty location. 44 | */ 45 | public static final TextFormatParseLocation EMPTY = new TextFormatParseLocation(-1, -1); 46 | 47 | /** 48 | * Create a location. 49 | * 50 | * @param line the starting line number 51 | * @param column the starting column number 52 | * @return a {@code ParseLocation} 53 | */ 54 | static TextFormatParseLocation create(int line, int column) { 55 | if (line == -1 && column == -1) { 56 | return EMPTY; 57 | } 58 | if (line < 0 || column < 0) { 59 | throw new IllegalArgumentException( 60 | String.format("line and column values must be >= 0: line %d, column: %d", line, column)); 61 | } 62 | return new TextFormatParseLocation(line, column); 63 | } 64 | 65 | private final int line; 66 | private final int column; 67 | 68 | private TextFormatParseLocation(int line, int column) { 69 | this.line = line; 70 | this.column = column; 71 | } 72 | 73 | public int getLine() { 74 | return line; 75 | } 76 | 77 | public int getColumn() { 78 | return column; 79 | } 80 | 81 | @Override 82 | public String toString() { 83 | return String.format("ParseLocation{line=%d, column=%d}", line, column); 84 | } 85 | 86 | @Override 87 | public boolean equals(Object o) { 88 | if (o == this) { 89 | return true; 90 | } 91 | if (!(o instanceof TextFormatParseLocation)) { 92 | return false; 93 | } 94 | TextFormatParseLocation that = (TextFormatParseLocation) o; 95 | return (this.line == that.getLine()) 96 | && (this.column == that.getColumn()); 97 | } 98 | 99 | @Override 100 | public int hashCode() { 101 | int[] values = {line, column}; 102 | return Arrays.hashCode(values); 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /protobuf-java/src/com/google/protobuf/UninitializedMessageException.java: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | package com.google.protobuf; 32 | 33 | import java.util.Collections; 34 | import java.util.List; 35 | 36 | /** 37 | * Thrown when attempting to build a protocol message that is missing required 38 | * fields. This is a {@code RuntimeException} because it normally represents 39 | * a programming error: it happens when some code which constructs a message 40 | * fails to set all the fields. {@code parseFrom()} methods do not 41 | * throw this; they throw an {@link InvalidProtocolBufferException} if 42 | * required fields are missing, because it is not a programming error to 43 | * receive an incomplete message. In other words, 44 | * {@code UninitializedMessageException} should never be thrown by correct 45 | * code, but {@code InvalidProtocolBufferException} might be. 46 | * 47 | * @author kenton@google.com Kenton Varda 48 | */ 49 | public class UninitializedMessageException extends RuntimeException { 50 | private static final long serialVersionUID = -7466929953374883507L; 51 | 52 | public UninitializedMessageException(final MessageLite message) { 53 | super("Message was missing required fields. (Lite runtime could not " + 54 | "determine which fields were missing)."); 55 | missingFields = null; 56 | } 57 | 58 | public UninitializedMessageException(final List missingFields) { 59 | super(buildDescription(missingFields)); 60 | this.missingFields = missingFields; 61 | } 62 | 63 | private final List missingFields; 64 | 65 | /** 66 | * Get a list of human-readable names of required fields missing from this 67 | * message. Each name is a full path to a field, e.g. "foo.bar[5].baz". 68 | * Returns null if the lite runtime was used, since it lacks the ability to 69 | * find missing fields. 70 | */ 71 | public List getMissingFields() { 72 | return Collections.unmodifiableList(missingFields); 73 | } 74 | 75 | /** 76 | * Converts this exception to an {@link InvalidProtocolBufferException}. 77 | * When a parsed message is missing required fields, this should be thrown 78 | * instead of {@code UninitializedMessageException}. 79 | */ 80 | public InvalidProtocolBufferException asInvalidProtocolBufferException() { 81 | return new InvalidProtocolBufferException(getMessage()); 82 | } 83 | 84 | /** Construct the description string for this exception. */ 85 | private static String buildDescription(final List missingFields) { 86 | final StringBuilder description = 87 | new StringBuilder("Message missing required fields: "); 88 | boolean first = true; 89 | for (final String field : missingFields) { 90 | if (first) { 91 | first = false; 92 | } else { 93 | description.append(", "); 94 | } 95 | description.append(field); 96 | } 97 | return description.toString(); 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /protobuf-java/src/com/google/protobuf/UnmodifiableLazyStringList.java: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | package com.google.protobuf; 32 | 33 | import java.util.AbstractList; 34 | import java.util.Collection; 35 | import java.util.Collections; 36 | import java.util.Iterator; 37 | import java.util.List; 38 | import java.util.ListIterator; 39 | import java.util.RandomAccess; 40 | 41 | /** 42 | * An implementation of {@link LazyStringList} that wraps another 43 | * {@link LazyStringList} such that it cannot be modified via the wrapper. 44 | * 45 | * @author jonp@google.com (Jon Perlow) 46 | */ 47 | public class UnmodifiableLazyStringList extends AbstractList 48 | implements LazyStringList, RandomAccess { 49 | 50 | private final LazyStringList list; 51 | 52 | public UnmodifiableLazyStringList(LazyStringList list) { 53 | this.list = list; 54 | } 55 | 56 | @Override 57 | public String get(int index) { 58 | return list.get(index); 59 | } 60 | 61 | @Override 62 | public Object getRaw(int index) { 63 | return list.getRaw(index); 64 | } 65 | 66 | @Override 67 | public int size() { 68 | return list.size(); 69 | } 70 | 71 | //@Override (Java 1.6 override semantics, but we must support 1.5) 72 | public ByteString getByteString(int index) { 73 | return list.getByteString(index); 74 | } 75 | 76 | //@Override (Java 1.6 override semantics, but we must support 1.5) 77 | public void add(ByteString element) { 78 | throw new UnsupportedOperationException(); 79 | } 80 | 81 | //@Override (Java 1.6 override semantics, but we must support 1.5) 82 | public void set(int index, ByteString element) { 83 | throw new UnsupportedOperationException(); 84 | } 85 | 86 | //@Override (Java 1.6 override semantics, but we must support 1.5) 87 | public boolean addAllByteString(Collection element) { 88 | throw new UnsupportedOperationException(); 89 | } 90 | 91 | //@Override (Java 1.6 override semantics, but we must support 1.5) 92 | public byte[] getByteArray(int index) { 93 | return list.getByteArray(index); 94 | } 95 | 96 | //@Override (Java 1.6 override semantics, but we must support 1.5) 97 | public void add(byte[] element) { 98 | throw new UnsupportedOperationException(); 99 | } 100 | 101 | //@Override (Java 1.6 override semantics, but we must support 1.5) 102 | public void set(int index, byte[] element) { 103 | throw new UnsupportedOperationException(); 104 | } 105 | 106 | //@Override (Java 1.6 override semantics, but we must support 1.5) 107 | public boolean addAllByteArray(Collection element) { 108 | throw new UnsupportedOperationException(); 109 | } 110 | 111 | @Override 112 | public ListIterator listIterator(final int index) { 113 | return new ListIterator() { 114 | ListIterator iter = list.listIterator(index); 115 | 116 | //@Override (Java 1.6 override semantics, but we must support 1.5) 117 | public boolean hasNext() { 118 | return iter.hasNext(); 119 | } 120 | 121 | //@Override (Java 1.6 override semantics, but we must support 1.5) 122 | public String next() { 123 | return iter.next(); 124 | } 125 | 126 | //@Override (Java 1.6 override semantics, but we must support 1.5) 127 | public boolean hasPrevious() { 128 | return iter.hasPrevious(); 129 | } 130 | 131 | //@Override (Java 1.6 override semantics, but we must support 1.5) 132 | public String previous() { 133 | return iter.previous(); 134 | } 135 | 136 | //@Override (Java 1.6 override semantics, but we must support 1.5) 137 | public int nextIndex() { 138 | return iter.nextIndex(); 139 | } 140 | 141 | //@Override (Java 1.6 override semantics, but we must support 1.5) 142 | public int previousIndex() { 143 | return iter.previousIndex(); 144 | } 145 | 146 | //@Override (Java 1.6 override semantics, but we must support 1.5) 147 | public void remove() { 148 | throw new UnsupportedOperationException(); 149 | } 150 | 151 | //@Override (Java 1.6 override semantics, but we must support 1.5) 152 | public void set(String o) { 153 | throw new UnsupportedOperationException(); 154 | } 155 | 156 | //@Override (Java 1.6 override semantics, but we must support 1.5) 157 | public void add(String o) { 158 | throw new UnsupportedOperationException(); 159 | } 160 | }; 161 | } 162 | 163 | @Override 164 | public Iterator iterator() { 165 | return new Iterator() { 166 | Iterator iter = list.iterator(); 167 | 168 | //@Override (Java 1.6 override semantics, but we must support 1.5) 169 | public boolean hasNext() { 170 | return iter.hasNext(); 171 | } 172 | 173 | //@Override (Java 1.6 override semantics, but we must support 1.5) 174 | public String next() { 175 | return iter.next(); 176 | } 177 | 178 | //@Override (Java 1.6 override semantics, but we must support 1.5) 179 | public void remove() { 180 | throw new UnsupportedOperationException(); 181 | } 182 | }; 183 | } 184 | 185 | //@Override (Java 1.6 override semantics, but we must support 1.5) 186 | public List getUnderlyingElements() { 187 | // The returned value is already unmodifiable. 188 | return list.getUnderlyingElements(); 189 | } 190 | 191 | //@Override (Java 1.6 override semantics, but we must support 1.5) 192 | public void mergeFrom(LazyStringList other) { 193 | throw new UnsupportedOperationException(); 194 | } 195 | 196 | //@Override (Java 1.6 override semantics, but we must support 1.5) 197 | public List asByteArrayList() { 198 | return Collections.unmodifiableList(list.asByteArrayList()); 199 | } 200 | 201 | //@Override (Java 1.6 override semantics, but we must support 1.5) 202 | public List asByteStringList() { 203 | return Collections.unmodifiableList(list.asByteStringList()); 204 | } 205 | 206 | //@Override (Java 1.6 override semantics, but we must support 1.5) 207 | public LazyStringList getUnmodifiableView() { 208 | return this; 209 | } 210 | } 211 | -------------------------------------------------------------------------------- /protobuf-java/src/com/google/protobuf/UnsafeByteOperations.java: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | package com.google.protobuf; 32 | 33 | import java.io.IOException; 34 | import java.nio.ByteBuffer; 35 | 36 | /** 37 | * Provides a number of unsafe byte operations to be used by advanced applications with high 38 | * performance requirements. These methods are referred to as "unsafe" due to the fact that they 39 | * potentially expose the backing buffer of a {@link ByteString} to the application. 40 | * 41 | *

DISCLAIMER: The methods in this class should only be called if it is 42 | * guaranteed that the buffer backing the {@link ByteString} will never change! Mutation of a 43 | * {@link ByteString} can lead to unexpected and undesirable consequences in your application, 44 | * and will likely be difficult to debug. Proceed with caution! 45 | */ 46 | @ExperimentalApi 47 | public final class UnsafeByteOperations { 48 | private UnsafeByteOperations() {} 49 | 50 | /** 51 | * An unsafe operation that returns a {@link ByteString} that is backed by the provided buffer. 52 | * 53 | * @param buffer the Java NIO buffer to be wrapped 54 | * @return a {@link ByteString} backed by the provided buffer 55 | */ 56 | public static ByteString unsafeWrap(ByteBuffer buffer) { 57 | if (buffer.hasArray()) { 58 | final int offset = buffer.arrayOffset(); 59 | return ByteString.wrap(buffer.array(), offset + buffer.position(), buffer.remaining()); 60 | } else { 61 | return new NioByteString(buffer); 62 | } 63 | } 64 | 65 | /** 66 | * Writes the given {@link ByteString} to the provided {@link ByteOutput}. Calling this method may 67 | * result in multiple operations on the target {@link ByteOutput} 68 | * (i.e. for roped {@link ByteString}s). 69 | * 70 | *

This method exposes the internal backing buffer(s) of the {@link ByteString} to the {@link 71 | * ByteOutput} in order to avoid additional copying overhead. It would be possible for a malicious 72 | * {@link ByteOutput} to corrupt the {@link ByteString}. Use with caution! 73 | * 74 | *

NOTE: The {@link ByteOutput} MUST NOT modify the provided buffers. Doing 75 | * so may result in corrupted data, which would be difficult to debug. 76 | * 77 | * @param bytes the {@link ByteString} to be written 78 | * @param output the output to receive the bytes 79 | * @throws IOException if an I/O error occurs 80 | */ 81 | public static void unsafeWriteTo(ByteString bytes, ByteOutput output) throws IOException { 82 | bytes.writeTo(output); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /protoc-as3/protoc-as3.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /protoc-as3/src/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Main-Class: com.google.protobuf.compiler.as3.CodeGenerator 3 | 4 | -------------------------------------------------------------------------------- /protoc-as3/src/com/google/protobuf/compiler/as3/CodeGenerator.java: -------------------------------------------------------------------------------- 1 | package com.google.protobuf.compiler.as3; 2 | 3 | import com.google.protobuf.DescriptorProtos.DescriptorProto; 4 | import com.google.protobuf.DescriptorProtos.EnumDescriptorProto; 5 | import com.google.protobuf.DescriptorProtos.FileDescriptorProto; 6 | import com.google.protobuf.compiler.PluginProtos.CodeGeneratorRequest; 7 | import com.google.protobuf.compiler.PluginProtos.CodeGeneratorResponse; 8 | 9 | import java.io.FileOutputStream; 10 | import java.util.HashMap; 11 | import java.util.Map; 12 | 13 | public class CodeGenerator { 14 | 15 | public static void main(String[] args) { 16 | new CodeGenerator(); 17 | } 18 | 19 | private HashMap _classRef = new HashMap<>(); 20 | private HashMap _fileToGenerate = new HashMap<>(); 21 | 22 | public CodeGenerator() { 23 | try { 24 | //writeToFile(); 25 | //CodeGeneratorRequest request = CodeGeneratorRequest.parseFrom(new FileInputStream("E:\\ttsz\\client\\protobuf-as3\\tools\\protobuf.test")); 26 | CodeGeneratorRequest request = CodeGeneratorRequest.parseFrom(System.in); 27 | CodeGeneratorResponse.Builder response = CodeGeneratorResponse.newBuilder(); 28 | 29 | for (FileDescriptorProto proto : request.getProtoFileList()) { 30 | buildClassRefs(proto); 31 | } 32 | 33 | for (FileDescriptorProto proto : request.getProtoFileList()) { 34 | if (request.getFileToGenerateList().contains(proto.getName())) { 35 | if ("proto3".equals(proto.getSyntax())) { 36 | buildMessageGenerators(proto); 37 | } else { 38 | throw new Exception("need syntax=\"proto3\": " + proto.getName()); 39 | } 40 | } 41 | } 42 | 43 | for (Map.Entry entry : _fileToGenerate.entrySet()) { 44 | Printer printer = new Printer(0); 45 | entry.getValue().generate(printer); 46 | 47 | CodeGeneratorResponse.File.Builder file = CodeGeneratorResponse.File.newBuilder(); 48 | file.setName(entry.getKey().replace('.', '/') + ".as"); 49 | file.setContent(printer.toString()); 50 | response.addFile(file); 51 | } 52 | 53 | response.build().writeTo(System.out); 54 | System.out.flush(); 55 | } catch (Exception e) { 56 | e.printStackTrace(); 57 | } 58 | } 59 | 60 | private void writeToFile() { 61 | try { 62 | CodeGeneratorRequest request1 = CodeGeneratorRequest.parseFrom(System.in); 63 | FileOutputStream os = new FileOutputStream("protobuf.test"); 64 | request1.writeTo(new FileOutputStream("protobuf.test")); 65 | System.err.println("success xxxxxx"); 66 | } catch (Throwable e) { 67 | e.printStackTrace(); 68 | } 69 | } 70 | 71 | private void buildClassRefs(FileDescriptorProto fileProto) { 72 | String packageName = fileProto.getPackage(); 73 | 74 | for (DescriptorProto proto : fileProto.getMessageTypeList()) { 75 | addClassRef(packageName, "", proto); 76 | } 77 | 78 | for (EnumDescriptorProto proto : fileProto.getEnumTypeList()) { 79 | addEnumRef(packageName, "", proto); 80 | } 81 | } 82 | 83 | private void addClassRef(String packageName, String scope, DescriptorProto descriptor) { 84 | String name = descriptor.getName(); 85 | if (Util.isMapEntry(descriptor)) { 86 | _classRef.put( 87 | Util.makeQualifiedClassName(packageName, scope, name), 88 | Util.makeASQualifiedClassName(packageName, scope, name)); 89 | } else { 90 | _classRef.put( 91 | Util.makeQualifiedClassName(packageName, scope, name), 92 | Util.makeASQualifiedClassName(packageName, scope, name)); 93 | 94 | for (DescriptorProto nested : descriptor.getNestedTypeList()) { 95 | addClassRef(packageName, Util.makeScope(scope, name), nested); 96 | } 97 | 98 | for (EnumDescriptorProto nested : descriptor.getEnumTypeList()) { 99 | addEnumRef(packageName, Util.makeScope(scope, name), nested); 100 | } 101 | } 102 | } 103 | 104 | private void addEnumRef(String packageName, String scope, EnumDescriptorProto descriptor) { 105 | String name = descriptor.getName(); 106 | _classRef.put( 107 | Util.makeQualifiedClassName(packageName, scope, name), 108 | Util.makeASQualifiedClassName(packageName, scope, name)); 109 | } 110 | 111 | private void buildMessageGenerators(FileDescriptorProto fileProto) { 112 | String packageName = fileProto.getPackage(); 113 | 114 | for (DescriptorProto descriptor : fileProto.getMessageTypeList()) { 115 | addMessageGenerator(packageName, "", descriptor); 116 | } 117 | 118 | for (EnumDescriptorProto descriptor : fileProto.getEnumTypeList()) { 119 | _fileToGenerate.put( 120 | Util.makeASQualifiedClassName(packageName, "", descriptor.getName()), 121 | new EnumGenerator(descriptor, packageName, "")); 122 | } 123 | } 124 | 125 | private void addMessageGenerator(String packageName, String scope, DescriptorProto descriptor) { 126 | String name = descriptor.getName(); 127 | if (descriptor.hasOptions() && descriptor.getOptions().getMapEntry()) { 128 | _fileToGenerate.put( 129 | Util.makeASQualifiedClassName(packageName, scope, name), 130 | new MapGenerator(descriptor, _classRef, packageName, scope)); 131 | } else { 132 | _fileToGenerate.put( 133 | Util.makeASQualifiedClassName(packageName, scope, name), 134 | new MessageGenerator(descriptor, _classRef, packageName, scope)); 135 | 136 | scope = Util.makeScope(scope, name); 137 | 138 | for (DescriptorProto nestedProto : descriptor.getNestedTypeList()) { 139 | addMessageGenerator(packageName, scope, nestedProto); 140 | } 141 | 142 | for (EnumDescriptorProto nestedEnum : descriptor.getEnumTypeList()) { 143 | _fileToGenerate.put( 144 | Util.makeASQualifiedClassName(packageName, scope, nestedEnum.getName()), 145 | new EnumGenerator(nestedEnum, packageName, scope)); 146 | } 147 | } 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /protoc-as3/src/com/google/protobuf/compiler/as3/EnumGenerator.java: -------------------------------------------------------------------------------- 1 | package com.google.protobuf.compiler.as3; 2 | 3 | import com.google.protobuf.DescriptorProtos.EnumDescriptorProto; 4 | import com.google.protobuf.DescriptorProtos.EnumValueDescriptorProto; 5 | 6 | import java.util.HashMap; 7 | import java.util.Map; 8 | 9 | public class EnumGenerator implements IGenerator { 10 | private EnumDescriptorProto _descriptor; 11 | private Map _variables = new HashMap<>(); 12 | 13 | public EnumGenerator(EnumDescriptorProto descriptor, 14 | String packageName, 15 | String scope) { 16 | _descriptor = descriptor; 17 | _variables.put("class", Util.makeASClassName(scope, descriptor.getName())); 18 | _variables.put("package", packageName); 19 | } 20 | 21 | @Override 22 | public void generate(Printer printer) { 23 | printer.writeln(_variables, "" + 24 | "package #package# {\n" + 25 | "import com.google.protobuf.Enum;\n" + 26 | "\n" + 27 | "public class #class# extends Enum {"); 28 | 29 | for (EnumValueDescriptorProto field : _descriptor.getValueList()) { 30 | _variables.put("field_name", field.getName()); 31 | _variables.put("field_value", String.valueOf(field.getNumber())); 32 | printer.writeln(_variables, "" + 33 | " public static const #field_name#:#class# = new #class#(\"#field_name#\", #field_value#);"); 34 | if (field.getNumber() == 0) { 35 | _variables.put("default_field_value", field.getName()); 36 | } 37 | } 38 | 39 | printer.writeln(); 40 | printer.writeln(_variables, "" + 41 | " public function #class#(name:String, value:int) {\n" + 42 | " super(name, value);\n" + 43 | " }\n" + 44 | " \n" + 45 | " public static function valueOf(value:int):#class# {\n" + 46 | " switch (value) {\n" + 47 | " default:\n" + 48 | " return #default_field_value#;"); 49 | printer.indent(); 50 | for (EnumValueDescriptorProto field : _descriptor.getValueList()) { 51 | _variables.put("field_name", field.getName()); 52 | _variables.put("field_value", String.valueOf(field.getNumber())); 53 | printer.writeln(_variables, "" + 54 | " case #field_value#:\n" + 55 | " return #field_name#;"); 56 | } 57 | printer.outdent(); 58 | printer.writeln(_variables, "" + 59 | " }\n" + 60 | " }\n" + 61 | " \n" + 62 | " public static function toEnums(values:Vector.):Vector.<#class#> {\n" + 63 | " var enums:Vector.<#class#> = new Vector.<#class#>();\n" + 64 | " for each (var value:int in values) {\n" + 65 | " enums.push(#class#.valueOf(value));\n" + 66 | " }\n" + 67 | " return enums;\n" + 68 | " }\n" + 69 | "}\n" + 70 | "}"); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /protoc-as3/src/com/google/protobuf/compiler/as3/IGenerator.java: -------------------------------------------------------------------------------- 1 | package com.google.protobuf.compiler.as3; 2 | 3 | public interface IGenerator { 4 | void generate(Printer printer); 5 | } 6 | -------------------------------------------------------------------------------- /protoc-as3/src/com/google/protobuf/compiler/as3/MapGenerator.java: -------------------------------------------------------------------------------- 1 | package com.google.protobuf.compiler.as3; 2 | 3 | import com.google.protobuf.DescriptorProtos.DescriptorProto; 4 | import com.google.protobuf.DescriptorProtos.FieldDescriptorProto; 5 | 6 | import java.util.Arrays; 7 | import java.util.HashMap; 8 | import java.util.HashSet; 9 | import java.util.Map; 10 | 11 | public class MapGenerator implements IGenerator { 12 | private DescriptorProto _descriptor; 13 | private Map _classRef; 14 | private HashMap _variables = new HashMap<>(); 15 | 16 | public MapGenerator(DescriptorProto descriptor, 17 | Map classRef, 18 | String packageName, 19 | String scope) { 20 | _descriptor = descriptor; 21 | _classRef = classRef; 22 | 23 | _variables.put("class", Util.makeASClassName(scope, descriptor.getName())); 24 | _variables.put("package", packageName); 25 | 26 | for (FieldDescriptorProto keyOrValue : descriptor.getFieldList()) { 27 | if (keyOrValue.getNumber() == 1) { 28 | _variables.put("key_type", Util.getASClass(keyOrValue)); 29 | } else if (keyOrValue.getNumber() == 2) { 30 | _variables.put("value_type", Util.getASClass(keyOrValue, classRef)); 31 | } 32 | } 33 | } 34 | 35 | @Override 36 | public void generate(Printer printer) { 37 | printer.writeln(_variables, "" + 38 | "package #package# {"); 39 | 40 | // import class 41 | generateImportClass(printer); 42 | printer.writeln(); 43 | 44 | // class 45 | printer.writeln(_variables, "" + 46 | "internal class #class# {\n" + 47 | " private var _dict:Dictionary = new Dictionary();\n" + 48 | " \n" + 49 | " public function #class#() {\n" + 50 | " }\n" + 51 | " \n" + 52 | " public function putValue(key:#key_type#, value:#value_type#):void {\n" + 53 | " _dict[key] = value;\n" + 54 | " }\n" + 55 | " \n" + 56 | " public function getValue(key:#key_type#):#value_type# {\n" + 57 | " return _dict[key];\n" + 58 | " }\n" + 59 | " \n" + 60 | " public function clean():void {\n" + 61 | " _dict = new Dictionary();\n" + 62 | " }\n" + 63 | " \n" + 64 | " public function toArray():Vector. {\n" + 65 | " var values:Vector. = new Vector.();\n" + 66 | " for (var key:* in _dict) {\n" + 67 | " if (key != null && _dict[key] != null) {\n" + 68 | " values.push(new MapEntry(key, _dict[key]));\n" + 69 | " }\n" + 70 | " }\n" + 71 | " \n" + 72 | " values.sort(Array.CASEINSENSITIVE);\n" + 73 | " \n" + 74 | " return values;\n" + 75 | " }"); 76 | printer.writeln(); 77 | 78 | printer.writeln("}"); // class 79 | printer.writeln("}"); // package 80 | } 81 | 82 | private void generateImportClass(Printer printer) { 83 | HashSet classSet = new HashSet<>(); 84 | 85 | for (FieldDescriptorProto field : _descriptor.getFieldList()) { 86 | switch (field.getType()) { 87 | case TYPE_MESSAGE: 88 | case TYPE_ENUM: 89 | classSet.add(_classRef.get(field.getTypeName())); 90 | break; 91 | case TYPE_BYTES: 92 | classSet.add("flash.utils.ByteArray"); 93 | break; 94 | } 95 | } 96 | 97 | classSet.add("com.google.protobuf.*"); 98 | classSet.add("flash.utils.Dictionary"); 99 | classSet.remove(null); 100 | 101 | String[] imports = classSet.toArray(new String[classSet.size()]); 102 | Arrays.sort(imports); 103 | 104 | for (String clazz : imports) { 105 | if (clazz != null) { 106 | printer.writeln("import %s;", clazz); 107 | } 108 | } 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /protoc-as3/src/com/google/protobuf/compiler/as3/Printer.java: -------------------------------------------------------------------------------- 1 | package com.google.protobuf.compiler.as3; 2 | 3 | import java.util.Map; 4 | 5 | public class Printer { 6 | private int _indent; 7 | private StringBuilder _content; 8 | 9 | public Printer(int indent) { 10 | _indent = indent; 11 | _content = new StringBuilder(); 12 | } 13 | 14 | private void appendSpace(int number) { 15 | for (int i = 0; i < number; i++) { 16 | _content.append(' '); 17 | } 18 | } 19 | 20 | public Printer indent() { 21 | _indent += 4; 22 | 23 | return this; 24 | } 25 | 26 | public Printer outdent() { 27 | _indent -= 4; 28 | 29 | return this; 30 | } 31 | 32 | public void writeln(Map variables, String fmt) { 33 | appendSpace(_indent); 34 | int start = -1; 35 | int len = fmt.length(); 36 | for (int i = 0; i < len; i++) { 37 | char c = fmt.charAt(i); 38 | if (start < 0 || c == '#') { 39 | if (c == '\n') { 40 | _content.append(c); 41 | appendSpace(_indent); 42 | } else if (c == '#') { 43 | if (start == -1) { 44 | start = i + 1; 45 | } else { 46 | String name = variables.get(fmt.substring(start, i)); 47 | if (name != null) { 48 | _content.append(name); 49 | } else { 50 | Util.printError("no variable: %s\n%s", fmt.substring(start, i), fmt); 51 | } 52 | 53 | start = -1; 54 | } 55 | } else { 56 | _content.append(c); 57 | } 58 | } 59 | } 60 | _content.append('\n'); 61 | 62 | if (start != -1) { 63 | Util.printError("invalid variable format: %s\n%s", fmt.substring(start), fmt); 64 | } 65 | } 66 | 67 | public void writeln(String fmt, Object... args) { 68 | appendSpace(_indent); 69 | _content.append(String.format(fmt, args)); 70 | _content.append('\n'); 71 | } 72 | 73 | public void writeln() { 74 | _content.append('\n'); 75 | } 76 | 77 | @Override 78 | public String toString() { 79 | return _content.toString(); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /test-as3/src/Main.as: -------------------------------------------------------------------------------- 1 | package { 2 | 3 | import com.google.protobuf.CodedInputStream; 4 | import com.google.protobuf.CodedOutputStream; 5 | import com.google.protobuf.Int64; 6 | 7 | import flash.display.Sprite; 8 | import flash.text.TextField; 9 | import flash.utils.ByteArray; 10 | 11 | import test.Battle$Player; 12 | import test.Battle$Skill; 13 | import test.Element; 14 | import test.Element$Type; 15 | import test.Response; 16 | 17 | public class Main extends Sprite { 18 | public function Main() { 19 | var textField:TextField = new TextField(); 20 | textField.text = "Hello, World"; 21 | addChild(textField); 22 | 23 | 24 | var ele:Element = new Element(); 25 | ele.boolValue = true; 26 | ele.floatValue = -234.22; 27 | ele.doubleValue = 88757989.99589; 28 | ele.int32Value = -13; 29 | ele.int64Value = new Int64(-2, 10); 30 | trace(ele.int64Value); 31 | ele.uint32Value = 34; 32 | ele.uint64Value = new Int64(109, 810); 33 | trace(ele.uint64Value); 34 | ele.sint32Value = -23; 35 | ele.sint64Value = new Int64(994, 4443); 36 | trace(ele.sint64Value); 37 | ele.fixed32Value = 321; 38 | ele.fixed64Value = new Int64(90, 664); 39 | trace(ele.fixed32Value); 40 | ele.sfixed32Value = -98494839; 41 | ele.sfixed64Value = new Int64(-98, 2001); 42 | trace(ele.sfixed64Value); 43 | ele.stringValue = "hello,我是?"; 44 | ele.bytesValue.writeUTFBytes("ele is ele?"); 45 | 46 | ele.unionInt64Value = new Int64(-223, 400); 47 | 48 | ele.int64Values.push(new Int64(-2, -1)); 49 | ele.types.push(new Element$Type()); 50 | ele.types[0].id = 3; 51 | 52 | ele.resp = Response.NO; 53 | 54 | var skill:Battle$Skill = new Battle$Skill(); 55 | skill.id = 301; 56 | var player:Battle$Player = new Battle$Player(); 57 | player.id = 10001; 58 | player.name = "curry"; 59 | player.skill.putValue(skill.id, skill); 60 | 61 | ele.player = player; 62 | ele.players.push(player); 63 | 64 | var bytes:ByteArray = new ByteArray(); 65 | var output:CodedOutputStream = new CodedOutputStream(bytes); 66 | ele.writeTo(output); 67 | 68 | var xxxx:Element = new Element(); 69 | bytes.position = 0; 70 | xxxx.readFrom(new CodedInputStream(bytes)); 71 | 72 | trace(ele); 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /test-as3/src/test/Battle$Player$SkillEntry.as: -------------------------------------------------------------------------------- 1 | package test { 2 | import com.google.protobuf.*; 3 | import flash.utils.Dictionary; 4 | import test.Battle$Skill; 5 | 6 | internal class Battle$Player$SkillEntry { 7 | private var _dict:Dictionary = new Dictionary(); 8 | 9 | public function Battle$Player$SkillEntry() { 10 | } 11 | 12 | public function putValue(key:int, value:test.Battle$Skill):void { 13 | _dict[key] = value; 14 | } 15 | 16 | public function getValue(key:int):test.Battle$Skill { 17 | return _dict[key]; 18 | } 19 | 20 | public function clean():void { 21 | _dict = new Dictionary(); 22 | } 23 | 24 | public function toArray():Vector. { 25 | var values:Vector. = new Vector.(); 26 | for (var key:* in _dict) { 27 | if (key != null && _dict[key] != null) { 28 | values.push(new MapEntry(key, _dict[key])); 29 | } 30 | } 31 | 32 | values.sort(Array.CASEINSENSITIVE); 33 | 34 | return values; 35 | } 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /test-as3/src/test/Battle$Player.as: -------------------------------------------------------------------------------- 1 | package test { 2 | import com.google.protobuf.*; 3 | import test.Battle$Skill; 4 | 5 | public class Battle$Player extends Message { 6 | public function Battle$Player() { 7 | } 8 | 9 | private var _id:int = 0; 10 | public function get id():int { 11 | return _id; 12 | } 13 | public function set id(value:int):void { 14 | _id = value; 15 | } 16 | 17 | private var _name:String = ""; 18 | public function get name():String { 19 | return _name; 20 | } 21 | public function set name(value:String):void { 22 | _name = value || ""; 23 | } 24 | 25 | private var _x:Number = 0; 26 | public function get x():Number { 27 | return _x; 28 | } 29 | public function set x(value:Number):void { 30 | _x = value; 31 | } 32 | 33 | private var _y:Number = 0; 34 | public function get y():Number { 35 | return _y; 36 | } 37 | public function set y(value:Number):void { 38 | _y = value; 39 | } 40 | 41 | private var _skill:Battle$Player$SkillEntry = new Battle$Player$SkillEntry(); 42 | public function get skill():Battle$Player$SkillEntry { 43 | return _skill; 44 | } 45 | 46 | override public function writeTo(output:CodedOutputStream):void { 47 | if (!(_id == 0)) { 48 | output.writeInt32(1, _id); 49 | } 50 | if (!(_name.length == 0)) { 51 | output.writeString(2, _name); 52 | } 53 | if (!(_x == 0)) { 54 | output.writeFloat(3, _x); 55 | } 56 | if (!(_y == 0)) { 57 | output.writeFloat(4, _y); 58 | } 59 | output.writeMap(_skill.toArray(), 5, FieldDescriptorType.INT32, 60 | FieldDescriptorType.MESSAGE); 61 | 62 | super.writeTo(output); 63 | } 64 | 65 | override public function readFrom(input:CodedInputStream):void { 66 | while(true) { 67 | var tag:int = input.readTag(); 68 | switch(tag) { 69 | case 0: { 70 | return; 71 | } 72 | default: { 73 | if (!input.skipField(tag)) { 74 | return; 75 | } 76 | break; 77 | } 78 | case 8: { 79 | _id = input.readInt32(); 80 | break; 81 | } 82 | case 18: { 83 | _name = input.readString(); 84 | break; 85 | } 86 | case 29: { 87 | _x = input.readFloat(); 88 | break; 89 | } 90 | case 37: { 91 | _y = input.readFloat(); 92 | break; 93 | } 94 | case 42: { 95 | var skillEntry:MapEntry = input.readMap(FieldDescriptorType.INT32, 96 | FieldDescriptorType.MESSAGE, new test.Battle$Skill(), 8, 18); 97 | _skill.putValue(skillEntry.key, skillEntry.value); 98 | break; 99 | } 100 | } 101 | } 102 | } 103 | 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /test-as3/src/test/Battle$Skill.as: -------------------------------------------------------------------------------- 1 | package test { 2 | import com.google.protobuf.*; 3 | 4 | public class Battle$Skill extends Message { 5 | public function Battle$Skill() { 6 | } 7 | 8 | private var _id:int = 0; 9 | public function get id():int { 10 | return _id; 11 | } 12 | public function set id(value:int):void { 13 | _id = value; 14 | } 15 | 16 | override public function writeTo(output:CodedOutputStream):void { 17 | if (!(_id == 0)) { 18 | output.writeInt32(1, _id); 19 | } 20 | 21 | super.writeTo(output); 22 | } 23 | 24 | override public function readFrom(input:CodedInputStream):void { 25 | while(true) { 26 | var tag:int = input.readTag(); 27 | switch(tag) { 28 | case 0: { 29 | return; 30 | } 31 | default: { 32 | if (!input.skipField(tag)) { 33 | return; 34 | } 35 | break; 36 | } 37 | case 8: { 38 | _id = input.readInt32(); 39 | break; 40 | } 41 | } 42 | } 43 | } 44 | 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /test-as3/src/test/Battle.as: -------------------------------------------------------------------------------- 1 | package test { 2 | import com.google.protobuf.*; 3 | 4 | public class Battle extends Message { 5 | public function Battle() { 6 | } 7 | 8 | private var _id:int = 0; 9 | public function get id():int { 10 | return _id; 11 | } 12 | public function set id(value:int):void { 13 | _id = value; 14 | } 15 | 16 | override public function writeTo(output:CodedOutputStream):void { 17 | if (!(_id == 0)) { 18 | output.writeInt32(1, _id); 19 | } 20 | 21 | super.writeTo(output); 22 | } 23 | 24 | override public function readFrom(input:CodedInputStream):void { 25 | while(true) { 26 | var tag:int = input.readTag(); 27 | switch(tag) { 28 | case 0: { 29 | return; 30 | } 31 | default: { 32 | if (!input.skipField(tag)) { 33 | return; 34 | } 35 | break; 36 | } 37 | case 8: { 38 | _id = input.readInt32(); 39 | break; 40 | } 41 | } 42 | } 43 | } 44 | 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /test-as3/src/test/Element$Type.as: -------------------------------------------------------------------------------- 1 | package test { 2 | import com.google.protobuf.*; 3 | 4 | public class Element$Type extends Message { 5 | public function Element$Type() { 6 | } 7 | 8 | private var _id:int = 0; 9 | public function get id():int { 10 | return _id; 11 | } 12 | public function set id(value:int):void { 13 | _id = value; 14 | } 15 | 16 | override public function writeTo(output:CodedOutputStream):void { 17 | if (!(_id == 0)) { 18 | output.writeInt32(1, _id); 19 | } 20 | 21 | super.writeTo(output); 22 | } 23 | 24 | override public function readFrom(input:CodedInputStream):void { 25 | while(true) { 26 | var tag:int = input.readTag(); 27 | switch(tag) { 28 | case 0: { 29 | return; 30 | } 31 | default: { 32 | if (!input.skipField(tag)) { 33 | return; 34 | } 35 | break; 36 | } 37 | case 8: { 38 | _id = input.readInt32(); 39 | break; 40 | } 41 | } 42 | } 43 | } 44 | 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /test-as3/src/test/Response.as: -------------------------------------------------------------------------------- 1 | package test { 2 | import com.google.protobuf.Enum; 3 | 4 | public class Response extends Enum { 5 | public static const OK:Response = new Response(0); 6 | public static const NO:Response = new Response(1); 7 | 8 | public function Response(value:int) { 9 | super(value); 10 | } 11 | 12 | public static function valueOf(value:int):Response { 13 | switch (value) { 14 | default: 15 | return OK; 16 | case 0: 17 | return OK; 18 | case 1: 19 | return NO; 20 | } 21 | } 22 | 23 | public static function toEnums(values:Vector.):Vector. { 24 | var enums:Vector. = new Vector.(); 25 | for each (var value:int in values) { 26 | enums.push(Response.valueOf(value)); 27 | } 28 | return enums; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /test-as3/test-as3.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /test-java/src/Main.java: -------------------------------------------------------------------------------- 1 | public class Main { 2 | public static void main(String[] argvs) { 3 | 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /test-java/src/test/BattleOrBuilder.java: -------------------------------------------------------------------------------- 1 | // Generated by the protocol buffer compiler. DO NOT EDIT! 2 | // source: protos/element.proto 3 | 4 | package test; 5 | 6 | public interface BattleOrBuilder extends 7 | // @@protoc_insertion_point(interface_extends:test.Battle) 8 | com.google.protobuf.MessageOrBuilder { 9 | 10 | /** 11 | * optional int32 id = 1; 12 | */ 13 | int getId(); 14 | } 15 | -------------------------------------------------------------------------------- /test-java/src/test/Response.java: -------------------------------------------------------------------------------- 1 | // Generated by the protocol buffer compiler. DO NOT EDIT! 2 | // source: protos/element.proto 3 | 4 | package test; 5 | 6 | /** 7 | * Protobuf enum {@code test.Response} 8 | */ 9 | public enum Response 10 | implements com.google.protobuf.ProtocolMessageEnum { 11 | /** 12 | * OK = 0; 13 | */ 14 | OK(0, 0), 15 | /** 16 | * NO = 1; 17 | */ 18 | NO(1, 1), 19 | UNRECOGNIZED(-1, -1), 20 | ; 21 | 22 | /** 23 | * OK = 0; 24 | */ 25 | public static final int OK_VALUE = 0; 26 | /** 27 | * NO = 1; 28 | */ 29 | public static final int NO_VALUE = 1; 30 | 31 | 32 | public final int getNumber() { 33 | if (index == -1) { 34 | throw new java.lang.IllegalArgumentException( 35 | "Can't get the number of an unknown enum value."); 36 | } 37 | return value; 38 | } 39 | 40 | public static Response valueOf(int value) { 41 | switch (value) { 42 | case 0: return OK; 43 | case 1: return NO; 44 | default: return null; 45 | } 46 | } 47 | 48 | public static com.google.protobuf.Internal.EnumLiteMap 49 | internalGetValueMap() { 50 | return internalValueMap; 51 | } 52 | private static final com.google.protobuf.Internal.EnumLiteMap< 53 | Response> internalValueMap = 54 | new com.google.protobuf.Internal.EnumLiteMap() { 55 | public Response findValueByNumber(int number) { 56 | return Response.valueOf(number); 57 | } 58 | }; 59 | 60 | public final com.google.protobuf.Descriptors.EnumValueDescriptor 61 | getValueDescriptor() { 62 | return getDescriptor().getValues().get(index); 63 | } 64 | public final com.google.protobuf.Descriptors.EnumDescriptor 65 | getDescriptorForType() { 66 | return getDescriptor(); 67 | } 68 | public static final com.google.protobuf.Descriptors.EnumDescriptor 69 | getDescriptor() { 70 | return test.ElementDef.getDescriptor() 71 | .getEnumTypes().get(0); 72 | } 73 | 74 | private static final Response[] VALUES = values(); 75 | 76 | public static Response valueOf( 77 | com.google.protobuf.Descriptors.EnumValueDescriptor desc) { 78 | if (desc.getType() != getDescriptor()) { 79 | throw new java.lang.IllegalArgumentException( 80 | "EnumValueDescriptor is not for this type."); 81 | } 82 | if (desc.getIndex() == -1) { 83 | return UNRECOGNIZED; 84 | } 85 | return VALUES[desc.getIndex()]; 86 | } 87 | 88 | private final int index; 89 | private final int value; 90 | 91 | private Response(int index, int value) { 92 | this.index = index; 93 | this.value = value; 94 | } 95 | 96 | // @@protoc_insertion_point(enum_scope:test.Response) 97 | } 98 | 99 | -------------------------------------------------------------------------------- /test-java/test-java.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /tools/build_macosx_linux.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ./protoc --java_out=../test-java/src/ --plugin=protoc-gen-as3="protoc-as3" --as3_out=../test-as3/src/ ./protos/*.proto -------------------------------------------------------------------------------- /tools/build_win.bat: -------------------------------------------------------------------------------- 1 | protoc --java_out=../test-java/src/ --plugin=protoc-gen-as3="protoc-as3.bat" --as3_out=../test-as3/src/ ./protos/*.proto 2 | -------------------------------------------------------------------------------- /tools/google/protobuf/any.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto3"; 32 | 33 | package google.protobuf; 34 | 35 | option csharp_namespace = "Google.Protobuf.WellKnownTypes"; 36 | option java_package = "com.google.protobuf"; 37 | option java_outer_classname = "AnyProto"; 38 | option java_multiple_files = true; 39 | option java_generate_equals_and_hash = true; 40 | option objc_class_prefix = "GPB"; 41 | 42 | // `Any` contains an arbitrary serialized message along with a URL 43 | // that describes the type of the serialized message. 44 | // 45 | // 46 | // JSON 47 | // ==== 48 | // The JSON representation of an `Any` value uses the regular 49 | // representation of the deserialized, embedded message, with an 50 | // additional field `@type` which contains the type URL. Example: 51 | // 52 | // package google.profile; 53 | // message Person { 54 | // string first_name = 1; 55 | // string last_name = 2; 56 | // } 57 | // 58 | // { 59 | // "@type": "type.googleapis.com/google.profile.Person", 60 | // "firstName": , 61 | // "lastName": 62 | // } 63 | // 64 | // If the embedded message type is well-known and has a custom JSON 65 | // representation, that representation will be embedded adding a field 66 | // `value` which holds the custom JSON in addition to the `@type` 67 | // field. Example (for message [google.protobuf.Duration][]): 68 | // 69 | // { 70 | // "@type": "type.googleapis.com/google.protobuf.Duration", 71 | // "value": "1.212s" 72 | // } 73 | // 74 | message Any { 75 | // A URL/resource name whose content describes the type of the 76 | // serialized message. 77 | // 78 | // For URLs which use the schema `http`, `https`, or no schema, the 79 | // following restrictions and interpretations apply: 80 | // 81 | // * If no schema is provided, `https` is assumed. 82 | // * The last segment of the URL's path must represent the fully 83 | // qualified name of the type (as in `path/google.protobuf.Duration`). 84 | // * An HTTP GET on the URL must yield a [google.protobuf.Type][] 85 | // value in binary format, or produce an error. 86 | // * Applications are allowed to cache lookup results based on the 87 | // URL, or have them precompiled into a binary to avoid any 88 | // lookup. Therefore, binary compatibility needs to be preserved 89 | // on changes to types. (Use versioned type names to manage 90 | // breaking changes.) 91 | // 92 | // Schemas other than `http`, `https` (or the empty schema) might be 93 | // used with implementation specific semantics. 94 | // 95 | string type_url = 1; 96 | 97 | // Must be valid serialized data of the above specified type. 98 | bytes value = 2; 99 | } 100 | -------------------------------------------------------------------------------- /tools/google/protobuf/duration.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto3"; 32 | 33 | package google.protobuf; 34 | 35 | option csharp_namespace = "Google.Protobuf.WellKnownTypes"; 36 | option java_package = "com.google.protobuf"; 37 | option java_outer_classname = "DurationProto"; 38 | option java_multiple_files = true; 39 | option java_generate_equals_and_hash = true; 40 | option objc_class_prefix = "GPB"; 41 | 42 | // A Duration represents a signed, fixed-length span of time represented 43 | // as a count of seconds and fractions of seconds at nanosecond 44 | // resolution. It is independent of any calendar and concepts like "day" 45 | // or "month". It is related to Timestamp in that the difference between 46 | // two Timestamp values is a Duration and it can be added or subtracted 47 | // from a Timestamp. Range is approximately +-10,000 years. 48 | // 49 | // Example 1: Compute Duration from two Timestamps in pseudo code. 50 | // 51 | // Timestamp start = ...; 52 | // Timestamp end = ...; 53 | // Duration duration = ...; 54 | // 55 | // duration.seconds = end.seconds - start.seconds; 56 | // duration.nanos = end.nanos - start.nanos; 57 | // 58 | // if (duration.seconds < 0 && duration.nanos > 0) { 59 | // duration.seconds += 1; 60 | // duration.nanos -= 1000000000; 61 | // } else if (durations.seconds > 0 && duration.nanos < 0) { 62 | // duration.seconds -= 1; 63 | // duration.nanos += 1000000000; 64 | // } 65 | // 66 | // Example 2: Compute Timestamp from Timestamp + Duration in pseudo code. 67 | // 68 | // Timestamp start = ...; 69 | // Duration duration = ...; 70 | // Timestamp end = ...; 71 | // 72 | // end.seconds = start.seconds + duration.seconds; 73 | // end.nanos = start.nanos + duration.nanos; 74 | // 75 | // if (end.nanos < 0) { 76 | // end.seconds -= 1; 77 | // end.nanos += 1000000000; 78 | // } else if (end.nanos >= 1000000000) { 79 | // end.seconds += 1; 80 | // end.nanos -= 1000000000; 81 | // } 82 | // 83 | message Duration { 84 | 85 | // Signed seconds of the span of time. Must be from -315,576,000,000 86 | // to +315,576,000,000 inclusive. 87 | int64 seconds = 1; 88 | 89 | // Signed fractions of a second at nanosecond resolution of the span 90 | // of time. Durations less than one second are represented with a 0 91 | // `seconds` field and a positive or negative `nanos` field. For durations 92 | // of one second or more, a non-zero value for the `nanos` field must be 93 | // of the same sign as the `seconds` field. Must be from -999,999,999 94 | // to +999,999,999 inclusive. 95 | int32 nanos = 2; 96 | } 97 | -------------------------------------------------------------------------------- /tools/google/protobuf/empty.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto3"; 32 | 33 | package google.protobuf; 34 | 35 | option csharp_namespace = "Google.Protobuf.WellKnownTypes"; 36 | option java_package = "com.google.protobuf"; 37 | option java_outer_classname = "EmptyProto"; 38 | option java_multiple_files = true; 39 | option java_generate_equals_and_hash = true; 40 | option objc_class_prefix = "GPB"; 41 | option cc_enable_arenas = true; 42 | 43 | // A generic empty message that you can re-use to avoid defining duplicated 44 | // empty messages in your APIs. A typical example is to use it as the request 45 | // or the response type of an API method. For instance: 46 | // 47 | // service Foo { 48 | // rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty); 49 | // } 50 | // 51 | // The JSON representation for `Empty` is empty JSON object `{}`. 52 | message Empty {} 53 | -------------------------------------------------------------------------------- /tools/google/protobuf/field_mask.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto3"; 32 | 33 | package google.protobuf; 34 | 35 | option csharp_namespace = "Google.Protobuf.WellKnownTypes"; 36 | option java_package = "com.google.protobuf"; 37 | option java_outer_classname = "FieldMaskProto"; 38 | option java_multiple_files = true; 39 | option objc_class_prefix = "GPB"; 40 | option java_generate_equals_and_hash = true; 41 | 42 | // `FieldMask` represents a set of symbolic field paths, for example: 43 | // 44 | // paths: "f.a" 45 | // paths: "f.b.d" 46 | // 47 | // Here `f` represents a field in some root message, `a` and `b` 48 | // fields in the message found in `f`, and `d` a field found in the 49 | // message in `f.b`. 50 | // 51 | // Field masks are used to specify a subset of fields that should be 52 | // returned by a get operation or modified by an update operation. 53 | // Field masks also have a custom JSON encoding (see below). 54 | // 55 | // # Field Masks in Projections 56 | // 57 | // When used in the context of a projection, a response message or 58 | // sub-message is filtered by the API to only contain those fields as 59 | // specified in the mask. For example, if the mask in the previous 60 | // example is applied to a response message as follows: 61 | // 62 | // f { 63 | // a : 22 64 | // b { 65 | // d : 1 66 | // x : 2 67 | // } 68 | // y : 13 69 | // } 70 | // z: 8 71 | // 72 | // The result will not contain specific values for fields x,y and z 73 | // (their value will be set to the default, and omitted in proto text 74 | // output): 75 | // 76 | // 77 | // f { 78 | // a : 22 79 | // b { 80 | // d : 1 81 | // } 82 | // } 83 | // 84 | // A repeated field is not allowed except at the last position of a 85 | // field mask. 86 | // 87 | // If a FieldMask object is not present in a get operation, the 88 | // operation applies to all fields (as if a FieldMask of all fields 89 | // had been specified). 90 | // 91 | // Note that a field mask does not necessarily applies to the 92 | // top-level response message. In case of a REST get operation, the 93 | // field mask applies directly to the response, but in case of a REST 94 | // list operation, the mask instead applies to each individual message 95 | // in the returned resource list. In case of a REST custom method, 96 | // other definitions may be used. Where the mask applies will be 97 | // clearly documented together with its declaration in the API. In 98 | // any case, the effect on the returned resource/resources is required 99 | // behavior for APIs. 100 | // 101 | // # Field Masks in Update Operations 102 | // 103 | // A field mask in update operations specifies which fields of the 104 | // targeted resource are going to be updated. The API is required 105 | // to only change the values of the fields as specified in the mask 106 | // and leave the others untouched. If a resource is passed in to 107 | // describe the updated values, the API ignores the values of all 108 | // fields not covered by the mask. 109 | // 110 | // In order to reset a field's value to the default, the field must 111 | // be in the mask and set to the default value in the provided resource. 112 | // Hence, in order to reset all fields of a resource, provide a default 113 | // instance of the resource and set all fields in the mask, or do 114 | // not provide a mask as described below. 115 | // 116 | // If a field mask is not present on update, the operation applies to 117 | // all fields (as if a field mask of all fields has been specified). 118 | // Note that in the presence of schema evolution, this may mean that 119 | // fields the client does not know and has therefore not filled into 120 | // the request will be reset to their default. If this is unwanted 121 | // behavior, a specific service may require a client to always specify 122 | // a field mask, producing an error if not. 123 | // 124 | // As with get operations, the location of the resource which 125 | // describes the updated values in the request message depends on the 126 | // operation kind. In any case, the effect of the field mask is 127 | // required to be honored by the API. 128 | // 129 | // ## Considerations for HTTP REST 130 | // 131 | // The HTTP kind of an update operation which uses a field mask must 132 | // be set to PATCH instead of PUT in order to satisfy HTTP semantics 133 | // (PUT must only be used for full updates). 134 | // 135 | // # JSON Encoding of Field Masks 136 | // 137 | // In JSON, a field mask is encoded as a single string where paths are 138 | // separated by a comma. Fields name in each path are converted 139 | // to/from lower-camel naming conventions. 140 | // 141 | // As an example, consider the following message declarations: 142 | // 143 | // message Profile { 144 | // User user = 1; 145 | // Photo photo = 2; 146 | // } 147 | // message User { 148 | // string display_name = 1; 149 | // string address = 2; 150 | // } 151 | // 152 | // In proto a field mask for `Profile` may look as such: 153 | // 154 | // mask { 155 | // paths: "user.display_name" 156 | // paths: "photo" 157 | // } 158 | // 159 | // In JSON, the same mask is represented as below: 160 | // 161 | // { 162 | // mask: "user.displayName,photo" 163 | // } 164 | // 165 | message FieldMask { 166 | // The set of field mask paths. 167 | repeated string paths = 1; 168 | } 169 | -------------------------------------------------------------------------------- /tools/google/protobuf/source_context.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto3"; 32 | 33 | package google.protobuf; 34 | 35 | option csharp_namespace = "Google.Protobuf.WellKnownTypes"; 36 | option java_package = "com.google.protobuf"; 37 | option java_outer_classname = "SourceContextProto"; 38 | option java_multiple_files = true; 39 | option java_generate_equals_and_hash = true; 40 | option objc_class_prefix = "GPB"; 41 | 42 | // `SourceContext` represents information about the source of a 43 | // protobuf element, like the file in which it is defined. 44 | message SourceContext { 45 | // The path-qualified name of the .proto file that contained the associated 46 | // protobuf element. For example: `"google/protobuf/source.proto"`. 47 | string file_name = 1; 48 | } 49 | -------------------------------------------------------------------------------- /tools/google/protobuf/struct.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto3"; 32 | 33 | package google.protobuf; 34 | 35 | option csharp_namespace = "Google.Protobuf.WellKnownTypes"; 36 | option java_package = "com.google.protobuf"; 37 | option java_outer_classname = "StructProto"; 38 | option java_multiple_files = true; 39 | option java_generate_equals_and_hash = true; 40 | option objc_class_prefix = "GPB"; 41 | 42 | 43 | // `Struct` represents a structured data value, consisting of fields 44 | // which map to dynamically typed values. In some languages, `Struct` 45 | // might be supported by a native representation. For example, in 46 | // scripting languages like JS a struct is represented as an 47 | // object. The details of that representation are described together 48 | // with the proto support for the language. 49 | // 50 | // The JSON representation for `Struct` is JSON object. 51 | message Struct { 52 | // Map of dynamically typed values. 53 | map fields = 1; 54 | } 55 | 56 | // `Value` represents a dynamically typed value which can be either 57 | // null, a number, a string, a boolean, a recursive struct value, or a 58 | // list of values. A producer of value is expected to set one of that 59 | // variants, absence of any variant indicates an error. 60 | // 61 | // The JSON representation for `Value` is JSON value. 62 | message Value { 63 | // The kind of value. 64 | oneof kind { 65 | // Represents a null value. 66 | NullValue null_value = 1; 67 | // Represents a double value. 68 | double number_value = 2; 69 | // Represents a string value. 70 | string string_value = 3; 71 | // Represents a boolean value. 72 | bool bool_value = 4; 73 | // Represents a structured value. 74 | Struct struct_value = 5; 75 | // Represents a repeated `Value`. 76 | ListValue list_value = 6; 77 | } 78 | } 79 | 80 | // `NullValue` is a singleton enumeration to represent the null value for the 81 | // `Value` type union. 82 | // 83 | // The JSON representation for `NullValue` is JSON `null`. 84 | enum NullValue { 85 | // Null value. 86 | NULL_VALUE = 0; 87 | } 88 | 89 | // `ListValue` is a wrapper around a repeated field of values. 90 | // 91 | // The JSON representation for `ListValue` is JSON array. 92 | message ListValue { 93 | // Repeated field of dynamically typed values. 94 | repeated Value values = 1; 95 | } 96 | -------------------------------------------------------------------------------- /tools/google/protobuf/timestamp.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto3"; 32 | 33 | package google.protobuf; 34 | 35 | option csharp_namespace = "Google.Protobuf.WellKnownTypes"; 36 | option cc_enable_arenas = true; 37 | option java_package = "com.google.protobuf"; 38 | option java_outer_classname = "TimestampProto"; 39 | option java_multiple_files = true; 40 | option java_generate_equals_and_hash = true; 41 | option objc_class_prefix = "GPB"; 42 | 43 | // A Timestamp represents a point in time independent of any time zone 44 | // or calendar, represented as seconds and fractions of seconds at 45 | // nanosecond resolution in UTC Epoch time. It is encoded using the 46 | // Proleptic Gregorian Calendar which extends the Gregorian calendar 47 | // backwards to year one. It is encoded assuming all minutes are 60 48 | // seconds long, i.e. leap seconds are "smeared" so that no leap second 49 | // table is needed for interpretation. Range is from 50 | // 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. 51 | // By restricting to that range, we ensure that we can convert to 52 | // and from RFC 3339 date strings. 53 | // See [https://www.ietf.org/rfc/rfc3339.txt](https://www.ietf.org/rfc/rfc3339.txt). 54 | // 55 | // Example 1: Compute Timestamp from POSIX `time()`. 56 | // 57 | // Timestamp timestamp; 58 | // timestamp.set_seconds(time(NULL)); 59 | // timestamp.set_nanos(0); 60 | // 61 | // Example 2: Compute Timestamp from POSIX `gettimeofday()`. 62 | // 63 | // struct timeval tv; 64 | // gettimeofday(&tv, NULL); 65 | // 66 | // Timestamp timestamp; 67 | // timestamp.set_seconds(tv.tv_sec); 68 | // timestamp.set_nanos(tv.tv_usec * 1000); 69 | // 70 | // Example 3: Compute Timestamp from Win32 `GetSystemTimeAsFileTime()`. 71 | // 72 | // FILETIME ft; 73 | // GetSystemTimeAsFileTime(&ft); 74 | // UINT64 ticks = (((UINT64)ft.dwHighDateTime) << 32) | ft.dwLowDateTime; 75 | // 76 | // // A Windows tick is 100 nanoseconds. Windows epoch 1601-01-01T00:00:00Z 77 | // // is 11644473600 seconds before Unix epoch 1970-01-01T00:00:00Z. 78 | // Timestamp timestamp; 79 | // timestamp.set_seconds((INT64) ((ticks / 10000000) - 11644473600LL)); 80 | // timestamp.set_nanos((INT32) ((ticks % 10000000) * 100)); 81 | // 82 | // Example 4: Compute Timestamp from Java `System.currentTimeMillis()`. 83 | // 84 | // long millis = System.currentTimeMillis(); 85 | // 86 | // Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000) 87 | // .setNanos((int) ((millis % 1000) * 1000000)).build(); 88 | // 89 | // 90 | // Example 5: Compute Timestamp from current time in Python. 91 | // 92 | // now = time.time() 93 | // seconds = int(now) 94 | // nanos = int((now - seconds) * 10**9) 95 | // timestamp = Timestamp(seconds=seconds, nanos=nanos) 96 | // 97 | // 98 | message Timestamp { 99 | 100 | // Represents seconds of UTC time since Unix epoch 101 | // 1970-01-01T00:00:00Z. Must be from from 0001-01-01T00:00:00Z to 102 | // 9999-12-31T23:59:59Z inclusive. 103 | int64 seconds = 1; 104 | 105 | // Non-negative fractions of a second at nanosecond resolution. Negative 106 | // second values with fractions must still have non-negative nanos values 107 | // that count forward in time. Must be from 0 to 999,999,999 108 | // inclusive. 109 | int32 nanos = 2; 110 | } 111 | -------------------------------------------------------------------------------- /tools/google/protobuf/type.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | syntax = "proto3"; 32 | 33 | package google.protobuf; 34 | 35 | import "google/protobuf/any.proto"; 36 | import "google/protobuf/source_context.proto"; 37 | 38 | option csharp_namespace = "Google.Protobuf.WellKnownTypes"; 39 | option java_package = "com.google.protobuf"; 40 | option java_outer_classname = "TypeProto"; 41 | option java_multiple_files = true; 42 | option java_generate_equals_and_hash = true; 43 | option objc_class_prefix = "GPB"; 44 | 45 | // A protocol buffer message type. 46 | message Type { 47 | // The fully qualified message name. 48 | string name = 1; 49 | // The list of fields. 50 | repeated Field fields = 2; 51 | // The list of types appearing in `oneof` definitions in this type. 52 | repeated string oneofs = 3; 53 | // The protocol buffer options. 54 | repeated Option options = 4; 55 | // The source context. 56 | SourceContext source_context = 5; 57 | // The source syntax. 58 | Syntax syntax = 6; 59 | } 60 | 61 | // A single field of a message type. 62 | message Field { 63 | // Basic field types. 64 | enum Kind { 65 | // Field type unknown. 66 | TYPE_UNKNOWN = 0; 67 | // Field type double. 68 | TYPE_DOUBLE = 1; 69 | // Field type float. 70 | TYPE_FLOAT = 2; 71 | // Field type int64. 72 | TYPE_INT64 = 3; 73 | // Field type uint64. 74 | TYPE_UINT64 = 4; 75 | // Field type int32. 76 | TYPE_INT32 = 5; 77 | // Field type fixed64. 78 | TYPE_FIXED64 = 6; 79 | // Field type fixed32. 80 | TYPE_FIXED32 = 7; 81 | // Field type bool. 82 | TYPE_BOOL = 8; 83 | // Field type string. 84 | TYPE_STRING = 9; 85 | // Field type group. Proto2 syntax only, and deprecated. 86 | TYPE_GROUP = 10; 87 | // Field type message. 88 | TYPE_MESSAGE = 11; 89 | // Field type bytes. 90 | TYPE_BYTES = 12; 91 | // Field type uint32. 92 | TYPE_UINT32 = 13; 93 | // Field type enum. 94 | TYPE_ENUM = 14; 95 | // Field type sfixed32. 96 | TYPE_SFIXED32 = 15; 97 | // Field type sfixed64. 98 | TYPE_SFIXED64 = 16; 99 | // Field type sint32. 100 | TYPE_SINT32 = 17; 101 | // Field type sint64. 102 | TYPE_SINT64 = 18; 103 | }; 104 | 105 | // Whether a field is optional, required, or repeated. 106 | enum Cardinality { 107 | // For fields with unknown cardinality. 108 | CARDINALITY_UNKNOWN = 0; 109 | // For optional fields. 110 | CARDINALITY_OPTIONAL = 1; 111 | // For required fields. Proto2 syntax only. 112 | CARDINALITY_REQUIRED = 2; 113 | // For repeated fields. 114 | CARDINALITY_REPEATED = 3; 115 | }; 116 | 117 | // The field type. 118 | Kind kind = 1; 119 | // The field cardinality. 120 | Cardinality cardinality = 2; 121 | // The field number. 122 | int32 number = 3; 123 | // The field name. 124 | string name = 4; 125 | // The field type URL, without the scheme, for message or enumeration 126 | // types. Example: `"type.googleapis.com/google.protobuf.Timestamp"`. 127 | string type_url = 6; 128 | // The index of the field type in `Type.oneofs`, for message or enumeration 129 | // types. The first type has index 1; zero means the type is not in the list. 130 | int32 oneof_index = 7; 131 | // Whether to use alternative packed wire representation. 132 | bool packed = 8; 133 | // The protocol buffer options. 134 | repeated Option options = 9; 135 | // The field JSON name. 136 | string json_name = 10; 137 | // The string value of the default value of this field. Proto2 syntax only. 138 | string default_value = 11; 139 | } 140 | 141 | // Enum type definition. 142 | message Enum { 143 | // Enum type name. 144 | string name = 1; 145 | // Enum value definitions. 146 | repeated EnumValue enumvalue = 2; 147 | // Protocol buffer options. 148 | repeated Option options = 3; 149 | // The source context. 150 | SourceContext source_context = 4; 151 | // The source syntax. 152 | Syntax syntax = 5; 153 | } 154 | 155 | // Enum value definition. 156 | message EnumValue { 157 | // Enum value name. 158 | string name = 1; 159 | // Enum value number. 160 | int32 number = 2; 161 | // Protocol buffer options. 162 | repeated Option options = 3; 163 | } 164 | 165 | // A protocol buffer option, which can be attached to a message, field, 166 | // enumeration, etc. 167 | message Option { 168 | // The option's name. For example, `"java_package"`. 169 | string name = 1; 170 | // The option's value. For example, `"com.google.protobuf"`. 171 | Any value = 2; 172 | } 173 | 174 | // The syntax in which a protocol buffer element is defined. 175 | enum Syntax { 176 | // Syntax `proto2`. 177 | SYNTAX_PROTO2 = 0; 178 | // Syntax `proto3`. 179 | SYNTAX_PROTO3 = 1; 180 | } 181 | -------------------------------------------------------------------------------- /tools/google/protobuf/wrappers.proto: -------------------------------------------------------------------------------- 1 | // Protocol Buffers - Google's data interchange format 2 | // Copyright 2008 Google Inc. All rights reserved. 3 | // https://developers.google.com/protocol-buffers/ 4 | // 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following disclaimer 13 | // in the documentation and/or other materials provided with the 14 | // distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived from 17 | // this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Wrappers for primitive (non-message) types. These types are useful 32 | // for embedding primitives in the `google.protobuf.Any` type and for places 33 | // where we need to distinguish between the absence of a primitive 34 | // typed field and its default value. 35 | 36 | syntax = "proto3"; 37 | 38 | package google.protobuf; 39 | 40 | option csharp_namespace = "Google.Protobuf.WellKnownTypes"; 41 | option cc_enable_arenas = true; 42 | option java_package = "com.google.protobuf"; 43 | option java_outer_classname = "WrappersProto"; 44 | option java_multiple_files = true; 45 | option java_generate_equals_and_hash = true; 46 | option objc_class_prefix = "GPB"; 47 | 48 | // Wrapper message for `double`. 49 | // 50 | // The JSON representation for `DoubleValue` is JSON number. 51 | message DoubleValue { 52 | // The double value. 53 | double value = 1; 54 | } 55 | 56 | // Wrapper message for `float`. 57 | // 58 | // The JSON representation for `FloatValue` is JSON number. 59 | message FloatValue { 60 | // The float value. 61 | float value = 1; 62 | } 63 | 64 | // Wrapper message for `int64`. 65 | // 66 | // The JSON representation for `Int64Value` is JSON string. 67 | message Int64Value { 68 | // The int64 value. 69 | int64 value = 1; 70 | } 71 | 72 | // Wrapper message for `uint64`. 73 | // 74 | // The JSON representation for `UInt64Value` is JSON string. 75 | message UInt64Value { 76 | // The uint64 value. 77 | uint64 value = 1; 78 | } 79 | 80 | // Wrapper message for `int32`. 81 | // 82 | // The JSON representation for `Int32Value` is JSON number. 83 | message Int32Value { 84 | // The int32 value. 85 | int32 value = 1; 86 | } 87 | 88 | // Wrapper message for `uint32`. 89 | // 90 | // The JSON representation for `UInt32Value` is JSON number. 91 | message UInt32Value { 92 | // The uint32 value. 93 | uint32 value = 1; 94 | } 95 | 96 | // Wrapper message for `bool`. 97 | // 98 | // The JSON representation for `BoolValue` is JSON `true` and `false`. 99 | message BoolValue { 100 | // The bool value. 101 | bool value = 1; 102 | } 103 | 104 | // Wrapper message for `string`. 105 | // 106 | // The JSON representation for `StringValue` is JSON string. 107 | message StringValue { 108 | // The string value. 109 | string value = 1; 110 | } 111 | 112 | // Wrapper message for `bytes`. 113 | // 114 | // The JSON representation for `BytesValue` is JSON string. 115 | message BytesValue { 116 | // The bytes value. 117 | bytes value = 1; 118 | } 119 | -------------------------------------------------------------------------------- /tools/protobuf.test: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhongfq/protobuf-as3/12642983d16c2e38c24217e0d54bf2e8e71e6f52/tools/protobuf.test -------------------------------------------------------------------------------- /tools/protoc-as3: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | cd "`dirname "$0"`" && java -jar protoc-as3.jar 3 | -------------------------------------------------------------------------------- /tools/protoc-as3.bat: -------------------------------------------------------------------------------- 1 | @cd %~dp0 2 | @java -jar protoc-as3.jar 3 | -------------------------------------------------------------------------------- /tools/protoc-as3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhongfq/protobuf-as3/12642983d16c2e38c24217e0d54bf2e8e71e6f52/tools/protoc-as3.jar -------------------------------------------------------------------------------- /tools/protoc.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhongfq/protobuf-as3/12642983d16c2e38c24217e0d54bf2e8e71e6f52/tools/protoc.exe -------------------------------------------------------------------------------- /tools/protos/element.proto: -------------------------------------------------------------------------------- 1 | syntax="proto3"; 2 | package test; 3 | 4 | option java_multiple_files=true; 5 | option java_outer_classname="ElementDef"; 6 | 7 | message Battle { 8 | int32 id = 1; 9 | 10 | message Player { 11 | int32 id = 1; 12 | string name = 2; 13 | float x = 3; 14 | float y = 4; 15 | map skill = 5; 16 | } 17 | 18 | message Skill { 19 | int32 id = 1; 20 | } 21 | } 22 | 23 | enum Response { 24 | OK = 0; 25 | NO = 1; 26 | } 27 | 28 | message Element { 29 | message Type { 30 | int32 id = 1; 31 | } 32 | bool bool_value = 1; 33 | float float_value = 2; 34 | double double_value = 3; 35 | int32 int32_value = 4; 36 | int64 int64_value = 5; 37 | uint32 uint32_value = 6; 38 | uint64 uint64_value = 7; 39 | sint32 sint32_value = 8; 40 | sint64 sint64_value = 9; 41 | fixed32 fixed32_value = 10; 42 | fixed64 fixed64_value = 11; 43 | sfixed32 sfixed32_value = 12; 44 | sfixed64 sfixed64_value = 13; 45 | string string_value = 14; 46 | bytes bytes_value = 15; 47 | Type type = 16; 48 | Battle.Player player = 17; 49 | Battle.Skill skill = 18; 50 | 51 | oneof union { 52 | bool union_bool_value = 19; 53 | float union_float_value = 20; 54 | double union_double_value = 21; 55 | int32 union_int32_value = 22; 56 | int64 union_int64_value = 23; 57 | uint32 union_uint32_value = 24; 58 | uint64 union_uint64_value = 25; 59 | sint32 union_sint32_value = 26; 60 | sint64 union_sint64_value = 27; 61 | fixed32 union_fixed32_value = 28; 62 | fixed64 union_fixed64_value = 29; 63 | sfixed32 union_sfixed32_value = 30; 64 | sfixed64 union_sfixed64_value = 31; 65 | string union_string_value = 32; 66 | bytes union_bytes_value = 33; 67 | Type union_type = 34; 68 | Battle.Player union_player = 35; 69 | Battle.Skill union_skill = 36; 70 | } 71 | 72 | repeated bool bool_values = 37; 73 | repeated float float_values = 38; 74 | repeated double double_values = 39; 75 | repeated int32 int32_values = 40; 76 | repeated int64 int64_values = 41; 77 | repeated uint32 uint32_values = 42; 78 | repeated uint64 uint64_values = 43; 79 | repeated sint32 sint32_values = 44; 80 | repeated sint64 sint64_values = 45; 81 | repeated fixed32 fixed32_values = 46; 82 | repeated fixed64 fixed64_values = 47; 83 | repeated sfixed32 sfixed32_values = 48; 84 | repeated sfixed64 sfixed64_values = 49; 85 | repeated string string_values = 50; 86 | repeated bytes bytes_values = 51; 87 | repeated Type types = 52; 88 | repeated Battle.Player players = 53; 89 | repeated Battle.Skill skills = 54; 90 | 91 | Response resp = 55; 92 | } --------------------------------------------------------------------------------