Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Commit

Permalink
Merge pull request #29 from luxas/frame_utils
Browse files Browse the repository at this point in the history
Add a set of small Frame utils
  • Loading branch information
luxas authored Jul 16, 2020
2 parents 1a2d475 + 42b682c commit 65d1093
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions pkg/serializer/frame_utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package serializer

import "io"

// FrameList is a list of frames (byte arrays), used for convenience functions
type FrameList [][]byte

// ReadFrameList is a convenience method that reads all available frames from the FrameReader
// into a returned FrameList
func ReadFrameList(fr FrameReader) (FrameList, error) {
// TODO: Create an unit test for this function
var frameList [][]byte
for {
// Read until we get io.EOF or an error
frame, err := fr.ReadFrame()
if err == io.EOF {
break
} else if err != nil {
return nil, err
}
// Append all frames to the returned list
frameList = append(frameList, frame)
}
return frameList, nil
}

// WriteFrameList is a convenience method that writes a set of frames to a FrameWriter
func WriteFrameList(fw FrameWriter, frameList FrameList) error {
// TODO: Create an unit test for this function
// Loop all frames in the list, and write them individually to the FrameWriter
for _, frame := range frameList {
if _, err := fw.Write(frame); err != nil {
return err
}
}
return nil
}

0 comments on commit 65d1093

Please sign in to comment.