Sproto.SprotoStream.WriteByte C# (CSharp) Method

WriteByte() public method

public WriteByte ( byte v ) : void
v byte
return void
		public void WriteByte(byte v) {
			this._expand(sizeof(byte));
			this.buffer [this.pos++] = v;
		}

Usage Example

Ejemplo n.º 1
0
        public static byte[] Pack(byte[] data, int len = 0)
        {
            SprotoStream packed = new SprotoStream();
            int          idx    = 0;
            int          i      = 0;

            len = len == 0 ? data.Length : len;
            while (idx < len)
            {
                byte         mapz  = 0;
                SprotoStream group = new SprotoStream(GROUP_SZ);
                for (i = 0; i < GROUP_SZ && idx < len; ++i)
                {
                    if (data[idx] != 0)
                    {
                        mapz |= (byte)((1 << i) & 0xff);
                        group.Write(data, idx, 1);
                    }
                    ++idx;
                }
                packed.WriteByte(mapz);
                packed.Write(group.Buffer, 0, group.Position);
            }
            // If it is an unsaturated group, then fill a byte of padding.
            if (i < GROUP_SZ)
            {
                byte padding = (byte)(GROUP_SZ - i);
                packed.WriteByte(padding);
            }
            return(packed.Buffer.Take <byte>(packed.Position).ToArray());
        }
All Usage Examples Of Sproto.SprotoStream::WriteByte