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


Golang proto.Bool函数代码示例

本文整理汇总了Golang中goprotobuf/googlecode/com/hg/proto.Bool函数的典型用法代码示例。如果您正苦于以下问题:Golang Bool函数的具体用法?Golang Bool怎么用?Golang Bool使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: toProto

// toProto converts the query to a protocol buffer.
func (q *Query) toProto(appID string) (*pb.Query, os.Error) {
	if q.kind == "" {
		return nil, os.NewError("datastore: empty query kind")
	}
	x := &pb.Query{
		App:  proto.String(appID),
		Kind: proto.String(q.kind),
	}
	if q.ancestor != nil {
		x.Ancestor = keyToProto(appID, q.ancestor)
	}
	if q.keysOnly {
		x.KeysOnly = proto.Bool(true)
		x.RequirePerfectPlan = proto.Bool(true)
	}
	for _, qf := range q.filter {
		if qf.FieldName == "" {
			return nil, os.NewError("datastore: empty query filter field name")
		}
		p, errStr := valueToProto(appID, qf.FieldName, reflect.ValueOf(qf.Value), false)
		if errStr != "" {
			return nil, os.NewError("datastore: bad query filter value type: " + errStr)
		}
		xf := &pb.Query_Filter{
			Op:       operatorToProto[qf.Op],
			Property: []*pb.Property{p},
		}
		if xf.Op == nil {
			return nil, os.NewError("datastore: unknown query filter operator")
		}
		x.Filter = append(x.Filter, xf)
	}
	for _, qo := range q.order {
		if qo.FieldName == "" {
			return nil, os.NewError("datastore: empty query order field name")
		}
		xo := &pb.Query_Order{
			Property:  proto.String(qo.FieldName),
			Direction: sortDirectionToProto[qo.Direction],
		}
		if xo.Direction == nil {
			return nil, os.NewError("datastore: unknown query order direction")
		}
		x.Order = append(x.Order, xo)
	}
	if q.limit != 0 {
		x.Limit = proto.Int(q.limit)
	}
	if q.offset != 0 {
		x.Offset = proto.Int(q.offset)
	}
	return x, nil
}
开发者ID:sarnowski,项目名称:google-go-lang-idea-plugin,代码行数:54,代码来源:query.go

示例2: toProto

// toProto converts the query to a protocol buffer.
func (q *Query) toProto(dst *pb.Query, appID string, zlp zeroLimitPolicy) error {
	if q.kind == "" {
		return errors.New("datastore: empty query kind")
	}
	dst.Reset()
	dst.App = proto.String(appID)
	dst.Kind = proto.String(q.kind)
	if q.ancestor != nil {
		dst.Ancestor = keyToProto(appID, q.ancestor)
	}
	if q.keysOnly {
		dst.KeysOnly = proto.Bool(true)
		dst.RequirePerfectPlan = proto.Bool(true)
	}
	for _, qf := range q.filter {
		if qf.FieldName == "" {
			return errors.New("datastore: empty query filter field name")
		}
		p, errStr := valueToProto(appID, qf.FieldName, reflect.ValueOf(qf.Value), false)
		if errStr != "" {
			return errors.New("datastore: bad query filter value type: " + errStr)
		}
		xf := &pb.Query_Filter{
			Op:       operatorToProto[qf.Op],
			Property: []*pb.Property{p},
		}
		if xf.Op == nil {
			return errors.New("datastore: unknown query filter operator")
		}
		dst.Filter = append(dst.Filter, xf)
	}
	for _, qo := range q.order {
		if qo.FieldName == "" {
			return errors.New("datastore: empty query order field name")
		}
		xo := &pb.Query_Order{
			Property:  proto.String(qo.FieldName),
			Direction: sortDirectionToProto[qo.Direction],
		}
		if xo.Direction == nil {
			return errors.New("datastore: unknown query order direction")
		}
		dst.Order = append(dst.Order, xo)
	}
	if q.limit != 0 || zlp == zeroLimitMeansZero {
		dst.Limit = proto.Int32(q.limit)
	}
	if q.offset != 0 {
		dst.Offset = proto.Int32(q.offset)
	}
	return nil
}
开发者ID:ashokgelal,项目名称:gorilla,代码行数:53,代码来源:query.go

示例3: valueToProto

// valueToProto converts a named value to a newly allocated Property.
// The returned error string is empty on success.
func valueToProto(defaultAppID, name string, v reflect.Value, multiple bool) (p *pb.Property, errStr string) {
	var (
		pv          pb.PropertyValue
		unsupported bool
	)
	switch v.Kind() {
	case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
		pv.Int64Value = proto.Int64(v.Int())
	case reflect.Bool:
		pv.BooleanValue = proto.Bool(v.Bool())
	case reflect.String:
		pv.StringValue = proto.String(v.String())
	case reflect.Float32, reflect.Float64:
		pv.DoubleValue = proto.Float64(v.Float())
	case reflect.Ptr:
		if k, ok := v.Interface().(*Key); ok {
			if k == nil {
				return nil, nilKeyErrStr
			}
			pv.Referencevalue = keyToReferenceValue(defaultAppID, k)
		} else {
			unsupported = true
		}
	case reflect.Slice:
		if b, ok := v.Interface().([]byte); ok {
			pv.StringValue = proto.String(string(b))
		} else {
			// nvToProto should already catch slice values.
			// If we get here, we have a slice of slice values.
			unsupported = true
		}
	default:
		unsupported = true
	}
	if unsupported {
		return nil, "unsupported datastore value type: " + v.Type().String()
	}
	p = &pb.Property{
		Name:     proto.String(name),
		Value:    &pv,
		Multiple: proto.Bool(multiple),
	}
	switch v.Interface().(type) {
	case []byte:
		p.Meaning = pb.NewProperty_Meaning(pb.Property_BLOB)
	case appengine.BlobKey:
		p.Meaning = pb.NewProperty_Meaning(pb.Property_BLOBKEY)
	case Time:
		p.Meaning = pb.NewProperty_Meaning(pb.Property_GD_WHEN)
	}
	return p, ""
}
开发者ID:sarnowski,项目名称:google-go-lang-idea-plugin,代码行数:54,代码来源:save.go

示例4: userEnterChannel

// Helper method for users entering new channels
func (server *Server) userEnterChannel(client *Client, channel *Channel, userstate *mumbleproto.UserState) {
	if client.Channel == channel {
		return
	}

	oldchan := client.Channel
	if oldchan != nil {
		oldchan.RemoveClient(client)
	}
	channel.AddClient(client)

	server.ClearACLCache()
	// fixme(mkrautz): Set LastChannel for user in datastore
	// fixme(mkrautz): Remove channel if temporary

	canspeak := server.HasPermission(client, channel, SpeakPermission)
	if canspeak == client.Suppress {
		client.Suppress = !canspeak
		userstate.Suppress = proto.Bool(client.Suppress)
	}

	server.sendClientPermissions(client, channel)
	if channel.parent != nil {
		server.sendClientPermissions(client, channel.parent)
	}
}
开发者ID:pcgod,项目名称:grumble,代码行数:27,代码来源:server.go

示例5: readField

