Refactor client into separate files
Add a main loop, move I/O code into io.go, move configuration into config.go. Use shared.Decode24BitLength instead of manually decoding block lengths. Fix response block decoding and checksum validation. Add constants for commonly used byte values and use these in the signer and the client.
This commit is contained in:
parent
65855152ce
commit
42d1e6e991
8 changed files with 322 additions and 241 deletions
|
|
@ -6,6 +6,15 @@ type Action uint8
|
|||
|
||||
const ActionNul = Action(0)
|
||||
|
||||
func (a Action) String() string {
|
||||
switch a {
|
||||
case ActionNul:
|
||||
return "NUL"
|
||||
default:
|
||||
return "unknown"
|
||||
}
|
||||
}
|
||||
|
||||
func encode24BitLength(data []byte) []byte {
|
||||
lengthBytes := make([]byte, 4)
|
||||
binary.BigEndian.PutUint32(lengthBytes, uint32(len(data)))
|
||||
|
|
@ -13,7 +22,7 @@ func encode24BitLength(data []byte) []byte {
|
|||
}
|
||||
|
||||
// calculate length from 24 bits of data in network byte order
|
||||
func decode24BitLength(bytes []byte) int {
|
||||
func Decode24BitLength(bytes []byte) int {
|
||||
return int(binary.BigEndian.Uint32([]byte{0x0, bytes[0], bytes[1], bytes[2]}))
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue