Java - Write a string prefixed with the 7 bit encoded length

76 views Asked by At

I am trying to recreate C#'s BinaryWriter's Write function on a string in Java.
The C# method writes a string's length encoded in 7-bit format, and then the string. Is there any way I can implement this in Java?
I've tried implementing it like so, to no success:

long v = value & 0x00000000ffffffffL;
while (v >= 0x80) {
  writeByte((byte) (v | 0x80));
  v >>= 7;
}
writeByte((byte) v);
0

There are 0 answers