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
1
Issues
1
List
Boards
Labels
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
neoppod
Commits
ea297397
Commit
ea297397
authored
Sep 04, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
172e8831
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
64 additions
and
56 deletions
+64
-56
go/neo/proto.go
go/neo/proto.go
+64
-56
No files found.
go/neo/proto.go
View file @
ea297397
...
@@ -76,6 +76,8 @@ const (
...
@@ -76,6 +76,8 @@ const (
// PktHeader represents header of a raw packet.
// PktHeader represents header of a raw packet.
//
//
// A packet contains connection ID and message.
//
//neo:proto typeonly
//neo:proto typeonly
type
PktHeader
struct
{
type
PktHeader
struct
{
ConnId
be32
// NOTE is .msgid in py
ConnId
be32
// NOTE is .msgid in py
...
@@ -83,6 +85,31 @@ type PktHeader struct {
...
@@ -83,6 +85,31 @@ type PktHeader struct {
MsgLen
be32
// payload message length (excluding packet header)
MsgLen
be32
// payload message length (excluding packet header)
}
}
// Msg is the interface implemented by all NEO messages.
type
Msg
interface
{
// marshal/unmarshal into/from wire format:
// neoMsgCode returns message code needed to be used for particular message type
// on the wire.
neoMsgCode
()
uint16
// neoMsgEncodedLen returns how much space is needed to encode current message payload.
neoMsgEncodedLen
()
int
// neoMsgEncode encodes current message state into buf.
//
// len(buf) must be >= neoMsgEncodedLen().
neoMsgEncode
(
buf
[]
byte
)
// neoMsgDecode decodes data into message in-place.
neoMsgDecode
(
data
[]
byte
)
(
nread
int
,
err
error
)
}
// ErrDecodeOverflow is the error returned by neoMsgDecode when decoding hits buffer overflow
var
ErrDecodeOverflow
=
errors
.
New
(
"decode: bufer overflow"
)
// ---- messages ----
type
ErrorCode
uint32
type
ErrorCode
uint32
const
(
const
(
ACK
ErrorCode
=
iota
ACK
ErrorCode
=
iota
...
@@ -190,28 +217,8 @@ type NodeUUID int32
...
@@ -190,28 +217,8 @@ type NodeUUID int32
// TODO NodeType -> base NodeUUID
// TODO NodeType -> base NodeUUID
// ErrDecodeOverflow is the error returned by neoMsgDecode when decoding hits buffer overflow
// Address represents host:port network endpoint.
var
ErrDecodeOverflow
=
errors
.
New
(
"decode: bufer overflow"
)
//
// Msg is the interface implemented by all NEO messages.
type
Msg
interface
{
// marshal/unmarshal into/from wire format:
// neoMsgCode returns message code needed to be used for particular message type
// on the wire
neoMsgCode
()
uint16
// neoMsgEncodedLen returns how much space is needed to encode current message payload
neoMsgEncodedLen
()
int
// neoMsgEncode encodes current message state into buf.
// len(buf) must be >= neoMsgEncodedLen()
neoMsgEncode
(
buf
[]
byte
)
// neoMsgDecode decodes data into message in-place.
neoMsgDecode
(
data
[]
byte
)
(
nread
int
,
err
error
)
}
//neo:proto typeonly
//neo:proto typeonly
type
Address
struct
{
type
Address
struct
{
Host
string
Host
string
...
@@ -247,47 +254,15 @@ func (a *Address) neoDecode(b []byte) int {
...
@@ -247,47 +254,15 @@ func (a *Address) neoDecode(b []byte) int {
return
n
return
n
}
}
//
A SHA1 hash
//
Checksum is a SHA1 hash.
type
Checksum
[
20
]
byte
type
Checksum
[
20
]
byte
// Partition Table identifier.
// P
Tid is P
artition Table identifier.
//
//
// Zero value means "invalid id" (<-> None in py.PPTID)
// Zero value means "invalid id" (<-> None in py.PPTID)
type
PTid
uint64
type
PTid
uint64
// XXX move -> marshalutil.go ?
func
byte2bool
(
b
byte
)
bool
{
return
b
!=
0
}
func
bool2byte
(
b
bool
)
byte
{
if
b
{
return
1
}
else
{
return
0
}
}
// NOTE py.None encodes as '\xff' * 8 (-> we use NaN for None)
// NOTE '\xff' * 8 represents FP NaN but many other NaN bits representations exist
func
float64_NEOEncode
(
b
[]
byte
,
f
float64
)
{
var
fu
uint64
if
!
math
.
IsNaN
(
f
)
{
fu
=
math
.
Float64bits
(
f
)
}
else
{
// convert all NaNs to canonical \xff * 8
fu
=
1
<<
64
-
1
}
binary
.
BigEndian
.
PutUint64
(
b
,
fu
)
}
func
float64_NEODecode
(
b
[]
byte
)
float64
{
fu
:=
binary
.
BigEndian
.
Uint64
(
b
)
return
math
.
Float64frombits
(
fu
)
}
// NodeInfo is information about a node
// NodeInfo is information about a node
//neo:proto typeonly
//neo:proto typeonly
type
NodeInfo
struct
{
type
NodeInfo
struct
{
...
@@ -1034,3 +1009,36 @@ type Truncate struct {
...
@@ -1034,3 +1009,36 @@ type Truncate struct {
// XXX _answer = Error
// XXX _answer = Error
}
}
// ---- runtime support for protogen and custom encodings ----
func
byte2bool
(
b
byte
)
bool
{
return
b
!=
0
}
func
bool2byte
(
b
bool
)
byte
{
if
b
{
return
1
}
else
{
return
0
}
}
// NOTE py.None encodes as '\xff' * 8 (-> we use NaN for None)
// NOTE '\xff' * 8 represents FP NaN but many other NaN bits representations exist
func
float64_NEOEncode
(
b
[]
byte
,
f
float64
)
{
var
fu
uint64
if
!
math
.
IsNaN
(
f
)
{
fu
=
math
.
Float64bits
(
f
)
}
else
{
// convert all NaNs to canonical \xff * 8
fu
=
1
<<
64
-
1
}
binary
.
BigEndian
.
PutUint64
(
b
,
fu
)
}
func
float64_NEODecode
(
b
[]
byte
)
float64
{
fu
:=
binary
.
BigEndian
.
Uint64
(
b
)
return
math
.
Float64frombits
(
fu
)
}
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