// Reads a single arbitrary type and returns the proper StateValue.
func readField(val reflect.Value) *protocol.StateValue {
	msg := &protocol.StateValue{}
	switch f := val.(type) {
	case *reflect.BoolValue:
		msg.Type = protocol.NewStateValue_Type(protocol.StateValue_BOOL)
		msg.BoolVal = proto.Bool(f.Get())
	case *reflect.IntValue:
		msg.Type = protocol.NewStateValue_Type(protocol.StateValue_INT)
		msg.IntVal = proto.Int(int(f.Get()))
	case *reflect.FloatValue:
		msg.Type = protocol.NewStateValue_Type(protocol.StateValue_FLOAT)
		msg.FloatVal = proto.Float32(float32(f.Get()))
	case *reflect.StringValue:
		msg.Type = protocol.NewStateValue_Type(protocol.StateValue_STRING)
		msg.StringVal = proto.String(f.Get())
	case *reflect.SliceValue:
		msg.Type = protocol.NewStateValue_Type(protocol.StateValue_ARRAY)
		msg.ArrayVal = makeStateValueArray(f, f.Len())
	case *reflect.StructValue:
		msg = readStructField(f)
	case *reflect.PtrValue:
		return readField(reflect.Indirect(f)) // Dereference and recurse
	default:
		panic("State value not supported: " + val.Type().String())
	}
	return msg
}
开发者ID:archwyrm,项目名称:ghack,代码行数:28,代码来源:statevalue.go

示例6: updateCodecVersions

func (server *Server) updateCodecVersions() {
	codecusers := map[int32]int{}
	var winner int32
	var count int

	for _, client := range server.clients {
		for _, codec := range client.codecs {
			codecusers[codec] += 1
		}
	}

	for codec, users := range codecusers {
		if users > count {
			count = users
			winner = codec
		}
		if users == count && codec > winner {
			winner = codec
		}
	}

	var current int32
	if server.PreferAlphaCodec {
		current = server.AlphaCodec
	} else {
		current = server.BetaCodec
	}

	if winner == current {
		return
	}

	if winner == CeltCompatBitstream {
		server.PreferAlphaCodec = true
	} else {
		server.PreferAlphaCodec = !server.PreferAlphaCodec
	}

	if server.PreferAlphaCodec {
		server.AlphaCodec = winner
	} else {
		server.BetaCodec = winner
	}

	err := server.broadcastProtoMessage(MessageCodecVersion, &mumbleproto.CodecVersion{
		Alpha:       proto.Int32(server.AlphaCodec),
		Beta:        proto.Int32(server.BetaCodec),
		PreferAlpha: proto.Bool(server.PreferAlphaCodec),
	})
	if err != nil {
		log.Printf("Unable to broadcast.")
		return
	}

	log.Printf("CELT codec switch %#x %#x (PreferAlpha %v)", uint32(server.AlphaCodec), uint32(server.BetaCodec), server.PreferAlphaCodec)
	return
}
开发者ID:pcgod,项目名称:grumble,代码行数:57,代码来源:server.go

示例7: set

// set sets the given items using the given conflict resolution policy.
// The returned slice will have the same length as the input slice.
// If value is not nil, each element should correspond to an item.
func set(c appengine.Context, item []*Item, value [][]byte, policy int32) []os.Error {
	req := &pb.MemcacheSetRequest{
		Item: make([]*pb.MemcacheSetRequest_Item, len(item)),
	}
	for i, t := range item {
		p := &pb.MemcacheSetRequest_Item{
			Key: []byte(t.Key),
		}
		if value == nil {
			p.Value = t.Value
		} else {
			p.Value = value[i]
		}
		if t.Flags != 0 {
			p.Flags = proto.Uint32(t.Flags)
		}
		if t.Expiration != 0 {
			// In the .proto file, MemcacheSetRequest_Item uses a fixed32 (i.e. unsigned)
			// for expiration time, while MemcacheGetRequest_Item uses int32 (i.e. signed).
			// Throughout this .go file, we use int32.
			p.ExpirationTime = proto.Uint32(uint32(t.Expiration))
		}
		if t.casID != 0 {
			p.CasId = proto.Uint64(t.casID)
			p.ForCas = proto.Bool(true)
		}
		p.SetPolicy = pb.NewMemcacheSetRequest_SetPolicy(policy)
		req.Item[i] = p
	}
	res := &pb.MemcacheSetResponse{}
	e := make([]os.Error, len(item))
	if err := c.Call("memcache", "Set", req, res); err != nil {
		for i := range e {
			e[i] = err
		}
		return e
	}
	if len(e) != len(res.SetStatus) {
		for i := range e {
			e[i] = ErrServerError
		}
		return e
	}
	for i := range e {
		switch res.SetStatus[i] {
		case pb.MemcacheSetResponse_STORED:
			e[i] = nil
		case pb.MemcacheSetResponse_NOT_STORED:
			e[i] = ErrNotStored
		case pb.MemcacheSetResponse_EXISTS:
			e[i] = ErrCASConflict
		default:
			e[i] = ErrServerError
		}
	}
	return e
}
开发者ID:sarnowski,项目名称:google-go-lang-idea-plugin,代码行数:60,代码来源:memcache.go

