function genVerifyValue(gen, field, fieldIndex, ref) {
        /* eslint-disable no-unexpected-multiline */
        if (field.resolvedType) {
          if (field.resolvedType instanceof Enum) {
            gen("switch(%s){", ref)("default:")(
              "return%j",
              invalid(field, "enum value")
            );
            for (
              var keys = Object.keys(field.resolvedType.values), j = 0;
              j < keys.length;
              ++j
            )
              gen("case %i:", field.resolvedType.values[keys[j]]);
            gen("break")("}");
          } else {
            gen("{")("var e=types[%i].verify(%s);", fieldIndex, ref)("if(e)")(
              "return%j+e",
              field.name + "."
            )("}");
          }
        } else {
          switch (field.type) {
            case "int32":
            case "uint32":
            case "sint32":
            case "fixed32":
            case "sfixed32":
              gen("if(!util.isInteger(%s))", ref)(
                "return%j",
                invalid(field, "integer")
              );
              break;
            case "int64":
            case "uint64":
            case "sint64":
            case "fixed64":
            case "sfixed64":
              gen(
                "if(!util.isInteger(%s)&&!(%s&&util.isInteger(%s.low)&&util.isInteger(%s.high)))",
                ref,
                ref,
                ref,
                ref
              )("return%j", invalid(field, "integer|Long"));
              break;
            case "float":
            case "double":
              gen('if(typeof %s!=="number")', ref)(
                "return%j",
                invalid(field, "number")
              );
              break;
            case "bool":
              gen('if(typeof %s!=="boolean")', ref)(
                "return%j",
                invalid(field, "boolean")
              );
              break;
            case "string":
              gen("if(!util.isString(%s))", ref)(
                "return%j",
                invalid(field, "string")
              );
              break;
            case "bytes":
              gen(
                'if(!(%s&&typeof %s.length==="number"||util.isString(%s)))',
                ref,
                ref,
                ref
              )("return%j", invalid(field, "buffer"));
              break;
          }
        }
        return gen;
        /* eslint-enable no-unexpected-multiline */
      }
/**
       * Generates a partial value verifier.
       * @param {Codegen} gen Codegen instance
       * @param {Field} field Reflected field
       * @param {number} fieldIndex Field index
       * @param {string} ref Variable reference
       * @returns {Codegen} Codegen instance
       * @ignore
       */
Generates a partial value verifier.
Generates a partial value verifier .
function genVerifyValue(gen, field, fieldIndex, ref) {
        if (field.resolvedType) {
          if (field.resolvedType instanceof Enum) {
            gen("switch(%s){", ref)("default:")(
              "return%j",
              invalid(field, "enum value")
            );
            for (
              var keys = Object.keys(field.resolvedType.values), j = 0;
              j < keys.length;
              ++j
            )
              gen("case %i:", field.resolvedType.values[keys[j]]);
            gen("break")("}");
          } else {
            gen("{")("var e=types[%i].verify(%s);", fieldIndex, ref)("if(e)")(
              "return%j+e",
              field.name + "."
            )("}");
          }
        } else {
          switch (field.type) {
            case "int32":
            case "uint32":
            case "sint32":
            case "fixed32":
            case "sfixed32":
              gen("if(!util.isInteger(%s))", ref)(
                "return%j",
                invalid(field, "integer")
              );
              break;
            case "int64":
            case "uint64":
            case "sint64":
            case "fixed64":
            case "sfixed64":
              gen(
                "if(!util.isInteger(%s)&&!(%s&&util.isInteger(%s.low)&&util.isInteger(%s.high)))",
                ref,
                ref,
                ref,
                ref
              )("return%j", invalid(field, "integer|Long"));
              break;
            case "float":
            case "double":
              gen('if(typeof %s!=="number")', ref)(
                "return%j",
                invalid(field, "number")
              );
              break;
            case "bool":
              gen('if(typeof %s!=="boolean")', ref)(
                "return%j",
                invalid(field, "boolean")
              );
              break;
            case "string":
              gen("if(!util.isString(%s))", ref)(
                "return%j",
                invalid(field, "string")
              );
              break;
            case "bytes":
              gen(
                'if(!(%s&&typeof %s.length==="number"||util.isString(%s)))',
                ref,
                ref,
                ref
              )("return%j", invalid(field, "buffer"));
              break;
          }
        }
        return gen;
      }
function genVerifyValue ( gen , field , fieldIndex , ref ) { if ( field . resolvedType ) { if ( field . resolvedType instanceof Enum ) { gen ( "switch(%s){" , ref ) ( "default:" ) ( "return%j" , invalid ( field , "enum value" ) ) ; for ( var keys = Object . keys ( field . resolvedType . values ) , j = 0 ; j < keys . length ; ++ j ) gen ( "case %i:" , field . resolvedType . values [ keys [ j ] ] ) ; gen ( "break" ) ( "}" ) ; } else { gen ( "{" ) ( "var e=types[%i].verify(%s);" , fieldIndex , ref ) ( "if(e)" ) ( "return%j+e" , field . name + "." ) ( "}" ) ; } } else { switch ( field . type ) { case "int32" : case "uint32" : case "sint32" : case "fixed32" : case "sfixed32" : gen ( "if(!util.isInteger(%s))" , ref ) ( "return%j" , invalid ( field , "integer" ) ) ; break ; case "int64" : case "uint64" : case "sint64" : case "fixed64" : case "sfixed64" : gen ( "if(!util.isInteger(%s)&&!(%s&&util.isInteger(%s.low)&&util.isInteger(%s.high)))" , ref , ref , ref , ref ) ( "return%j" , invalid ( field , "integer|Long" ) ) ; break ; case "float" : case "double" : gen ( 'if(typeof %s!=="number")' , ref ) ( "return%j" , invalid ( field , "number" ) ) ; break ; case "bool" : gen ( 'if(typeof %s!=="boolean")' , ref ) ( "return%j" , invalid ( field , "boolean" ) ) ; break ; case "string" : gen ( "if(!util.isString(%s))" , ref ) ( "return%j" , invalid ( field , "string" ) ) ; break ; case "bytes" : gen ( 'if(!(%s&&typeof %s.length==="number"||util.isString(%s)))' , ref , ref , ref ) ( "return%j" , invalid ( field , "buffer" ) ) ; break ; } } return gen ; }
Generates a partial value verifier.
Generates a partial value verifier .
/* eslint-disable no-unexpected-multiline */ /* eslint-enable no-unexpected-multiline */