Skip to content

Commit

Permalink
Merge pull request #624 from Reousa/update-serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
PhantomGamers authored Dec 23, 2023
2 parents fd7ed2a + 934810c commit 682a761
Show file tree
Hide file tree
Showing 11 changed files with 2,087 additions and 2,215 deletions.
151 changes: 151 additions & 0 deletions NebulaAPI/Interfaces/INetDataReader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
// #pragma once
// #ifndef INetDataReader.cs_H_
// #define INetDataReader.cs_H_
//
// #endif

using System;
using System.Net;
using System.Runtime.CompilerServices;

namespace NebulaAPI.Interfaces;

public interface INetDataReader
{
byte[] RawData
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get;
}

int RawDataSize
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get;
}

int UserDataOffset
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get;
}

int UserDataSize
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get;
}

bool IsNull
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get;
}

int Position
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get;
}

bool EndOfData
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get;
}

int AvailableBytes
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get;
}

void SkipBytes(int count);
void SetPosition(int position);
void SetSource(INetDataWriter dataWriter);
void SetSource(byte[] source);
void SetSource(byte[] source, int offset, int maxSize);
IPEndPoint GetNetEndPoint();
byte GetByte();
sbyte GetSByte();
T[] GetArray<T>(int size);
bool[] GetBoolArray();
ushort[] GetUShortArray();
short[] GetShortArray();
int[] GetIntArray();
uint[] GetUIntArray();
float[] GetFloatArray();
double[] GetDoubleArray();
long[] GetLongArray();
ulong[] GetULongArray();
string[] GetStringArray();

/// <summary>
/// Note that "maxStringLength" only limits the number of characters in a string, not its size in bytes.
/// Strings that exceed this parameter are returned as empty
/// </summary>
string[] GetStringArray(int maxStringLength);

bool GetBool();
char GetChar();
ushort GetUShort();
short GetShort();
long GetLong();
ulong GetULong();
int GetInt();
uint GetUInt();
float GetFloat();
double GetDouble();

/// <summary>
/// Note that "maxLength" only limits the number of characters in a string, not its size in bytes.
/// </summary>
/// <returns>"string.Empty" if value > "maxLength"</returns>
string GetString(int maxLength);

string GetString();
ArraySegment<byte> GetBytesSegment(int count);
ArraySegment<byte> GetRemainingBytesSegment();
T Get<T>() where T : struct, INetSerializable;
T Get<T>(Func<T> constructor) where T : class, INetSerializable;
byte[] GetRemainingBytes();
void GetBytes(byte[] destination, int start, int count);
void GetBytes(byte[] destination, int count);
sbyte[] GetSBytesWithLength();
byte[] GetBytesWithLength();
byte PeekByte();
sbyte PeekSByte();
bool PeekBool();
char PeekChar();
ushort PeekUShort();
short PeekShort();
long PeekLong();
ulong PeekULong();
int PeekInt();
uint PeekUInt();
float PeekFloat();
double PeekDouble();

/// <summary>
/// Note that "maxLength" only limits the number of characters in a string, not its size in bytes.
/// </summary>
string PeekString(int maxLength);

string PeekString();
bool TryGetByte(out byte result);
bool TryGetSByte(out sbyte result);
bool TryGetBool(out bool result);
bool TryGetChar(out char result);
bool TryGetShort(out short result);
bool TryGetUShort(out ushort result);
bool TryGetInt(out int result);
bool TryGetUInt(out uint result);
bool TryGetLong(out long result);
bool TryGetULong(out ulong result);
bool TryGetFloat(out float result);
bool TryGetDouble(out double result);
bool TryGetString(out string result);
bool TryGetStringArray(out string[] result);
bool TryGetBytesWithLength(out byte[] result);
void Clear();
}
85 changes: 85 additions & 0 deletions NebulaAPI/Interfaces/INetDataWriter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// #pragma once
// #ifndef INetDataWriter.cs_H_
// #define INetDataWriter.cs_H_
//
// #endif

using System;
using System.Net;
using System.Runtime.CompilerServices;

namespace NebulaAPI.Interfaces;

public interface INetDataWriter
{
int Capacity
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get;
}