示例8: makeLoginResult

func makeLoginResult(succeeded bool, reason int32) (msg *protocol.Message) {
	loginResult := &protocol.LoginResult{
		Succeeded: proto.Bool(succeeded),
		Reason:    protocol.NewLoginResult_Reason(reason),
	}

	return &protocol.Message{
		LoginResult: loginResult,
		Type:        protocol.NewMessage_Type(protocol.Message_LOGINRESULT),
	}
}
开发者ID:archwyrm,项目名称:ghack,代码行数:11,代码来源:messages.go

示例9: newTestMessage

func newTestMessage() *pb.MyMessage {
	msg := &pb.MyMessage{
		Count: proto.Int32(42),
		Name:  proto.String("Dave"),
		Quote: proto.String(`"I didn't want to go."`),
		Pet:   []string{"bunny", "kitty", "horsey"},
		Inner: &pb.InnerMessage{
			Host:      proto.String("footrest.syd"),
			Port:      proto.Int32(7001),
			Connected: proto.Bool(true),
		},
		Others: []*pb.OtherMessage{
			&pb.OtherMessage{
				Key:   proto.Int64(0xdeadbeef),
				Value: []byte{1, 65, 7, 12},
			},
			&pb.OtherMessage{
				Weight: proto.Float32(6.022),
				Inner: &pb.InnerMessage{
					Host: proto.String("lesha.mtv"),
					Port: proto.Int32(8002),
				},
			},
		},
		Bikeshed: pb.NewMyMessage_Color(pb.MyMessage_BLUE),
		Somegroup: &pb.MyMessage_SomeGroup{
			GroupField: proto.Int32(8),
		},
		// One normally wouldn't do this.
		// This is an undeclared tag 13, as a varint (wire type 0) with value 4.
		XXX_unrecognized: []byte{13<<3 | 0, 4},
	}
	ext := &pb.Ext{
		Data: proto.String("Big gobs for big rats"),
	}
	if err := proto.SetExtension(msg, pb.E_Ext_More, ext); err != nil {
		panic(err)
	}

	// Add an unknown extension. We marshal a pb.Ext, and fake the ID.
	b, err := proto.Marshal(&pb.Ext{Data: proto.String("3G skiing")})
	if err != nil {
		panic(err)
	}
	b = append(proto.EncodeVarint(104<<3|proto.WireBytes), b...)
	proto.SetRawExtension(msg, 104, b)

	// Extensions can be plain fields, too, so let's test that.
	b = append(proto.EncodeVarint(105<<3|proto.WireVarint), 19)
	proto.SetRawExtension(msg, 105, b)

	return msg
}
开发者ID:ashokgelal,项目名称:gorilla,代码行数:53,代码来源:text_test.go

示例10: runPlugin

