-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
44 changed files
with
757 additions
and
586 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
package build | ||
|
||
const CVersion = "v1.7.6" | ||
const CVersion = "v1.7.7" |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package adapters | ||
|
||
import ( | ||
"context" | ||
|
||
net_message "github.com/number571/go-peer/pkg/network/message" | ||
) | ||
|
||
var ( | ||
_ IAdapter = &sAdapter{} | ||
) | ||
|
||
type ( | ||
iProducerF func(context.Context, net_message.IMessage) error | ||
iConsumerF func(context.Context) (net_message.IMessage, error) | ||
) | ||
|
||
type sAdapter struct { | ||
fProduce iProducerF | ||
fConsume iConsumerF | ||
} | ||
|
||
func NewAdapterByFuncs(pProduce iProducerF, pConsume iConsumerF) IAdapter { | ||
return &sAdapter{ | ||
fProduce: pProduce, | ||
fConsume: pConsume, | ||
} | ||
} | ||
|
||
func (p *sAdapter) Produce(pCtx context.Context, pMsg net_message.IMessage) error { | ||
return p.fProduce(pCtx, pMsg) | ||
} | ||
|
||
func (p *sAdapter) Consume(pCtx context.Context) (net_message.IMessage, error) { | ||
return p.fConsume(pCtx) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package adapters | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"testing" | ||
|
||
"github.com/number571/go-peer/pkg/network/message" | ||
"github.com/number571/go-peer/pkg/payload" | ||
) | ||
|
||
const ( | ||
tcMessage = "hello, world!" | ||
) | ||
|
||
func TestAdapter(t *testing.T) { | ||
msgChan := make(chan message.IMessage, 1) | ||
adapter := NewAdapterByFuncs( | ||
func(_ context.Context, msg message.IMessage) error { | ||
msgChan <- msg | ||
return nil | ||
}, | ||
func(_ context.Context) (message.IMessage, error) { | ||
return <-msgChan, nil | ||
}, | ||
) | ||
|
||
ctx := context.Background() | ||
|
||
err := adapter.Produce(ctx, message.NewMessage( | ||
message.NewConstructSettings(&message.SConstructSettings{ | ||
FSettings: message.NewSettings(&message.SSettings{}), | ||
}), | ||
payload.NewPayload32(0x01, []byte(tcMessage)), | ||
)) | ||
if err != nil { | ||
t.Error(err) | ||
return | ||
} | ||
|
||
msg, err := adapter.Consume(ctx) | ||
if err != nil { | ||
t.Error(err) | ||
return | ||
} | ||
if !bytes.Equal(msg.GetPayload().GetBody(), []byte(tcMessage)) { | ||
t.Error("consume invalid message") | ||
return | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package adapters | ||
|
||
import ( | ||
"context" | ||
|
||
net_message "github.com/number571/go-peer/pkg/network/message" | ||
) | ||
|
||
type IAdapter interface { | ||
IProducer | ||
IConsumer | ||
} | ||
|
||
type IProducer interface { | ||
Produce(context.Context, net_message.IMessage) error | ||
} | ||
|
||
type IConsumer interface { | ||
Consume(context.Context) (net_message.IMessage, error) | ||
} |
Oops, something went wrong.