byte[] Data
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get;
}

int Length
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get;
}

void ResizeIfNeed(int newSize);
void EnsureFit(int additionalSize);
void Reset(int size);
void Reset();
byte[] CopyData();

/// <summary>
/// Sets position of NetDataWriter to rewrite previous values
/// </summary>
/// <param name="position">new byte position</param>
/// <returns>previous position of data writer</returns>
int SetPosition(int position);

void Put(float value);
void Put(double value);
void Put(long value);
void Put(ulong value);
void Put(int value);
void Put(uint value);
void Put(char value);
void Put(ushort value);
void Put(short value);
void Put(sbyte value);
void Put(byte value);
void Put(byte[] data, int offset, int length);
void Put(byte[] data);
void Put(bool value);
void Put(IPEndPoint endPoint);
void Put(string value);

/// <summary>
/// Note that "maxLength" only limits the number of characters in a string, not its size in bytes.
/// </summary>
void Put(string value, int maxLength);

void Put<T>(T obj) where T : INetSerializable;
void PutSBytesWithLength(sbyte[] data, int offset, int length);
void PutSBytesWithLength(sbyte[] data);
void PutBytesWithLength(byte[] data, int offset, int length);
void PutBytesWithLength(byte[] data);
void PutArray(Array arr, int sz);
void PutArray(float[] value);
void PutArray(double[] value);
void PutArray(long[] value);
void PutArray(ulong[] value);
void PutArray(int[] value);
void PutArray(uint[] value);
void PutArray(ushort[] value);
void PutArray(short[] value);
void PutArray(bool[] value);
void PutArray(string[] value);
void PutArray(string[] value, int strMaxLength);
}
138 changes: 0 additions & 138 deletions NebulaAPI/Interfaces/INetSerializable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,141 +13,3 @@ public interface INetSerializable

void Deserialize(INetDataReader reader);
}

public interface INetDataWriter
{
void Put(float value);

void Put(double value);

void Put(long value);

void Put(ulong value);

void Put(int value);

void Put(uint value);

void Put(char value);

void Put(ushort value);

void Put(short value);

void Put(sbyte value);

void Put(byte value);

void Put(byte[] data, int offset, int length);

void Put(byte[] data);

void PutSBytesWithLength(sbyte[] data, int offset, int length);

void PutSBytesWithLength(sbyte[] data);

void PutBytesWithLength(byte[] data, int offset, int length);

void PutBytesWithLength(byte[] data);

void Put(bool value);

void PutArray(float[] value);

void PutArray(double[] value);

void PutArray(long[] value);

void PutArray(ulong[] value);

void PutArray(int[] value);

void PutArray(uint[] value);

void PutArray(ushort[] value);

void PutArray(short[] value);

void PutArray(bool[] value);

void PutArray(string[] value);

void PutArray(string[] value, int maxLength);

void Put(IPEndPoint endPoint);

void Put(string value);

void Put(string value, int maxLength);

void Put<T>(T obj) where T : INetSerializable;
}

public interface INetDataReader
{
IPEndPoint GetNetEndPoint();

byte GetByte();

sbyte GetSByte();

bool[] GetBoolArray();

ushort[] GetUShortArray();

short[] GetShortArray();

long[] GetLongArray();

ulong[] GetULongArray();

int[] GetIntArray();

uint[] GetUIntArray();

float[] GetFloatArray();

double[] GetDoubleArray();

string[] GetStringArray();

string[] GetStringArray(int maxStringLength);

bool GetBool();

char GetChar();

ushort GetUShort();

short GetShort();

long GetLong();

ulong GetULong();

int GetInt();

uint GetUInt();

float GetFloat();

double GetDouble();

string GetString(int maxLength);

string GetString();

ArraySegment<byte> GetRemainingBytesSegment();

T Get<T>() where T : INetSerializable, new();

byte[] GetRemainingBytes();

void GetBytes(byte[] destination, int start, int count);

void GetBytes(byte[] destination, int count);

sbyte[] GetSBytesWithLength();

byte[] GetBytesWithLength();
}
Loading

0 comments on commit 682a761

Please sign in to comment.