internal static int[] ReadIntArray(Stream input) { int length = TagInt.ReadInt(input); int bufferLength = length * 4; byte[] buffer = new byte[bufferLength]; if (bufferLength != input.Read(buffer, 0, bufferLength)) { throw new Exception(); } int[] ints = new int[length]; for (int i = 0; i < length; i++) { if (BitConverter.IsLittleEndian) { BitHelper.SwapBytes(buffer, i * 4, 4); } ints[i] = BitConverter.ToInt32(buffer, i * 4); } buffer = null; return(ints); }
internal static byte[] ReadByteArray(Stream input) { int length = TagInt.ReadInt(input); byte[] bytes = new byte[length]; if (length != input.Read(bytes, 0, length)) { throw new Exception(); } return(bytes); }
internal static void WriteByteArray(Stream output, byte[] value) { if (value != null) { TagInt.WriteInt(output, value.Length); output.Write(value, 0, value.Length); } else { TagInt.WriteInt(output, 0); } }
private static void WriteIntArray(Stream output, int[] value) { if (value != null) { TagInt.WriteInt(output, value.Length); for (int i = 0; i < value.Length; i++) { TagInt.WriteInt(output, value[i]); } } else { TagInt.WriteInt(output, 0); } }
internal static void WriteList(Stream output, List <AbstractTag> Value) { if (Value.Count > 0) { output.WriteByte((byte)Value[0].Type); TagInt.WriteInt(output, Value.Count); for (int i = 0; i < Value.Count; i++) { Value[i].WriteUnnamed(output); } } else { output.WriteByte(0); output.WriteByte(0); } }
public override void Write(Stream output) { output.WriteByte((byte)Type); TagString.WriteString(output, Name); TagInt.WriteInt(output, Value); }
internal static List <AbstractTag> ReadTagList(Stream input) { TagType tagType = (TagType)TagByte.ReadByte(input); int length = TagInt.ReadInt(input); List <AbstractTag> tags = new List <AbstractTag>(); for (int i = 0; i < length; i++) { AbstractTag tag = null; switch (tagType) { case TagType.Byte: tag = TagByte.ReadUnnamedTagByte(input); break; case TagType.ByteArray: tag = TagByteArray.ReadUnnamedTagByteArray(input); break; case TagType.Compound: tag = TagCompound.ReadUnnamedTagCompound(input); break; case TagType.Double: tag = TagDouble.ReadUnnamedTagDouble(input); break; case TagType.End: tag = new TagEnd(); break; case TagType.Float: tag = TagFloat.ReadUnnamedTagFloat(input); break; case TagType.Int: tag = TagInt.ReadUnnamedTagInt(input); break; case TagType.IntArray: tag = TagIntArray.ReadUnnamedTagIntArray(input); break; case TagType.List: tag = TagList.ReadUnnamedTagList(input); break; case TagType.Long: tag = TagLong.ReadUnnamedTagLong(input); break; case TagType.Short: tag = TagShort.ReadUnnamedTagShort(input); break; case TagType.String: tag = TagString.ReadUnnamedTagString(input); break; default: tag = null; break; } if (tag != null) { tags.Add(tag); } } return(tags); }