Package codechicken.mixin.scala
Class ByteCodecs
java.lang.Object
codechicken.mixin.scala.ByteCodecs
This class is borrowed from scala-reflect found at
scala.reflect.internal.pickling.ByteCodecs.
It is unmodified, except for its conversion from Scala to Java and minor syntactic cleanups.
Created by covers1624 on 18/1/24.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]avoidZero(byte[] src) Increment each element by 1, then map 0x00 to 0xC0 0x80.static intdecode(byte[] xs) Destructively decodes array xs and returns the length of the decoded array.static intdecode7to8(byte[] src, int srclen) In-placestatic byte[]encode(byte[] xs) static byte[]encode8to7(byte[] src) Returns a new arraystatic intregenerateZero(byte[] src) Map 0xC0 0x80 to 0x00, then subtract 1 from each element.
-
Constructor Details
-
ByteCodecs
public ByteCodecs()
-
-
Method Details
-
avoidZero
public static byte[] avoidZero(byte[] src) Increment each element by 1, then map 0x00 to 0xC0 0x80. Returns a fresh array. -
regenerateZero
public static int regenerateZero(byte[] src) Map 0xC0 0x80 to 0x00, then subtract 1 from each element. In-place. -
encode8to7
public static byte[] encode8to7(byte[] src) Returns a new array -
decode7to8
public static int decode7to8(byte[] src, int srclen) In-place -
encode
public static byte[] encode(byte[] xs) -
decode
public static int decode(byte[] xs) Destructively decodes array xs and returns the length of the decoded array.Sometimes returns (length+1) of the decoded array. Example:
scala> val enc = scala.reflect.internal.pickling.ByteCodecs.encode(Array(1,2,3)) enc: Array[Byte] = Array(2, 5, 13, 1)
scala> scala.reflect.internal.pickling.ByteCodecs.decode(enc) res43: Int = 4
scala> enc res44: Array[Byte] = Array(1, 2, 3, 0)
However, this does not always happen.
-