diff --git a/bindings/fileTransfer.go b/bindings/fileTransfer.go index d8292623100d2517be86e2f716cba5491972b2be..cd688771a97556a574730aafbd51c44b6f5f30bc 100644 --- a/bindings/fileTransfer.go +++ b/bindings/fileTransfer.go @@ -203,6 +203,7 @@ func (f *FileTransfer) Send(payload, recipientID []byte, retry float32, base64.StdEncoding.EncodeToString(recipientID)) // Unmarshal recipient ID + jww.INFO.Printf("** FileTransfer.Send before id.Unmarshal") recipient, err := id.Unmarshal(recipientID) if err != nil { return nil, err @@ -219,7 +220,11 @@ func (f *FileTransfer) Send(payload, recipientID []byte, retry float32, Transmitted: int(arrived), Total: int(total), } - pm, err := json.Marshal(progress) + pm, err2 := json.Marshal(progress) + if err2 != nil { + jww.FATAL.Panicf( + "[FT] Failed to JSON marshal sent Progress object: %+v", err) + } callback.Callback(pm, &FilePartTracker{t}, err) } @@ -295,7 +300,11 @@ func (f *FileTransfer) RegisterSentProgressCallback(tidBytes []byte, Transmitted: int(arrived), Total: int(total), } - pm, err := json.Marshal(progress) + pm, err2 := json.Marshal(progress) + if err2 != nil { + jww.FATAL.Panicf( + "[FT] Failed to JSON marshal sent Progress object: %+v", err) + } callback.Callback(pm, &FilePartTracker{t}, err) } p := time.Millisecond * time.Duration(period) @@ -325,7 +334,11 @@ func (f *FileTransfer) RegisterReceivedProgressCallback(tidBytes []byte, Transmitted: int(received), Total: int(total), } - pm, err := json.Marshal(progress) + pm, err2 := json.Marshal(progress) + if err2 != nil { + jww.FATAL.Panicf( + "[FT] Failed to JSON marshal received Progress object: %+v", err) + } callback.Callback(pm, &FilePartTracker{t}, err) } p := time.Millisecond * time.Duration(period) @@ -392,10 +405,10 @@ func (fpt FilePartTracker) GetNumParts() int { // // Example JSON: // { -// "Priority":1, -// "Category":"Test Events", -// "EventType":"Ping", -// "Details":"This is an example of an event report" +// "Priority": 1, +// "Category": "Test Events", +// "EventType": "Ping", +// "Details": "This is an example of an event report" // } type EventReport struct { Priority int diff --git a/bindings/fileTransfer_test.go b/bindings/fileTransfer_test.go index 42d22a77ca6a23da4c67e3bbe1a324f77646bc1e..96900489ad61c77ff9b128a5575002b803903f68 100644 --- a/bindings/fileTransfer_test.go +++ b/bindings/fileTransfer_test.go @@ -17,7 +17,9 @@ import ( "gitlab.com/xx_network/primitives/id" ) +// Creates example JSON outputs used in documentation. func TestFileTransfer_inputs(t *testing.T) { + // FileSend fs := &FileSend{ Name: "testfile.txt", Type: "text file", @@ -28,6 +30,7 @@ func TestFileTransfer_inputs(t *testing.T) { t.Log("FileSend example JSON:") fmt.Printf("%s\n\n", fsm) + // ReceivedFile tid, _ := fileTransfer.NewTransferID(csprng.NewSystemRNG()) sid, _ := id.NewRandomID(csprng.NewSystemRNG(), id.User) rf := &ReceivedFile{ @@ -42,6 +45,7 @@ func TestFileTransfer_inputs(t *testing.T) { t.Log("ReceivedFile example JSON:") fmt.Printf("%s\n\n", rfm) + // Progress p := &Progress{ TransferID: &tid, Completed: false, @@ -52,6 +56,7 @@ func TestFileTransfer_inputs(t *testing.T) { t.Log("Progress example JSON:") fmt.Printf("%s\n\n", pm) + // EventReport er := &EventReport{ Priority: 1, Category: "Test Events",