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 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 | *
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 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
45 | *
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
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