 ! Copyright (C) 2013 John Benediktsson
 ! See http://factorcode.org/license.txt for BSD license
 
-USING: arrays assocs byte-arrays byte-vectors combinators
-grouping hashtables io io.binary io.streams.string kernel math
-math.bitwise math.order sbufs sequences strings ;
+USING: arrays assocs byte-arrays combinators grouping hashtables
+io io.binary io.encodings io.encodings.binary
+io.encodings.string io.encodings.utf8 io.streams.byte-array
+io.streams.string kernel math math.bitwise math.order namespaces
+sequences strings ;
 
 IN: msgpack
 

    dup 0 >= [
        {
            { [ dup 0x7f <= ] [ write1 ] }
            { [ dup 0xff <= ] [ 0xcc write1 1 >be write ] }
            { [ dup 0xffff <= ] [ 0xcd write1 2 >be write ] }
            { [ dup 0xffffffff <= ] [ 0xce write1 4 >be write ] }
            { [ dup 0xffffffffffffffff <= ] [ 0xcf write1 8 >be write ] }

        { [ dup 0xffff <= ] [ 0xda write1 2 >be write ] }
        { [ dup 0xffffffff <= ] [ 0xdb write1 4 >be write ] }
        [ cannot-convert ]
    } cond output-stream get utf8 encode-string ;

M: byte-array write-msgpack
    dup length {
