public int Serialize(ref Span <byte> buffer) { var index = 0; BinSerialize.WriteULong(ref buffer, U64); index += 8; BinSerialize.WriteLong(ref buffer, S64); index += 8; BinSerialize.WriteDouble(ref buffer, D); index += 8; for (var i = 0; i < U64Array.Length; i++) { BinSerialize.WriteULong(ref buffer, U64Array[i]); index += 8; } for (var i = 0; i < S64Array.Length; i++) { BinSerialize.WriteLong(ref buffer, S64Array[i]); index += 8; } for (var i = 0; i < DArray.Length; i++) { BinSerialize.WriteDouble(ref buffer, DArray[i]); index += 8; } BinSerialize.WriteUInt(ref buffer, U32); index += 4; BinSerialize.WriteInt(ref buffer, S32); index += 4; BinSerialize.WriteFloat(ref buffer, F); index += 4; for (var i = 0; i < U32Array.Length; i++) { BinSerialize.WriteUInt(ref buffer, U32Array[i]); index += 4; } for (var i = 0; i < S32Array.Length; i++) { BinSerialize.WriteInt(ref buffer, S32Array[i]); index += 4; } for (var i = 0; i < FArray.Length; i++) { BinSerialize.WriteFloat(ref buffer, FArray[i]); index += 4; } BinSerialize.WriteUShort(ref buffer, U16); index += 2; BinSerialize.WriteShort(ref buffer, S16); index += 2; for (var i = 0; i < U16Array.Length; i++) { BinSerialize.WriteUShort(ref buffer, U16Array[i]); index += 2; } for (var i = 0; i < S16Array.Length; i++) { BinSerialize.WriteShort(ref buffer, S16Array[i]); index += 2; } BinSerialize.WriteByte(ref buffer, (byte)C); index += 1; unsafe { fixed(byte *bytePointer = buffer) fixed(char *charPointer = S) { Encoding.ASCII.GetBytes(charPointer, S.Length, bytePointer, S.Length); } } buffer = buffer.Slice(S.Length); index += S.Length; BinSerialize.WriteByte(ref buffer, (byte)U8); index += 1; BinSerialize.WriteByte(ref buffer, (byte)S8); index += 1; for (var i = 0; i < U8Array.Length; i++) { BinSerialize.WriteByte(ref buffer, (byte)U8Array[i]); index += 1; } for (var i = 0; i < S8Array.Length; i++) { BinSerialize.WriteByte(ref buffer, (byte)S8Array[i]); index += 1; } return(index); // /*PayloadByteSize*/179; }