// chasing a moving target with exec here. currently it's kind of
// clumsy to pull out the return code. with luck the target will
// move again in a way i like.
func runPlugin(cmd, env []string, timeout int64) (result *CheckResult) {
	var output bytes.Buffer
	rc := 0
	log.Printf("running check %s", cmd)

	/* c := exec.Command(cmd[0], cmd...)*/
	c := exec.Command(cmd[0], cmd[1:]...)
	c.Stdout = &output
	starttime := time.Nanoseconds()
	err := c.Start()
	if err != nil {
		log.Fatal("Error running command ", cmd, ": ", err)
	}
	defer c.Process.Release()
	timer := time.AfterFunc(timeout, func() { c.Process.Kill() })
	err = c.Wait()
	timer.Stop()
	endtime := time.Nanoseconds()
	/* log.Print(msg)*/
	if err != nil {
		if msg, ok := err.(*os.Waitmsg); ok {
			rc = msg.ExitStatus()
		} else {
			log.Print("Error running command ", cmd, ": ", err)
		}
	}

	result = &CheckResult{
		StartTimestamp: proto.Int64(starttime),
		EndTimestamp:   proto.Int64(endtime),
		Status:         NewCheckStatus(CheckStatus(rc)),
		CheckPassive:   proto.Bool(*flagPassive),
	}
	switch rc {
	case 0, 1, 2, 3:
		// this is ok!
		log.Printf("%s: returned %s", cmd, CheckStatus_name[int32(rc)])
		result.Status = NewCheckStatus(CheckStatus(rc))
		result.CheckOutput = proto.String(string(bytes.TrimSpace(output.Bytes())))
		break
	default:
		// XXX check for timeout/sig9, presently assumed
		log.Printf("%s: return code %d", cmd, rc)
		result.Status = NewCheckStatus(CheckStatus_UNKNOWN)
		result.CheckOutput = proto.String(fmt.Sprintf("UNKNOWN: Command timed out after %d seconds\n", *flagCmdTimeout) + string(bytes.TrimSpace(output.Bytes())))
	}
	return result
}
开发者ID:pjjw,项目名称:ncd,代码行数:51,代码来源:send_check.go

示例11: runOnce

func runOnce(c appengine.Context, f func(appengine.Context) error, opts *TransactionOptions) error {
	// Begin the transaction.
	t := &transaction{Context: c}
	req := &pb.BeginTransactionRequest{
		App: proto.String(c.FullyQualifiedAppID()),
	}
	if opts != nil && opts.XG {
		req.AllowMultipleEg = proto.Bool(true)
	}
	if err := t.Context.Call("datastore_v3", "BeginTransaction", req, &t.transaction, nil); err != nil {
		return err
	}

	// Call f, rolling back the transaction if f returns a non-nil error, or panics.
	// The panic is not recovered.
	defer func() {
		if t.finished {
			return
		}
		t.finished = true
		// Ignore the error return value, since we are already returning a non-nil
		// error (or we're panicking).
		c.Call("datastore_v3", "Rollback", &t.transaction, &pb.VoidProto{}, nil)
	}()
	if err := f(t); err != nil {
		return err
	}
	t.finished = true

	// Commit the transaction.
	res := &pb.CommitResponse{}
	err := c.Call("datastore_v3", "Commit", &t.transaction, res, nil)
	if ae, ok := err.(*appengine_internal.APIError); ok {
		if appengine.IsDevAppServer() {
			// The Python Dev AppServer raises an ApplicationError with error code 2 (which is
			// Error.CONCURRENT_TRANSACTION) and message "Concurrency exception.".
			if ae.Code == int32(pb.Error_BAD_REQUEST) && ae.Detail == "ApplicationError: 2 Concurrency exception." {
				return ErrConcurrentTransaction
			}
		}
		if ae.Code == int32(pb.Error_CONCURRENT_TRANSACTION) {
			return ErrConcurrentTransaction
		}
	}
	return err
}
开发者ID:ashokgelal,项目名称:gorilla,代码行数:46,代码来源:transaction.go

示例12: callNext

