func newPresenceResponse(isAvailable bool, presence pb.PresenceResponse_SHOW, valid bool) *pb.PresenceResponse { return &pb.PresenceResponse{ IsAvailable: proto.Bool(isAvailable), Presence: presence.Enum(), Valid: proto.Bool(valid), } }
func TestParseSectionDnsTableA_Valid(t *testing.T) { lines := []string{ "10 11", "12 13 0 DOM1 IP1 14", "15 16 1 DOM2 IP2 17", } trace := Trace{} err := parseSectionDnsTableA(lines, &trace) if err != nil { t.Fatal("Unexpected error:", err) } expectedTrace := Trace{ ARecordsDropped: proto.Int32(10), CnameRecordsDropped: proto.Int32(11), ARecord: []*DnsARecord{ &DnsARecord{ PacketId: proto.Int32(12), AddressId: proto.Int32(13), Anonymized: proto.Bool(false), Domain: proto.String("DOM1"), IpAddress: proto.String("IP1"), Ttl: proto.Int32(14), }, &DnsARecord{ PacketId: proto.Int32(15), AddressId: proto.Int32(16), Anonymized: proto.Bool(true), Domain: proto.String("DOM2"), IpAddress: proto.String("IP2"), Ttl: proto.Int32(17), }, }, } checkProtosEqual(t, &expectedTrace, &trace) }
// toProto converts the query to a protocol buffer. func (q *Query) toProto(dst *pb.Query, appID string) 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 { dst.Limit = proto.Int32(q.limit) } if q.offset != 0 { dst.Offset = proto.Int32(q.offset) } dst.CompiledCursor = q.start dst.EndCompiledCursor = q.end dst.Compile = proto.Bool(true) return nil }
func fakeRunQuery(in *pb.Query, out *pb.QueryResult) error { expectedIn := &pb.Query{ App: proto.String("dev~fake-app"), Kind: proto.String("Gopher"), Compile: proto.Bool(true), } if !proto.Equal(in, expectedIn) { return fmt.Errorf("unsupported argument: got %v want %v", in, expectedIn) } *out = pb.QueryResult{ Result: []*pb.EntityProto{ { Key: &pb.Reference{ App: proto.String("s~test-app"), Path: path1, }, EntityGroup: path1, Property: []*pb.Property{ { Meaning: pb.Property_TEXT.Enum(), Name: proto.String("Name"), Value: &pb.PropertyValue{ StringValue: proto.String("George"), }, }, { Name: proto.String("Height"), Value: &pb.PropertyValue{ Int64Value: proto.Int64(32), }, }, }, }, { Key: &pb.Reference{ App: proto.String("s~test-app"), Path: path2, }, EntityGroup: path1, // ancestor is George Property: []*pb.Property{ { Meaning: pb.Property_TEXT.Enum(), Name: proto.String("Name"), Value: &pb.PropertyValue{ StringValue: proto.String("Rufus"), }, }, // No height for Rufus. }, }, }, MoreResults: proto.Bool(false), } return nil }
// Freeze a Group into a flattened protobuf-based structure // ready to be persisted to disk. func FreezeGroup(group acl.Group) (*freezer.Group, error) { frozenGroup := &freezer.Group{} frozenGroup.Name = proto.String(group.Name) frozenGroup.Inherit = proto.Bool(group.Inherit) frozenGroup.Inheritable = proto.Bool(group.Inheritable) for _, id := range group.AddUsers() { frozenGroup.Add = append(frozenGroup.Add, uint32(id)) } for _, id := range group.RemoveUsers() { frozenGroup.Remove = append(frozenGroup.Remove, uint32(id)) } return frozenGroup, nil }
// Freeze a ChannelACL into it a flattened protobuf-based structure // ready to be persisted to disk. func FreezeACL(aclEntry acl.ACL) (*freezer.ACL, error) { frozenAcl := &freezer.ACL{} if aclEntry.UserId != -1 { frozenAcl.UserId = proto.Uint32(uint32(aclEntry.UserId)) } else { frozenAcl.Group = proto.String(aclEntry.Group) } frozenAcl.ApplyHere = proto.Bool(aclEntry.ApplyHere) frozenAcl.ApplySubs = proto.Bool(aclEntry.ApplySubs) frozenAcl.Allow = proto.Uint32(uint32(aclEntry.Allow)) frozenAcl.Deny = proto.Uint32(uint32(aclEntry.Deny)) return frozenAcl, nil }
func (p *Peer) handleHello(m *Manager, hello *protocol.Hello) { cookie, err := p.getSessionCookie() if err != nil { glog.Errorf("%s:Bad cookie: %s", p.String(), err.Error()) p.UpdateStatus(HelloFailed) return } pubKey, err := crypto.ParsePublicKeyFromHash(hello.GetNodePublic()) if err != nil { glog.Errorf("Bad public key: %X", hello.GetNodePublic()) p.UpdateStatus(HelloFailed) return } ok, err := crypto.Verify(pubKey.SerializeUncompressed(), hello.GetNodeProof(), cookie) if !ok { glog.Errorf("%s:Bad signature: %X public key: %X hash: %X", p.String(), hello.GetNodeProof(), hello.GetNodePublic(), cookie) p.UpdateStatus(HelloFailed) return } if err != nil { glog.Errorf("%s:Bad signature verification: %s", p.String(), err.Error()) p.UpdateStatus(HelloFailed) return } proof, err := m.Key.Sign(cookie) if err != nil { glog.Errorf("%s:Bad signature creation: %X", p.String(), cookie) p.UpdateStatus(HelloFailed) return } if err := p.ProcessHello(hello); err != nil { glog.Errorf("%s:%s", p.String(), err.Error()) return } port, _ := strconv.ParseUint(m.Port, 10, 32) p.Outgoing <- &protocol.TMHello{ FullVersion: proto.String(m.Name), ProtoVersion: proto.Uint32(uint32(maxVersion)), ProtoVersionMin: proto.Uint32(uint32(minVersion)), NodePublic: []byte(m.PublicKey.String()), NodeProof: proof, Ipv4Port: proto.Uint32(uint32(port)), NetTime: proto.Uint64(uint64(data.Now().Uint32())), NodePrivate: proto.Bool(true), TestNet: proto.Bool(false), } if hello.ProofOfWork != nil { go p.handleProofOfWork(hello.ProofOfWork) } }
func parseSuccessCode(succ uint32) *contester_proto.ExecutionResultFlags { if succ == 0 { return nil } result := &contester_proto.ExecutionResultFlags{} if succ&subprocess.EF_KILLED != 0 { result.Killed = proto.Bool(true) } if succ&subprocess.EF_TIME_LIMIT_HIT != 0 { result.TimeLimitHit = proto.Bool(true) } if succ&subprocess.EF_MEMORY_LIMIT_HIT != 0 { result.MemoryLimitHit = proto.Bool(true) } if succ&subprocess.EF_INACTIVE != 0 { result.Inactive = proto.Bool(true) } if succ&subprocess.EF_TIME_LIMIT_HARD != 0 { result.TimeLimitHard = proto.Bool(true) } if succ&subprocess.EF_TIME_LIMIT_HIT_POST != 0 { result.TimeLimitHitPost = proto.Bool(true) } if succ&subprocess.EF_MEMORY_LIMIT_HIT_POST != 0 { result.MemoryLimitHitPost = proto.Bool(true) } if succ&subprocess.EF_PROCESS_LIMIT_HIT != 0 { result.ProcessLimitHit = proto.Bool(true) } return result }
func duplicateProtoList(duplicates []*models.DuplicateData, configs []*models.ConfigDuplicate) []*protodata.ChapterData { //list := models.ConfigDuplicateList() var result []*protodata.ChapterData result = append(result, &protodata.ChapterData{ ChapterId: proto.Int32(int32(configs[0].Chapter)), ChapterName: proto.String(configs[0].ChapterName), ChapterDesc: proto.String(""), IsUnlock: proto.Bool(true), }) for index, section := range configs { var sectionProto protodata.SectionData sectionProto.SectionId = proto.Int32(int32(section.Section)) sectionProto.SectionName = proto.String(section.SectionName) sectionProto.SectionDesc = proto.String("") sectionProto.IsUnlock = proto.Bool(true) var find bool if index > 0 { for _, d := range duplicates { if d.Chapter == configs[index-1].Chapter && d.Section == configs[index-1].Section { find = true break } else { find = false } } if !find { sectionProto.IsUnlock = proto.Bool(false) } } if section.Chapter != int(*result[len(result)-1].ChapterId) { result = append(result, &protodata.ChapterData{ ChapterId: proto.Int32(int32(section.Chapter)), ChapterName: proto.String(section.ChapterName), ChapterDesc: proto.String(""), IsUnlock: proto.Bool(find), }) } result[len(result)-1].Sections = append(result[len(result)-1].Sections, §ionProto) } return result }
// Freeze a ChannelACL into it a flattened protobuf-based structure // ready to be persisted to disk. func (acl *ChannelACL) Freeze() (facl *freezer.ACL, err error) { facl = new(freezer.ACL) if acl.UserId != -1 { facl.UserId = proto.Uint32(uint32(acl.UserId)) } else { facl.Group = proto.String(acl.Group) } facl.ApplyHere = proto.Bool(acl.ApplyHere) facl.ApplySubs = proto.Bool(acl.ApplySubs) facl.Allow = proto.Uint32(uint32(acl.Allow)) facl.Deny = proto.Uint32(uint32(acl.Deny)) return }
func lease(c appengine.Context, maxTasks int, queueName string, leaseTime int, groupByTag bool, tag []byte) ([]*Task, error) { req := &taskqueue_proto.TaskQueueQueryAndOwnTasksRequest{ QueueName: []byte(queueName), LeaseSeconds: proto.Float64(float64(leaseTime)), MaxTasks: proto.Int64(int64(maxTasks)), GroupByTag: proto.Bool(groupByTag), Tag: tag, } res := &taskqueue_proto.TaskQueueQueryAndOwnTasksResponse{} callOpts := &appengine_internal.CallOptions{ Timeout: 10 * time.Second, } if err := c.Call("taskqueue", "QueryAndOwnTasks", req, res, callOpts); err != nil { return nil, err } tasks := make([]*Task, len(res.Task)) for i, t := range res.Task { tasks[i] = &Task{ Payload: t.Body, Name: string(t.TaskName), Method: "PULL", ETA: time.Unix(0, *t.EtaUsec*1e3), RetryCount: *t.RetryCount, Tag: string(t.Tag), } } return tasks, nil }
func ExampleLookupsPerDevice_oneDomain() { trace := Trace{ ARecord: []*DnsARecord{ &DnsARecord{ AddressId: proto.Int32(0), Anonymized: proto.Bool(false), Domain: proto.String("m.domain"), }, }, } traces := map[string]Trace{ string(lex.EncodeOrDie("node1", "anon1", int64(0), int32(0))): trace, } consistentRanges := []*store.Record{ &store.Record{ Key: lex.EncodeOrDie("node1", "anon1", int64(0), int32(0)), Value: lex.EncodeOrDie("node1", "anon1", int64(0), int32(0)), }, } addressIdStore := map[string]string{ string(lex.EncodeOrDie("node1", "anon1", int64(0), int32(0), int32(0))): string(lex.EncodeOrDie("mac1")), } runLookupsPerDevicePipeline(traces, consistentRanges, addressIdStore) // Output: // LookupsPerDevice: // node1,mac1,m.domain: 1 // // LookupsPerDevicePerHour: // node1,mac1,m.domain,0: 1 }
func (w protobufStreamWriter) Close() error { _, err := protocol.Messages(&protocol.StreamChunk{ EOF: proto.Bool(true), }).WriteTo(w.conn) return err }
func StatFile(name string, hash_it bool) (*contester_proto.FileStat, error) { result := &contester_proto.FileStat{} result.Name = &name info, err := os.Stat(name) if err != nil { // Handle ERROR_FILE_NOT_FOUND - return no error and nil instead of stat struct if IsStatErrorFileNotFound(err) { return nil, nil } return nil, NewError(err, "statFile", "os.Stat") } if info.IsDir() { result.IsDirectory = proto.Bool(true) } else { result.Size = proto.Uint64(uint64(info.Size())) if hash_it { checksum, err := HashFileString(name) if err != nil { return nil, NewError(err, "statFile", "hashFile") } result.Checksum = &checksum } } return result, nil }
// 客户端申请建立讨论组 func HandleClientBuildGroup(conn *net.TCPConn, recPacket *packet.Packet) { // read readMsg := &pb.PbClientBuildGroup{} packet.Unpack(recPacket, readMsg) uuid := ConnMapUuid.Get(conn).(string) group_name := readMsg.GetGroupName() // 建立讨论组 ret, group_id := groupinfo.BuildGroup(group_name, uuid) tips_msg := "讨论组[" + group_name + "]建立成功" if ret { tips_msg = "讨论组[" + group_name + "]建立失败" } // write writeMsg := &pb.PbServerNotifyBuildGroup{ Build: proto.Bool(ret), GroupId: proto.String(group_id), GroupName: proto.String(group_name), OwnerUuid: proto.String(uuid), TipsMsg: proto.String(tips_msg), Timestamp: proto.Int64(time.Now().Unix()), } SendPbData(conn, packet.PK_ServerNotifyBuildGroup, writeMsg) }
func createSubmit(db *sqlx.DB, sub *scannedSubmit, submitNo int) *tickets.Ticket_Submit { var result tickets.Ticket_Submit result.SubmitNumber = proto.Uint32(uint32(submitNo)) if sub.Arrived > 0 { result.Arrived = proto.Uint64(uint64(sub.Arrived)) } if result.Compiled = proto.Bool(sub.Compiled == 1); !result.GetCompiled() { return &result } if sub.SchoolMode != 0 { result.School = &tickets.Ticket_Submit_School{TestsTaken: proto.Uint32(uint32(sub.Taken)), TestsPassed: proto.Uint32(uint32(sub.Passed))} } else { var description string var test int64 err := db.QueryRow("select ResultDesc.Description, Results.Test from Results, ResultDesc where "+ "Results.UID = ? and ResultDesc.ID = Results.Result and not ResultDesc.Success order by Results.Test", sub.TestingID).Scan(&description, &test) switch { case err == sql.ErrNoRows: if sub.Passed != 0 && sub.Passed == sub.Taken { result.Acm = &tickets.Ticket_Submit_ACM{Result: proto.String("ACCEPTED")} } case err != nil: log.Fatal(err) return nil default: result.Acm = &tickets.Ticket_Submit_ACM{Result: &description, TestId: proto.Uint32(uint32(test))} } } return &result }
func (pkgr *Packager) Build() { pkgr.resolveDependencies() // add the submixer boundary info // thisOffset := int32(len(pkgr.Mixer.Package.Functions)) // info := &tp.SubmixerInfo{ // Name: proto.String(pkgr.GetName()), // Version: proto.String(pkgr.GetVersion()), // Offset: proto.Int32(thisOffset), // // set the length below // } pkgr.resolveTypeDeclarations() pkgr.populateTypeList() pkgr.buildLib() // length of Functions array has changed; recompute it and subtract the last offset to get the length of this component // info.Length = proto.Int32(int32(len(pkgr.Mixer.Package.Functions))-thisOffset) // pkgr.Mixer.Submixers = append(pkgr.Mixer.Submixers, info) if pkgr.IsHttpTransformer { pkgr.Mixer.IsHttpTransformer = proto.Bool(true) pkgr.Mixer.Rewriters = tp.CollectFiles(filepath.Join(pkgr.MixerDir, SCRIPTS_DIR)) if pkgr.Mixer.Package.Dependencies == nil { pkgr.Mixer.Package.Dependencies = make([]string, 0) } for name, version := range pkgr.Dependencies { pkgr.Mixer.Package.Dependencies = append(pkgr.Mixer.Package.Dependencies, fmt.Sprintf("%s:%s", name, version)) } } }
// Write a channel's ACL and Group data to disk. Mumble doesn't support // incremental ACL updates and as such we must write all ACLs and groups // to the datastore on each change. func (server *Server) UpdateFrozenChannelACLs(channel *Channel) { fc := &freezer.Channel{} fc.Id = proto.Uint32(uint32(channel.Id)) fc.InheritAcl = proto.Bool(channel.ACL.InheritACL) acls := []*freezer.ACL{} for _, aclEntry := range channel.ACL.ACLs { facl, err := FreezeACL(aclEntry) if err != nil { return } acls = append(acls, facl) } fc.Acl = acls groups := []*freezer.Group{} for _, grp := range channel.ACL.Groups { fgrp, err := FreezeGroup(grp) if err != nil { return } groups = append(groups, fgrp) } fc.Groups = groups err := server.freezelog.Put(fc) if err != nil { server.Fatal(err) } server.numLogOps += 1 }
func (c *connection) Stop(handle string, background, kill bool) error { err := c.roundTrip( &protocol.StopRequest{ Handle: proto.String(handle), Background: proto.Bool(background), Kill: proto.Bool(kill), }, &protocol.StopResponse{}, ) if err != nil { return err } return nil }
// 客户端登陆 func HandleClientLogin(conn *net.TCPConn, recPacket *packet.Packet) { // read readMsg := &pb.PbClientLogin{} packet.Unpack(recPacket, readMsg) uuid := readMsg.GetUuid() // 检测uuid合法性 if cid.UuidCheckExist(uuid) { // 如果已经在线则关闭以前的conn if cid.UuidCheckOnline(uuid) { co := UuidMapConn.Get(uuid) if co != nil { CloseConn(co.(*net.TCPConn)) } } // 上线conn InitConn(conn, uuid) } else { CloseConn(conn) } // fmt.Println("uuid:", readMsg.GetUuid()) // fmt.Println("version:", readMsg.GetVersion()) // fmt.Println("timestamp:", convert.TimestampToTimeString(readMsg.GetTimestamp())) // write writeMsg := &pb.PbServerAcceptLogin{ Login: proto.Bool(true), TipsMsg: proto.String("登陆成功"), Timestamp: proto.Int64(time.Now().Unix()), } SendPbData(conn, packet.PK_ServerAcceptLogin, writeMsg) }
func (pkg *Package) readHeaderFile(location string) { // println("READING FUNCTION HEADER FILE") // TODO : plug in new go parser to do this input_file := filepath.Join(location, "headers.tf") if _, err := os.Open(input_file); err != nil { pkg.Log.Infof("Warning -- found no headers.tf") return } stubs := parser.ParseFile(location, ".", "headers.tf", false, make([]string, 0)) for _, function := range stubs.Functions { // Verify that signatures for primitives refer to things that actually exist // println("HEY, LINKING BUILTIN:", function.Stub(pkg.Package)) stubStr := strings.Replace(function.Stub(pkg.Package), ",", ".", -1) if whale.LookupBuiltIn(stubStr) == nil { // TODO: figure out why the panic string is suppressed so that we can remove the println // println("in " + input_file + " -- attempt to provide signature for nonexistent built-in " + stubStr) panic("in " + input_file + " -- attempt to provide signature for nonexistent built-in " + stubStr) } pkg.resolveHeader(function) function.BuiltIn = proto.Bool(true) pkg.Package.Functions = append(pkg.Package.Functions, function) } }
// 客户端(群主)申请解散讨论组 func HandleClientDisbandGroup(conn *net.TCPConn, recPacket *packet.Packet) { // read readMsg := &pb.PbClientDisbandGroup{} packet.Unpack(recPacket, readMsg) from_id := readMsg.GetFromUuid() group_id := readMsg.GetGroupId() // timestamp := readMsg.GetTimestamp() // 验证from_id确实是该conn,并且是group_id的群主 group_name, group_owner := groupinfo.GetGroupNameAndOwner(group_id) if from_id != ConnMapUuid.Get(conn).(string) || group_owner != from_id { CloseConn(conn) return } // 解散讨论组 ret := groupinfo.DisbandGroup(from_id, group_id) tips_msg := "解散讨论组[" + group_name + "]成功" if ret { tips_msg = "解散讨论组[" + group_name + "]失败" } // write writeMsg := &pb.PbServerNotifyDisbandGroup{ Disband: proto.Bool(ret), GroupId: proto.String(group_id), GroupName: proto.String(group_name), TipsMsg: proto.String(tips_msg), Timestamp: proto.Int64(time.Now().Unix()), } SendPbData(conn, packet.PK_ServerNotifyDisbandGroup, writeMsg) }
// TODO: only download new resources if updated versions func netGetClResources(e *Engine) netHandler { return func(msg messages.GetCLResources, conn netengine.Connection) []byte { appendResourceScript := func(dest []*messages.Resource, script *Script) []*messages.Resource { res := new(messages.Resource) res.Name = proto.String(script.Path) kind := messages.ResourceType_RType_Script res.Type = &kind res.Script = proto.String(string(script.Source)) res.ShouldExecSCript = proto.Bool(script.ShouldExec) dest = append(dest, res) return dest } // get all resources resources := make([]*messages.Resource, 0) for _, addon := range e.Addons { for _, script := range addon.ClientScripts { resources = appendResourceScript(resources, script) } } response := new(messages.GetCLResourcesResp) response.Resources = resources encoded, err := netengine.EncodeMessage(response, int32(messages.MessageTypes_GETCLRESOURCESRESP)) if err != nil { e.Log.Error("Error encoding GetClResources response ", err) return make([]byte, 0) } return encoded } }
func (sf *StateFile) Create(pw string) error { var salt [kdfSaltLen]byte if _, err := io.ReadFull(sf.Rand, salt[:]); err != nil { return err } if len(pw) > 0 { sf.header.KdfSalt = salt[:] if err := sf.deriveKey(pw); err != nil { return err } sf.header.Scrypt = new(Header_SCrypt) } if sf.Erasure != nil { if err := sf.Erasure.Create(&sf.header, &sf.key); err != nil { return err } if _, err := io.ReadFull(sf.Rand, sf.mask[:]); err != nil { return err } if err := sf.Erasure.Write(&sf.key, &sf.mask); err != nil { return err } } else { sf.header.NoErasureStorage = proto.Bool(true) } sf.valid = true return nil }
// 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) if oldchan.IsTemporary() && oldchan.IsEmpty() { server.tempRemove <- oldchan } } channel.AddClient(client) server.ClearCaches() server.UpdateFrozenUserLastChannel(client) canspeak := acl.HasPermission(&channel.ACL, client, acl.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) } }
func generalProto(general *models.GeneralData, baseGeneral *models.Base_General) *protodata.GeneralData { var unlock bool if general.BaseId == 0 { general.Atk = baseGeneral.Atk general.Def = baseGeneral.Def general.Hp = baseGeneral.Hp general.Speed = baseGeneral.Speed general.Dex = baseGeneral.Dex general.Range = baseGeneral.Range } else { unlock = true } return &protodata.GeneralData{ GeneralId: proto.Int32(int32(baseGeneral.BaseId)), GeneralName: proto.String(baseGeneral.Name), GeneralDesc: proto.String(baseGeneral.Desc), Level: proto.Int32(int32(general.Level)), Atk: proto.Int32(int32(general.Atk)), Def: proto.Int32(int32(general.Def)), Hp: proto.Int32(int32(general.Hp)), Speed: proto.Int32(int32(general.Speed)), Dex: proto.Int32(int32(general.Dex)), TriggerR: proto.Int32(int32(general.Range)), AtkR: proto.Int32(int32(baseGeneral.AtkRange)), SkillAtk: proto.Int32(int32(baseGeneral.SkillAtk)), GeneralType: proto.Int32(int32(baseGeneral.Type)), LevelUpCoin: proto.Int32(int32(baseGeneral.LevelUpCoin[general.Level])), BuyDiamond: proto.Int32(int32(baseGeneral.BuyDiamond)), KillNum: proto.Int32(int32(general.KillNum)), IsUnlock: proto.Bool(unlock)} }
func init() { user = &User{ Password: proto.String("123456"), Time: proto.Int64(time.Now().Unix()), IsNice: proto.Bool(true), Info: &Info{Name: proto.String("jack"), Age: proto.Int32(22)}, } }
// Freeze a Group into a flattened protobuf-based structure // ready to be persisted to disk. func (group *Group) Freeze() (fgrp *freezer.Group, err error) { fgrp = new(freezer.Group) fgrp.Name = proto.String(group.Name) fgrp.Inherit = proto.Bool(group.Inherit) fgrp.Inheritable = proto.Bool(group.Inheritable) for _, id := range group.AddUsers() { fgrp.Add = append(fgrp.Add, uint32(id)) } for _, id := range group.RemoveUsers() { fgrp.Remove = append(fgrp.Remove, uint32(id)) } return }
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{ { Key: proto.Int64(0xdeadbeef), Value: []byte{1, 65, 7, 12}, }, { Weight: proto.Float32(6.022), Inner: &pb.InnerMessage{ Host: proto.String("lesha.mtv"), Port: proto.Int32(8002), }, }, }, Bikeshed: pb.MyMessage_BLUE.Enum(), 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) } greetings := []string{"adg", "easy", "cow"} if err := proto.SetExtension(msg, pb.E_Greeting, greetings); 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(201<<3|proto.WireBytes), b...) proto.SetRawExtension(msg, 201, b) // Extensions can be plain fields, too, so let's test that. b = append(proto.EncodeVarint(202<<3|proto.WireVarint), 19) proto.SetRawExtension(msg, 202, b) return msg }
func (ctx *LinkingContext) error(obj interface{}, format string, data ...interface{}) { message := fmt.Sprintf(format, data...) ctx.Errors = append(ctx.Errors, message) ins, ok := obj.(*tp.Instruction) if ok { ins.IsValid = proto.Bool(false) } log.Printf("%s\n", message) }