Exemplo n.º 1
0
        public static string BinReadString(BinaryReader reader, EnumIOLenType lenType, Encoding encode)
        {
            int len = 0;

            switch (lenType)
            {
            case EnumIOLenType.Byte:
                len = reader.ReadByte();
                break;

            case EnumIOLenType.Short:
                len = reader.ReadInt16();
                break;

            case EnumIOLenType.Int:
                len = reader.ReadInt32();
                break;
            }
            if (len == 0)
            {
                return(string.Empty);
            }
            var bytes = reader.ReadBytes(len);

            return(encode.GetString(bytes));
        }
Exemplo n.º 2
0
        public static void BinWriteString(BinaryWriter writer, string val, EnumIOLenType lenType, Encoding encode)
        {
            int len = 0;

            byte[] bytes = null;
            if (!string.IsNullOrEmpty(val))
            {
                bytes = encode.GetBytes(val);
                len   = bytes.Length;
            }
            switch (lenType)
            {
            case EnumIOLenType.Byte:
                writer.Write((byte)len);
                break;

            case EnumIOLenType.Short:
                writer.Write((short)len);
                break;

            case EnumIOLenType.Int:
                writer.Write((int)len);
                break;
            }
            if (len == 0)
            {
                return;
            }
            writer.Write(bytes);
        }