WriteByte() public method

public WriteByte ( byte v ) : void
v byte
return void
Example #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());
        }
Example #2
0
 private void WriteUInt32(SprotoStream writer, UInt32 v)
 {
     //Console.WriteLine("WriteUInt32: {0}",v);
     writer.WriteByte((byte)(v & 0xff));
     writer.WriteByte((byte)((v >> 8) & 0xff));
     writer.WriteByte((byte)((v >> 16) & 0xff));
     writer.WriteByte((byte)((v >> 24) & 0xff));
 }
Example #3
0
        private UInt32 EncodeIntegerList(List <Int64> integer_list, SprotoStream writer)
        {
            UInt32 sizeof_uint32 = sizeof(UInt32);
            UInt32 sizeof_uint64 = sizeof(UInt64);
            UInt32 elem_size     = sizeof_uint32;

            foreach (var integer in integer_list)
            {
                if (this.RealSizeOfInteger(integer) == sizeof_uint64)
                {
                    elem_size = sizeof_uint64;
                    break;
                }
            }
            UInt32 size = 1;

            writer.WriteByte(Convert.ToByte(elem_size));
            foreach (var integer in integer_list)
            {
                if (elem_size == sizeof_uint64)
                {
                    UInt64 number = (UInt64)integer;
                    this.WriteUInt64(writer, number);
                }
                else
                {
                    UInt32 number = (UInt32)integer;
                    this.WriteUInt32(writer, number);
                }
                size += elem_size;
            }
            return(size);
        }
Example #4
0
        private UInt32 EncodeBoolean(bool ok, SprotoStream writer)
        {
            Int64 integer = (ok)?(1):(0);

            writer.WriteByte(Convert.ToByte(integer));
            return(1);
        }
Example #5
0
 private void WriteUInt64(SprotoStream writer, UInt64 v)
 {
     //Console.WriteLine("WriteUInt64: {0}",v);
     writer.WriteByte((byte)(v & 0xff));
     writer.WriteByte((byte)((v >> 8) & 0xff));
     writer.WriteByte((byte)((v >> 16) & 0xff));
     writer.WriteByte((byte)((v >> 24) & 0xff));
     writer.WriteByte((byte)((v >> 32) & 0xff));
     writer.WriteByte((byte)((v >> 40) & 0xff));
     writer.WriteByte((byte)((v >> 48) & 0xff));
     writer.WriteByte((byte)((v >> 56) & 0xff));
 }
Example #6
0
        private UInt32 EncodeBooleanList(List <bool> boolean_list, SprotoStream writer)
        {
            UInt32 size = (UInt32)boolean_list.Count;

            foreach (var boolean in boolean_list)
            {
                int integer = boolean ? 1 : 0;
                writer.WriteByte(Convert.ToByte(integer));
            }
            return(size);
        }