func (self *Graphics) reader(index IndexStruct) (*utils.ByteSlice, error) { data := utils.NewByteSlice(self.data) err := data.Seek(index.StartAddress) if err != nil { return nil, err } return data, nil }
// Creates a new SaveState from an uncompressed state file. // // Use the RLE decoder to uncompress before handing the raw data to this function. // The function errors out if state is of the wrong length. func NewSaveState(state []byte) (*SaveState, error) { s := &SaveState{nil} if len(state) != SaveStateSize { return s, errors.New("Save states must be exactly " + strconv.Itoa(SaveStateSize) + " bytes in size.") } s.data = utils.NewByteSlice(state) return s, nil }
func (d *IndexDecoder) Decode(data []byte) (Index, error) { elements := len(data) / 16 result := make([]IndexStruct, 0, elements) input := utils.NewByteSlice(data) for input.At() < input.Size() { result = append(result, IndexStruct{ input.ConsumeUint32(), input.ConsumeUint16(), input.ConsumeUint16(), input.ConsumeInt16(), input.ConsumeInt16(), ElementType(input.ConsumeByte() & 0x0F), }) // padding input.Skip(3) } return Index{result}, nil }