 
 class IntegerCodec
 
-  constructor: (@length, @signed) ->
+  constructor: (@length, {@signed}) ->
     @bitLength = @length * 8
     if @signed
       @signBit = Math.pow(2, @bitLength - 1)

  # FIXME: Could probably do this a bit more efficiently by encoding UTF-8
  # ourselves instead of using encodeURIComponent.

  fromByteArray: (bytes, byteIndex, littleEndian) ->
    # First read the number of characters in the string
    lengthFormat = if littleEndian then '<I' else '>I'
    length = jspack.Unpack(lengthFormat, bytes, byteIndex)[0]
    # Then read the characters. The string is in UTF-8 format, so we'll need
    # to convert it back into UTF-16.
    if length > 0
      string = ''
      for i in [byteIndex + UINT32_LENGTH...byteIndex + UINT32_LENGTH + length]
        string += String.fromCharCode(bytes[i])
      @length = length + UINT32_LENGTH
      decodeURIComponent(escape(string))
    else
      @length = UINT32_LENGTH
      ''

  toByteArray: (string, littleEndian) ->
    if string
      utf8 = unescape(encodeURIComponent(string))
      length = utf8.length
      lengthFormat = if littleEndian then '<I' else '>I'
      bytes = jspack.Pack(lengthFormat, [length])
      for i in [0...utf8.length]
        bytes.push(utf8.charCodeAt(i))
      bytes
    else
      # Undefined or empty string, just send a zero length
      [0, 0, 0, 0]


# This is a set of codecs that can be used by fields to convert typed values

Math.log2 ||= (value) -> Math.log(value) / Math.LN2


class BooleanCodec
