From c785beecc0e36761f65b7665aea244b99603821b Mon Sep 17 00:00:00 2001 From: morkt Date: Thu, 18 Oct 2018 23:00:21 +0400 Subject: [PATCH] (BigEndian): added Pack methods. --- GameRes/Utility.cs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/GameRes/Utility.cs b/GameRes/Utility.cs index 5ee28135..315b9120 100644 --- a/GameRes/Utility.cs +++ b/GameRes/Utility.cs @@ -176,6 +176,41 @@ namespace GameRes.Utility { return (int)ToUInt32 (value, index); } + + public static void Pack (ushort value, byte[] buf, int index) + { + buf[index] = (byte)(value >> 8); + buf[index+1] = (byte)(value); + } + + public static void Pack (uint value, byte[] buf, int index) + { + buf[index] = (byte)(value >> 24); + buf[index+1] = (byte)(value >> 16); + buf[index+2] = (byte)(value >> 8); + buf[index+3] = (byte)(value); + } + + public static void Pack (ulong value, byte[] buf, int index) + { + Pack ((uint)(value >> 32), buf, index); + Pack ((uint)value, buf, index+4); + } + + public static void Pack (short value, byte[] buf, int index) + { + Pack ((ushort)value, buf, index); + } + + public static void Pack (int value, byte[] buf, int index) + { + Pack ((uint)value, buf, index); + } + + public static void Pack (long value, byte[] buf, int index) + { + Pack ((ulong)value, buf, index); + } } public static class LittleEndian