public static BytesRef toBytesRef(IntsRef input, BytesRefBuilder scratch) {scratch.grow(input.length);for(int i=0;i<input.length;i++) {int value = input.ints[i+input.offset];assert value >= Byte.MIN_VALUE && value <= 255: "value " + value + " doesn't fit into byte";scratch.setByteAt(i, (byte) value);}scratch.setLength(input.length);return scratch.get();}

public static BytesRef ToBytesRef(Int32sRef input, BytesRef scratch){scratch.Grow(input.Length);for (int i = 0; i < input.Length; i++){int value = input.Int32s[i + input.Offset];Debug.Assert(value >= sbyte.MinValue && value <= 255, "value " + value + " doesn't fit into byte");scratch.Bytes[i] = (byte)value;}scratch.Length = input.Length;return scratch;}
