Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neoppod
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Levin Zimmermann
neoppod
Commits
d3cae883
Commit
d3cae883
authored
May 06, 2024
by
Levin Zimmermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
proto: Fix Error -> ErrorCode is int on the wire and not extension type
parent
d4317253
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
41 deletions
+41
-41
go/neo/proto/protogen.go
go/neo/proto/protogen.go
+34
-29
go/neo/proto/zproto-marshal.go
go/neo/proto/zproto-marshal.go
+7
-12
No files found.
go/neo/proto/protogen.go
View file @
d3cae883
...
...
@@ -1095,35 +1095,6 @@ func (d *decoderM) expectEnum(assignto string, enumType int) {
}
func
(
d
*
decoderM
)
genBasic
(
assignto
string
,
typ
*
types
.
Basic
,
userType
types
.
Type
)
{
// zodb.Tid and zodb.Oid are encoded as [8]bin or Nil
if
userType
==
zodbTid
||
userType
==
zodbOid
{
d
.
emit
(
"if data[%v] == byte(msgpack.Nil) {"
,
d
.
n
)
d
.
emit
(
"%s = %s(%v)"
,
assignto
,
typeName
(
userType
),
INVALID_ID
)
d
.
emit
(
"data = data[%v:]"
,
d
.
n
+
1
)
d
.
emit
(
"} else {"
)
d
.
expectBin8Fix
(
assignto
,
8
)
d
.
emit
(
"%s= %s(binary.BigEndian.Uint64(data[%v:]))"
,
assignto
,
typeName
(
userType
),
d
.
n
)
d
.
n
+=
8
d
.
overflow
.
Add
(
8
)
d
.
resetPos
()
d
.
emit
(
"}"
)
return
}
// enums are encoded as `fixext1 enumType fixint<value>`
if
enum
,
ok
:=
enumRegistry
[
userType
];
ok
{
d
.
expectEnum
(
assignto
,
enum
)
d
.
emit
(
"{"
)
d
.
emit
(
"v := data[%v]"
,
d
.
n
);
d
.
n
++
d
.
emit
(
"if !(0 <= v && v <= 0x7f) {"
)
// mposfixint
d
.
emit
(
" return 0, mdecodeEnumValueErr(%q, v)"
,
d
.
pathName
(
assignto
))
d
.
emit
(
"}"
)
d
.
emit
(
"%s= %s(v)"
,
assignto
,
typeName
(
userType
))
d
.
emit
(
"}"
)
d
.
overflow
.
Add
(
1
)
return
}
// v represents basic decoded value casted to user type if needed
v
:=
"v"
if
userType
.
Underlying
()
!=
userType
{
...
...
@@ -1185,6 +1156,40 @@ func (d *decoderM) genBasic(assignto string, typ *types.Basic, userType types.Ty
d
.
emit
(
"}"
)
}
// zodb.Tid and zodb.Oid are encoded as [8]bin or Nil
if
userType
==
zodbTid
||
userType
==
zodbOid
{
d
.
emit
(
"if data[%v] == byte(msgpack.Nil) {"
,
d
.
n
)
d
.
emit
(
"%s = %s(%v)"
,
assignto
,
typeName
(
userType
),
INVALID_ID
)
d
.
emit
(
"data = data[%v:]"
,
d
.
n
+
1
)
d
.
emit
(
"} else {"
)
d
.
expectBin8Fix
(
assignto
,
8
)
d
.
emit
(
"%s= %s(binary.BigEndian.Uint64(data[%v:]))"
,
assignto
,
typeName
(
userType
),
d
.
n
)
d
.
n
+=
8
d
.
overflow
.
Add
(
8
)
d
.
resetPos
()
d
.
emit
(
"}"
)
return
}
if
typeName
(
userType
)
==
"ErrorCode"
{
mgetint
(
""
,
32
,
""
)
return
}
// enums are encoded as `fixext1 enumType fixint<value>`
if
enum
,
ok
:=
enumRegistry
[
userType
];
ok
{
d
.
expectEnum
(
assignto
,
enum
)
d
.
emit
(
"{"
)
d
.
emit
(
"v := data[%v]"
,
d
.
n
);
d
.
n
++
d
.
emit
(
"if !(0 <= v && v <= 0x7f) {"
)
// mposfixint
d
.
emit
(
" return 0, mdecodeEnumValueErr(%q, v)"
,
d
.
pathName
(
assignto
))
d
.
emit
(
"}"
)
d
.
emit
(
"%s= %s(v)"
,
assignto
,
typeName
(
userType
))
d
.
emit
(
"}"
)
d
.
overflow
.
Add
(
1
)
return
}
// IdTime can be nil ('None' in py), in this case we use
// infinite -1, see
// https://lab.nexedi.com/kirr/neo/-/blob/1ad088c8/go/neo/proto/proto.go#L352-357
...
...
go/neo/proto/zproto-marshal.go
View file @
d3cae883
...
...
@@ -85,7 +85,7 @@ func (p *Error) neoMsgEncodeM(data []byte) {
func
(
p
*
Error
)
neoMsgDecodeM
(
data
[]
byte
)
(
int
,
error
)
{
var
nread
uint64
if
len
(
data
)
<
4
{
if
len
(
data
)
<
1
{
goto
overflow
}
if
op
,
opOk
:=
msgpack
.
Op
(
data
[
0
]),
msgpack
.
FixArray_4
|
2
;
op
!=
opOk
{
...
...
@@ -98,20 +98,15 @@ func (p *Error) neoMsgDecodeM(data []byte) (int, error) {
}
data
=
tail
}
if
op
:=
msgpack
.
Op
(
data
[
0
]);
op
!=
msgpack
.
FixExt1
{
return
0
,
mdecodeOpErr
(
"Error.Code"
,
op
,
msgpack
.
FixExt1
)
}
if
enumType
:=
data
[
1
];
enumType
!=
2
{
return
0
,
mdecodeEnumTypeErr
(
"Error.Code"
,
enumType
,
2
)
}
{
v
:=
data
[
2
]
if
!
(
0
<=
v
&&
v
<=
0x7f
)
{
return
0
,
mdecodeE
numValueErr
(
"Error.Code"
,
v
)
v
,
tail
,
err
:=
msgp
.
ReadInt32Bytes
(
data
)
if
err
!=
nil
{
return
0
,
mdecodeE
rr
(
"Error.Code"
,
err
)
}
p
.
Code
=
ErrorCode
(
v
)
nread
+=
uint64
(
len
(
data
)
-
len
(
tail
))
data
=
tail
}
data
=
data
[
3
:
]
{
b
,
tail
,
err
:=
msgp
.
ReadBytesZC
(
data
)
if
err
!=
nil
{
...
...
@@ -121,7 +116,7 @@ func (p *Error) neoMsgDecodeM(data []byte) (int, error) {
nread
+=
uint64
(
len
(
data
)
-
len
(
tail
))
data
=
tail
}
return
4
+
int
(
nread
),
nil
return
1
+
int
(
nread
),
nil
overflow
:
return
0
,
ErrDecodeOverflow
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment