🗒️C# 数据类型于byte[] 互转 ByteBuffer.cs 脚本
00 分钟
2023-11-23
2023-11-23
type
status
date
slug
summary
tags
category
icon
password
😀
前言: 欢迎您来到我的知识海洋~
 
  • byte[] ToBytes() 底层实现创建新的byte[]
  • (byte[], int) GetBuffer() 获取当前内存流引用,使用时注意 数组长度时2次幂,实际长度为返回的int
  • void Flush 刷新内存流
  • void Reset 重置Postion,以及长度=0
  • void ResetLength 重置位置,并且赋值指定长度
  • void Write<T>(T data) 写泛型,自动识别数据类型
  • T Read<T>() 读泛型,自动识别数据类型
  • 写方法
    • public void WriteByte(int v){}
    • public void WriteInt(int v){}
    • public void WriteShort(short v){}
    • public void WriteUShort(ushort v){}
    • public void WriteLong(long v){}
    • public void WriteFloat(float v){}
    • public void WriteDouble(double v){}
    • public void WriteString(string v){}
    • public void WriteBytes(byte[] v){}
    • public void WriteShortArray(short[] values){}
    • public void WriteIntArray(int[] values){}
    • public void WriteLongArray(long[] values){}
    • public void WriteFloatArray(float[] values){}
    • public void WriteDoubleArray(double[] values){}
    • public void WriteIntArrays(int[][] values){}
  • 读方法
    • public byte ReadByte(){}
    • public int ReadInt(){}
    • public short ReadShort(){}
    • public ushort ReadUShort(){}
    • public long ReadLong(){}
    • public float ReadFloat(){}
    • public double ReadDouble(){}
    • public string ReadString(int len){}
    • public byte[] ReadBytes(int len){}
    • public short[] ReadShortArray(int len){}
    • public ushort[] ReadUShortArray(int len){}
    • public int[] ReadIntArray(int len){}
    • public long[] ReadLongArray(int len){}
    • public float[] ReadFloatArray(int len){}
    • public double[] ReadDoubleArray(int len){}
 

  • ByteBuffer.cs

 
  • 附属另外 MemoryStream 扩展脚本 StreamHelper.cs
 

 
💡
欢迎您在底部评论区留言,一起交流~
 

评论
  • Valine