From bf1ababe94f0f9b101ddc48de19e979a5216bdce Mon Sep 17 00:00:00 2001 From: Pavel Merzlyakov Date: Tue, 12 Sep 2023 13:50:28 +0300 Subject: [PATCH] using meta v5 --- tpl/codegen_bundle.twig | 8 ++++++-- tpl/macros_rpc.twig | 16 +++++++++++++++- tpl/macros_struct.twig | 4 ++-- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/tpl/codegen_bundle.twig b/tpl/codegen_bundle.twig index 4e8bc4f..9be16a9 100644 --- a/tpl/codegen_bundle.twig +++ b/tpl/codegen_bundle.twig @@ -11,7 +11,7 @@ import ( "strconv" "strings" - "git.bit5.ru/backend/meta/v4" + "git.bit5.ru/backend/meta/v5" "git.bit5.ru/backend/versioning" "git.bit5.ru/gomodules/metadb" "github.com/go-logr/logr" @@ -95,11 +95,15 @@ type Rpc interface { Error() (int32, string) SetError(int32, string) - Request() meta.Readable + Request() meta.ReadableWritable + Response() meta.ReadableWritable Execute(RpcContext, RpcHandler) error ReadRequest(meta.Reader) error + WriteRequest(meta.Writer) error + + ReadResponse(meta.Reader) error WriteResponse(meta.Writer) error } diff --git a/tpl/macros_rpc.twig b/tpl/macros_rpc.twig index 7b267bd..341b582 100644 --- a/tpl/macros_rpc.twig +++ b/tpl/macros_rpc.twig @@ -42,14 +42,28 @@ func (rpc {{ name }}) Execute(ctx RpcContext, h RpcHandler) error { return h.{{ prefix }}(ctx, rpc) } -func (rpc {{ name }}) Request() meta.Readable { +func (rpc {{ name }}) Request() meta.ReadableWritable { return rpc.Req } +func (rpc {{ name }}) Response() meta.ReadableWritable { + return rpc.Rsp +} + func (rpc *{{ name }}) ReadRequest(reader meta.Reader) error { return rpc.Req.Read(reader) } +func (rpc *{{ name }}) WriteRequest(writer meta.Writer) error { + return rpc.Req.Write(writer) +} + +func (rpc *{{ name }}) ReadResponse(reader meta.Reader) error { + rpc.errCode = 0 + rpc.errMsg = "" + return rpc.Rsp.Read(reader) +} + func (rpc *{{ name }}) WriteResponse(writer meta.Writer) error { return rpc.Rsp.Write(writer) } diff --git a/tpl/macros_struct.twig b/tpl/macros_struct.twig index 706e655..e2c50e4 100644 --- a/tpl/macros_struct.twig +++ b/tpl/macros_struct.twig @@ -621,7 +621,7 @@ func (s *{{ name|default(s.name) }}) ReadFields(reader meta.Reader) error { {% set name = fname|split('.')|last %} {% set size_var = name|lcfirst ~ 'Size' %} {% set tmp_var = 'tmp' ~ name %} - if err := reader.BeginContainer("{{ alias }}"); err != nil { + if err := reader.BeginCollection("{{ alias }}"); err != nil { if err != meta.FieldNotFound { return err } @@ -635,7 +635,7 @@ func (s *{{ name|default(s.name) }}) ReadFields(reader meta.Reader) error { {{ _self.meta_read_field(type.value, tmp_var, '', tokens) }} {{ fname }} = append({{ fname }}, {{ tmp_var }}) } - if err := reader.EndContainer(); err != nil { + if err := reader.EndCollection(); err != nil { return err } {% if has_table_token %}