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

grpc / grpc-java / #19681

07 Feb 2025 08:46AM CUT coverage: 88.609% (-0.008%) from 88.617%
#19681

push

github

web-flow
protobuf: Stabilize marshallerWithRecursionLimit (#11884)

33776 of 38118 relevant lines covered (88.61%)

0.89 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.Metadata;
22
import io.grpc.MethodDescriptor.Marshaller;
23
import io.grpc.protobuf.lite.ProtoLiteUtils;
24

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

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

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

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

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

81
  /**
82
   * Produce a metadata marshaller for a protobuf type.
83
   *
84
   * @since 1.13.0
85
   */
86
  public static <T extends Message> Metadata.BinaryMarshaller<T> metadataMarshaller(T instance) {
87
    return ProtoLiteUtils.metadataMarshaller(instance);
1✔
88
  }
89

90
  private ProtoUtils() {
91
  }
92
}
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

© 2025 Coveralls, Inc