當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Message.Dictionary方法代碼示例

本文整理匯總了Golang中github.com/fiorix/go-diameter/diam.Message.Dictionary方法的典型用法代碼示例。如果您正苦於以下問題:Golang Message.Dictionary方法的具體用法?Golang Message.Dictionary怎麽用?Golang Message.Dictionary使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/fiorix/go-diameter/diam.Message的用法示例。


在下文中一共展示了Message.Dictionary方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: messageSetAVPsWithPath

// messageAddAVPsWithPath will dynamically add AVPs into the message
// 	append:	append to the message, on false overwrite if AVP is single or add to group if AVP is Grouped
func messageSetAVPsWithPath(m *diam.Message, path []interface{}, avpValStr string, appnd bool, timezone string) error {
	if len(path) == 0 {
		return errors.New("Empty path as AVP filter")
	}
	dictAVPs := make([]*dict.AVP, len(path)) // for each subpath, one dictionary AVP
	for i, subpath := range path {
		if dictAVP, err := m.Dictionary().FindAVP(m.Header.ApplicationID, subpath); err != nil {
			return err
		} else if dictAVP == nil {
			return fmt.Errorf("Cannot find AVP with id: %s", path[len(path)-1])
		} else {
			dictAVPs[i] = dictAVP
		}
	}
	if dictAVPs[len(path)-1].Data.Type == diam.GroupedAVPType {
		return errors.New("Last AVP in path needs not to be GroupedAVP")
	}
	var msgAVP *diam.AVP // Keep a reference here towards last AVP
	lastAVPIdx := len(path) - 1
	for i := lastAVPIdx; i >= 0; i-- {
		var typeVal datatype.Type
		if i == lastAVPIdx {
			avpValByte, err := serializeAVPValueFromString(dictAVPs[i], avpValStr, timezone)
			if err != nil {
				return err
			}
			typeVal, err = datatype.Decode(dictAVPs[i].Data.Type, avpValByte)
			if err != nil {
				return err
			}
		} else {
			typeVal = &diam.GroupedAVP{
				AVP: []*diam.AVP{msgAVP}}
		}
		newMsgAVP := diam.NewAVP(dictAVPs[i].Code, avp.Mbit, dictAVPs[i].VendorID, typeVal) // FixMe: maybe Mbit with dictionary one
		if i == lastAVPIdx-1 && !appnd {                                                    // last AVP needs to be appended in group
			avps, _ := m.FindAVPsWithPath(path[:lastAVPIdx], dict.UndefinedVendorID)
			if len(avps) != 0 { // Group AVP already in the message
				prevGrpData := avps[0].Data.(*diam.GroupedAVP)
				prevGrpData.AVP = append(prevGrpData.AVP, msgAVP)
				m.Header.MessageLength += uint32(msgAVP.Len())
				return nil
			}
		}
		msgAVP = newMsgAVP
	}
	if !appnd { // Not group AVP, replace the previous set one with this one
		avps, _ := m.FindAVPsWithPath(path, dict.UndefinedVendorID)
		if len(avps) != 0 { // Group AVP already in the message
			m.Header.MessageLength -= uint32(avps[0].Len()) // decrease message length since we overwrite
			*avps[0] = *msgAVP
			m.Header.MessageLength += uint32(msgAVP.Len())
			return nil
		}
	}
	m.AVP = append(m.AVP, msgAVP)
	m.Header.MessageLength += uint32(msgAVP.Len())
	return nil
}
開發者ID:bhepp,項目名稱:cgrates,代碼行數:61,代碼來源:libdmt.go

示例2: Parse

// Parse parses and validates the given message.
func (cea *CEA) Parse(m *diam.Message) (err error) {
	if err = m.Unmarshal(cea); err != nil {
		return err
	}
	if err = cea.sanityCheck(); err != nil {
		return err
	}
	app := &Application{
		AcctApplicationID:           cea.AcctApplicationID,
		AuthApplicationID:           cea.AuthApplicationID,
		VendorSpecificApplicationID: cea.VendorSpecificApplicationID,
	}
	if _, err := app.Parse(m.Dictionary()); err != nil {
		return err
	}
	cea.appID = app.ID()
	return nil
}
開發者ID:Gladmir,項目名稱:go-diameter,代碼行數:19,代碼來源:cea.go

示例3: Parse

// Parse parses and validates the given message, and returns nil when
// all AVPs are ok, and all accounting or authentication applications
// in the CER match the applications in our dictionary. If one or more
// mandatory AVPs are missing, it returns a nil failedAVP and a proper
// error. If all mandatory AVPs are present but no common application
// is found, then it returns the failedAVP (with the application that
// we don't support in our dictionary) and an error. Another cause
// for error is the presence of Inband Security, we don't support that.
func (cer *CER) Parse(m *diam.Message) (failedAVP *diam.AVP, err error) {
	if err = m.Unmarshal(cer); err != nil {
		return nil, err
	}
	if err = cer.sanityCheck(); err != nil {
		return nil, err
	}
	if cer.InbandSecurityID != nil {
		if v := cer.InbandSecurityID.Data.(datatype.Unsigned32); v != 0 {
			return cer.InbandSecurityID, ErrNoCommonSecurity
		}
	}
	app := &Application{
		AcctApplicationID:           cer.AcctApplicationID,
		AuthApplicationID:           cer.AuthApplicationID,
		VendorSpecificApplicationID: cer.VendorSpecificApplicationID,
	}
	if failedAVP, err = app.Parse(m.Dictionary()); err != nil {
		return failedAVP, err
	}
	cer.appID = app.ID()
	return nil, nil
}
開發者ID:aSimpleboy,項目名稱:go-diameter,代碼行數:31,代碼來源:cer.go


注:本文中的github.com/fiorix/go-diameter/diam.Message.Dictionary方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。