code: public static int computeFieldSize(final FieldDescriptorLite<?> descriptor,
                                       final Object value) {
      WireFormat.FieldType type = descriptor.getLiteType();
      int number = descriptor.getNumber();
      if (descriptor.isRepeated()) {
        if (descriptor.isPacked()) {
          int dataSize = 0;
          for (final Object element : (List<?>)value) {
            dataSize += computeElementSizeNoTag(type, element);
          }
          return dataSize +
              CodedOutputStream.computeTagSize(number) +
              CodedOutputStream.computeRawVarint32Size(dataSize);
        } else {
          int size = 0;
          for (final Object element : (List<?>)value) {
            size += computeElementSize(type, number, element);
          }
          return size;
        }
      } else {
        return computeElementSize(type, number, value);
      }
    }
docs: Compute the number of bytes needed to encode a particular field.