Skip to content

Commit

Permalink
Implement more Bytes()
Browse files Browse the repository at this point in the history
  • Loading branch information
markwinter committed Dec 21, 2024
1 parent 7c88359 commit 5ddf1c8
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
16 changes: 15 additions & 1 deletion itch/5.0/luld_collar.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,21 @@ func (l LuldCollar) Type() uint8 {

func (l LuldCollar) Bytes() []byte {
data := make([]byte, luldSize)
// TODO: implement

data[0] = MESSAGE_LULD_COLLAR
binary.BigEndian.PutUint16(data[1:3], l.StockLocate)

// Order of these fields are important. We write timestamp to 3:11 first to let us write a uint64, then overwrite 3:5 with tracking number
binary.BigEndian.PutUint64(data[3:11], uint64(l.Timestamp.Nanoseconds()))
binary.BigEndian.PutUint16(data[3:5], l.TrackingNumber)

copy(data[11:19], []byte(fmt.Sprintf("%-8s", l.Stock)))

binary.BigEndian.PutUint32(data[19:23], l.ReferencePrice)
binary.BigEndian.PutUint32(data[23:27], l.UpperPrice)
binary.BigEndian.PutUint32(data[27:31], l.LowerPrice)
binary.BigEndian.PutUint32(data[31:], l.Extension)

return data
}

Expand Down
13 changes: 12 additions & 1 deletion itch/5.0/mwcb_level.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,18 @@ func (m MwcbLevel) Type() uint8 {

func (m MwcbLevel) Bytes() []byte {
data := make([]byte, mwcbLevelSize)
// TODO: implement

data[0] = MESSAGE_MWCB_LEVEL
binary.BigEndian.PutUint16(data[1:3], m.StockLocate)

// Order of these fields are important. We write timestamp to 3:11 first to let us write a uint64, then overwrite 3:5 with tracking number
binary.BigEndian.PutUint64(data[3:11], uint64(m.Timestamp.Nanoseconds()))
binary.BigEndian.PutUint16(data[3:5], m.TrackingNumber)

binary.BigEndian.PutUint64(data[11:19], m.LevelOne)
binary.BigEndian.PutUint64(data[19:27], m.LevelTwo)
binary.BigEndian.PutUint64(data[27:], m.LevelThree)

return data
}

Expand Down
11 changes: 10 additions & 1 deletion itch/5.0/mwcb_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,16 @@ func (m MwcbStatus) Type() uint8 {

func (m MwcbStatus) Bytes() []byte {
data := make([]byte, mwcbStatusSize)
// TODO: implement

data[0] = MESSAGE_MWCB_STATUS
binary.BigEndian.PutUint16(data[1:3], m.StockLocate)

// Order of these fields are important. We write timestamp to 3:11 first to let us write a uint64, then overwrite 3:5 with tracking number
binary.BigEndian.PutUint64(data[3:11], uint64(m.Timestamp.Nanoseconds()))
binary.BigEndian.PutUint16(data[3:5], m.TrackingNumber)

data[11] = m.BreachedLevel

return data
}

Expand Down

0 comments on commit 5ddf1c8

Please sign in to comment.