Skip to content

Instantly share code, notes, and snippets.

@scottstamp
Created April 27, 2020 19:36
Show Gist options
  • Save scottstamp/0a8a6c201b0606ffff6f392885466020 to your computer and use it in GitHub Desktop.
Save scottstamp/0a8a6c201b0606ffff6f392885466020 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Text;
namespace Hideaway.Common.Communication
{
public class ProtocolReader
{
private byte[] _buffer;
private int position = 0;
public ProtocolReader(byte[] buffer)
{
_buffer = buffer;
}
public byte[] ReadBytes(int length)
{
var value = new byte[length];
Buffer.BlockCopy(_buffer, position, value, 0, length);
position += length;
return value;
}
public byte ReadByte()
{
var value = _buffer[position];
position++;
return value;
}
public bool ReadBool()
{
bool value = BitConverter.ToBoolean(_buffer, position);
position += sizeof(bool);
return value;
}
public short ReadShort()
{
var value = BitConverter.ToInt16(_buffer, position);
position += sizeof(short);
return value;
}
public int ReadInt()
{
var value = BitConverter.ToInt32(_buffer, position);
position += sizeof(int);
return value;
}
public long ReadLong()
{
var value = BitConverter.ToInt64(_buffer, position);
position += sizeof(long);
return value;
}
public string ReadString()
{
var length = ReadShort();
var value = BitConverter.ToString(_buffer, position, length);
position += sizeof(short);
return value;
}
public void ReadTimestamp() { }
public void ReadPlayerId() { }
public void ReadAccountId() { }
public void ReadProductId() { }
public void ReadProductCode() { }
public void ReadClothingSetId() { }
public void ReadGestureId() { }
public void ReadOfferId() { }
public bool HasMore
{
get
{
return false;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment