Copyright 2015 The Go Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

package gensupport

import (
	
	
	
	
)
MarshalJSON returns a JSON encoding of schema containing only selected fields. A field is selected if any of the following is true: * it has a non-empty value * its field name is present in forceSendFields and it is not a nil pointer or nil interface * its field name is present in nullFields. The JSON key for each selected field is taken from the field's json: struct tag.
func ( interface{}, ,  []string) ([]byte, error) {
	if len() == 0 && len() == 0 {
		return json.Marshal()
	}

	 := make(map[string]bool)
	for ,  := range  {
		[] = true
	}
	 := make(map[string]bool)
	 := make(map[string]map[string]bool)
	for ,  := range  {
		 := strings.SplitN(, ".", 2)
		 := [0]
		if len() == 1 {
			[] = true
		} else {
			if [] == nil {
				[] = map[string]bool{}
			}
			[][[1]] = true
		}
	}

	,  := schemaToMap(, , , )
	if  != nil {
		return nil, 
	}
	return json.Marshal()
}

func ( interface{}, ,  map[string]bool,  map[string]map[string]bool) (map[string]interface{}, error) {
	 := make(map[string]interface{})
	 := reflect.ValueOf()
	 := .Type()

	for  := 0;  < .NumField(); ++ {
		 := .Field().Tag.Get("json")
		if  == "" {
			continue
		}
		,  := parseJSONTag()
		if  != nil {
			return nil, 
		}
		if .ignore {
			continue
		}

		 := .Field()
		 := .Field()

		if [.Name] {
			if !isEmptyValue() {
				return nil, fmt.Errorf("field %q in NullFields has non-empty value", .Name)
			}
			[.apiName] = nil
			continue
		}

		if !includeField(, , ) {
			continue
		}
If map fields are explicitly set to null, use a map[string]interface{}.
		if .Type.Kind() == reflect.Map && [.Name] != nil {
			,  := .Interface().(map[string]string)
			if ! {
				return nil, fmt.Errorf("field %q has keys in NullFields but is not a map[string]string", .Name)
			}
			 := map[string]interface{}{}
			for ,  := range  {
				[] = 
			}
			for  := range [.Name] {
				[] = nil
			}
			[.apiName] = 
			continue
		}
nil maps are treated as empty maps.
		if .Type.Kind() == reflect.Map && .IsNil() {
			[.apiName] = map[string]string{}
			continue
		}
nil slices are treated as empty slices.
		if .Type.Kind() == reflect.Slice && .IsNil() {
			[.apiName] = []bool{}
			continue
		}

		if .stringFormat {
			[.apiName] = formatAsString(, .Type.Kind())
		} else {
			[.apiName] = .Interface()
		}
	}
	return , nil
}
formatAsString returns a string representation of v, dereferencing it first if possible.
func ( reflect.Value,  reflect.Kind) string {
	if  == reflect.Ptr && !.IsNil() {
		 = .Elem()
	}

	return fmt.Sprintf("%v", .Interface())
}
jsonTag represents a restricted version of the struct tag format used by encoding/json. It is used to describe the JSON encoding of fields in a Schema struct.
parseJSONTag parses a restricted version of the struct tag format used by encoding/json. The format of the tag must match that generated by the Schema.writeSchemaStruct method in the api generator.
func ( string) (jsonTag, error) {
	if  == "-" {
		return jsonTag{ignore: true}, nil
	}

	var  jsonTag

	 := strings.Index(, ",")
	if  == -1 || [:] == "" {
		return , fmt.Errorf("malformed json tag: %s", )
	}

	 = jsonTag{
		apiName: [:],
	}

	switch [+1:] {
	case "omitempty":
	case "omitempty,string":
		.stringFormat = true
	default:
		return , fmt.Errorf("malformed json tag: %s", )
	}

	return , nil
}
Reports whether the struct field "f" with value "v" should be included in JSON output.
The regular JSON encoding of a nil pointer is "null", which means "delete this field". Therefore, we could enable field deletion by honoring pointer fields' presence in the mustInclude set. However, many fields are not pointers, so there would be no way to delete these fields. Rather than partially supporting field deletion, we ignore mustInclude for nil pointer fields. Deletion will be handled by a separate mechanism.
	if .Type.Kind() == reflect.Ptr && .IsNil() {
		return false
	}
The "any" type is represented as an interface{}. If this interface is nil, there is no reasonable representation to send. We ignore these fields, for the same reasons as given above for pointers.
	if .Type.Kind() == reflect.Interface && .IsNil() {
		return false
	}

	return [.Name] || !isEmptyValue()
}
isEmptyValue reports whether v is the empty value for its type. This implementation is based on that of the encoding/json package, but its correctness does not depend on it being identical. What's important is that this function return false in situations where v should not be sent as part of a PATCH operation.
func ( reflect.Value) bool {
	switch .Kind() {
	case reflect.Array, reflect.Map, reflect.Slice, reflect.String:
		return .Len() == 0
	case reflect.Bool:
		return !.Bool()
	case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
		return .Int() == 0
	case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
		return .Uint() == 0
	case reflect.Float32, reflect.Float64:
		return .Float() == 0
	case reflect.Interface, reflect.Ptr:
		return .IsNil()
	}
	return false