コード例 #1
0
ファイル: main.go プロジェクト: Gladmir/go-diameter
func copyVendors(src []*Vendor, dst *dict.App) {
	for _, vendor := range src {
		dst.Vendor = append(dst.Vendor, &dict.Vendor{
			ID:   vendor.ID,
			Name: vendor.Name,
		})
	}
}
コード例 #2
0
ファイル: main.go プロジェクト: Gladmir/go-diameter
func copyCommands(src []*Cmd, dst *dict.App) {
	for _, cmd := range src {
		newCmd := &dict.Command{
			Code:  cmd.Code,
			Name:  cmd.Name,
			Short: cmd.Name,
		}
		copyCmdRules(cmd.Request.Fixed.Rule, &newCmd.Request, false)
		copyCmdRules(cmd.Request.Required.Rule, &newCmd.Request, true)
		copyCmdRules(cmd.Request.Optional.Rule, &newCmd.Request, false)
		copyCmdRules(cmd.Answer.Fixed.Rule, &newCmd.Answer, false)
		copyCmdRules(cmd.Answer.Required.Rule, &newCmd.Answer, true)
		copyCmdRules(cmd.Answer.Optional.Rule, &newCmd.Answer, false)
		dst.Command = append(dst.Command, newCmd)
	}
}
コード例 #3
0
ファイル: main.go プロジェクト: Gladmir/go-diameter
func copyAvps(src []*AVP, dst *dict.App) {
	for _, avp := range src {
		newAVP := &dict.AVP{
			Name: avp.Name,
			Code: avp.Code,
		}
		if avp.Type.Name == "" && avp.Grouped != nil {
			newAVP.Data = dict.Data{TypeName: "Grouped"}
		} else {
			newAVP.Data = dict.Data{TypeName: avp.Type.Name}
		}
		switch avp.MayEncrypt {
		case "yes":
			newAVP.MayEncrypt = "Y"
		case "no":
			newAVP.MayEncrypt = "N"
		default:
			newAVP.MayEncrypt = "-"
		}
		switch avp.Mandatory {
		case "must":
			newAVP.Must = "M"
		case "may":
			newAVP.May = "P"
		default:
			newAVP.Must = ""
		}
		if newAVP.May != "" {
			switch avp.Protected {
			case "may":
				newAVP.May = "P"
			default:
				newAVP.May = ""
			}
		}
		for _, p := range avp.Enum {
			newAVP.Data.Enum = append(newAVP.Data.Enum,
				&dict.Enum{
					Name: p.Name,
					Code: p.Code,
				})
		}
		for _, grp := range avp.Grouped {
			for _, p := range grp.GAVP {
				newAVP.Data.Rule = append(newAVP.Data.Rule,
					&dict.Rule{
						AVP: p.Name,
						Min: p.Min,
						Max: p.Max,
					})
			}
			for _, p := range grp.Required.Rule {
				newAVP.Data.Rule = append(newAVP.Data.Rule,
					&dict.Rule{
						AVP:      p.Name,
						Required: true,
						Min:      p.Min,
						Max:      p.Max,
					})
			}
			for _, p := range grp.Optional.Rule {
				newAVP.Data.Rule = append(newAVP.Data.Rule,
					&dict.Rule{
						AVP:      p.Name,
						Required: false,
						Min:      p.Min,
						Max:      p.Max,
					})
			}
		}
		dst.AVP = append(dst.AVP, newAVP)
	}
}