MCPcopy Create free account
hub / github.com/apache/fory / DecodeGeneric

Method DecodeGeneric

csharp/src/Fory/MetaString.cs:459–487  ·  view source on GitHub ↗
(byte[] bytes, int bitsPerChar, Func<byte, char> mapper)

Source from the content-addressed store, hash-verified

457 }
458
459 private string DecodeGeneric(byte[] bytes, int bitsPerChar, Func<byte, char> mapper)
460 {
461 if (bytes.Length == 0)
462 {
463 return string.Empty;
464 }
465
466 bool stripLast = (bytes[0] & 0x80) != 0;
467 int totalBits = bytes.Length * 8;
468 int bitIndex = 1;
469 StringBuilder sb = new(bytes.Length);
470 while (bitIndex + bitsPerChar <= totalBits &&
471 !(stripLast && (bitIndex + 2 * bitsPerChar > totalBits)))
472 {
473 byte value = 0;
474 for (var i = 0; i < bitsPerChar; i++)
475 {
476 int byteIndex = bitIndex / 8;
477 int intra = bitIndex % 8;
478 byte bit = (byte)((bytes[byteIndex] >> (7 - intra)) & 0x01);
479 value = (byte)((value << 1) | bit);
480 bitIndex++;
481 }
482
483 sb.Append(mapper(value));
484 }
485
486 return sb.ToString();
487 }
488
489 private static char UnmapLowerSpecial(byte value)
490 {

Callers

nothing calls this directly

Calls 2

AppendMethod · 0.80
ToStringMethod · 0.45

Tested by

no test coverage detected