当前位置: 首页>>代码示例>>Golang>>正文


Golang Message.Address方法代码示例

本文整理汇总了Golang中github.com/scgolang/osc.Message.Address方法的典型用法代码示例。如果您正苦于以下问题:Golang Message.Address方法的具体用法?Golang Message.Address怎么用?Golang Message.Address使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/scgolang/osc.Message的用法示例。


在下文中一共展示了Message.Address方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: parseGroup

// parseGroup parses information about a group from a message
// received at /g_queryTree
// it *does not* recursively query for child groups
func parseGroup(msg *osc.Message) (*Group, error) {
	// return an error if msg.Address is not right
	if msg.Address() != gQueryTreeReply {
		return nil, fmt.Errorf("msg.Address should be %s, got %s", gQueryTreeReply, msg.Address())
	}
	// g_queryTree replies should have at least 3 arguments
	g, numArgs := new(Group), msg.CountArguments()
	if numArgs < 3 {
		return nil, fmt.Errorf("expected 3 arguments for message, got %d", numArgs)
	}
	// get the id of the group this reply is for
	nodeID, err := msg.ReadInt32()
	if err != nil {
		return nil, err
	}
	g.Node.id = nodeID

	// initialize the children array
	numChildren, err := msg.ReadInt32()
	if err != nil {
		return nil, err
	}
	if numChildren < 0 {
		return nil, fmt.Errorf("expected numChildren >= 0, got %d", numChildren)
	}
	g.children = make([]*Node, numChildren)
	// get the childrens' ids
	var numControls, numSubChildren int32
	for i := 3; i < numArgs; {
		nodeID, err = msg.ReadInt32()
		if err != nil {
			return nil, err
		}
		g.children[i-3] = &Node{nodeID}
		// get the number of children of this node
		// if -1 this is a synth, if >= 0 this is a group
		numSubChildren, err = msg.ReadInt32()
		if err != nil {
			return nil, err
		}
		if numSubChildren == -1 {
			// synth
			i += 3
			numControls, err = msg.ReadInt32()
			if err != nil {
				return nil, err
			}
			i += 1 + int(numControls*2)
		} else if numSubChildren >= 0 {
			// group
			i += 2
		}
	}
	return g, nil
}
开发者ID:go-on,项目名称:sc,代码行数:58,代码来源:group.go


注:本文中的github.com/scgolang/osc.Message.Address方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。