Skip to content

Add serialization to idtcp server internally #3

@MIXISAMA

Description

@MIXISAMA

Implement a new feature, that idtcp server use Instruction to internally parse out the structure instance corresponding to Data.

It better be like this:

type Fruit struct {
    name string
    price int
}

func receive_fruit(fruit *Fruit) error {
    // do something
}

var Endpoints = []func(interface{}) error {
    ...
    recive_fruit,
    ...
}

// run server
idtcp.NewServer(
   ...
   Endpoints,
   ...
).Run()

But it's hard, so may be like this:

type Request struct {
	Conn     *net.TCPConn
	Payloads []interface{}
}

type IReceive interface {
	Receive(*Request)
}

type Apple struct {
	Color string
	Sweet bool
}

type Banana struct {
	Thickness int
	Length    int
}

func (apple *Apple) Receive(req *Request) {
	fmt.Println(apple)
}

func (banana *Banana) Receive(req *Request) {
	fmt.Println(banana)
}

var Endpoints = []IReceive{
	&Apple{},
	&Banana{},
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

Status

No status

Relationships

None yet

Development

No branches or pull requests

Issue actions