code: def encode_sub(self, validator, value):
          # type: (bv.Validator, typing.Any) -> typing.Any
          
  
          if isinstance(validator, bv.List):
              # Because Lists are mutable, we always validate them during
              # serialization
              validate_f = validator.validate  # type: typing.Callable[[typing.Any], None]
              encode_f = self.encode_list  # type: typing.Callable[[typing.Any, typing.Any], typing.Any] # noqa: E501
          elif isinstance(validator, bv.Map):
              # Also validate maps during serialization because they are also mutable
              validate_f = validator.validate
              encode_f = self.encode_map
          elif isinstance(validator, bv.Nullable):
              validate_f = validator.validate
              encode_f = self.encode_nullable
          elif isinstance(validator, bv.Primitive):
              validate_f = validator.validate
              encode_f = self.encode_primitive
          elif isinstance(validator, bv.Struct):
              if isinstance(validator, bv.StructTree):
                  if self.caller_permissions.permissions:
                      def validate_with_permissions(val):
                          validator.validate_with_permissions(val, self.caller_permissions)
  
                      validate_f = validate_with_permissions
                  else:
                      validate_f = validator.validate
                  encode_f = self.encode_struct_tree
              else:
                  # Fields are already validated on assignment
                  if self.caller_permissions.permissions:
                      def validate_with_permissions(val):
                          validator.validate_with_permissions(val, self.caller_permissions)
  
                      validate_f = validate_with_permissions
                  else:
                      validate_f = validator.validate_type_only
                  encode_f = self.encode_struct
          elif isinstance(validator, bv.Union):
              # Fields are already validated on assignment
              validate_f = validator.validate_type_only
              encode_f = self.encode_union
          else:
              raise bv.ValidationError('Unsupported data type {}'.format(type(validator).__name__))
  
          validate_f(value)
  
          return encode_f(validator, value)
docs: Callback intended to be called by other ``encode`` methods to
          delegate encoding of sub-values. Arguments have the same semantics
          as with the ``encode`` method.