chore: module payload evaluation
This commit is contained in:
parent
e7ccc37c26
commit
fc9c12195a
|
@ -10,7 +10,7 @@ type PacketReq struct {
|
|||
|
||||
// Which shm fields should be written to and the
|
||||
// values that should be written.
|
||||
Write map[string]interface{}
|
||||
Write map[string]any
|
||||
|
||||
// Whether to return a list of all active memory cells
|
||||
// in the response. Runs after Req.Payload.Write.
|
||||
|
|
|
@ -6,10 +6,7 @@ type PacketRes struct {
|
|||
// The main body of the response.
|
||||
Payload struct {
|
||||
// A map of all read cells and their contents.
|
||||
Read map[string]interface{}
|
||||
|
||||
// An array of all cells which were successfully written.
|
||||
Written []string
|
||||
Read map[string]any
|
||||
|
||||
// An array of all cells present in the shm if it was
|
||||
// requested.
|
||||
|
|
|
@ -86,15 +86,40 @@ func (m *ModulePinecomms) handleRequest(ctx context.Context, w *libwraith.Wraith
|
|||
// Execute the packet payload.
|
||||
//
|
||||
|
||||
// TODO
|
||||
// Read cells.
|
||||
readCells := make(map[string]any, len(packetData.Payload.Read))
|
||||
for _, cell := range packetData.Payload.Read {
|
||||
readCells[cell] = w.SHMGet(cell)
|
||||
}
|
||||
|
||||
// Write cells.
|
||||
for cell, value := range packetData.Payload.Write {
|
||||
w.SHMSet(cell, value)
|
||||
}
|
||||
|
||||
// List cells.
|
||||
var memList []string
|
||||
if packetData.Payload.ListMem {
|
||||
mem := w.SHMDump()
|
||||
memList = make([]string, 0, len(mem))
|
||||
for key := range mem {
|
||||
memList = append(memList, key)
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Respond to the packet.
|
||||
//
|
||||
|
||||
responseData := proto.PacketRes{
|
||||
Payload: struct {
|
||||
Read map[string]any
|
||||
MemList []string
|
||||
}{
|
||||
Read: readCells,
|
||||
MemList: memList,
|
||||
},
|
||||
TxId: packetData.TxId,
|
||||
// TODO
|
||||
}
|
||||
|
||||
responseDataBytes, err := proto.Marshal(&responseData, m.OwnPrivKey)
|
||||
|
|
Loading…
Reference in New Issue
Block a user