Class FieldDescriptorCache


  • public class FieldDescriptorCache
    extends java.lang.Object
    Caches the results of looking up fields in a protobuf message's Descriptor.

    Empirical testing suggests that the first request for a message's descriptor is quite slow, for instance GoogleAdsRow takes about 0.5 seconds. Future requests to the protobuf descriptor API take around 3 usec. This cache reduces the ongoing lookup time to around 1 usec, but still suffers from the slow initial request performance.

    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static FieldDescriptorCache getDefault()
      Obtains a global instance of the cache.
      java.util.Optional<com.google.protobuf.Descriptors.FieldDescriptor> lookupField​(java.lang.String fieldName, com.google.protobuf.MessageOrBuilder containingMessage)
      Retrieves a named field from a MessageOrBuilder.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getDefault

        public static FieldDescriptorCache getDefault()
        Obtains a global instance of the cache.
      • lookupField

        public java.util.Optional<com.google.protobuf.Descriptors.FieldDescriptor> lookupField​(java.lang.String fieldName,
                                                                                               com.google.protobuf.MessageOrBuilder containingMessage)
        Retrieves a named field from a MessageOrBuilder. If the field is not in the cache then it is first populated and then returned.