• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

grpc / grpc-java / #18726

pending completion
#18726

push

github-actions

web-flow
Stabilize setExtensionRegistry() of ProtoLiteUtils and ProtoUtils (#10392)

Closes #1787

29151 of 33044 relevant lines covered (88.22%)

0.88 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

62.5
/../protobuf/src/main/java/io/grpc/protobuf/ProtoUtils.java
1
/*
2
 * Copyright 2014 The gRPC Authors
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16

17
package io.grpc.protobuf;
18

19
import com.google.protobuf.ExtensionRegistry;
20
import com.google.protobuf.Message;
21
import io.grpc.ExperimentalApi;
22
import io.grpc.Metadata;
23
import io.grpc.MethodDescriptor.Marshaller;
24
import io.grpc.protobuf.lite.ProtoLiteUtils;
25

26
/**
27
 * Utility methods for using protobuf with grpc.
28
 */
29
public final class ProtoUtils {
30

31
  /**
32
   * Sets the global registry for proto marshalling shared across all servers and clients.
33
   *
34
   * <p>Warning:  This API will likely change over time.  It is not possible to have separate
35
   * registries per Process, Server, Channel, Service, or Method.  This is intentional until there
36
   * is a more appropriate API to set them.
37
   *
38
   * <p>Warning:  Do NOT modify the extension registry after setting it.  It is thread safe to call
39
   * {@link #setExtensionRegistry}, but not to modify the underlying object.
40
   *
41
   * <p>If you need custom parsing behavior for protos, you will need to make your own
42
   * {@code MethodDescriptor.Marshaller} for the time being.
43
   *
44
   * @since 1.16.0
45
   */
46
  public static void setExtensionRegistry(ExtensionRegistry registry) {
47
    ProtoLiteUtils.setExtensionRegistry(registry);
×
48
  }
×
49

50
  /**
51
   * Create a {@link Marshaller} for protos of the same type as {@code defaultInstance}.
52
   *
53
   * @since 1.0.0
54
   */
55
  public static <T extends Message> Marshaller<T> marshaller(final T defaultInstance) {
56
    return ProtoLiteUtils.marshaller(defaultInstance);
1✔
57
  }
58

59
  /**
60
   * Creates a {@link Marshaller} for protos of the same type as {@code defaultInstance} and a
61
   * custom limit for the recursion depth. Any negative number will leave the limit to its default
62
   * value as defined by the protobuf library.
63
   *
64
   * @since 1.56.0
65
   */
66
  @ExperimentalApi("https://github.com/grpc/grpc-java/issues/10108")
67
  public static <T extends Message> Marshaller<T> marshallerWithRecursionLimit(T defaultInstance,
68
      int recursionLimit) {
69
    return ProtoLiteUtils.marshallerWithRecursionLimit(defaultInstance, recursionLimit);
×
70
  }
71

72
  /**
73
   * Produce a metadata key for a generated protobuf type.
74
   *
75
   * @since 1.0.0
76
   */
77
  public static <T extends Message> Metadata.Key<T> keyForProto(T instance) {
78
    return Metadata.Key.of(
1✔
79
        instance.getDescriptorForType().getFullName() + Metadata.BINARY_HEADER_SUFFIX,
1✔
80
        metadataMarshaller(instance));
1✔
81
  }
82

83
  /**
84
   * Produce a metadata marshaller for a protobuf type.
85
   *
86
   * @since 1.13.0
87
   */
88
  @ExperimentalApi("https://github.com/grpc/grpc-java/issues/4477")
89
  public static <T extends Message> Metadata.BinaryMarshaller<T> metadataMarshaller(T instance) {
90
    return ProtoLiteUtils.metadataMarshaller(instance);
1✔
91
  }
92

93
  private ProtoUtils() {
94
  }
95
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc