package etdd

// #include <stdlib.h>
// #include "huffenstein.h"
import "C"
import "unsafe"

func HuffInit() {
	C.Huff_Init()
}

func HuffOffsetReceive(ch *int, fin []byte, offset *int, bloc *int) {

	cCh := C.int(*ch)
	cOffset := C.int(*offset)
	cBloc := C.int(*bloc)

	cFin := (*C.uchar)(unsafe.Pointer(&fin[0]))
	C.Huff_OffsetReceive((*C.int)(&cCh), cFin, (*C.int)(&cOffset), (*C.int)(&cBloc))

	*ch = int(cCh)
	*offset = int(cOffset)
	*bloc = int(cBloc)

}

func HuffGetBit(fin []byte, offset *int, bloc *int) int {

	cFin := (*C.uchar)(unsafe.Pointer(&fin[0]))
	cOffset := C.int(*offset)
	cBloc := C.int(*bloc)

	value := int(C.Huff_GetBit(cFin, (*C.int)(&cOffset), (*C.int)(&cBloc)))
	*offset = int(cOffset)
	*bloc = int(cBloc)

	return value

}