code: def encode_field(self, field, value):
          
          if isinstance(field, messages.BytesField):
              if field.repeated:
                  value = [base64.b64encode(byte) for byte in value]
              else:
                  value = base64.b64encode(value)
          elif isinstance(field, message_types.DateTimeField):
              # DateTimeField stores its data as a RFC 3339 compliant string.
              if field.repeated:
                  value = [i.isoformat() for i in value]
              else:
                  value = value.isoformat()
          return value
docs: Encode a python field value to a JSON value.
  
          Args:
            field: A ProtoRPC field instance.
            value: A python value supported by field.
  
          Returns:
            A JSON serializable value appropriate for field.