OpenDiablo2 / dcc

DCC file transcoder library. The DCC file format represents multiple sequences (typically directions) of animation frames, but lacks a palette. Similar in function to the DC6 format, but highly compressed. An arcane format, used by Blizzard's Diablo II.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Write DCC encoder implementation

gravestench opened this issue · comments

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
    }
}