func signProto(day int) []*protodata.RewardData { var result []*protodata.RewardData Lua, _ := lua.NewLua("conf/sign_reward.lua") begin := day/7 - 1 if begin < 0 { begin = 0 } begin = begin*7 + 1 for i := begin; i <= begin+7; i++ { //Lua.L.GetGlobal("signReward") Lua.L.DoString(fmt.Sprintf("coin, diamond, action, generalId = signReward(%d)", i)) coin := Lua.GetInt("coin") diamond := Lua.GetInt("diamond") action := Lua.GetInt("action") generalId := Lua.GetInt("generalId") temp := new(protodata.RewardData) temp.RewardCoin = proto.Int32(int32(coin)) temp.RewardDiamond = proto.Int32(int32(diamond)) temp.Stamina = proto.Int32(int32(action)) if generalId > 0 { config := models.BaseGeneral(generalId, nil) temp.General = generalProto(new(models.GeneralData), config) } result = append(result, temp) } Lua.Close() return result }
func ExampleBytesPerDevice_missingFlow() { trace := Trace{ PacketSeries: []*PacketSeriesEntry{ &PacketSeriesEntry{ TimestampMicroseconds: proto.Int64(0), Size: proto.Int32(10), FlowId: proto.Int32(4), }, }, } consistentRanges := []*store.Record{ &store.Record{ Key: lex.EncodeOrDie("node0", "anon0", int64(0), int32(0)), Value: lex.EncodeOrDie("node0", "anon0", int64(0), int32(0)), }, } records := map[string]Trace{ string(lex.EncodeOrDie("node0", "anon0", int64(0), int32(0))): trace, } runBytesPerDevicePipeline(consistentRanges, records) fmt.Printf("No output") // Output: // No output }
func (self *Client) SendBussiness(ziptype int32, datatype int32, data []byte) (uint64, string) { fun := "Client.SendBussiness" msgid, err := self.manager.Msgid() if err != nil { slog.Errorf("%s get msgid error:%s", fun, err) return 0, self.remoteaddr } buss := &pushproto.Talk{ Type: pushproto.Talk_BUSSINESS.Enum(), Msgid: proto.Uint64(msgid), Ziptype: proto.Int32(ziptype), Datatype: proto.Int32(datatype), Bussdata: data, } spb, err := proto.Marshal(buss) if err != nil { slog.Errorf("%s marshaling error: ", fun, err) return 0, self.remoteaddr } p := util.Packdata(spb) self.sendBussRetry(msgid, p) slog.Infof("%s client:%s send msgid:%d", fun, self, msgid) self.Send(p) return msgid, self.remoteaddr }
func MakeImport(path string, lineNum int32) *Instruction { return &Instruction{ Type: pb.Int32(constants.Instruction_IMPORT), Value: pb.String(path), LineNumber: pb.Int32(lineNum), } }
func MakeComment(comment string, lineNum int32) *Instruction { return &Instruction{ Type: pb.Int32(constants.Instruction_COMMENT), Value: pb.String(comment), LineNumber: pb.Int32(lineNum), } }
func init() { netlib.RegisterHandler(int(protocol.CoreBuiltinPacketID_PACKET_SS_SLICES), &PacketSlicesHandler{}) netlib.RegisterFactory(int(protocol.CoreBuiltinPacketID_PACKET_SS_SLICES), &PacketSlicesPacketFactory{}) netlib.DefaultBuiltinProtocolEncoder.PacketCutor = func(data []byte) (packs []interface{}) { var ( offset = 0 sendSize = 0 seqNo = 1 totalSize = len(data) restSize = len(data) ) for restSize > 0 { sendSize = restSize if sendSize > netlib.MaxPacketSize-128 { sendSize = netlib.MaxPacketSize - 128 } pack := &protocol.SSPacketSlices{ SeqNo: proto.Int32(int32(seqNo)), TotalSize: proto.Int32(int32(totalSize)), Offset: proto.Int32(int32(offset)), PacketData: data[offset : offset+sendSize], } proto.SetDefaults(pack) seqNo++ restSize -= sendSize offset += sendSize packs = append(packs, pack) } return } }
// can't re-use the legacy native function resolver because it's a method of a // type that provides its own helpers and contextual data, all of which would // be too hard to reproduce func (pkgr *Packager) resolveNativeDeclaration(f *tp.Function, path string) { // first we should check that the signature refers to something that actually exists sigStr := strings.Replace(f.Stub(pkgr.Package), ",", ".", -1) if whale.LookupBuiltIn(sigStr) == nil { panic(fmt.Sprintf("attempt to provide signature for nonexistent native function `%s` in `%s`", sigStr, path)) } // now turn the type names into the appropriate numeric ids if returnType := f.GetReturnType(); len(returnType) > 0 { f.ReturnTypeId = proto.Int32(int32(pkgr.TypeMap[returnType])) f.ReturnType = nil } if scopeType := f.GetScopeType(); len(scopeType) > 0 { f.ScopeTypeId = proto.Int32(int32(pkgr.TypeMap[scopeType])) f.ScopeType = nil } if opensType := f.GetOpensType(); len(opensType) > 0 { f.OpensTypeId = proto.Int32(int32(pkgr.TypeMap[opensType])) f.OpensType = nil } for _, arg := range f.Args { if typeName := arg.GetTypeString(); len(typeName) > 0 { arg.TypeId = proto.Int32(int32(pkgr.TypeMap[typeName])) arg.TypeString = nil } } }
func (pkg *Package) resolveHeader(function *tp.Function) { returnType := null.GetString(function.ReturnType) if len(returnType) > 0 { function.ReturnTypeId = proto.Int32(int32(pkg.findTypeIndex(returnType))) function.ReturnType = nil } scopeType := null.GetString(function.ScopeType) if len(scopeType) > 0 { function.ScopeTypeId = proto.Int32(int32(pkg.findTypeIndex(scopeType))) function.ScopeType = nil } opensType := null.GetString(function.OpensType) if len(opensType) > 0 { function.OpensTypeId = proto.Int32(int32(pkg.findTypeIndex(opensType))) function.OpensType = nil } for _, arg := range function.Args { typeName := null.GetString(arg.TypeString) if len(typeName) > 0 { arg.TypeId = proto.Int32(int32(pkg.findTypeIndex(typeName))) arg.TypeString = nil } } }
func TestParseSectionIntro_Valid(t *testing.T) { lines := []string{ "10", "BUILDID", "NODEID 123 321 789", "12 23 34", } trace := Trace{} err := parseSectionIntro(lines, &trace) if err != nil { t.Fatal("Unexpected error:", err) } expectedTrace := Trace{ FileFormatVersion: proto.Int32(10), BuildId: proto.String("BUILDID"), NodeId: proto.String("NODEID"), ProcessStartTimeMicroseconds: proto.Int64(123), SequenceNumber: proto.Int32(321), TraceCreationTimestamp: proto.Int64(789), PcapReceived: proto.Uint32(12), PcapDropped: proto.Uint32(23), InterfaceDropped: proto.Uint32(34), } checkProtosEqual(t, &expectedTrace, &trace) }
func MakeBlock(children []*Instruction, lineNum int32) *Instruction { return &Instruction{ Type: pb.Int32(constants.Instruction_BLOCK), Children: children, LineNumber: pb.Int32(lineNum), } }
func ReadRewriteRules(rules []string) []*RewriteRule { if ruleNum := len(rules); ruleNum/4 > 0 { rrules := make([]*RewriteRule, 0, ruleNum/4) for i := 0; i < ruleNum/4; i++ { newRule := &RewriteRule{} newRule.Proxy = new(string) newRule.Upstream = new(string) newRule.CookieDomain = new(string) direction := rules[4*i] *(newRule.Proxy) = rules[4*i+1] *(newRule.Upstream) = rules[4*i+2] *(newRule.CookieDomain) = rules[4*i+3] if direction == RuleToProxy { newRule.Direction = pb.Int32(constants.RewriteRule_UPSTREAM_TO_PROXY) } else if direction == RuleToUpstream { newRule.Direction = pb.Int32(constants.RewriteRule_PROXY_TO_UPSTREAM) } else { newRule.Direction = pb.Int32(constants.RewriteRule_BIDIRECTIONAL) } rrules = append(rrules, newRule) } return rrules } return nil }
// Insert can insert record into a btree func (t *Btree) insert(record TreeLog) error { tnode, err := t.getTreeNode(t.GetRoot()) if err != nil { if err.Error() != "no data" { return err } nnode := t.newTreeNode() nnode.NodeType = proto.Int32(isLeaf) _, err = nnode.insertRecord(record, t) if err == nil { t.Nodes[nnode.GetId()], err = proto.Marshal(nnode) } t.Root = proto.Int64(nnode.GetId()) return err } clonednode, err := tnode.insertRecord(record, t) if err == nil && len(clonednode.GetKeys()) > int(t.GetNodeMax()) { nnode := t.newTreeNode() nnode.NodeType = proto.Int32(isNode) key, left, right := clonednode.split(t) nnode.insertOnce(key, left, right, t) t.Nodes[nnode.GetId()], err = proto.Marshal(nnode) t.Root = proto.Int64(nnode.GetId()) } else { t.Root = proto.Int64(clonednode.GetId()) } return err }
func MakeText(text string, lineNum int32) *Instruction { return &Instruction{ Type: pb.Int32(constants.Instruction_TEXT), Value: pb.String(text), LineNumber: pb.Int32(lineNum), } }
func MakePosition(pos string, lineNum int32) *Instruction { return &Instruction{ Type: pb.Int32(constants.Instruction_POSITION), Value: pb.String(pos), LineNumber: pb.Int32(lineNum), } }
func rewardProto(coin, diamond, actionValue int, generalData *protodata.GeneralData) *protodata.RewardData { return &protodata.RewardData{ RewardCoin: proto.Int32(int32(coin)), RewardDiamond: proto.Int32(int32(diamond)), Stamina: proto.Int32(int32(actionValue)), General: generalData} }
func TestParseSectionAddressTable_Valid(t *testing.T) { lines := []string{ "10 11", "MAC1 IP1", "MAC2 IP2", } trace := Trace{} err := parseSectionAddressTable(lines, &trace) if err != nil { t.Fatal("Unexpected error:", err) } expectedTrace := Trace{ AddressTableFirstId: proto.Int32(10), AddressTableSize: proto.Int32(11), AddressTableEntry: []*AddressTableEntry{ &AddressTableEntry{ MacAddress: proto.String("MAC1"), IpAddress: proto.String("IP1"), }, &AddressTableEntry{ MacAddress: proto.String("MAC2"), IpAddress: proto.String("IP2"), }, }, } checkProtosEqual(t, &expectedTrace, &trace) }
func writerPipe(conn *net.TCPConn) { for { var msg string fmt.Scanln(&msg) if strings.EqualFold(msg, "quit") { quitSp <- true break } testMessage := &pb.TestMessage{ TestInt: proto.Int32(123), TestString: proto.String("est"), } fmt.Println(testMessage) byt, _ := proto.Marshal(testMessage) fmt.Println(byt) buff := &pb.MobileSuiteProtobuf{ Type: proto.Int32(321), Arena: proto.Int32(111), Command: proto.Int32(0xa), Message: byt, } fmt.Println(buff) bybuf, _ := proto.Marshal(buff) fmt.Println(bybuf) conn.Write(bybuf) } }
func (f *Function) RelocateTypes(relocations map[int]int) { f.ScopeTypeId = pb.Int32(int32(relocations[int(f.GetScopeTypeId())])) f.ReturnTypeId = pb.Int32(int32(relocations[int(f.GetReturnTypeId())])) f.OpensTypeId = pb.Int32(int32(relocations[int(f.GetOpensTypeId())])) for _, arg := range f.Args { arg.TypeId = pb.Int32(int32(relocations[int(arg.GetTypeId())])) } }
func (t *Arith) Divide(args *arith.ArithRequest, reply *arith.ArithResponse) error { if args.GetB() == 0 { return errors.New("divide by zero") } reply.Quo = proto.Int32(args.GetA() / args.GetB()) reply.Rem = proto.Int32(args.GetA() % args.GetB()) return nil }
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 MakeFunctionCall(name string, args []*Instruction, block []*Instruction, lineNum int32) *Instruction { return &Instruction{ Type: pb.Int32(constants.Instruction_FUNCTION_CALL), Value: pb.String(name), Arguments: args, Children: block, LineNumber: pb.Int32(lineNum), } }
func init() { osmsg = &OSMsg{Pattern: &login} loginMsg = &LoginMsg{ Pattern: &login, From: proto.Int32(111), To: proto.Int32(112), Msg: proto.String("hello, world."), } loginMsgBytes, _ = proto.Marshal(loginMsg) }
// 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 (sfcl *SessionHandlerClientLoad) reportLoad(s *netlib.Session) { sc := s.GetSessionConfig() pack := &protocol.ServerLoad{ SrvType: proto.Int32(int32(sc.Type)), SrvId: proto.Int32(int32(sc.Id)), CurLoad: proto.Int32(int32(srvlib.ClientSessionMgrSington.Count())), } proto.SetDefaults(pack) srvlib.ServerSessionMgrSington.Broadcast(pack, netlib.Config.SrvInfo.AreaID, srvlib.BalanceServerType) logger.Tracef("SessionHandlerClientLoad.reportLoad %v", pack) }
func itemProto(item *models.ItemData, config *models.Base_Item) *protodata.ItemData { return &protodata.ItemData{ ItemId: proto.Int32(int32(config.BaseId)), ItemName: proto.String(config.Name), ItemDesc: proto.String(config.Desc), ItemValue: proto.Int32(int32(config.Value + item.Level*config.Group)), ItemPro: proto.Int32(int32(config.Probability)), Level: proto.Int32(int32(item.Level)), LevelUpCoin: proto.Int32(int32(config.LevelUpCoin[item.Level]))} }
func ExampleBytesPerDevice_macBoundAtStartOfFlow() { trace1 := Trace{ PacketSeries: []*PacketSeriesEntry{ &PacketSeriesEntry{ TimestampMicroseconds: proto.Int64(0), Size: proto.Int32(10), FlowId: proto.Int32(4), }, }, FlowTableEntry: []*FlowTableEntry{ &FlowTableEntry{ FlowId: proto.Int32(4), SourceIp: proto.String("1.2.3.4"), DestinationIp: proto.String("4.3.2.1"), }, }, AddressTableEntry: []*AddressTableEntry{ &AddressTableEntry{ IpAddress: proto.String("1.2.3.4"), MacAddress: proto.String("AABBCCDDEEFF"), }, }, } trace2 := Trace{ PacketSeries: []*PacketSeriesEntry{ &PacketSeriesEntry{ TimestampMicroseconds: proto.Int64(0), Size: proto.Int32(12), FlowId: proto.Int32(4), }, }, AddressTableEntry: []*AddressTableEntry{ &AddressTableEntry{ IpAddress: proto.String("1.2.3.4"), MacAddress: proto.String("FFEEDDCCBBAA"), }, }, } consistentRanges := []*store.Record{ &store.Record{ Key: lex.EncodeOrDie("node0", "anon0", int64(0), int32(0)), Value: lex.EncodeOrDie("node0", "anon0", int64(0), int32(1)), }, } records := map[string]Trace{ string(lex.EncodeOrDie("node0", "anon0", int64(0), int32(0))): trace1, string(lex.EncodeOrDie("node0", "anon0", int64(0), int32(1))): trace2, } runBytesPerDevicePipeline(consistentRanges, records) // Output: // node0,AABBCCDDEEFF,0: 22 }
func main() { m := new(msg.FindNode) m.MsgType = proto.Int32(1) m.Timeout = proto.Int32(1) m.NodeId = proto.String("haha") m.AccID = proto.Uint64(1) buf, _ := proto.Marshal(m) fmt.Println(buf) base := new(msg.BaseMsg) proto.Unmarshal(buf, base) fmt.Println(*base.MsgType, *base.Timeout) }
func MakeLocalVar(name string, val *Instruction, block []*Instruction, lineNum int32) *Instruction { node := &Instruction{ Type: pb.Int32(constants.Instruction_LOCAL_VAR), Value: pb.String(name), Children: block, LineNumber: pb.Int32(lineNum), } if val == nil { node.Arguments = nil } else { node.Arguments = ListInstructions(val) } return node }
func sendLogin(conn *net.TCPConn) { m := md5.New() io.WriteString(m, "123456") password := string(m.Sum(nil)) password = hex.EncodeToString([]byte(password)) loginInfo := &Auth_C2S.LoginInfo{ Name: proto.String(" "), Passworld: proto.String(password), ClientType: proto.Int32(1), MachineId: proto.String("ddd"), SoftwareVersion: proto.Int32(1), } sendMsg(conn, byte(C2S_LoginInfo_CMD), loginInfo) }
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) }