Commit 2ed6cfd8 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 171422b2
......@@ -16,7 +16,8 @@
//
// See COPYING file for full licensing terms.
// See https://www.nexedi.com/licensing for rationale and options.
//go:generate stringer -output zproto-str.go -type ErrorCode,ClusterState,NodeType,NodeState proto.go
//go:generate stringer -output zproto-str.go -type ErrorCode,ClusterState,NodeType,NodeState proto.go packed.go
package neo
// supporting code for types defined in proto.go
......
......@@ -243,7 +243,7 @@ func (a *Address) neoEncode(b []byte) int {
return n
}
func (a *Address) neoDecode(b []byte) (int, bool) {
func (a *Address) neoDecode(b []byte) (uint32, bool) {
n, ok := string_neoDecode(&a.Host, b)
if !ok {
return 0, false
......@@ -1025,7 +1025,7 @@ type Truncate struct {
type customCodec interface {
neoEncodedLen() int
neoEncode(buf []byte) (nwrote int)
neoDecode(data []byte) (nread int, ok bool)
neoDecode(data []byte) (nread uint32, ok bool) // XXX uint32 or int here?
}
func byte2bool(b byte) bool {
......@@ -1074,7 +1074,7 @@ func string_neoEncode(s string, data []byte) int {
return 4 + l
}
func string_neoDecode(sp *string, data []byte) (nread int, ok bool) {
func string_neoDecode(sp *string, data []byte) (nread uint32, ok bool) {
if len(data) < 4 {
return 0, false
}
......@@ -1085,5 +1085,5 @@ func string_neoDecode(sp *string, data []byte) (nread int, ok bool) {
}
*sp = string(data[:l])
return 4 + int(l), true
return 4 + l, true
}
......@@ -1091,21 +1091,23 @@ func (s *sizer) genCustom(path string) {
func (e *encoder) genCustom(path string) {
e.emit("{")
e.emit("n := %s.neoEncode(data[%v:])", e.n)
e.emit("n := %s.neoEncode(data[%v:])", path, e.n)
e.emit("data = data[%v + n:]", e.n)
e.emit("}")
e.n = 0
}
func (d *decoder) genCustom(path string) {
d.resetPos()
// make sure we check for overflow previous-code before proceeding to custom decoder.
d.overflowCheck()
d.resetPos()
d.emit("{")
d.emit("n, ok := %s.neoDecode(data)")
d.emit("n, ok := %s.neoDecode(data)", path)
d.emit("if !ok { goto overflow }")
d.emit("data = data[n:]")
d.emit("%v += n", d.var_("nread"))
d.emit("}")
// insert overflow checkpoint after custom decoder so that overflow
......@@ -1118,7 +1120,8 @@ func (d *decoder) genCustom(path string) {
// obj is object that uses this type in source program (so in case of an error
// we can point to source location for where it happened)
func codegenType(path string, typ types.Type, obj types.Object, codegen CodeGenerator) {
if types.Implements(typ, neo_customCodec) {
if types.Implements(typ, neo_customCodec) ||
types.Implements(types.NewPointer(typ), neo_customCodec) {
codegen.genCustom(path)
return
}
......
This diff is collapsed.
// Code generated by "stringer -output zproto-str.go -type ErrorCode,ClusterState,NodeType,NodeState proto.go"; DO NOT EDIT.
// Code generated by "stringer -output zproto-str.go -type ErrorCode,ClusterState,NodeType,NodeState proto.go packed.go"; DO NOT EDIT.
package neo
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment