Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EIP-0004] Give reference of algorithm intToVlq #13

Open
scalahub opened this issue Jun 5, 2020 · 2 comments
Open

[EIP-0004] Give reference of algorithm intToVlq #13

scalahub opened this issue Jun 5, 2020 · 2 comments

Comments

@scalahub
Copy link
Contributor

scalahub commented Jun 5, 2020

In EIP-0004, the encoding in R4 is given as '\x0e' + intToVlq(byteArray.length) + byteArray
Would be good to have a link or a code snippet explaining how to implement intToVlq

@scalahub scalahub changed the title Give reference of algorithm intToVlq and test vectors [EIP-0004] Give reference of algorithm intToVlq and test vectors Jun 5, 2020
@scalahub scalahub changed the title [EIP-0004] Give reference of algorithm intToVlq and test vectors [EIP-0004] Give reference of algorithm intToVlq Jun 7, 2020
@gagarin55
Copy link
Contributor

FYI, it is Base 128 Varints encoding - https://developers.google.com/protocol-buffers/docs/encoding, not VLQ

@HazeyOneKenobi
Copy link

From testing and minting NFT's that match anon_real's implementation on auctionhouse, I think it is VLQ. Sample Java below;

public static byte[] vlqEncode(long n) {

  int numRelevantBits = 64 - Long.numberOfLeadingZeros(n);
  int numBytes = (numRelevantBits + 6) / 7;
  if (numBytes == 0)
    numBytes = 1;
  byte[] output = new byte[numBytes];
  for (int i = numBytes - 1; i >= 0; i--)
  {
    int curByte = (int)(n & 0x7F);
    if (i != (numBytes - 1))
      curByte |= 0x80;
    output[i] = (byte)curByte;
    n >>>= 7;
  }
  return output;
}

N.B. If encoding a hex string, halve the value of it's string length that you feed into this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants