Skip to content

Commit

Permalink
pkg/cbfs: add segments to JSON marshalling for payload
Browse files Browse the repository at this point in the history
This aligns more with the string representation (`cbfs foo.bin list`).

Signed-off-by: Daniel Maslowski <[email protected]>
  • Loading branch information
orangecms committed Sep 18, 2023
1 parent 36c8fa6 commit 905be14
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions pkg/cbfs/payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package cbfs

import (
"encoding/json"
"fmt"
"io"
"log"
Expand Down Expand Up @@ -59,6 +60,27 @@ func (p *PayloadRecord) Read(in io.ReadSeeker) error {
return nil
}

// struct for PayloadRecord marshalling
type mPayloadRecord struct {
Name string
Start uint32
Size uint32
Type string
Segments []PayloadHeader
Compression string
}

func (r *PayloadRecord) MarshalJSON() ([]byte, error) {
return json.Marshal(mPayloadRecord{
Name: r.Name,
Start: r.RecordStart,
Size: r.FileHeader.Size,
Type: r.FileHeader.Type.String(),
Segments: r.Segs,
Compression: r.File.Compression().String(),
})
}

func (h *PayloadRecord) String() string {
s := recString(h.File.Name, h.RecordStart, h.Type.String(), h.Size, "none")
for i, seg := range h.Segs {
Expand All @@ -68,6 +90,27 @@ func (h *PayloadRecord) String() string {
return s
}

// struct for PayloadHeader marshalling
type mPayloadHeader struct {
Type string
Compression string
Offset uint32
LoadAddress uint64
Size uint32
MemSize uint32
}

func (h *PayloadHeader) MarshalJSON() ([]byte, error) {
return json.Marshal(mPayloadHeader{
Type: h.Type.String(),
Compression: h.Compression.String(),
Offset: h.Offset,
LoadAddress: h.LoadAddress,
Size: h.Size,
MemSize: h.MemSize,
})
}

func (r *PayloadHeader) String() string {
return fmt.Sprintf("Type %#x Compression %#x Offset %#x LoadAddress %#x Size %#x MemSize %#x",
r.Type,
Expand Down

0 comments on commit 905be14

Please sign in to comment.