code: def validate(self, val):
          if type(val) is not dict:
              return False, "%s is not a dict" % (str(val))
          for k, v in val.items():
              field = self.field(k)
              if field:
                  ok, msg = self.contract.validate(field, field.is_array, v)
                  if not ok:
                      return False, "field '%s': %s" % (field.name, msg)
              else:
                  return False, "field '%s' not found in struct %s" % (k, self.name)
          all_fields = self.get_all_fields([])
          for field in all_fields:
              if not val.has_key(field.name) and not field.optional:
                  return False, "field '%s' missing from: %s" % (field.name, str(val))
          return True, None