A Kansas-City standard decoder written in Haxe
Ported from py-kcs
- Target agnostic (tested mostly with Flash, but should work on any target)
- UTF-8 support
- No unit tests ;)
import kcs.Decoder;
import flash.media.Microphone;
import flash.events.SampleDataEvent;
class Test {
static function main(){
var mic = Microphone.get();
var kcs = new Decoder();
mic.addEventListener( SampleEventData.SAMPLE_EVENT , readMic );
}
static function readMic( e : SampleEventData ){
var output : BytesData = kcs.decode( e.data );
var str : String = output.toString();
trace(str);
}
}
The decoder keeps data that couldn't be decoded
after every decode()
call (incomplete bytes, unterminated UTF-8 characters, etc).
You can flush these remaining data using the decoder's init()
method.