Here are the examples of the csharp api System.Collections.Generic.List.Add(byte[]) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
727 Examples
19
View Source File : CodedInputStream.cs
License : MIT License
Project Creator : 404Lcc
License : MIT License
Project Creator : 404Lcc
internal byte[] ReadRawBytes(int size)
{
if (size < 0)
{
throw InvalidProtocolBufferException.NegativeSize();
}
if (totalBytesRetired + bufferPos + size > currentLimit)
{
// Read to the end of the stream (up to the current limit) anyway.
SkipRawBytes(currentLimit - totalBytesRetired - bufferPos);
// Then fail.
throw InvalidProtocolBufferException.TruncatedMessage();
}
if (size <= bufferSize - bufferPos)
{
// We have all the bytes we need already.
byte[] bytes = new byte[size];
ByteArray.Copy(buffer, bufferPos, bytes, 0, size);
bufferPos += size;
return bytes;
}
else if (size < buffer.Length)
{
// Reading more bytes than are in the buffer, but not an excessive number
// of bytes. We can safely allocate the resulting array ahead of time.
// First copy what we have.
byte[] bytes = new byte[size];
int pos = bufferSize - bufferPos;
ByteArray.Copy(buffer, bufferPos, bytes, 0, pos);
bufferPos = bufferSize;
// We want to use RefillBuffer() and then copy from the buffer into our
// byte array rather than reading directly into our byte array because
// the input may be unbuffered.
RefillBuffer(true);
while (size - pos > bufferSize)
{
Buffer.BlockCopy(buffer, 0, bytes, pos, bufferSize);
pos += bufferSize;
bufferPos = bufferSize;
RefillBuffer(true);
}
ByteArray.Copy(buffer, 0, bytes, pos, size - pos);
bufferPos = size - pos;
return bytes;
}
else
{
// The size is very large. For security reasons, we can't allocate the
// entire byte array yet. The size comes directly from the input, so a
// maliciously-crafted message could provide a bogus very large size in
// order to trick the app into allocating a lot of memory. We avoid this
// by allocating and reading only a small chunk at a time, so that the
// malicious message must actually *be* extremely large to cause
// problems. Meanwhile, we limit the allowed size of a message elsewhere.
// Remember the buffer markers since we'll have to copy the bytes out of
// it later.
int originalBufferPos = bufferPos;
int originalBufferSize = bufferSize;
// Mark the current buffer consumed.
totalBytesRetired += bufferSize;
bufferPos = 0;
bufferSize = 0;
// Read all the rest of the bytes we need.
int sizeLeft = size - (originalBufferSize - originalBufferPos);
List<byte[]> chunks = new List<byte[]>();
while (sizeLeft > 0)
{
byte[] chunk = new byte[Math.Min(sizeLeft, buffer.Length)];
int pos = 0;
while (pos < chunk.Length)
{
int n = (input == null) ? -1 : input.Read(chunk, pos, chunk.Length - pos);
if (n <= 0)
{
throw InvalidProtocolBufferException.TruncatedMessage();
}
totalBytesRetired += n;
pos += n;
}
sizeLeft -= chunk.Length;
chunks.Add(chunk);
}
// OK, got everything. Now concatenate it all into one buffer.
byte[] bytes = new byte[size];
// Start by copying the leftover bytes from this.buffer.
int newPos = originalBufferSize - originalBufferPos;
ByteArray.Copy(buffer, originalBufferPos, bytes, 0, newPos);
// And now all the chunks.
foreach (byte[] chunk in chunks)
{
Buffer.BlockCopy(chunk, 0, bytes, newPos, chunk.Length);
newPos += chunk.Length;
}
// Done.
return bytes;
}
}
19
View Source File : Util.cs
License : MIT License
Project Creator : 499116344
License : MIT License
Project Creator : 499116344
public static List<byte[]> WriteSnippet(TextSnippet snippet, int length)
{
// TODO: 富文本支持
var ret = new List<byte[]>();
var bw = new BinaryWriter(new MemoryStream());
switch (snippet.Type)
{
case MessageType.Normal:
{
if (length + 6 >= 699) // 数字应该稍大点,但是我不清楚具体是多少
{
length = 0;
ret.Add(new byte[0]);
}
bw.BaseStream.Position = 6;
foreach (var chr in snippet.Content)
{
var bytes = Encoding.UTF8.GetBytes(chr.ToString());
// 705 = 699 + 6个byte: (byte + short + byte + short)
if (length + bw.BaseStream.Length + bytes.Length > 705)
{
var pos = bw.BaseStream.Position;
bw.BaseStream.Position = 0;
bw.Write(new byte[]
{
0x01
});
bw.BeWrite((ushort) (pos - 3)); // 本来是+3和0的,但是提前预留了6个byte给它们,所以变成了-3和-6。下同理。
bw.Write(new byte[]
{
0x01
});
bw.BeWrite((ushort) (pos - 6));
bw.BaseStream.Position = pos;
ret.Add(bw.BaseStream.ToBytesArray());
bw = new BinaryWriter(new MemoryStream());
bw.BaseStream.Position = 6;
length = 0;
}
bw.Write(bytes);
}
// 在最后一段的开头补充结构
{
var pos = bw.BaseStream.Position;
bw.BaseStream.Position = 0;
bw.Write(new byte[]
{
0x01
});
bw.BeWrite((ushort) (pos - 3));
bw.Write(new byte[]
{
0x01
});
bw.BeWrite((ushort) (pos - 6));
bw.BaseStream.Position = pos;
}
break;
}
case MessageType.At:
break;
case MessageType.Emoji:
{
if (length + 12 > 699)
{
ret.Add(new byte[0]);
}
var faceIndex = Convert.ToByte(snippet.Content);
if (faceIndex > 199)
{
faceIndex = 0;
}
bw.Write(new byte[]
{
0x02,
0x00,
0x14,
0x01,
0x00,
0x01
});
bw.Write(faceIndex);
bw.Write(new byte[]
{
0xFF,
0x00,
0x02,
0x14
});
bw.Write((byte) (faceIndex + 65));
bw.Write(new byte[]
{
0x0B,
0x00,
0x08,
0x00,
0x01,
0x00,
0x04,
0x52,
0xCC,
0x85,
0x50
});
break;
}
case MessageType.Picture:
break;
case MessageType.Xml:
break;
case MessageType.Json:
break;
case MessageType.Shake:
break;
case MessageType.Audio:
break;
case MessageType.Video:
break;
case MessageType.ExitGroup:
break;
case MessageType.GetGroupImformation:
break;
case MessageType.AddGroup:
break;
default:
throw new ArgumentOutOfRangeException();
}
if (bw.BaseStream.Position != 0)
{
ret.Add(bw.BaseStream.ToBytesArray());
}
return ret;
}
19
View Source File : Util.cs
License : MIT License
Project Creator : 499116344
License : MIT License
Project Creator : 499116344
public static List<byte[]> WriteRichtext(Richtext richtext)
{
if (richtext.Snippets.Count > 1)
{
if (!richtext.Snippets.TrueForAll(s =>
s.Type == MessageType.Normal || s.Type == MessageType.At || s.Type == MessageType.Emoji ||
s.Type == MessageType.Picture))
{
throw new NotSupportedException("富文本中包含多个非聊天代码");
}
}
// TODO: 富文本支持
var ret = new List<byte[]>();
var bw = new BinaryWriter(new MemoryStream());
foreach (var snippet in richtext.Snippets)
{
var list = WriteSnippet(snippet, (int) bw.BaseStream.Position);
for (var i = 0; i < list.Count; i++)
{
bw.Write(list[i]);
// 除最后一个以外别的都开新的包
// 如果有多个,那前几个一定是太长了被分段了,所以开新的包
// 如果只有一个/是最后一个,那就不开
if (i == list.Count - 1)
{
break;
}
ret.Add(bw.BaseStream.ToBytesArray());
bw = new BinaryWriter(new MemoryStream());
}
}
ret.Add(bw.BaseStream.ToBytesArray());
return ret;
}
19
View Source File : ByteBuffer.cs
License : MIT License
Project Creator : a1q123456
License : MIT License
Project Creator : a1q123456
private void AddNewBufferSegment()
{
var arr = _arrayPool.Rent(BufferSegmentSize);
Debug.replacedert(_buffers.IndexOf(arr) == -1);
_buffers.Add(arr);
_bufferEnd = 0;
}
19
View Source File : ByteBuffer.cs
License : MIT License
Project Creator : a1q123456
License : MIT License
Project Creator : a1q123456
private void TakeOutMemoryNoCheck(Span<byte> buffer)
{
lock (_sync)
{
var discardBuffers = new List<byte[]>();
bool prevDiscarded = false;
if (Length < buffer.Length && _maxiumBufferSize >= 0)
{
throw new InvalidProgramException();
}
foreach (var b in _buffers)
{
if (buffer.Length == 0)
{
break;
}
var start = 0;
var end = BufferSegmentSize;
var isFirst = b == _buffers.First() || prevDiscarded;
var isLast = b == _buffers.Last();
if (isFirst)
{
start = _bufferStart;
}
if (isLast)
{
end = _bufferEnd;
}
var length = end - start;
var needToCopy = Math.Min(buffer.Length, length);
b.replacedpan(start, needToCopy).CopyTo(buffer);
start += needToCopy;
if (isFirst)
{
_bufferStart += needToCopy;
}
if (end - start == 0)
{
if (isFirst)
{
_bufferStart = 0;
}
if (isLast)
{
_bufferEnd = 0;
}
discardBuffers.Add(b);
prevDiscarded = true;
}
else
{
prevDiscarded = false;
}
buffer = buffer.Slice(needToCopy);
}
//Console.WriteLine(Length);
Debug.replacedert(buffer.Length == 0 || _maxiumBufferSize < 0);
while (discardBuffers.Any())
{
var b = discardBuffers.First();
_arrayPool.Return(b);
discardBuffers.Remove(b);
_buffers.Remove(b);
}
if (!_buffers.Any())
{
AddNewBufferSegment();
}
}
if (Length <= _maxiumBufferSize && _maxiumBufferSize >= 0)
{
_memoryUnderLimit?.Invoke();
}
}
19
View Source File : OvrAvatarPacket.cs
License : MIT License
Project Creator : absurd-joy
License : MIT License
Project Creator : absurd-joy
public static OvrAvatarPacket Read(Stream stream)
{
BinaryReader reader = new BinaryReader(stream);
// Todo: bounds check frame count
int frameCount = reader.ReadInt32();
List<float> frameTimes = new List<float>(frameCount);
for (int i = 0; i < frameCount; ++i)
{
frameTimes.Add(reader.ReadSingle());
}
List<OvrAvatarDriver.PoseFrame> frames = new List<OvrAvatarDriver.PoseFrame>(frameCount);
for (int i = 0; i < frameCount; ++i)
{
frames.Add(reader.ReadPoseFrame());
}
// Todo: bounds check audio packet count
int audioPacketCount = reader.ReadInt32();
List<byte[]> audioPackets = new List<byte[]>(audioPacketCount);
for (int i = 0; i < audioPacketCount; ++i)
{
int audioPacketSize = reader.ReadInt32();
byte[] audioPacket = reader.ReadBytes(audioPacketSize);
audioPackets.Add(audioPacket);
}
return new OvrAvatarPacket(frameTimes, frames, audioPackets);
}
19
View Source File : DigitalAnalyzerExampleViewModel.cs
License : MIT License
Project Creator : ABTSoftware
License : MIT License
Project Creator : ABTSoftware
private async Task AddChannels(int digitalChannelsCount, int replacedogChannelsCount)
{
List<byte[]> digitalChannels = new List<byte[]>();
List<float[]> replacedogChannels = new List<float[]>();
// Force GC to free memory
GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce;
GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, true);
try
{
// Allocate memory first
await Task.Run(() =>
{
for (var i = 0; i < digitalChannelsCount; i++)
{
var newArray = new byte[SelectedPointCount];
digitalChannels.Add(newArray);
}
for (var i = 0; i < replacedogChannelsCount; i++)
{
var newArray = new float[SelectedPointCount];
replacedogChannels.Add(newArray);
}
});
// Generate random data and fill channels
await GenerateData(digitalChannels, replacedogChannels);
}
catch (OutOfMemoryException)
{
await Application.Current.Dispatcher.BeginInvoke(new Action(() => ChannelViewModels.Clear()));
MessageBox.Show(string.Format($"There is not enough RAM memory to allocate {SelectedChannelCount} channels with {SelectedPointCount} points each. Please select less channels or less points and try again."));
}
finally
{
OnPropertyChanged(nameof(IsEmpty));
OnPropertyChanged(nameof(ChannelViewModels));
OnPropertyChanged(nameof(SelectedPointCount));
OnPropertyChanged(nameof(TotalPoints));
OnPropertyChanged(nameof(XRange));
IsLoading = false;
}
}
19
View Source File : DigitalAnalyzerExampleViewModel.cs
License : MIT License
Project Creator : ABTSoftware
License : MIT License
Project Creator : ABTSoftware
private async Task AddChannels(int digitalChannelsCount)
{
var digitalChannels = new List<byte[]>();
// Force GC to free memory
GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce;
GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, true);
try
{
// Allocate memory first
await Task.Run(() =>
{
for (var i = 0; i < digitalChannelsCount; i++)
{
var newArray = new byte[SelectedPointCount];
digitalChannels.Add(newArray);
}
});
// Generate random data and fill channels
await GenerateData(digitalChannels);
}
catch (OutOfMemoryException)
{
await Application.Current.Dispatcher.BeginInvoke(new Action(() => ChannelViewModels.Clear()));
MessageBox.Show(string.Format($"There is not enough RAM memory to allocate {SelectedChannelCount} channels with {SelectedPointCount} points each. Please select less channels or less points and try again."));
}
finally
{
OnPropertyChanged(nameof(IsEmpty));
OnPropertyChanged(nameof(ChannelViewModels));
OnPropertyChanged(nameof(SelectedPointCount));
OnPropertyChanged(nameof(TotalPoints));
OnPropertyChanged(nameof(XRange));
IsLoading = false;
}
}
19
View Source File : Assistant.cs
License : Apache License 2.0
Project Creator : ac87
License : Apache License 2.0
Project Creator : ac87
private void ProcessInAudio(object sender, WaveInEventArgs e)
{
OnDebug?.Invoke($"Process Audio {e.Buffer.Length} SendSpeech={_sendSpeech} Writing={_writing}", true);
if (_sendSpeech)
{
// cannot do more than one write at a time so if its writing already add the new data to the queue
if (_writing)
_writeBuffer.Add(e.Buffer);
else
WriteAudioData(e.Buffer);
}
}
19
View Source File : TextureCache.cs
License : GNU General Public License v3.0
Project Creator : ACEmulator
License : GNU General Public License v3.0
Project Creator : ACEmulator
public static Texture2D GenerateMipMaps(byte[] data, int size)
{
var source = new Texture2D(GraphicsDevice, size, size, false, SurfaceFormat.Color);
source.SetData(data);
var texture = new Texture2D(GraphicsDevice, size, size, true, SurfaceFormat.Color);
texture.SetData(0, null, data, 0, data.Length);
var miplevel = new List<byte[]>();
var mipsize = size / 2;
while (true)
{
var mipmap = GenerateMipMap(source, mipsize);
var mipdata = new byte[mipsize * mipsize * 4];
mipmap.GetData(mipdata);
miplevel.Add(mipdata);
if (mipsize > 1)
mipsize /= 2;
else
break;
};
for (var i = 0; i < miplevel.Count; i++)
{
texture.SetData(i + 1, null, miplevel[i], 0, miplevel[i].Length);
}
return texture;
}
19
View Source File : TextureExtensions.cs
License : GNU General Public License v3.0
Project Creator : ACEmulator
License : GNU General Public License v3.0
Project Creator : ACEmulator
public static List<byte[]> GetMipData(this Texture2D texture, int size)
{
var numLevels = texture.LevelCount;
var mipData = new List<byte[]>();
var mipsize = size * 4;
for (var i = 0; i < numLevels; i++)
{
var data = new byte[mipsize];
texture.GetData(i, null, data, 0, mipsize);
mipData.Add(data);
mipsize /= 4;
}
return mipData;
}
19
View Source File : KoiHeap.cs
License : GNU General Public License v3.0
Project Creator : Aekras1a
License : GNU General Public License v3.0
Project Creator : Aekras1a
public uint AddChunk(byte[] chunk)
{
var offset = currentLen;
chunks.Add(chunk);
currentLen += (uint) chunk.Length;
return offset;
}
19
View Source File : SecretSharingHelper.cs
License : MIT License
Project Creator : AElfProject
License : MIT License
Project Creator : AElfProject
public static List<byte[]> EncodeSecret(byte[] secretMessage, int threshold, int totalParts)
{
// Polynomial construction.
var coefficients = new BigInteger[threshold];
// Set p(0) = secret message.
coefficients[0] = secretMessage.ToBigInteger();
for (var i = 1; i < threshold; i++)
{
var foo = new byte[32];
Array.Copy(HashHelper.ComputeFrom(Guid.NewGuid().ToByteArray()).ToArray(), foo, 32);
coefficients[i] = BigInteger.Abs(new BigInteger(foo));
}
var result = new List<byte[]>();
for (var i = 1; i < totalParts + 1; i++)
{
var secretBigInteger = coefficients[0];
for (var j = 1; j < threshold; j++)
{
secretBigInteger += coefficients[j] * BigInteger.Pow(new BigInteger(i), j);
secretBigInteger %= SecretSharingConsts.FieldPrime;
}
result.Add(secretBigInteger.ToByteArray());
}
return result;
}
19
View Source File : InMemoryDatabase.cs
License : MIT License
Project Creator : AElfProject
License : MIT License
Project Creator : AElfProject
public Task<List<byte[]>> GetAllAsync(IList<string> keys)
{
if (keys.Count == 0)
return null;
var result = new List<byte[]>();
foreach (var key in keys)
{
Check.NotNullOrWhiteSpace(key, nameof(key));
_dictionary.TryGetValue(key, out var value);
result.Add(value);
}
return result.Any() ? Task.FromResult(result) : Task.FromResult<List<byte[]>>(null);
}
19
View Source File : EpubBuilder.cs
License : GNU General Public License v3.0
Project Creator : Aeroblast
License : GNU General Public License v3.0
Project Creator : Aeroblast
string ProcEmbed(string uri)
{
string link;
Regex reg_path = new Regex("kindle:embed:([0-9|A-V]+)");
Regex reg_query = new Regex("mime=(.*)/(.*)");
Match m = reg_path.Match(uri);
if (!m.Success) { Log.log("[Error]link unsolved: " + uri); return ""; }
int resid = (int)Util.DecodeBase32(m.Groups[1].Value) - 1;
if (uri.IndexOf('?') > 1)
{
m = reg_query.Match(uri);
if (m.Groups[1].Value == "image")
{
string name = AddImage(resid);
link = "../Images/" + name;
}
else
{
throw new NotImplementedException();
}
}
else
{
Section section = azw3.sections[azw3.mobi_header.first_res_index + resid];
switch (section.type)
{
case "FONT":
{
Font_Section font_Section = (Font_Section)section;
string name = "embed" + Util.Number(resid) + font_Section.ext;
link = "../Fonts/" + name;
font_Section.comment = name;
fonts.Add(font_Section.data);
font_names.Add(name);
}
break;
default:
throw new NotImplementedException();
}
}
return link;
}
19
View Source File : Decompress.cs
License : GNU General Public License v3.0
Project Creator : Aeroblast
License : GNU General Public License v3.0
Project Creator : Aeroblast
public void Add(byte[] raw)
{
string ident = Encoding.ASCII.GetString(raw, 0, 4);
if (ident != "CDIC") { throw new UnpackKindleSException("Unexpect Section Header at CDIC"); }
UInt32 phases = Util.GetUInt32(raw, 8);
UInt32 bits = Util.GetUInt32(raw, 12);
long n = Math.Min(1 << (int)bits, phases - slice.Count);
for (int i = 0; i < n; i++)
{
UInt16 off = Util.GetUInt16(raw, (ulong)(16 + i * 2));
UInt16 length = Util.GetUInt16(raw, (ulong)(16 + off));
slice_flag.Add((length & 0x8000) > 0);
slice.Add(Util.SubArray(raw, (ulong)(18 + off), (ulong)(length & 0x7fff)));
}
}
19
View Source File : EpubBuilder.cs
License : GNU General Public License v3.0
Project Creator : Aeroblast
License : GNU General Public License v3.0
Project Creator : Aeroblast
string AddImage(int id, string message = "")
{
string name = null; byte[] data = null;
Section toComment = null;
if (azw6 != null)
{
int r = azw6.image_sections.Find(s => s == (id + 1));
if (r != 0)
{
CRES_Section sec = (CRES_Section)azw6.sections[r];
name = ImageNameHD(id, sec);
data = sec.img;
sec.comment = name;
toComment = azw3.sections[azw3.mobi_header.first_res_index + id];
}
}
if (name == null)
{
Image_Section section = (Image_Section)azw3.sections[azw3.mobi_header.first_res_index + id];
name = ImageName(id, section);
data = section.raw;
toComment = section;
}
if (img_names.Find(s => s == name) != null) return name;
imgs.Add(data);
img_names.Add(name);
toComment.comment = name + " | " + message;
return name;
}
19
View Source File : RedisClientEx.cs
License : Mozilla Public License 2.0
Project Creator : agebullhu
License : Mozilla Public License 2.0
Project Creator : agebullhu
public SetScanResult ScanSet(byte[] setId, long cursor, long count = 10L)
{
var cmd = new[] { cSScan, setId, cursor.ToUtf8Bytes(), cCount, count.ToUtf8Bytes() };//cMatch, cAnyone,
if (!this.SendCommand(cmd))
{
Status = -1;
LastError = string.Join(" ", "SSCAN", Encoding.UTF8.GetString(setId), cursor, count);
return null;
}
SetScanResult result = new SetScanResult();
LineResult line = new LineResult();
if (!ReadSingleLine(line))
{
return result;
}
#if DEBUG
if (line.type != 1)
{
this.Status = 2;
return result;
}
int lines;
if (!int.TryParse(line.sValue, out lines) || lines <= 0)
{
this.Status = 2;
return result;
}
#endif
result.NextCursor = int.Parse(this.ReadString());
var cnt = ReadNumber();
for (int i = 0; i < cnt; i++)
{
if (!ReadSingleLine(line))
{
return result;
}
#if DEBUG
if (line.type != 2)
{
this.Status = 3;
return result;
}
#endif
result.Values.Add(line.bValue);
}
return result;
}
19
View Source File : Asn1IntegerConverter.cs
License : Mozilla Public License 2.0
Project Creator : agebullhu
License : Mozilla Public License 2.0
Project Creator : agebullhu
private static byte[] TwoToThePowerOf(int n)
{
using (ThreadLockScope.Scope(powersOfTwo))
{
if (n >= powersOfTwo.Count)
{
for (var i = powersOfTwo.Count; i <= n; i++)
{
var list = new List<byte>(powersOfTwo[i - 1]);
byte num2 = 0;
for (var j = 0; j < list.Count; j++)
{
var num4 = (byte)((list[j] << 1) + num2);
list[j] = (byte)(num4 % 10);
num2 = (byte)(num4 / 10);
}
if (num2 > 0)
{
list.Add(num2);
}
powersOfTwo.Add(list.ToArray());
}
}
return powersOfTwo[n];
}
}
19
View Source File : RedisClientEx.cs
License : Mozilla Public License 2.0
Project Creator : agebullhu
License : Mozilla Public License 2.0
Project Creator : agebullhu
public SetScanResult ScanSet(byte[] setId, long cursor, long count = 10L)
{
var cmd = new[] { cSScan, setId, cursor.ToUtf8Bytes(), cCount, count.ToUtf8Bytes() };//cMatch, cAnyone,
if (!SendCommand(cmd))
{
Status = -1;
LastError = string.Join(" ", "SSCAN", Encoding.UTF8.GetString(setId), cursor, count);
return null;
}
SetScanResult result = new SetScanResult();
LineResult line = new LineResult();
if (!ReadSingleLine(line))
{
return result;
}
#if DEBUG
if (line.type != 1)
{
Status = 2;
return result;
}
int lines;
if (!int.TryParse(line.sValue, out lines) || lines <= 0)
{
Status = 2;
return result;
}
#endif
result.NextCursor = int.Parse(ReadString());
var cnt = ReadNumber();
for (int i = 0; i < cnt; i++)
{
if (!ReadSingleLine(line))
{
return result;
}
#if DEBUG
if (line.type != 2)
{
Status = 3;
return result;
}
#endif
result.Values.Add(line.bValue);
}
return result;
}
19
View Source File : WSPublisher.cs
License : Mozilla Public License 2.0
Project Creator : agebullhu
License : Mozilla Public License 2.0
Project Creator : agebullhu
protected override void OnNewClient(byte[] idenreplacedy)
{
_idenreplacedies.Add(idenreplacedy);
}
19
View Source File : Alternating.cs
License : GNU General Public License v3.0
Project Creator : akmadian
License : GNU General Public License v3.0
Project Creator : akmadian
public List<byte[]> BuildBytes(NZXTDeviceType Type, IChannel Channel) {
switch (Type)
{
case NZXTDeviceType.HuePlus:
List<byte[]> outList = new List<byte[]>();
for (int colorIndex = 0; colorIndex < Colors.Length; colorIndex++)
{
byte[] SettingsBytes = new byte[] { 0x4b, (byte)Channel.ChannelByte, 0x05, _Param1, new CISS(colorIndex, this.speed) };
byte[] final = SettingsBytes.ConcatenateByteArr(Channel.BuildColorBytes(Colors[colorIndex]));
outList.Add(final);
}
return outList;
case NZXTDeviceType.KrakenX:
DCBWM direction = new DCBWM(Channel.ChannelByte, _Param1.IsForward, _Param1.WithMovement);
List<byte[]> KrakenXOutList = new List<byte[]>();
for (int colorIndex = 0; colorIndex < Colors.Length; colorIndex++)
{
byte[] KrakenXSettingsBytes = new byte[] { 0x2, 0x4c, direction, 0x05, new CISS(colorIndex, this.speed) };
byte[] final = KrakenXSettingsBytes.ConcatenateByteArr(Channel.BuildColorBytes(Colors[colorIndex]));
KrakenXOutList.Add(final);
}
return KrakenXOutList;
default:
return null;
}
}
19
View Source File : Breathing.cs
License : GNU General Public License v3.0
Project Creator : akmadian
License : GNU General Public License v3.0
Project Creator : akmadian
public List<byte[]> BuildBytes(NZXTDeviceType Type, IChannel Channel) {
switch (Type) // Filter by device type
{
case NZXTDeviceType.HuePlus:
List<byte[]> outList = new List<byte[]>();
for (int colorIndex = 0; colorIndex < Colors.Length; colorIndex++)
{
byte[] SettingsBytes = new byte[] { 0x4b, (byte)Channel.ChannelByte, 0x07, 0x03, new CISS(colorIndex, this.speed) };
byte[] final = SettingsBytes.ConcatenateByteArr(Channel.BuildColorBytes(Colors[colorIndex]));
outList.Add(final);
}
return outList;
case NZXTDeviceType.KrakenX:
List<byte[]> KrakenOutList = new List<byte[]>();
for (int colorIndex = 0; colorIndex < Colors.Length; colorIndex++)
{
byte[] KrakenSettingsBytes = new byte[] { 0x02, 0x4c, (byte)Channel.ChannelByte, 0x06, new CISS(colorIndex, this.speed) };
byte[] KrakenFinal = KrakenSettingsBytes.ConcatenateByteArr(Channel.BuildColorBytes(Colors[colorIndex]));
KrakenOutList.Add(KrakenFinal);
}
return KrakenOutList;
default:
return null;
}
}
19
View Source File : CoveringMarquee.cs
License : GNU General Public License v3.0
Project Creator : akmadian
License : GNU General Public License v3.0
Project Creator : akmadian
public List<byte[]> BuildBytes(NZXTDeviceType Type, IChannel Channel) {
switch (Type)
{
case NZXTDeviceType.HuePlus:
List<byte[]> outList = new List<byte[]>();
for (int colorIndex = 0; colorIndex < _Colors.Length; colorIndex++)
{
byte[] SettingsBytes = new byte[] { 0x4b, (byte)Channel.ChannelByte, 0x04, Param1, new CISS(colorIndex, this._Speed) };
byte[] final = SettingsBytes.ConcatenateByteArr(Channel.BuildColorBytes(_Colors[colorIndex]));
outList.Add(final);
}
return outList;
case NZXTDeviceType.KrakenX:
List<byte[]> KrakenOutList = new List<byte[]>();
DCB param = new DCB(Channel.ChannelByte, Param1.IsForward);
for (int colorIndex = 0; colorIndex < _Colors.Length; colorIndex++)
{
byte[] KrakenSettingsBytes = new byte[] {0x2, 0x4c, (byte)param.GetValue(), 0x04, new CISS(colorIndex, _Speed)};
byte[] KrakenFinal = KrakenSettingsBytes.ConcatenateByteArr(Channel.BuildColorBytes(_Colors[colorIndex]));
KrakenOutList.Add(KrakenFinal);
}
return KrakenOutList;
default:
return null;
}
}
19
View Source File : Fading.cs
License : GNU General Public License v3.0
Project Creator : akmadian
License : GNU General Public License v3.0
Project Creator : akmadian
public List<byte[]> BuildBytes(NZXTDeviceType Type, IChannel Channel_) {
switch (Type)
{
case NZXTDeviceType.HuePlus:
List<byte[]> outList = new List<byte[]>();
for (int colorIndex = 0; colorIndex < Colors.Length; colorIndex++)
{
byte[] SettingsBytes = new byte[] { 0x4b, (byte)Channel_.ChannelByte, 0x01, 0x03, new CISS(colorIndex, this._Speed) };
byte[] final = SettingsBytes.ConcatenateByteArr(Channel_.BuildColorBytes(Colors[colorIndex]));
outList.Add(final);
}
return outList;
case NZXTDeviceType.KrakenX:
List<byte[]> KrakenXOutList = new List<byte[]>();
for (int colorIndex = 0; colorIndex < Colors.Length; colorIndex++)
{
byte[] SettingsBytes = new byte[] { 0x02, 0x4c, (byte)Channel_.ChannelByte, 0x01, new CISS(colorIndex, this._Speed) };
byte[] KrakenXfinal = SettingsBytes.ConcatenateByteArr(Channel_.BuildColorBytes(Colors[colorIndex]));
KrakenXOutList.Add(KrakenXfinal);
}
return KrakenXOutList;
default:
return null;
}
}
19
View Source File : Marquee.cs
License : GNU General Public License v3.0
Project Creator : akmadian
License : GNU General Public License v3.0
Project Creator : akmadian
public List<byte[]> BuildBytes(NZXTDeviceType Type, IChannel Channel) {
switch (Type)
{
case NZXTDeviceType.HuePlus:
List<byte[]> outList = new List<byte[]>();
byte[] SettingsBytes = new byte[] { 0x4b, (byte)Channel.ChannelByte, 0x03, Param1, Param2 };
byte[] final = SettingsBytes.ConcatenateByteArr(Channel.State == false ? Color.AllOff() : Channel.BuildColorBytes(_Color));
outList.Add(final);
return outList;
case NZXTDeviceType.KrakenX:
List<byte[]> KrakenXOutList = new List<byte[]>();
byte[] KrakenXSettingsBytes = new byte[] { 0x02, 0x4c, 0x02, 0x03, Param2 };
byte[] KrakenXfinal = KrakenXSettingsBytes.ConcatenateByteArr(Channel.State == false ? Color.AllOff() : Channel.BuildColorBytes(_Color));
KrakenXOutList.Add(KrakenXfinal);
return KrakenXOutList;
default:
return null;
}
}
19
View Source File : Pulse.cs
License : GNU General Public License v3.0
Project Creator : akmadian
License : GNU General Public License v3.0
Project Creator : akmadian
public List<byte[]> BuildBytes(NZXTDeviceType Type, IChannel Channel) {
switch (Type)
{
case NZXTDeviceType.HuePlus:
List<byte[]> outList = new List<byte[]>();
for (int colorIndex = 0; colorIndex < Colors.Length; colorIndex++)
{
byte[] SettingsBytes = new byte[] { 0x4b, (byte)Channel.ChannelByte, 0x06, 0x03, new CISS(colorIndex, this.speed) };
byte[] final = SettingsBytes.ConcatenateByteArr(Channel.BuildColorBytes(Colors[colorIndex]));
outList.Add(final);
}
return outList;
case NZXTDeviceType.KrakenX:
List<byte[]> KrakenOutList = new List<byte[]>();
Console.WriteLine("ColorsLength - " + Colors.Length);
for (int colorIndex = 0; colorIndex < Colors.Length; colorIndex++)
{
byte[] KrakenSettingsBytes = new byte[] { 0x02, 0x4c, (byte)Channel.ChannelByte, 0x07, new CISS(colorIndex, this.speed) };
byte[] KrakenFinal = KrakenSettingsBytes.ConcatenateByteArr(Channel.BuildColorBytes(Colors[colorIndex]));
KrakenOutList.Add(KrakenFinal);
}
Console.WriteLine("OutList Length - " + KrakenOutList.Count);
return KrakenOutList;
default:
return null;
}
}
19
View Source File : Wings.cs
License : GNU General Public License v3.0
Project Creator : akmadian
License : GNU General Public License v3.0
Project Creator : akmadian
public List<byte[]> BuildBytes(NZXTDeviceType Type, IChannel Channel)
{
switch (Type) {
case NZXTDeviceType.HuePlus:
List<byte[]> outList = new List<byte[]>();
byte[] SettingsBytes = new byte[] { 0x4b, (byte)Channel.ChannelByte, 0x0c, 0x03, new CISS(0, this.speed) };
byte[] final = SettingsBytes.ConcatenateByteArr(Channel.BuildColorBytes(Color));
outList.Add(final);
return outList;
case NZXTDeviceType.KrakenX:
List<byte[]> KrakenXOutBytes = new List<byte[]>();
byte[] KrakenXSettingsBytes = new byte[] { 0x02, 0x4c, (byte)Channel.ChannelByte, 0x0c, (byte)speed };
byte[] KrakenXFinal = KrakenXSettingsBytes.ConcatenateByteArr(Channel.BuildColorBytes(Color));
KrakenXOutBytes.Add(KrakenXFinal);
return KrakenXOutBytes;
default:
return null;
}
}
19
View Source File : Color.cs
License : GNU General Public License v3.0
Project Creator : akmadian
License : GNU General Public License v3.0
Project Creator : akmadian
internal byte[][] ExpandedChunks(int NumLeds)
{
List<byte[]> outBytes = new List<byte[]>();
for (int i = 0; i < NumLeds; i++)
{
byte[] arr = new byte[3]
{
Convert.ToByte(_G),
Convert.ToByte(_R),
Convert.ToByte(_B)
};
outBytes.Add(arr);
}
return outBytes.ToArray();
}
19
View Source File : HuePlus.cs
License : GNU General Public License v3.0
Project Creator : akmadian
License : GNU General Public License v3.0
Project Creator : akmadian
public void ApplyEffect(HuePlusChannel channel, IEffect effect, bool SaveToChannel = true)
{
if (!effect.IsCompatibleWith(Type))
throw new IncompatibleEffectException(Type.ToString(), effect.EffectName);
List<byte[]> commandQueue = new List<byte[]>();
// TODO : Improve this, not elegant.
if (channel == this._Both) // If both channels, build and send bytes for both individually
{
foreach (byte[] arr in effect.BuildBytes(Type, this._Channel1))
{
commandQueue.Add(arr);
}
foreach (byte[] arr in effect.BuildBytes(Type, this._Channel2))
{
commandQueue.Add(arr);
}
if (SaveToChannel)
{
_Channel1.UpdateEffect(effect);
_Channel2.UpdateEffect(effect);
}
}
else // Otherwise, just build for the selected channel
{
commandQueue = effect.BuildBytes(Type, channel);
}
if (SaveToChannel) { channel.UpdateEffect(effect); }
effect.Channel = channel;
foreach (byte[] command in commandQueue) // Send command buffer
{
_COMController.WriteNoReponse(command);
Thread.Sleep(10);
}
}
19
View Source File : Loading.cs
License : GNU General Public License v3.0
Project Creator : akmadian
License : GNU General Public License v3.0
Project Creator : akmadian
public List<byte[]> BuildBytes(NZXTDeviceType Type, IChannel Channel)
{
if (Channel.ChannelByte == 0x00 || Channel.ChannelByte == 0x01)
{
throw new IncompatibleParamException("TaiChi channel can only be Ring (ChanneByte: 0x02)");
}
List<byte[]> KrakenOutList = new List<byte[]>();
byte[] KrakenSettingsBytes = new byte[] { 0x02, 0x4c, (byte)Channel.ChannelByte, 0x0a, (byte)Speed };
byte[] KrakenFinal = KrakenSettingsBytes.ConcatenateByteArr(Channel.BuildColorBytes(Color));
KrakenOutList.Add(KrakenFinal);
return KrakenOutList;
}
19
View Source File : TaiChi.cs
License : GNU General Public License v3.0
Project Creator : akmadian
License : GNU General Public License v3.0
Project Creator : akmadian
public List<byte[]> BuildBytes(NZXTDeviceType Type, IChannel Channel)
{
if (Channel.ChannelByte == 0x00 || Channel.ChannelByte == 0x01)
{
throw new IncompatibleParamException("TaiChi channel can only be Ring or 0x02");
}
List<byte[]> KrakenOutList = new List<byte[]>();
for (int ColorIndex = 0; ColorIndex < Colors.Length; ColorIndex++)
{
byte[] KrakenSettingsBytes = new byte[] { 0x02, 0x4c, (byte)Channel.ChannelByte, 0x08, new CISS(ColorIndex, Speed) };
byte[] KrakenFinal = KrakenSettingsBytes.ConcatenateByteArr(Channel.BuildColorBytes(Colors[ColorIndex]));
KrakenOutList.Add(KrakenFinal);
}
return KrakenOutList;
}
19
View Source File : WaterCooler.cs
License : GNU General Public License v3.0
Project Creator : akmadian
License : GNU General Public License v3.0
Project Creator : akmadian
public List<byte[]> BuildBytes(NZXTDeviceType Type, IChannel Channel)
{
if (Channel.ChannelByte == 0x00 || Channel.ChannelByte == 0x01)
{
throw new IncompatibleParamException("TaiChi channel can only be Ring (ChanneByte: 0x02)");
}
List<byte[]> KrakenOutList = new List<byte[]>();
byte[] KrakenLogoBytes = new byte[] { 0x02, 0x4c, 0x01, 0x06, (byte)Speed };
byte[] KrakenLogoFinal = KrakenLogoBytes.ConcatenateByteArr(Channel.BuildColorBytes(new Color(255, 0, 0)));
KrakenOutList.Add(KrakenLogoFinal);
byte[] KrakenRingBytes = new byte[] { 0x02, 0x4c, 0x02, 0x09, (byte)Speed };
byte[] KrakenRingFinal = KrakenRingBytes.ConcatenateByteArr(Channel.BuildColorBytes(new Color(0, 0, 255)));
KrakenOutList.Add(KrakenRingFinal);
return KrakenOutList;
}
19
View Source File : MapboxUnitTests_Utils.cs
License : MIT License
Project Creator : alen-smajic
License : MIT License
Project Creator : alen-smajic
public void OnNext(RasterTile tile)
{
if (tile.CurrentState == Tile.State.Loaded && !tile.HasError)
{
tiles.Add(tile.Data);
}
}
19
View Source File : MapboxUnitTests_Utils.cs
License : MIT License
Project Creator : alen-smajic
License : MIT License
Project Creator : alen-smajic
public void OnNext(ClreplacedicRasterTile tile)
{
if (tile.CurrentState == Tile.State.Loaded && !tile.HasError)
{
tiles.Add(tile.Data);
}
}
19
View Source File : NSUrlSessionHandler.cs
License : MIT License
Project Creator : alexrainman
License : MIT License
Project Creator : alexrainman
public void AddByteArray(byte[] arrayToAdd)
{
if (exception != null) throw exception;
if (isCompleted) throw new InvalidOperationException("Can't add byte arrays once Complete() is called");
lock (bytes)
{
maxLength += arrayToAdd.Length;
bytes.Add(arrayToAdd);
//Console.WriteLine("Added a new byte array, {0}: max = {1}", arrayToAdd.Length, maxLength);
}
Interlocked.Exchange(ref lockRelease, EmptyDisposable.Instance).Dispose();
}
19
View Source File : AddressExtensions.cs
License : MIT License
Project Creator : allartprotocol
License : MIT License
Project Creator : allartprotocol
public static (byte[] Address, int Nonce) FindProgramAddress(IEnumerable<byte[]> seeds, byte[] programId)
{
var nonce = 255;
var buffer = seeds.ToList();
while (nonce-- != 0)
{
byte[] address;
try
{
buffer.Add(new [] { (byte) nonce });
address = CreateProgramAddress(buffer, programId);
}
catch (Exception)
{
buffer.RemoveAt(buffer.Count - 1);
continue;
}
return (address, nonce);
}
throw new Exception("unable to find viable program address nonce");
}
19
View Source File : ListBinarySetDdbConverter.cs
License : MIT License
Project Creator : AllocZero
License : MIT License
Project Creator : AllocZero
protected override void Add(List<byte[]> collection, byte[] item, int index) => collection.Add(item);
19
View Source File : IListBinarySetDdbConverter.cs
License : MIT License
Project Creator : AllocZero
License : MIT License
Project Creator : AllocZero
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private AttributeValue WriteInlined(ref IList<byte[]> value)
{
if (value is List<byte[]> list)
return new AttributeValue(new BinarySetAttributeValue(list));
list = new List<byte[]>(value.Count);
foreach (var item in value)
list.Add(item);
return new AttributeValue(new BinarySetAttributeValue(list));
}
19
View Source File : DocumentDdbReader.TryReadBinarySet.cs
License : MIT License
Project Creator : AllocZero
License : MIT License
Project Creator : AllocZero
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static List<byte[]> CreateBinarySetFromBuffer(ref ReusableBuffer<AttributeValue> buffer)
{
if (buffer.Index == 0)
return new List<byte[]>();
var set = new List<byte[]>(buffer.Index);
for (var i = 0; i < buffer.Index; i++)
set.Add(buffer.RentedBuffer![i].AsBinaryAttribute().Value);
return set;
}
19
View Source File : ColumnIndex.cs
License : MIT License
Project Creator : aloneguid
License : MIT License
Project Creator : aloneguid
public void Read (TProtocol iprot)
{
iprot.IncrementRecursionDepth();
try
{
bool isset_null_pages = false;
bool isset_min_values = false;
bool isset_max_values = false;
bool isset_boundary_order = false;
TField field;
iprot.ReadStructBegin();
while (true)
{
field = iprot.ReadFieldBegin();
if (field.Type == TType.Stop) {
break;
}
switch (field.ID)
{
case 1:
if (field.Type == TType.List) {
{
Null_pages = new List<bool>();
TList _list32 = iprot.ReadListBegin();
for( int _i33 = 0; _i33 < _list32.Count; ++_i33)
{
bool _elem34;
_elem34 = iprot.ReadBool();
Null_pages.Add(_elem34);
}
iprot.ReadListEnd();
}
isset_null_pages = true;
} else {
TProtocolUtil.Skip(iprot, field.Type);
}
break;
case 2:
if (field.Type == TType.List) {
{
Min_values = new List<byte[]>();
TList _list35 = iprot.ReadListBegin();
for( int _i36 = 0; _i36 < _list35.Count; ++_i36)
{
byte[] _elem37;
_elem37 = iprot.ReadBinary();
Min_values.Add(_elem37);
}
iprot.ReadListEnd();
}
isset_min_values = true;
} else {
TProtocolUtil.Skip(iprot, field.Type);
}
break;
case 3:
if (field.Type == TType.List) {
{
Max_values = new List<byte[]>();
TList _list38 = iprot.ReadListBegin();
for( int _i39 = 0; _i39 < _list38.Count; ++_i39)
{
byte[] _elem40;
_elem40 = iprot.ReadBinary();
Max_values.Add(_elem40);
}
iprot.ReadListEnd();
}
isset_max_values = true;
} else {
TProtocolUtil.Skip(iprot, field.Type);
}
break;
case 4:
if (field.Type == TType.I32) {
Boundary_order = (BoundaryOrder)iprot.ReadI32();
isset_boundary_order = true;
} else {
TProtocolUtil.Skip(iprot, field.Type);
}
break;
case 5:
if (field.Type == TType.List) {
{
Null_counts = new List<long>();
TList _list41 = iprot.ReadListBegin();
for( int _i42 = 0; _i42 < _list41.Count; ++_i42)
{
long _elem43;
_elem43 = iprot.ReadI64();
Null_counts.Add(_elem43);
}
iprot.ReadListEnd();
}
} else {
TProtocolUtil.Skip(iprot, field.Type);
}
break;
default:
TProtocolUtil.Skip(iprot, field.Type);
break;
}
iprot.ReadFieldEnd();
}
iprot.ReadStructEnd();
if (!isset_null_pages)
throw new TProtocolException(TProtocolException.INVALID_DATA);
if (!isset_min_values)
throw new TProtocolException(TProtocolException.INVALID_DATA);
if (!isset_max_values)
throw new TProtocolException(TProtocolException.INVALID_DATA);
if (!isset_boundary_order)
throw new TProtocolException(TProtocolException.INVALID_DATA);
}
finally
{
iprot.DecrementRecursionDepth();
}
}
19
View Source File : WriteStreamTest.cs
License : Apache License 2.0
Project Creator : aloneguid
License : Apache License 2.0
Project Creator : aloneguid
protected override void DumpBuffer(byte[] buffer, int count, bool isFinal)
{
byte[] chunk = new byte[count];
Array.Copy(buffer, chunk, count);
blocks.Add(chunk);
}
19
View Source File : Payloads.cs
License : MIT License
Project Creator : Andy53
License : MIT License
Project Creator : Andy53
public static List<int> PopPopRet(byte[] data)
{
List<int> locations = new List<int>();
List<byte[]> replacedemblies = new List<byte[]>();
byte[] R8 = new byte[] { 0x58, 0x41 };
byte[] R9 = new byte[] { 0x59, 0x41 };
byte[] R10 = new byte[] { 0x5A, 0x41 };
byte[] R11 = new byte[] { 0x5B, 0x41 };
byte[] R12 = new byte[] { 0x5C, 0x41 };
byte[] R13 = new byte[] { 0x5D, 0x41 };
byte[] R14 = new byte[] { 0x5E, 0x41 };
byte[] R15 = new byte[] { 0x5F, 0x41 };
replacedemblies.Add(BitConverter.GetBytes(0xC3));
replacedemblies.Add(BitConverter.GetBytes(0x58));
replacedemblies.Add(BitConverter.GetBytes(0x5D));
replacedemblies.Add(BitConverter.GetBytes(0x59));
replacedemblies.Add(BitConverter.GetBytes(0x5A));
replacedemblies.Add(BitConverter.GetBytes(0x5C));
replacedemblies.Add(BitConverter.GetBytes(0x5D));
replacedemblies.Add(BitConverter.GetBytes(0x5E));
replacedemblies.Add(BitConverter.GetBytes(0x5F));
replacedemblies.Add(R8);
replacedemblies.Add(R9);
replacedemblies.Add(R10);
replacedemblies.Add(R11);
replacedemblies.Add(R12);
replacedemblies.Add(R13);
replacedemblies.Add(R14);
replacedemblies.Add(R15);
replacedemblies.Add(BitConverter.GetBytes(0x5F));
replacedemblies.Add(BitConverter.GetBytes(0x5E));
replacedemblies.Add(BitConverter.GetBytes(0x5B));
replacedemblies.Add(BitConverter.GetBytes(0x5A));
replacedemblies.Add(BitConverter.GetBytes(0x59));
replacedemblies.Add(BitConverter.GetBytes(0x58));
replacedemblies.Add(BitConverter.GetBytes(0x5D));
replacedemblies.Add(BitConverter.GetBytes(0x5C));
for(int i = 2; i < data.Length; i++)
{
bool complete = false;
if (data[i].Equals(replacedemblies[0][0]))
{
for(int j = 1; j < replacedemblies.Count; j++)
{
if(data[i - 1].Equals(replacedemblies[j][0]))
{
if (replacedemblies[j].Length < 4)
{
for (int k = 1; k < replacedemblies.Count; k++)
{
if (data[i - 2].Equals(replacedemblies[k][0]) && replacedemblies[k].Length < 4 && complete == false)
{
locations.Add(i - 2);
complete = true;
}
else if(data[i - 2].Equals(replacedemblies[k][0]))
{
if (data[i - 3].Equals(0x41) && complete == false)
{
locations.Add(i - 3);
complete = true;
}
}
}
}
else
{
if (data[i - 2].Equals(0x41))
{
for (int k = 1; k < replacedemblies.Count; k++)
{
if (data[i - 3].Equals(replacedemblies[k][0]) && complete == false)
{
if(replacedemblies[k].Length < 4)
{
locations.Add(i - 3);
complete = true;
}
else if(replacedemblies[k].Length == 4 && data[i - 4].Equals(0x41) && complete == false)
{
locations.Add(i - 4);
complete = true;
}
}
}
}
}
}
}
}
}
return locations;
}
19
View Source File : KeyConfig.cs
License : MIT License
Project Creator : angshuman
License : MIT License
Project Creator : angshuman
public static IList<byte[]> Split(byte[] input)
{
if (input.Length == 1 && input[0] != 0) {
return new byte[][] { input };
} else if (input.Length == 1 && input[0] == 0) {
return new byte[][] { };
}
var list = new List<byte[]>();
var lastIndex = -1;
for (int i = 0; i < input.Length; i++) {
if (input[i] != 0) {
continue;
}
var item = new byte[i - lastIndex - 1];
Buffer.BlockCopy(input, lastIndex + 1, item, 0, item.Length);
list.Add(item);
lastIndex = i;
}
return list;
}
19
View Source File : ReverseComplementTests.cs
License : Apache License 2.0
Project Creator : AnthonyLloyd
License : Apache License 2.0
Project Creator : AnthonyLloyd
static void Grouper()
{
// Set up complements map
map = new byte[256];
for (byte b = 0; b < 255; b++) map[b] = b;
map[(byte)'A'] = (byte)'T'; map[(byte)'a'] = (byte)'T';
map[(byte)'B'] = (byte)'V';
map[(byte)'C'] = (byte)'G';
map[(byte)'D'] = (byte)'H';
map[(byte)'G'] = (byte)'C';
map[(byte)'H'] = (byte)'D';
map[(byte)'K'] = (byte)'M';
map[(byte)'M'] = (byte)'K';
map[(byte)'R'] = (byte)'Y';
map[(byte)'T'] = (byte)'A';
map[(byte)'V'] = (byte)'B';
map[(byte)'Y'] = (byte)'R';
map[(byte)'a'] = (byte)'T';
map[(byte)'b'] = (byte)'V';
map[(byte)'c'] = (byte)'G';
map[(byte)'d'] = (byte)'H';
map[(byte)'g'] = (byte)'C';
map[(byte)'h'] = (byte)'D';
map[(byte)'k'] = (byte)'M';
map[(byte)'m'] = (byte)'K';
map[(byte)'r'] = (byte)'Y';
map[(byte)'t'] = (byte)'A';
map[(byte)'v'] = (byte)'B';
map[(byte)'y'] = (byte)'R';
var startHeader = 0;
var i = 0;
bool afterFirst = false;
var data = new List<byte[]>();
while (TryTake(readQue, out byte[] bytes))
{
data.Add(bytes);
while ((i = Array.IndexOf<byte>(bytes, GT, i + 1)) != -1)
{
var sequence = new RevCompSequence
{
Pages = data
,
StartHeader = startHeader,
EndExclusive = i
};
if (afterFirst)
(sequence.ReverseThread = new Thread(() => Reverse(sequence))).Start();
else
afterFirst = true;
writeQue.Add(sequence);
startHeader = i;
data = new List<byte[]> { bytes };
}
}
i = Array.IndexOf<byte>(data[^1], 0, 0);
var lastSequence = new RevCompSequence
{
Pages = data
,
StartHeader = startHeader,
EndExclusive = i == -1 ? data[^1].Length : i
};
Reverse(lastSequence);
writeQue.Add(lastSequence);
writeQue.CompleteAdding();
}
19
View Source File : BlobHeap.cs
License : GNU General Public License v3.0
Project Creator : anydream
License : GNU General Public License v3.0
Project Creator : anydream
uint AddToCache(byte[] data) {
uint offset;
cached.Add(data);
cachedDict[data] = offset = nextOffset;
nextOffset += (uint)GetRawDataSize(data);
return offset;
}
19
View Source File : ZipEntry.Write.cs
License : Apache License 2.0
Project Creator : Appdynamics
License : Apache License 2.0
Project Creator : Appdynamics
private byte[] ConstructExtraField(bool forCentralDirectory)
{
var listOfBlocks = new System.Collections.Generic.List<byte[]>();
byte[] block;
// Conditionally emit an extra field with Zip64 information. If the
// Zip64 option is Always, we emit the field, before knowing that it's
// necessary. Later, if it turns out this entry does not need zip64,
// we'll set the header ID to rubbish and the data will be ignored.
// This results in additional overhead metadata in the zip file, but
// it will be small in comparison to the entry data.
//
// On the other hand if the Zip64 option is AsNecessary and it's NOT
// for the central directory, then we do the same thing. Or, if the
// Zip64 option is AsNecessary and it IS for the central directory,
// and the entry requires zip64, then emit the header.
if (_container.Zip64 == Zip64Option.Always ||
(_container.Zip64 == Zip64Option.AsNecessary &&
(!forCentralDirectory || _entryRequiresZip64.Value)))
{
// add extra field for zip64 here
// workitem 7924
int sz = 4 + (forCentralDirectory ? 28 : 16);
block = new byte[sz];
int i = 0;
if (_presumeZip64 || forCentralDirectory)
{
// HeaderId = always use zip64 extensions.
block[i++] = 0x01;
block[i++] = 0x00;
}
else
{
// HeaderId = dummy data now, maybe set to 0x0001 (ZIP64) later.
block[i++] = 0x99;
block[i++] = 0x99;
}
// DataSize
block[i++] = (byte)(sz - 4); // decimal 28 or 16 (workitem 7924)
block[i++] = 0x00;
// The actual metadata - we may or may not have real values yet...
// uncompressed size
Array.Copy(BitConverter.GetBytes(_UncompressedSize), 0, block, i, 8);
i += 8;
// compressed size
Array.Copy(BitConverter.GetBytes(_CompressedSize), 0, block, i, 8);
i += 8;
// workitem 7924 - only include this if the "extra" field is for
// use in the central directory. It is unnecessary and not useful
// for local header; makes WinZip choke.
if (forCentralDirectory)
{
// relative offset
Array.Copy(BitConverter.GetBytes(_RelativeOffsetOfLocalHeader), 0, block, i, 8);
i += 8;
// starting disk number
Array.Copy(BitConverter.GetBytes(0), 0, block, i, 4);
}
listOfBlocks.Add(block);
}
#if AESCRYPTO
if (Encryption == EncryptionAlgorithm.WinZipAes128 ||
Encryption == EncryptionAlgorithm.WinZipAes256)
{
block = new byte[4 + 7];
int i = 0;
// extra field for WinZip AES
// header id
block[i++] = 0x01;
block[i++] = 0x99;
// data size
block[i++] = 0x07;
block[i++] = 0x00;
// vendor number
block[i++] = 0x01; // AE-1 - means "Verify CRC"
block[i++] = 0x00;
// vendor id "AE"
block[i++] = 0x41;
block[i++] = 0x45;
// key strength
int keystrength = GetKeyStrengthInBits(Encryption);
if (keystrength == 128)
block[i] = 1;
else if (keystrength == 256)
block[i] = 3;
else
block[i] = 0xFF;
i++;
// actual compression method
block[i++] = (byte)(_CompressionMethod & 0x00FF);
block[i++] = (byte)(_CompressionMethod & 0xFF00);
listOfBlocks.Add(block);
}
#endif
if (_ntfsTimesAreSet && _emitNtfsTimes)
{
block = new byte[32 + 4];
// HeaderId 2 bytes 0x000a == NTFS times
// Datasize 2 bytes 32
// reserved 4 bytes ?? don't care
// timetag 2 bytes 0x0001 == NTFS time
// size 2 bytes 24 == 8 bytes each for ctime, mtime, atime
// mtime 8 bytes win32 ticks since win32epoch
// atime 8 bytes win32 ticks since win32epoch
// ctime 8 bytes win32 ticks since win32epoch
int i = 0;
// extra field for NTFS times
// header id
block[i++] = 0x0a;
block[i++] = 0x00;
// data size
block[i++] = 32;
block[i++] = 0;
i += 4; // reserved
// time tag
block[i++] = 0x01;
block[i++] = 0x00;
// data size (again)
block[i++] = 24;
block[i++] = 0;
Int64 z = _Mtime.ToFileTime();
Array.Copy(BitConverter.GetBytes(z), 0, block, i, 8);
i += 8;
z = _Atime.ToFileTime();
Array.Copy(BitConverter.GetBytes(z), 0, block, i, 8);
i += 8;
z = _Ctime.ToFileTime();
Array.Copy(BitConverter.GetBytes(z), 0, block, i, 8);
i += 8;
listOfBlocks.Add(block);
}
if (_ntfsTimesAreSet && _emitUnixTimes)
{
int len = 5 + 4;
if (!forCentralDirectory) len += 8;
block = new byte[len];
// local form:
// --------------
// HeaderId 2 bytes 0x5455 == unix timestamp
// Datasize 2 bytes 13
// flags 1 byte 7 (low three bits all set)
// mtime 4 bytes seconds since unix epoch
// atime 4 bytes seconds since unix epoch
// ctime 4 bytes seconds since unix epoch
//
// central directory form:
//---------------------------------
// HeaderId 2 bytes 0x5455 == unix timestamp
// Datasize 2 bytes 5
// flags 1 byte 7 (low three bits all set)
// mtime 4 bytes seconds since unix epoch
//
int i = 0;
// extra field for "unix" times
// header id
block[i++] = 0x55;
block[i++] = 0x54;
// data size
block[i++] = unchecked((byte)(len - 4));
block[i++] = 0;
// flags
block[i++] = 0x07;
Int32 z = unchecked((int)((_Mtime - _unixEpoch).TotalSeconds));
Array.Copy(BitConverter.GetBytes(z), 0, block, i, 4);
i += 4;
if (!forCentralDirectory)
{
z = unchecked((int)((_Atime - _unixEpoch).TotalSeconds));
Array.Copy(BitConverter.GetBytes(z), 0, block, i, 4);
i += 4;
z = unchecked((int)((_Ctime - _unixEpoch).TotalSeconds));
Array.Copy(BitConverter.GetBytes(z), 0, block, i, 4);
i += 4;
}
listOfBlocks.Add(block);
}
// inject other blocks here...
// concatenate any blocks we've got:
byte[] aggregateBlock = null;
if (listOfBlocks.Count > 0)
{
int totalLength = 0;
int i, current = 0;
for (i = 0; i < listOfBlocks.Count; i++)
totalLength += listOfBlocks[i].Length;
aggregateBlock = new byte[totalLength];
for (i = 0; i < listOfBlocks.Count; i++)
{
System.Array.Copy(listOfBlocks[i], 0, aggregateBlock, current, listOfBlocks[i].Length);
current += listOfBlocks[i].Length;
}
}
return aggregateBlock;
}
19
View Source File : CompoundDocumentFile.cs
License : Apache License 2.0
Project Creator : Appdynamics
License : Apache License 2.0
Project Creator : Appdynamics
private void LoadSectors(BinaryReader br)
{
_sectors = new List<byte[]>();
while (br.BaseStream.Position < br.BaseStream.Length)
{
_sectors.Add(br.ReadBytes(_sectorSize));
}
}
19
View Source File : CompoundDocumentFile.cs
License : Apache License 2.0
Project Creator : Appdynamics
License : Apache License 2.0
Project Creator : Appdynamics
private void GetMiniSectors(byte[] miniFATStream)
{
var br = new BinaryReader(new MemoryStream(miniFATStream));
_miniSectors = new List<byte[]>();
while (br.BaseStream.Position < br.BaseStream.Length)
{
_miniSectors.Add(br.ReadBytes(_miniSectorSize));
}
}
19
View Source File : SysBotMini.cs
License : MIT License
Project Creator : architdate
License : MIT License
Project Creator : architdate
public byte[] ReadLargeBytes(ulong offset, int length, RWMethod method)
{
const int maxlength = 344 * 30;
var concatlist = new List<byte[]>();
while (length > 0)
{
var readlength = Math.Min(maxlength, length);
length -= readlength;
concatlist.Add(ReadBytes(offset, readlength, method));
offset += (ulong)readlength;
}
return ArrayUtil.ConcatAll(concatlist.ToArray());
}
See More Examples