// callNext issues a datastore_v3/Next RPC to advance a cursor, such as that
// returned by a query with more results.
func callNext(c appengine.Context, res *pb.QueryResult, offset, limit int32, zlp zeroLimitPolicy) error {
	if res.Cursor == nil {
		return errors.New("datastore: internal error: server did not return a cursor")
	}
	// TODO: should I eventually call datastore_v3/DeleteCursor on the cursor?
	req := &pb.NextRequest{
		Cursor: res.Cursor,
		Offset: proto.Int32(offset),
	}
	if limit != 0 || zlp == zeroLimitMeansZero {
		req.Count = proto.Int32(limit)
	}
	if res.CompiledCursor != nil {
		req.Compile = proto.Bool(true)
	}
	res.Reset()
	return c.Call("datastore_v3", "Next", req, res, nil)
}
开发者ID:ashokgelal,项目名称:gorilla,代码行数:20,代码来源:query.go

示例13: sendChannelTree

func (client *Client) sendChannelTree(channel *Channel) {
	chanstate := &mumbleproto.ChannelState{
		ChannelId: proto.Uint32(uint32(channel.Id)),
		Name:      proto.String(channel.Name),
	}
	if channel.parent != nil {
		chanstate.Parent = proto.Uint32(uint32(channel.parent.Id))
	}

	if channel.HasDescription() {
		if client.Version >= 0x10202 {
			chanstate.DescriptionHash = channel.DescriptionBlobHashBytes()
		} else {
			buf, err := globalBlobstore.Get(channel.DescriptionBlob)
			if err != nil {
				panic("Blobstore error.")
			}
			chanstate.Description = proto.String(string(buf))
		}
	}

	if channel.Temporary {
		chanstate.Temporary = proto.Bool(true)
	}

	chanstate.Position = proto.Int32(int32(channel.Position))

	links := []uint32{}
	for cid, _ := range channel.Links {
		links = append(links, uint32(cid))
	}
	chanstate.Links = links

	err := client.sendProtoMessage(MessageChannelState, chanstate)
	if err != nil {
		client.Panic(err.String())
	}

	for _, subchannel := range channel.children {
		client.sendChannelTree(subchannel)
	}
}
开发者ID:pcgod,项目名称:grumble,代码行数:42,代码来源:client.go

示例14: GetMulti

// GetMulti is a batch version of Get. The returned map from keys to items may
// have fewer elements than the input slice, due to memcache cache misses.
// Each key must be at most 250 bytes in length.
func GetMulti(c appengine.Context, key []string) (map[string]*Item, os.Error) {
	keyAsBytes := make([][]byte, len(key))
	for i, k := range key {
		keyAsBytes[i] = []byte(k)
	}
	req := &pb.MemcacheGetRequest{
		Key:    keyAsBytes,
		ForCas: proto.Bool(true),
	}
	res := &pb.MemcacheGetResponse{}
	if err := c.Call("memcache", "Get", req, res); err != nil {
		return nil, err
	}
	m := make(map[string]*Item, len(res.Item))
	for _, p := range res.Item {
		t := protoToItem(p)
		m[t.Key] = t
	}
	return m, nil
}
开发者ID:sarnowski,项目名称:google-go-lang-idea-plugin,代码行数:23,代码来源:memcache.go

示例15: Close

// Close flushes outstanding buffered writes and finalizes the blob. After
// calling Close the key can be retrieved by calling Key.
func (w *Writer) Close() (closeErr error) {
	defer func() {
		// Save the error for Key
		w.closeErr = closeErr
	}()
	if w.closed {
		return errorf("Writer is already closed")
	}
	w.closed = true
	w.flush()
	if w.writeErr != nil {
		return w.writeErr
	}
	req := &files.CloseRequest{
		Filename: proto.String(w.filename),
		Finalize: proto.Bool(true),
	}
	res := &files.CloseResponse{}
	return w.c.Call("file", "Close", req, res, nil)
}
开发者ID:ashokgelal,项目名称:gorilla,代码行数:22,代码来源:blobstore.go


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