public AppParameter(AppParamTagId tagId, byte[] value) { TagId = tagId; if (value.Length > _MAX_LEN) { throw new NotSupportedException($"Array more that {_MAX_LEN} bytes is not allowed"); } Content = value; Length = (byte)value.Length; }
public AppParameter(AppParamTagId tagId, ushort value) { TagId = tagId; Length = sizeof(ushort); Content = BitConverter.GetBytes(value); if (BitConverter.IsLittleEndian) { Array.Reverse(Content); } }
public AppParameter(AppParamTagId tagId, string text) { TagId = tagId; int count = Encoding.UTF8.GetByteCount(text); if (count > _MAX_LEN) { throw new NotSupportedException("String more that 126 bytes is not allowed"); } Content = Encoding.UTF8.GetBytes(text); Length = (byte)count; }
public void FromBytes(byte[] bytes) { for (int i = 0; i < bytes.Length;) { AppParamTagId tagId = (AppParamTagId)bytes[i++]; byte len = bytes[i++]; byte[] buf = new byte[len]; Array.Copy(bytes, i, buf, 0, len); i += len; AppParameter param = new AppParameter(tagId, len); AppParameters.AddLast(param); } }
public AppParameter(AppParamTagId tagId, byte value) : this(tagId, new byte[] { value }) { }