/****************************************************************************
* Copyright 2019 Nreal Techonology Limited. All rights reserved.
*
* This file is part of NRSDK.
*
* https://www.nreal.ai/
*
*****************************************************************************/
namespace NRKernal.Experimental.NetWork
{
using System;
using System.Collections.Generic;
/// A message packer.
public class MessagePacker
{
/// The bytes.
private List bytes = new List();
/// Gets the package.
/// The package.
public byte[] Package
{
get { return bytes.ToArray(); }
}
/// Adds value.
/// The data to add.
/// A MessagePacker.
public MessagePacker Add(byte[] data)
{
bytes.AddRange(data);
return this;
}
/// Adds value.
/// The value to add.
/// A MessagePacker.
public MessagePacker Add(ushort value)
{
byte[] data = BitConverter.GetBytes(value);
bytes.AddRange(data);
return this;
}
/// Adds value.
/// The value to add.
/// A MessagePacker.
public MessagePacker Add(uint value)
{
byte[] data = BitConverter.GetBytes(value);
bytes.AddRange(data);
return this;
}
/// Adds value.
/// The value to add.
/// A MessagePacker.
public MessagePacker Add(ulong value)
{
byte[] data = BitConverter.GetBytes(value);
bytes.AddRange(data);
return this;
}
}
}