title: Borsh JS and Borsh Rust slightly different serialized output
body: <p>I am trying to send borsh serialized data from JS to rust application. However, when serialising data in javascript AND rust (to compare the outputs), I am getting 4 extra bytes in rust serialised output. Here is the code:</p>
  <p><strong>Borsh JS code</strong></p>
  <pre class="lang-js prettyprint-override"><code>// class
  class Poll {
    id: string = '';
    question: string = '';
    options: string[] = [];
    votes: number[] = [];
  
    constructor(fields?: {
      id: string;
      question: string;
      options: string[];
      votes: number[];
    }) {
      if (fields) {
        this.id = fields.id;
        this.question = fields.question;
        this.options = fields.options;
        this.votes = fields.votes;
      }
    }
  }
  
  // Schema
  const schema: Schema = new Map([
    [
      Poll,
      {
        kind: 'struct',
        fields: [
          ['id', 'string'],
          ['question', 'string'],
          ['options', ['string']],
          ['votes', ['u32', 1]],
        ],
      },
    ],
  ]);
  
  
  // class object
  const testPoll = new Poll({
    id: '1',
    question: 'What is your favorite color?',
    options: ['a', 'b', 'c'],
    votes: [100],
  });
  
  //object serialization
  let serializedPoll: Uint8Array = new Uint8Array();
  serializedPoll = serialize(schema, testPoll); // this succeeds
  
  // output
  
  [1, 0, 0, 0, 49, 28, 0, 0, 0, 87, 104, 97, 116, 32, 105, 115, 32, 121, 111, 117, 114, 32, 102, 97, 118, 111, 114, 105, 116, 101, 32, 99, 111, 108, 111, 114, 63, 3, 0, 0, 0, 1, 0, 0, 0, 97, 1, 0, 0, 0, 98, 1, 0, 0, 0, 99, 100, 0, 0, 0]
  </code></pre>
  <p><strong>Borsh Rust Code</strong></p>
  <pre class="lang-rust prettyprint-override"><code>#[derive(BorshDeserialize, BorshSerialize, Debug)]
  pub struct Poll {
      pub id: String,
      pub question: String,
      pub options: Vec&lt;String&gt;,
      pub votes: Vec&lt;u32&gt;,
  }
  
  // poll object - with same values as that in JS code above
  let p = Poll {
          id: &quot;1&quot;.to_string(),
          question: &quot;What is your favorite color?&quot;.to_string(),
          options: vec![&quot;a&quot;.to_string(), &quot;b&quot;.to_string(), &quot;c&quot;.to_string()],
          votes: vec![100],
  };
  
  // serialization
  let serialized_data = p.try_to_vec().unwrap(); // this succeeds
  
  //output
  [1, 0, 0, 0, 49, 28, 0, 0, 0, 87, 104, 97, 116, 32, 105, 115, 32, 121, 111, 117, 114, 32, 102, 97, 118, 111, 114, 105, 116, 101, 32, 99, 111, 108, 111, 114, 63, 3, 0, 0, 0, 1, 0, 0, 0, 97, 1, 0, 0, 0, 98, 1, 0, 0, 0, 99, 1, 0, 0, 0, 100, 0, 0, 0]
  </code></pre>
  <p><strong>Comparing outputs of both</strong></p>
  <ol>
  <li>Borsh JS</li>
  <li>Borsh Rust</li>
  </ol>
  <pre><code>[1, 0, 0, 0, 49, 28, 0, 0, 0, 87, 104, 97, 116, 32, 105, 115, 32, 121, 111, 117, 114, 32, 102, 97, 118, 111, 114, 105, 116, 101, 32, 99, 111, 108, 111, 114, 63, 3, 0, 0, 0, 1, 0, 0, 0, 97, 1, 0, 0, 0, 98, 1, 0, 0, 0, 99, 100, 0, 0, 0]
  
  [1, 0, 0, 0, 49, 28, 0, 0, 0, 87, 104, 97, 116, 32, 105, 115, 32, 121, 111, 117, 114, 32, 102, 97, 118, 111, 114, 105, 116, 101, 32, 99, 111, 108, 111, 114, 63, 3, 0, 0, 0, 1, 0, 0, 0, 97, 1, 0, 0, 0, 98, 1, 0, 0, 0, 99, 1, 0, 0, 0, 100, 0, 0, 0]
  </code></pre>
  <p>There are extra 4 bytes <em>(1, 0, 0, 0)</em> in rust serialised output.
  I believe this is happening because of <code>Vec&lt;u32&gt;</code> used for <code>votes</code> field (it works fine for <code>u32</code>). However I am unable to understand why this is happening.</p>
  <p>Any sort of help/insights are appreciated.</p>
  <p>Thank you!</p>