Skip to content

Write DCC encoder implementation #2

Description

@gravestench

We should write a DCC encoder as a method of the DCC struct.

func (d *DCC) Encode(w io.Writer) error { /* ... */ }

This should fully marshal our DCC struct to a byte slice, by writing the bytes sequentially into the given stream.

The use-case, as a user of this library, looks something like this:

import (
    "bufio"
    "ioutil"
    "os"

    dcc "github.com/gravestench/dcc/pkg"
)

func main() {
    // load a dcc file
    fileContents, err := ioutil.ReadFile("/path/to/something.dcc")
    if err != nil {
        // file io error
    }

    // parse the dcc file data into a dcc struct
    instance, err := dcc.FromBytes(fileContents)
    if err != nil {
        // dcc parse error
    }

    // re-encode the struct back to dcc data, should be identical to original file data
    f, err := os.Create("/path/to/something_else.dcc")
    if err != nil {
        // file io error
    }

    defer f.Close()

    stream := bufio.NewWriter(w)
    if err := instance.Encode(stream); err != nil {
        // dcc encode error
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions