コード例 #1
0
        public static Object Unpack(byte[] binary, int offset, out int endOffset)
        {
            if (binary == null || binary.Length == 0)
            {
                throw new InvalidDataException("MsgPack binary is empty.");
            }

            SAXInfo info = new SAXInfo(binary)
            {
                currIdx = offset
            };

            try
            {
                UnpackNext(info);
            }
            catch (ArgumentOutOfRangeException e)
            {
                throw new InvalidDataException("Incomplete msgPack binary data.", e);
            }

            endOffset = info.currIdx;

            return(info.GetRootObject());
        }
コード例 #2
0
        public static Dictionary <Object, Object> Unpack(byte[] binary, int offset, int length = 0)
        {
            SAXInfo info = new SAXInfo(binary)
            {
                currIdx = offset
            };

            int endIndx = info.binary.Length;

            if (length > 0)
            {
                endIndx = Math.Min(offset + length, info.binary.Length);
            }

            try
            {
                while (endIndx > info.currIdx)
                {
                    UnpackNext(info);
                }
            }
            catch (ArgumentOutOfRangeException e)
            {
                throw new InvalidDataException("Incomplete msgPack binary data.", e);
            }

            if (info.GetRootObject() is Dictionary <Object, Object> dict)
            {
                return(dict);
            }

            throw new InvalidDataException("MsgPack binary is not dictionary.");
        }