1{{define "minWireVersion" -}} 2{{- if $.MinWireVersion -}} 3 && (desc.WireVersion != nil && desc.WireVersion.Includes({{$.MinWireVersion}})) 4{{- end}}{{end}} 5 6{{define "minWireVersionRequired"}} 7{{- if $.MinWireVersionRequired}} 8if desc.WireVersion == nil || !desc.WireVersion.Includes({{$.MinWireVersionRequired}}) { 9 return nil, errors.New("the '{{$.ParameterName}}' command parameter requires a minimum server wire version of {{$.MinWireVersionRequired}}") 10} 11{{end}}{{end}} 12 13{{define "commandParamCollectionDatabase" -}} 14header := bsoncore.Value{Type: bsontype.String, Data: bsoncore.AppendString(nil, {{$.ShortName}}.collection)} 15if {{$.ShortName}}.collection == "" { 16 header = bsoncore.Value{Type: bsontype.Int32, Data: []byte{0x01, 0x00, 0x00, 0x00}} 17} 18dst = bsoncore.AppendValueElement(dst, "{{$.Command.Name}}", header) 19{{end}} 20 21{{define "commandParamDatabase"}} 22dst = bsoncore.AppendInt32Element(dst, "{{$.Command.Name}}", 1) 23{{end}} 24 25{{define "commandParamCollection" -}} 26dst = bsoncore.AppendStringElement(dst, "{{$.Command.Name}}", {{$.ShortName}}.collection) 27{{end}} 28 29{{define "commandParamDocument" -}} 30if {{$.ShortName}}.{{$.Name}} != nil {{template "minWireVersion" $}} { 31 {{- template "minWireVersionRequired" $ -}} 32 dst = bsoncore.AppendDocumentElement(dst, "{{$.ParameterName}}", {{$.ShortName}}.{{$.Name}}) 33} 34{{end}} 35 36{{define "commandParamArray" -}} 37if {{$.ShortName}}.{{$.Name}} != nil {{template "minWireVersion" $}} { 38 {{- template "minWireVersionRequired" $ -}} 39 dst = bsoncore.AppendArrayElement(dst, "{{$.ParameterName}}", {{$.ShortName}}.{{$.Name}}) 40} 41{{end}} 42 43{{define "commandParamValue" -}} 44if {{$.ShortName}}.{{$.Name}}.Type != bsontype.Type(0) {{template "minWireVersion" $}} { 45 {{- template "minWireVersionRequired" $ -}} 46 dst = bsoncore.AppendValueElement(dst, "{{$.ParameterName}}", {{$.ShortName}}.{{$.Name}}) 47} 48{{end}} 49 50{{define "commandParamInt32" -}} 51if {{$.ShortName}}.{{$.Name}} != nil {{template "minWireVersion" $}} { 52 {{- template "minWireVersionRequired" $ -}} 53 dst = bsoncore.AppendInt32Element(dst, "{{$.ParameterName}}", *{{$.ShortName}}.{{$.Name}}) 54} 55{{end}} 56 57{{define "commandParamInt64" -}} 58if {{$.ShortName}}.{{$.Name}} != nil {{template "minWireVersion" $}} { 59 {{- template "minWireVersionRequired" $ -}} 60 dst = bsoncore.AppendInt64Element(dst, "{{$.ParameterName}}", *{{$.ShortName}}.{{$.Name}}) 61} 62{{end}} 63 64{{define "commandParamDouble" -}} 65if {{$.ShortName}}.{{$.Name}} != nil {{template "minWireVersion" $}} { 66 {{- template "minWireVersionRequired" $ -}} 67 dst = bsoncore.AppendDoubleElement(dst, "{{$.ParameterName}}", *{{$.ShortName}}.{{$.Name}}) 68} 69{{end}} 70 71{{define "commandParamBoolean" -}} 72if {{$.ShortName}}.{{$.Name}} != nil {{template "minWireVersion" $}} { 73 {{- template "minWireVersionRequired" $ -}} 74 dst = bsoncore.AppendBooleanElement(dst, "{{$.ParameterName}}", *{{$.ShortName}}.{{$.Name}}) 75} 76{{end}} 77 78{{define "commandParamString" -}} 79if {{$.ShortName}}.{{$.Name}} != nil {{template "minWireVersion" $}} { 80 {{- template "minWireVersionRequired" $ -}} 81 dst = bsoncore.AppendStringElement(dst, "{{$.ParameterName}}", *{{$.ShortName}}.{{$.Name}}) 82} 83{{end}} 84