title: Decode Avro decimal-as-bytearray string
body: <p>I'm using Kafka with Avro messages. One of my fields is defined like this:</p>
  
  <pre><code>{ 
      "name": "a_number", 
      "type": "bytes", 
      "logicalType": "decimal", 
      "precision": 4, 
      "scale": 4 
  }
  </code></pre>
  
  <p>Using the Avro console consumer, I see a message like this:</p>
  
  <pre><code>{"a_number": "\t\u0000°"}
  </code></pre>
  
  <p>Which I expect to equal <code>59</code>.</p>
  
  <p>Supposedly, the bytearray <a href="https://docs.oracle.com/javase/7/docs/api/java/math/BigInteger.html#toByteArray()" rel="nofollow noreferrer">should be the twos-compliment of the number</a>. I've tried using Python's <a href="https://docs.python.org/3/library/struct.html" rel="nofollow noreferrer"><code>struct</code></a> module to decode it, but the values I get don't make any sense:</p>
  
  <pre><code>bs = '\t\u0000°'.encode('utf8')    # b'\t\x00\xc2\xb0'
  struct.unpack('&gt;l', bs)[0] / 1e4   # 15104.4784
  </code></pre>
  
  <p>How can I validate the message? Can I decode the string somehow, or has the Avro console consumer corrupted it?</p>