-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
31 additions
and
29 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 |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
| | | ||
| rpc/socket/common.go | | ||
| | | ||
| LastModified: May 9, 2021 | | ||
| LastModified: Mar 18, 2022 | | ||
| Author: Ma Bingyao <[email protected]> | | ||
| | | ||
\*________________________________________________________*/ | ||
|
@@ -28,30 +28,31 @@ type data struct { | |
} | ||
|
||
func makeHeader(length int, index int) (header [12]byte) { | ||
header[4] = byte((length >> 24 & 0xff) | 0x80) | ||
header[5] = byte(length >> 16 & 0xff) | ||
header[6] = byte(length >> 8 & 0xff) | ||
header[7] = byte(length & 0xff) | ||
header[8] = byte(index >> 24 & 0xff) | ||
header[9] = byte(index >> 16 & 0xff) | ||
header[10] = byte(index >> 8 & 0xff) | ||
header[11] = byte(index & 0xff) | ||
header[10] = byte(index >> 8 & 0xff) | ||
header[9] = byte(index >> 16 & 0xff) | ||
header[8] = byte(index >> 24 & 0xff) | ||
header[7] = byte(length & 0xff) | ||
header[6] = byte(length >> 8 & 0xff) | ||
header[5] = byte(length >> 16 & 0xff) | ||
header[4] = byte((length >> 24 & 0xff) | 0x80) | ||
crc := crc32.ChecksumIEEE(header[4:]) | ||
header[0] = byte(crc >> 24 & 0xff) | ||
header[1] = byte(crc >> 16 & 0xff) | ||
header[2] = byte(crc >> 8 & 0xff) | ||
header[3] = byte(crc & 0xff) | ||
header[2] = byte(crc >> 8 & 0xff) | ||
header[1] = byte(crc >> 16 & 0xff) | ||
header[0] = byte(crc >> 24 & 0xff) | ||
return | ||
} | ||
|
||
func parseHeader(header [12]byte) (length int, index int, ok bool) { | ||
crc := uint32(header[0])<<24 | uint32(header[1])<<16 | uint32(header[2])<<8 | uint32(header[3]) | ||
index = int(header[11]) | int(header[10])<<8 | int(header[9])<<16 | int(header[8])<<24 | ||
length = int(header[7]) | int(header[6])<<8 | int(header[5])<<16 | int(header[4]&0x7F)<<24 | ||
crc := uint32(header[3]) | uint32(header[2])<<8 | uint32(header[1])<<16 | uint32(header[0])<<24 | ||
if crc32.ChecksumIEEE(header[4:]) != crc { | ||
index = -1 | ||
length = 0 | ||
return | ||
} | ||
length = int(header[4]&0x7F)<<24 | int(header[5])<<16 | int(header[6])<<8 | int(header[7]) | ||
index = int(header[8])<<24 | int(header[9])<<16 | int(header[10])<<8 | int(header[11]) | ||
if ok = (header[8]&0x80 == 0); !ok { | ||
index &= 0x7fffffff | ||
} | ||
|
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 |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
| | | ||
| rpc/udp/common.go | | ||
| | | ||
| LastModified: May 5, 2021 | | ||
| LastModified: May 18, 2022 | | ||
| Author: Ma Bingyao <[email protected]> | | ||
| | | ||
\*________________________________________________________*/ | ||
|
@@ -26,26 +26,27 @@ type data struct { | |
} | ||
|
||
func makeHeader(length int, index int) (header [8]byte) { | ||
header[4] = byte(length >> 8 & 0xff) | ||
header[5] = byte(length & 0xff) | ||
header[6] = byte(index >> 8 & 0xff) | ||
header[7] = byte(index & 0xff) | ||
header[6] = byte(index >> 8 & 0xff) | ||
header[5] = byte(length & 0xff) | ||
header[4] = byte(length >> 8 & 0xff) | ||
crc := crc32.ChecksumIEEE(header[4:]) | ||
header[0] = byte(crc >> 24 & 0xff) | ||
header[1] = byte(crc >> 16 & 0xff) | ||
header[2] = byte(crc >> 8 & 0xff) | ||
header[3] = byte(crc & 0xff) | ||
header[2] = byte(crc >> 8 & 0xff) | ||
header[1] = byte(crc >> 16 & 0xff) | ||
header[0] = byte(crc >> 24 & 0xff) | ||
return | ||
} | ||
|
||
func parseHeader(header []byte) (length int, index int, ok bool) { | ||
crc := uint32(header[0])<<24 | uint32(header[1])<<16 | uint32(header[2])<<8 | uint32(header[3]) | ||
index = int(header[7]) | int(header[6])<<8 | ||
length = int(header[5]) | int(header[4])<<8 | ||
crc := uint32(header[3]) | uint32(header[2])<<8 | uint32(header[1])<<16 | uint32(header[0])<<24 | ||
if crc32.ChecksumIEEE(header[4:]) != crc { | ||
index = -1 | ||
length = 0 | ||
return | ||
} | ||
length = int(header[4])<<8 | int(header[5]) | ||
index = int(header[6])<<8 | int(header[7]) | ||
if ok = (header[6]&0x80 == 0); !ok { | ||
index &= 0x7fff | ||
} | ||
|
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 |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
| | | ||
| rpc/websocket/common.go | | ||
| | | ||
| LastModified: May 5, 2021 | | ||
| LastModified: Mar 18, 2022 | | ||
| Author: Ma Bingyao <[email protected]> | | ||
| | | ||
\*________________________________________________________*/ | ||
|
@@ -20,15 +20,15 @@ type data struct { | |
} | ||
|
||
func makeHeader(index int) (header [4]byte) { | ||
header[0] = byte(index >> 24 & 0xff) | ||
header[1] = byte(index >> 16 & 0xff) | ||
header[2] = byte(index >> 8 & 0xff) | ||
header[3] = byte(index & 0xff) | ||
header[2] = byte(index >> 8 & 0xff) | ||
header[1] = byte(index >> 16 & 0xff) | ||
header[0] = byte(index >> 24 & 0xff) | ||
return | ||
} | ||
|
||
func parseHeader(header []byte) (index int, ok bool) { | ||
index = int(header[0])<<24 | int(header[1])<<16 | int(header[2])<<8 | int(header[3]) | ||
index = int(header[3]) | int(header[2])<<8 | int(header[1])<<16 | int(header[0])<<24 | ||
if ok = (header[0]&0x80 == 0); !ok { | ||
index &= 0x7fffffff | ||
} | ||
|