Best Rod code snippet using proto.Area
proposal.go
Source:proposal.go
...261 proposalType: typePlaceHolder,262 content: make([]byte, 2*HeaderSizePerPlaceHolder),263 }264}265// ProposalArea represents for proposals in blocks.266type ProposalArea struct {267 PunishmentArea []*FaultPubKey268 OtherArea []*NormalProposal269}270func (pa *ProposalArea) Count() int {271 return len(pa.PunishmentArea) + len(pa.OtherArea)272}273func (pa *ProposalArea) PunishmentCount() int {274 return len(pa.PunishmentArea)275}276func (pa *ProposalArea) OtherCount() int {277 return len(pa.OtherArea)278}279func (pa *ProposalArea) Encode(w io.Writer, mode CodecMode) (n int, err error) {280 pb, err := pa.ToProto()281 if err != nil {282 return n, err283 }284 switch mode {285 case Packet, DB:286 buf, err := proto.Marshal(pb)287 if err != nil {288 return n, err289 }290 return w.Write(buf)291 case Plain:292 return pb.Write(w)293 default:294 return n, ErrInvalidCodecMode295 }296}297func (pa *ProposalArea) Decode(r io.Reader, mode CodecMode) (n int, err error) {298 switch mode {299 case Packet, DB:300 var buf bytes.Buffer301 n64, err := buf.ReadFrom(r)302 n = int(n64)303 if err != nil {304 return n, err305 }306 pb := new(wirepb.ProposalArea)307 err = proto.Unmarshal(buf.Bytes(), pb)308 if err != nil {309 return n, err310 }311 err = pa.FromProto(pb)312 return n, err313 default:314 return n, ErrInvalidCodecMode315 }316}317func (pa *ProposalArea) Bytes(mode CodecMode) ([]byte, error) {318 return getBytes(pa, mode)319}320func (pa *ProposalArea) SetBytes(bs []byte, mode CodecMode) error {321 return setFromBytes(pa, bs, mode)322}323func (pa *ProposalArea) PlainSize() int {324 size := getPlainSize(pa)325 if pa.PunishmentCount() == 0 {326 size += PlaceHolderSize327 }328 return size329}330func newEmptyProposalArea() *ProposalArea {331 return &ProposalArea{332 PunishmentArea: []*FaultPubKey{},333 OtherArea: []*NormalProposal{},334 }335}336func NewProposalArea(punishmentArea []*FaultPubKey, otherArea []*NormalProposal) (*ProposalArea, error) {337 for _, other := range otherArea {338 if other.proposalType < typeAnyMessage {339 return nil, errWrongProposalType340 }341 }342 return &ProposalArea{343 PunishmentArea: punishmentArea,344 OtherArea: otherArea,345 }, nil346}347// ToProto get proto ProposalArea from wire ProposalArea348func (pa *ProposalArea) ToProto() (*wirepb.ProposalArea, error) {349 punishments := make([]*wirepb.Punishment, pa.PunishmentCount())350 for i, fpk := range pa.PunishmentArea {351 punishments[i] = fpk.ToProto()352 }353 others := make([]*wirepb.Proposal, len(pa.OtherArea))354 for i, proposal := range pa.OtherArea {355 if proposal.proposalType < typeAnyMessage {356 return nil, errWrongProposalType357 }358 others[i] = proposal.ToProto()359 }360 return &wirepb.ProposalArea{361 Punishments: punishments,362 OtherProposals: others,363 }, nil364}365// FromProto load proto ProposalArea into wire ProposalArea,366// if error happens, old content is still immutable367func (pa *ProposalArea) FromProto(pb *wirepb.ProposalArea) error {368 if pb == nil {369 return errors.New("nil proto proposal_area")370 }371 var err error372 punishments := make([]*FaultPubKey, len(pb.Punishments))373 for i, v := range pb.Punishments {374 fpk := new(FaultPubKey)375 if err = fpk.FromProto(v); err != nil {376 return err377 }378 punishments[i] = fpk379 }380 others := make([]*NormalProposal, len(pb.OtherProposals))381 for i, v := range pb.OtherProposals {382 if ProposalType(v.Type) < typeAnyMessage {383 return errWrongProposalType384 }385 np := new(NormalProposal)386 if err = np.FromProto(v); err != nil {387 return err388 }389 others[i] = np390 }391 pa.PunishmentArea = punishments392 pa.OtherArea = others393 return nil394}395// NewProposalAreaFromProto get wire ProposalArea from proto ProposalArea396func NewProposalAreaFromProto(pb *wirepb.ProposalArea) (*ProposalArea, error) {397 pa := new(ProposalArea)398 err := pa.FromProto(pb)399 if err != nil {400 return nil, err401 }402 return pa, nil403}...
maps_broadcast.go
Source:maps_broadcast.go
...3 "game/global"4 "github.com/liangmanlin/gootp/kernel"5)6func (m *MapState)BroadCastPos(pos *global.PPos,proto interface{}) {7 m.BroadCastAreas(Get9AreaByPos(pos), proto)8}9func (m *MapState)BroadCastXY(x,y float32,proto interface{}) {10 m.BroadCastAreas(Get9AreaByArea(GetAreaByXY(x,y)), proto)11}12func (m *MapState)BroadCastAreas(areas []Area, proto interface{}) {13 bin := Encoder.Encode(proto, 2)14 roleAreaMap := m.AreaMap[global.ACTOR_ROLE]15 for i := range areas {16 l := roleAreaMap.AreaActorIDs(areas[i])17 for _, roleID := range l {18 if r, ok := m.Roles[roleID]; ok {19 kernel.Cast(r.TcpPid, bin)20 }21 }22 }23}24func (m *MapState)BroadCastMapAreas(areas map[Area]bool, proto interface{}) {25 bin := Encoder.Encode(proto, 2)26 rm := m.AreaMap[global.ACTOR_ROLE]27 for area,_ := range areas {28 l := rm.AreaActorIDs(area)29 for _, roleID := range l {30 if r, ok := m.Roles[roleID]; ok {31 kernel.Cast(r.TcpPid, bin)32 }33 }34 }35}36func (m *MapState)BroadCastPosExclude(pos *global.PPos,roleID int64,proto interface{}) {37 m.BroadCastAreasExclude(Get9AreaByPos(pos),roleID, proto)38}39func (m *MapState)BroadCastAreasExclude(areas []Area,roleID int64, proto interface{}) {40 bin := Encoder.Encode(proto, 2)41 rm := m.AreaMap[global.ACTOR_ROLE]42 for i := range areas {43 l := rm.AreaActorIDs(areas[i])44 for _, rid := range l {45 if rid == roleID {46 continue47 }48 if r, ok := m.Roles[rid]; ok {49 kernel.Cast(r.TcpPid, bin)50 }51 }52 }53}54func (m *MapState)BroadCastRoles(roles []int64, proto interface{}) {55 bin := Encoder.Encode(proto, 2)56 for _, roleID := range roles {57 if r, ok := m.Roles[roleID]; ok {...
Area
Using AI Code Generation
1import (2func main() {3 r := proto.Rectangle{Length: 10, Breadth: 5}4 fmt.Println("Area of Rectangle:", r.Area())5}6import (7func main() {8 r := proto.Rectangle{Length: 10, Breadth: 5}9 fmt.Println("Area of Rectangle:", r.Area())10}
Area
Using AI Code Generation
1import (2func main() {3 r := geometry.Rectangle{Width: 3, Height: 4}4 fmt.Println("Area of rectangle", r.Area())5}6import (7func main() {8 r := geometry.Rectangle{Width: 3, Height: 4}9 fmt.Println("Perimeter of rectangle", r.Perimeter())10}11import (12func main() {13 r := geometry.Rectangle{Width: 3, Height: 4}14 fmt.Println("Diagonal of rectangle", r.Diagonal())15}16import (17func main() {18 r := geometry.Rectangle{Width: 3, Height: 4}19 r.ScaleBy(2)20 fmt.Println("Area of rectangle", r.Area())21}22import (23func main() {24 r := geometry.Rectangle{Width: 3, Height: 4}25 r.ScaleBy(2)26 fmt.Println("Perimeter of rectangle", r.Perimeter())27}28import (29func main() {30 r := geometry.Rectangle{Width: 3, Height: 4}31 r.ScaleBy(2)32 fmt.Println("Diagonal of rectangle", r.Diagonal())33}
Area
Using AI Code Generation
1import (2func main() {3 fmt.Println(s.Area())4}5import proto "github.com/golang/protobuf/proto"6import fmt "fmt"7import math "math"8import _ "github.com/golang/protobuf/protoc-gen-go/descriptor"9const (10var Shape_Type_name = map[int32]string{11}12var Shape_Type_value = map[string]int32{13}14func (x Shape_Type) String() string {15 return proto.EnumName(Shape_Type_name, int32(x))16}17func (Shape_Type) EnumDescriptor() ([]byte, []int) { return fileDescriptor0, []int{0, 0} }18type Shape struct {19}20func (m *Shape) Reset() { *m = Shape{} }21func (m *Shape) String() string { return proto.CompactTextString(m) }22func (*Shape
Area
Using AI Code Generation
1import (2func main() {3 area = geometry.Area(5, 6)4 fmt.Println(area)5}6import (7func main() {8 area = geometry.Area(5, 6)9 fmt.Println(area)10}11import (12func main() {13 area = geometry.Area(5, 6)14 fmt.Println(area)15}16import (17func main() {18 area = geometry.Area(5, 6)19 fmt.Println(area)20}21import (22func main() {23 area = geometry.Area(5, 6)24 fmt.Println(area)25}26import (27func main() {28 area = geometry.Area(5, 6)29 fmt.Println(area)30}31import (32func main() {33 area = geometry.Area(5, 6)34 fmt.Println(area)35}36import (37func main() {38 area = geometry.Area(5, 6)39 fmt.Println(area)40}41import (42func main() {43 area = geometry.Area(5, 6)44 fmt.Println(area)45}46import (47func main() {
Area
Using AI Code Generation
1import (2func main() {3 s := proto.Shape{Height: 10, Width: 10}4 area := s.Area()5 fmt.Println(area)6}7import (8func main() {9 s := proto.Shape{Height: 10, Width: 10}10 area := s.Area()11 fmt.Println(area)12}13import (14func main() {15 s := proto.Shape{Height: 10, Width: 10}16 area := s.Area()17 fmt.Println(area)18}19import (20func main() {21 s := proto.Shape{Height: 10, Width: 10}22 area := s.Area()23 fmt.Println(area)24}25import (26func main() {27 s := proto.Shape{Height: 10, Width: 10}28 area := s.Area()29 fmt.Println(area)30}
Area
Using AI Code Generation
1import (2func main() {3 fmt.Print("Enter length and breath of rectangle: ")4 fmt.Scanln(&a, &b)5 obj := proto.Area(a, b)6 fmt.Println("Area of Rectangle:", obj)7}
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!