1
This commit is contained in:
46
Assets/BITKit/UnityPluginsSupport/Tests/MemoryStreamTest.cs
Normal file
46
Assets/BITKit/UnityPluginsSupport/Tests/MemoryStreamTest.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
using Newtonsoft.Json;
|
||||
using System.Reflection;
|
||||
using System.IO;
|
||||
using BITKit.IO;
|
||||
using System.Text;
|
||||
namespace BITKit
|
||||
{
|
||||
public class MemoryStreamTest
|
||||
{
|
||||
[Test]
|
||||
public void WriteStringToMemorySteam()
|
||||
{
|
||||
var _str = nameof(MemoryStreamTest);
|
||||
var _int = 256;
|
||||
var _float = 3.1415926;
|
||||
byte[] bytes;
|
||||
using (var ms = new MemoryStream())
|
||||
{
|
||||
using (BinaryWriter writer = new(ms))
|
||||
{
|
||||
writer.Write(_str);
|
||||
writer.Write(_int);
|
||||
writer.Write(_float);
|
||||
}
|
||||
bytes = ms.ToArray();
|
||||
}
|
||||
Debug.Log($"输入:\nstring:{_str}\nint{_int}\nfloat{_float}");
|
||||
using (var ms = new MemoryStream(bytes))
|
||||
{
|
||||
using (var reader = new BinaryReader(ms))
|
||||
{
|
||||
_str = reader.ReadString();
|
||||
_int = reader.ReadInt32();
|
||||
_float = (float)reader.ReadDouble();
|
||||
}
|
||||
}
|
||||
Debug.Log($":\nstring:{_str}\nint{_int}\nfloat{_float}");
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user