-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(jzero): ivm init support stream
- Loading branch information
Showing
12 changed files
with
317 additions
and
266 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
logic := {{ .OldService }}logic.New{{ .LogicTypeName | FirstUpper }}(l.ctx, l.svcCtx) | ||
marshal, err := proto.Marshal(in) | ||
if err != nil { | ||
return nil, err | ||
} | ||
var oldIn {{ .OldService }}pb.{{ .RequestTypeName }} | ||
err = proto.Unmarshal(marshal, &oldIn) | ||
if err != nil { | ||
return nil, err | ||
} | ||
result, err := logic.{{ .MethodName }}(&oldIn) | ||
if err != nil { | ||
return nil, err | ||
} | ||
marshal, err = proto.Marshal(result) | ||
if err != nil { | ||
return nil, err | ||
} | ||
var newResp {{ .Service }}pb.{{ .ResponseTypeName }} | ||
err = proto.Unmarshal(marshal, &newResp) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &newResp, nil |
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,49 @@ | ||
type {{ .MethodName | FirstUpper }}ServerAdapter struct { | ||
{{ .Service }}pb.{{ .Service | FirstUpper }}_{{ .MethodName | FirstUpper }}Server | ||
} | ||
|
||
func (s {{ .MethodName | FirstUpper }}ServerAdapter) Send(response *{{ .OldService }}pb.{{ .ResponseTypeName }}) error { | ||
marshal, err := proto.Marshal(response) | ||
if err != nil { | ||
return err | ||
} | ||
var newResp {{ .Service }}pb.{{ .ResponseTypeName }} | ||
err = proto.Unmarshal(marshal, &newResp) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = s.SendMsg(&newResp) | ||
if err != nil { | ||
if err == io.EOF { | ||
return nil | ||
} | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (s {{ .MethodName | FirstUpper }}ServerAdapter) Recv() (*{{ .OldService }}pb.{{ .RequestTypeName }}, error) { | ||
for { | ||
newIn, err := s.{{ .Service | FirstUpper }}_{{ .MethodName | FirstUpper }}Server.Recv() | ||
if err == io.EOF { | ||
return nil, io.EOF | ||
} | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
marshal, err := proto.Marshal(newIn) | ||
if err != nil { | ||
return nil, err | ||
} | ||
var oldIn {{ .OldService }}pb.{{ .RequestTypeName }} | ||
err = proto.Unmarshal(marshal, &oldIn) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &oldIn, nil | ||
} | ||
} |
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,8 @@ | ||
logic := {{ .OldService }}logic.New{{ .LogicTypeName }}(l.ctx, l.svcCtx) | ||
|
||
// Create the adapter | ||
adapter := &{{ .MethodName | FirstUpper }}ServerAdapter{ | ||
stream, | ||
} | ||
|
||
return logic.{{ .MethodName | FirstUpper }}(adapter) |
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,41 @@ | ||
type {{ .MethodName | FirstUpper }}ServerAdapter struct { | ||
{{ .Service }}pb.{{ .Service | FirstUpper }}_{{ .MethodName | FirstUpper }}Server | ||
} | ||
|
||
func (s *{{ .MethodName | FirstUpper }}ServerAdapter) SendAndClose(response *{{ .OldService }}pb.{{ .ResponseTypeName }}) error { | ||
marshal, err := proto.Marshal(response) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var newResp {{ .Service }}pb.{{ .ResponseTypeName }} | ||
err = proto.Unmarshal(marshal, &newResp) | ||
if err != nil { | ||
return err | ||
} | ||
return s.SendMsg(&newResp) | ||
} | ||
|
||
func (s *{{ .MethodName | FirstUpper }}ServerAdapter) Recv() (*{{ .OldService }}pb.{{ .RequestTypeName }}, error) { | ||
for { | ||
newIn, err := s.{{ .Service | FirstUpper }}_{{ .MethodName | FirstUpper }}Server.Recv() | ||
if err == io.EOF { | ||
return nil, io.EOF | ||
} | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
marshal, err := proto.Marshal(newIn) | ||
if err != nil { | ||
return nil, err | ||
} | ||
var oldIn {{ .OldService }}pb.{{ .RequestTypeName }} | ||
err = proto.Unmarshal(marshal, &oldIn) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &oldIn, nil | ||
} | ||
} |
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,8 @@ | ||
logic := {{ .OldService }}logic.New{{ .LogicTypeName }}(l.ctx, l.svcCtx) | ||
|
||
// Create the adapter | ||
adapter := &{{ .MethodName | FirstUpper }}ServerAdapter{ | ||
stream, | ||
} | ||
|
||
return logic.{{ .MethodName | FirstUpper }}(adapter) |
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,25 @@ | ||
type {{ .MethodName | FirstUpper }}ServerAdapter struct { | ||
{{ .Service }}pb.{{ .Service | FirstUpper }}_{{ .MethodName | FirstUpper }}Server | ||
} | ||
|
||
func (s *{{ .MethodName | FirstUpper }}ServerAdapter) Send(response *{{ .OldService }}pb.{{ .ResponseTypeName }}) error { | ||
marshal, err := proto.Marshal(response) | ||
if err != nil { | ||
return err | ||
} | ||
var newResp {{ .Service }}pb.{{ .ResponseTypeName }} | ||
err = proto.Unmarshal(marshal, &newResp) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = s.SendMsg(&newResp) | ||
if err != nil { | ||
if err == io.EOF { | ||
return nil | ||
} | ||
return err | ||
} | ||
|
||
return nil | ||
} |
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,19 @@ | ||
logic := {{ .OldService }}logic.New{{ .LogicTypeName }}(l.ctx, l.svcCtx) | ||
|
||
// Create the adapter | ||
adapter := &{{ .MethodName | FirstUpper }}ServerAdapter{ | ||
stream, | ||
} | ||
|
||
marshal, err := proto.Marshal(in) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var oldIn {{ .OldService }}pb.{{ .RequestTypeName }} | ||
err = proto.Unmarshal(marshal, &oldIn) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return logic.{{ .MethodName | FirstUpper }}(&oldIn, adapter) |
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
Oops, something went wrong.