Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull request proxy frame #19

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions proxy/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,21 @@ type rawCodec struct {
parentCodec grpc.Codec //nolint: staticcheck
}

type frame struct {
type Frame struct {
Copy link
Member

@smira smira May 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to expose this type as public, we can keep it frame, and add an interface

type SizeableFrame interface {
    FrameSize() int
}

This way any interceptor can typecast the payload and see if it implements the interface.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. I can change my request to do that instead.

payload []byte
}

func (f *Frame) Size() int {
return len(f.payload)
}

// NewFrame constructs a frame for raw codec.
func NewFrame(payload []byte) interface{} {
return &frame{payload: payload}
return &Frame{payload: payload}
}

func (c *rawCodec) Marshal(v interface{}) ([]byte, error) {
out, ok := v.(*frame)
out, ok := v.(*Frame)
if !ok {
return c.parentCodec.Marshal(v)
}
Expand All @@ -51,7 +55,7 @@ func (c *rawCodec) Marshal(v interface{}) ([]byte, error) {
}

func (c *rawCodec) Unmarshal(data []byte, v interface{}) error {
dst, ok := v.(*frame)
dst, ok := v.(*Frame)
if !ok {
return c.parentCodec.Unmarshal(data, v)
}
Expand Down
4 changes: 2 additions & 2 deletions proxy/handler_one2many.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (s *handler) forwardClientsToServerMultiUnary(sources []backendConnection,
return nil
}

f := &frame{}
f := &Frame{}

for j := 0; ; j++ {
if err := src.clientStream.RecvMsg(f); err != nil {
Expand Down Expand Up @@ -225,7 +225,7 @@ func (s *handler) forwardClientsToServerMultiStreaming(sources []backendConnecti
return s.sendError(src, dst, src.connError)
}

f := &frame{}
f := &Frame{}

for j := 0; ; j++ {
if err := src.clientStream.RecvMsg(f); err != nil {
Expand Down