本文整理汇总了C#中System.IO.MemoryStream.WriteByte方法的典型用法代码示例。如果您正苦于以下问题:C# System.IO.MemoryStream.WriteByte方法的具体用法?C# System.IO.MemoryStream.WriteByte怎么用?C# System.IO.MemoryStream.WriteByte使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.MemoryStream
的用法示例。
在下文中一共展示了System.IO.MemoryStream.WriteByte方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ECDHEPSKServerKeyExchange
public ECDHEPSKServerKeyExchange(ECDHEKeyExchange keyExchange)
{
_EllipticCurveType = TEllipticCurveType.NamedCurve;
_EllipticCurve = keyExchange.Curve;
System.IO.MemoryStream stream = new System.IO.MemoryStream();
stream.WriteByte((byte)_EllipticCurveType);
NetworkByteOrderConverter.WriteUInt16(stream, (ushort)_EllipticCurve);
byte[] pointEncoded = keyExchange.PublicKey.Q.GetEncoded(false);
stream.WriteByte((byte)pointEncoded.Length);
stream.Write(pointEncoded, 0, pointEncoded.Length);
_ServerParams = stream.ToArray();
}
示例2: start
private void start()
{
//Debug.Assert(MAPSIZE == 64, "The BlockBulkTransfer message requires a map size of 64.");
for (byte x = 0; x < MAPSIZE; x++)
for (byte y = 0; y < MAPSIZE; y += 16)
{
NetBuffer msgBuffer = infsN.CreateBuffer();
msgBuffer.Write((byte)Infiniminer.InfiniminerMessage.BlockBulkTransfer);
if (!compression)
{
msgBuffer.Write(x);
msgBuffer.Write(y);
for (byte dy = 0; dy < 16; dy++)
for (byte z = 0; z < MAPSIZE; z++)
msgBuffer.Write((byte)(infs.blockList[x, y + dy, z]));
if (client.Status == NetConnectionStatus.Connected)
infsN.SendMessage(msgBuffer, client, NetChannel.ReliableUnordered);
}
else
{
//Compress the data so we don't use as much bandwith - Xeio's work
var compressedstream = new System.IO.MemoryStream();
var uncompressed = new System.IO.MemoryStream();
var compresser = new System.IO.Compression.GZipStream(compressedstream, System.IO.Compression.CompressionMode.Compress);
//Send a byte indicating that yes, this is compressed
msgBuffer.Write((byte)255);
//Write everything we want to compress to the uncompressed stream
uncompressed.WriteByte(x);
uncompressed.WriteByte(y);
for (byte dy = 0; dy < 16; dy++)
for (byte z = 0; z < MAPSIZE; z++)
uncompressed.WriteByte((byte)(infs.blockList[x, y + dy, z]));
//Compress the input
compresser.Write(uncompressed.ToArray(), 0, (int)uncompressed.Length);
//infs.ConsoleWrite("Sending compressed map block, before: " + uncompressed.Length + ", after: " + compressedstream.Length);
compresser.Close();
//Send the compressed data
msgBuffer.Write(compressedstream.ToArray());
if (client.Status == NetConnectionStatus.Connected)
infsN.SendMessage(msgBuffer, client, NetChannel.ReliableUnordered);
}
}
conn.Abort();
}
示例3: EncodeDER
private static byte[] EncodeDER(byte[][] data)
{
byte[] payload;
using(var ms = new System.IO.MemoryStream())
{
foreach(var b in data)
{
ms.WriteByte(0x02);
var isNegative = (b[0] & 0x80) != 0;
EncodeDERLength(ms, (uint)(b.Length + (isNegative ? 1 : 0)));
if (isNegative)
ms.WriteByte(0);
ms.Write(b, 0, b.Length);
}
payload = ms.ToArray();
}
using(var ms = new System.IO.MemoryStream())
{
ms.WriteByte(0x30);
EncodeDERLength(ms, (uint)payload.Length);
ms.Write(payload, 0, payload.Length);
return ms.ToArray();
}
}
示例4: Decode
public override ScalarValue Decode(System.IO.Stream in_Renamed)
{
var buffer = new System.IO.MemoryStream();
byte byt;
try
{
do
{
byt = (byte)in_Renamed.ReadByte();
buffer.WriteByte( byt);
}
while ((byt & STOP_BIT) == 0);
}
catch (System.IO.IOException e)
{
throw new RuntimeException(e);
}
byte[] bytes = buffer.ToArray();
bytes[bytes.Length - 1] &= (0x7f);
if (bytes[0] == 0)
{
if (!ByteUtil.IsEmpty(bytes))
Global.HandleError(Error.FastConstants.R9_STRING_OVERLONG, null);
if (bytes.Length > 1 && bytes[1] == 0)
return new StringValue("\u0000");
return new StringValue("");
}
return new StringValue(System.Text.Encoding.UTF8.GetString(bytes));
}
示例5: Expand
/// <summary>
/// Expands the specified info.
/// </summary>
/// <param name="info">optional context and application specific information (can be a zero-length string)</param>
/// <param name="l">length of output keying material in octets (<= 255*HashLen)</param>
/// <returns>OKM (output keying material) of L octets</returns>
public byte[] Expand(byte[] info, int l)
{
if (info == null) info = new byte[0];
hmac.Key = this.prk;
var n = (int) System.Math.Ceiling(l * 1f / hashLength);
var t = new byte[n * hashLength];
using (var ms = new System.IO.MemoryStream())
{
var prev = new byte[0];
for (var i = 1; i <= n; i++)
{
ms.Write(prev, 0, prev.Length);
if (info.Length > 0) ms.Write(info, 0, info.Length);
ms.WriteByte((byte)(0x01 * i));
prev = hmac.ComputeHash(ms.ToArray());
Array.Copy(prev, 0, t, (i - 1) * hashLength, hashLength);
ms.SetLength(0); //reset
}
}
var okm = new byte[l];
Array.Copy(t, okm, okm.Length);
return okm;
}
示例6: Decode
public override ScalarValue Decode(System.IO.Stream in_Renamed)
{
var buffer = new System.IO.MemoryStream();
int byt;
do
{
try
{
byt = in_Renamed.ReadByte();
if (byt < 0)
{
return null;
}
}
catch (System.IO.IOException e)
{
throw new RuntimeException(e);
}
buffer.WriteByte((Byte) byt);
}
while ((byt & STOP_BIT) == 0);
return new BitVectorValue(new BitVector(buffer.ToArray()));
}
示例7: GenerateTestMemory
private byte [] GenerateTestMemory()
{
System.IO.MemoryStream stm = new System.IO.MemoryStream();
for (int i = 0; i < 1024; ++i)
{
stm.WriteByte((byte)i);
}
return stm.ToArray();
}
示例8: Serialize
public static ArraySegment<byte> Serialize(object message, byte[] buffer)
{
using (System.IO.MemoryStream stream = new System.IO.MemoryStream(buffer))
{
stream.Position = 0;
if (message is LogModel)
{
stream.WriteByte((byte)1);
}
else
{
stream.WriteByte((byte)2);
}
ProtoBuf.Meta.RuntimeTypeModel.Default.Serialize(stream, message);
return new ArraySegment<byte>(buffer, 0, (int)stream.Position);
}
}
示例9: Encode
public override void Encode()
{
int x = rectangle.X;
int y = rectangle.Y;
int w = rectangle.Width;
int h = rectangle.Height;
//Console.WriteLine("Landed at ZRLE start!");
int rawDataSize = w * h * (this.framebuffer.BitsPerPixel / 8);
byte[] data = new byte[rawDataSize];
int currentX, currentY;
int tileW, tileH;
//Bitmap bmp = PixelGrabber.GrabImage(rectangle.Width, rectangle.Height, pixels);
using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
{
for (currentY = y; currentY < y + h; currentY += TILE_HEIGHT)
{
tileH = TILE_HEIGHT;
tileH = Math.Min(tileH, y + h - currentY);
for (currentX = x; currentX < x + w; currentX += TILE_WIDTH)
{
tileW = TILE_WIDTH;
tileW = Math.Min(tileW, x + w - currentX);
int[] pixelz = CopyPixels(pixels, w, currentX, currentY, tileW, tileH);
byte subencoding = 0;
ms.WriteByte(subencoding);
//PixelGrabber.GrabPixels(pixels, new Rectangle(currentX, currentY, tileW, tileH), this.framebuffer);
for (int i = 0; i < pixelz.Length; ++i)
{
int bb = 0;
//The CPixel structure (Compressed Pixel) has 3 bytes, opposed to the normal pixel which has 4.
byte[] bytes = new byte[3];
int pixel = pixelz[i];
bytes[bb++] = (byte)(pixel & 0xFF);
bytes[bb++] = (byte)((pixel >> 8) & 0xFF);
bytes[bb++] = (byte)((pixel >> 16) & 0xFF);
//bytes[b++] = (byte)((pixel >> 24) & 0xFF);
ms.Write(bytes, 0, bytes.Length);
}
}
}
byte[] uncompressed = ms.ToArray();
this.bytes = uncompressed;
}
}
示例10: GetBytes
public override byte[] GetBytes(int countBytes)
{
using (var okm = new System.IO.MemoryStream())
{
do
{
if (k_unused > 0)
{
var min = Math.Min(k_unused, countBytes);
okm.Write(k, hashLength - k_unused, min);
countBytes -= min;
k_unused -= min;
}
if (countBytes == 0) break;
var n = countBytes / hashLength;
if (countBytes % hashLength > 0) ++n;
using (var hmac_msg = new System.IO.MemoryStream())
{
for (var i = 1; i <= n; ++i)
{
hmac_msg.Write(k, 0, k.Length);
if (context != null)
hmac_msg.Write(context, 0, context.Length);
hmac_msg.WriteByte(counter);
checked { ++counter; };
k = hmac.ComputeHash(hmac_msg.GetBuffer(), 0, (int)hmac_msg.Length);
okm.Write(k, 0, i < n ? hashLength : countBytes);
countBytes -= hashLength;
hmac_msg.SetLength(0);
}
k_unused = -countBytes;
}// using hmac_msg
} while (false);
return okm.ToArray();
}// using okm
}
示例11: ProcessMjpegFrame
//.........这里部分代码省略.........
{
//If the quality > 127 there are usually Quantization Tables
if (Quality > 127)
{
if ((packet.Payload[offset++]) != 0)
{
//Must Be Zero is Not Zero
if (System.Diagnostics.Debugger.IsAttached)
{
System.Diagnostics.Debugger.Break();
}
}
//Precision
PrecisionTable = (packet.Payload[offset++]);
#region RFC2435 Length Field
/*
The Length field is set to the length in bytes of the quantization
table data to follow. The Length field MAY be set to zero to
indicate that no quantization table data is included in this frame.
See section 4.2 for more information. If the Length field in a
received packet is larger than the remaining number of bytes, the
packet MUST be discarded.
When table data is included, the number of tables present depends on
the JPEG type field. For example, type 0 uses two tables (one for
the luminance component and one shared by the chrominance
components). Each table is an array of 64 values given in zig-zag
order, identical to the format used in a JFIF DQT marker segment.
For each quantization table present, a bit in the Precision field
specifies the size of the coefficients in that table. If the bit is
zero, the coefficients are 8 bits yielding a table length of 64
bytes. If the bit is one, the coefficients are 16 bits for a table
length of 128 bytes. For 16 bit tables, the coefficients are
presented in network byte order. The rightmost bit in the Precision
field (bit 15 in the diagram above) corresponds to the first table
and each additional table uses the next bit to the left. Bits beyond
those corresponding to the tables needed by the type in use MUST be
ignored.
*/
#endregion
//Length of all tables
ushort Length = (ushort)(packet.Payload[offset++] << 8 | packet.Payload[offset++]);
//If there is Table Data Read it
if (Length > 0)
{
tables = new ArraySegment<byte>(packet.Payload, offset, (int)Length);
offset += (int)Length;
}
else if (Length > packet.Payload.Length - offset)
{
continue; // The packet must be discarded
}
else // Create it from the Quality
{
tables = new ArraySegment<byte>(CreateQuantizationTables(Quality, type, PrecisionTable));
}
}
else // Create from the Quality
{
tables = new ArraySegment<byte>(CreateQuantizationTables(type, Quality, PrecisionTable));
}
byte[] header = CreateJFIFHeader(type, Width, Height, tables, PrecisionTable, RestartInterval);
Buffer.Write(header, 0, header.Length);
}
//Write the Payload data from the offset
Buffer.Write(packet.Payload, offset, packet.Payload.Length - offset);
}
//Check for EOI Marker
Buffer.Seek(-1, System.IO.SeekOrigin.Current);
if (Buffer.ReadByte() != Tags.EndOfInformation)
{
Buffer.WriteByte(Tags.Prefix);
Buffer.WriteByte(Tags.EndOfInformation);
}
//Go back to the beginning
Buffer.Position = 0;
//This article explains in detail what exactly happens: http://support.microsoft.com/kb/814675
//In short, for a lifetime of an Image constructed from a stream, the stream must not be destroyed.
//Image = new System.Drawing.Bitmap(System.Drawing.Image.FromStream(Buffer, true, true));
//DO NOT USE THE EMBEDDED COLOR MANGEMENT
// Image = System.Drawing.Image.FromStream(Buffer, false, true);
return Buffer.GetBuffer();
}
}
示例12: SetTemVDData
void SetTemVDData(string devname, int dir, int milek, int milem, System.Data.DataSet ds)
{
System.Text.StringBuilder sql = new StringBuilder();
System.IO.MemoryStream ms = new System.IO.MemoryStream();
ms.WriteByte(0x21);
ms.WriteByte((byte)dir);
ms.WriteByte((byte)(milek/256));
ms.WriteByte((byte)(milek % 256));
ms.WriteByte((byte)((milem ) / 256));
ms.WriteByte((byte)((milem ) % 256));
ms.WriteByte((byte)ds.Tables[1].Rows.Count); //lanecnt
ms.WriteByte(0); //odd
System.DateTime dt= DateTime.Now;
dt=dt.AddSeconds(-dt.Second).AddMinutes(-5);
dt=dt.AddMinutes(-(dt.Minute % 5));
//sql.Append("select ");
//for(int i=0;i<ds.Tables[1].Rows.Count;i++)
//{
//}
// string sql = "select small_car_volume_lane1,big_car_volume,connect_car_volume,small_car_speed,big_car_speed,connect_car_speed,average_occupancy from tblvddata5min where devicename='{0}' and timestamp='{1}' ";
System.Data.Odbc.OdbcConnection cn = new System.Data.Odbc.OdbcConnection(RemoteInterface.DbCmdServer.getDbConnectStr());
System.Data.Odbc.OdbcCommand cmd=new System.Data.Odbc.OdbcCommand();
cmd.Connection = cn;
try
{
cn.Open();
for (int i = 0; i < (byte)ds.Tables[1].Rows.Count; i++)
{
sql = new StringBuilder("select ");
sql.Append("small_car_volume_lane").Append(i + 1).Append(",");
sql.Append("big_car_volume_lane").Append(i + 1).Append(",");
sql.Append("connect_car_volume_lane").Append(i + 1).Append(",");
sql.Append("small_car_speed_lane").Append(i + 1).Append(",");
sql.Append("big_car_speed_lane").Append(i + 1).Append(",");
sql.Append("connect_car_speed_lane").Append(i + 1).Append(",");
sql.Append("average_occupancy_lane").Append(i + 1).Append(",");
sql.Remove(sql.ToString().Length - 1, 1).Append(" from tblvddata5min where devicename='{0}' and timestamp='{1}'");
cmd.CommandText = string.Format(sql.ToString(), devname, RemoteInterface.DbCmdServer.getTimeStampString(dt));
System.Data.Odbc.OdbcDataReader rd = cmd.ExecuteReader();
if (!rd.Read())
{
rd.Close();
continue;
}
// System.Data.DataRow r = ds.Tables[1].Rows[i];
ms.WriteByte((byte)i); //loopid
ms.WriteByte(0); //odd
int car_vol = System.Convert.ToInt32(rd[0]);
ms.WriteByte((byte)(car_vol / 256));
ms.WriteByte((byte)(car_vol % 256));
int big_vol = System.Convert.ToInt32(rd[1]);
ms.WriteByte((byte)(big_vol / 256));
ms.WriteByte((byte)(big_vol % 256));
int cn_vol = System.Convert.ToInt32(rd[2]);
ms.WriteByte((byte)(cn_vol / 256));
ms.WriteByte((byte)(cn_vol % 256));
int carspd = System.Convert.ToByte(rd[3]);
ms.WriteByte((byte)carspd);
carspd = System.Convert.ToByte(rd[4]);
ms.WriteByte((byte)carspd);
carspd = System.Convert.ToByte(rd[5]);
ms.WriteByte((byte)carspd);
ms.WriteByte(System.Convert.ToByte(rd[6]));
rd.Close();
}
}
catch (Exception ex)
{
ConsoleServer.WriteLine(ex.Message + "," + ex.StackTrace);
}
finally
{
cn.Close();
}
Comm.SendPackage pkg=new Comm.SendPackage(Comm.CmdType.CmdSet,Comm.CmdClass.A,0xffff,ms.ToArray());
Program.mfcc_tem.manager[TEM_DEVNAME].Send(pkg);
}
示例13: ReadText
//----------------------Read CDU
private TextPackage ReadText()
{
System.IO.MemoryStream ms = new System.IO.MemoryStream();
byte data;
TextPackage ret = new TextPackage();
while (true)
{
data =(byte) stream.ReadByte();
ms.WriteByte(data);
if (data == 0xF8 || data == 0xC7)
break;
}
byte[] databuff = ms.ToArray();
uint LCR = 0;
byte lcr1, lcr2;
for (int i = 0; i < databuff.Length - 3; i++) //cal lcr
LCR += databuff[i];
LCR =(uint)( (~LCR) + 1); //2's complement
lcr1 =(byte)( LCR & 0x0f);
lcr2 =(byte)( (LCR >> 4) & 0x0f);
ret.Text = new byte[databuff.Length - 3];
ret.CCU_EndCode = databuff[databuff.Length - 1];
System.Array.Copy(databuff, ret.Text, ret.Text.Length);
if (!(lcr1 == databuff[databuff.Length - 2] && lcr2 == databuff[databuff.Length - 3]))
{
ret.SetErrBit((int)V2DLE.DLE_ERR_LCR,true);
ret.eErrorDescription="LCR Error!";
ret.LRC =(byte)( (lcr2 << 4) | lcr1);
}
else
{
ret.LRC = (byte)LCR;
}
if(this.OnReceiveText!=null)
this.OnReceiveText(this, ret);
return ret;
}
示例14: GetMessageBody
public override byte[] GetMessageBody()
{
using (System.IO.MemoryStream MS = new System.IO.MemoryStream ()) {
using (System.IO.BinaryWriter BW = new System.IO.BinaryWriter (MS)) {
BW.Write (requestID.ToByteArray ());
BW.Write (tables.Length);
for (int n = 0; n != tables.Length; n++) {
byte[] bytes = tables [n].Serialize ();
BW.Write (bytes.Length);
BW.Write (bytes);
}
if (exception == null) {
MS.WriteByte (0);
} else {
MS.WriteByte (1);
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter BF = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter ();
long p = MS.Position;
try {
BF.Serialize (MS, exception);
} catch {
MS.Position = p;
BF.Serialize (MS, exception.ToString ());
MS.SetLength (MS.Position);
}
}
return MS.ToArray ();
}
}
}
示例15: get8bitByteArray
public virtual sbyte[] get8bitByteArray(int dataLength)
{
int length = dataLength;
int intData = 0;
System.IO.MemoryStream output = new System.IO.MemoryStream();
do
{
canvas.println("Length: " + length);
intData = getNextBits(8);
output.WriteByte((byte) intData);
length--;
}
while (length > 0);
return SystemUtils.ToSByteArray(output.ToArray());
}