コード例 #1
0
        /// <summary>Helper: create a new instance to deserializing into</summary>
        public static KVRequest DeserializeLength(Stream stream, int length)
        {
            KVRequest instance = new KVRequest();

            DeserializeLength(stream, length, instance);
            return(instance);
        }
コード例 #2
0
    static MemoryStream RequestToMemoryStream(Example.KVRequest request)
    {
        MemoryStream tempStream = new MemoryStream();

        Example.KVRequest.Serialize(tempStream, request);
        return(tempStream);
    }
コード例 #3
0
        /// <summary>Helper: create a new instance to deserializing into</summary>
        public static KVRequest DeserializeLengthDelimited(Stream stream)
        {
            KVRequest instance = new KVRequest();

            DeserializeLengthDelimited(stream, instance);
            return(instance);
        }
コード例 #4
0
        /// <summary>Helper: create a new instance to deserializing into</summary>
        public static KVRequest Deserialize(Stream stream)
        {
            KVRequest instance = new KVRequest();

            Deserialize(stream, instance);
            return(instance);
        }
コード例 #5
0
 /// <summary>Helper: Serialize into a MemoryStream and return its byte array</summary>
 public static byte[] SerializeToBytes(KVRequest instance)
 {
     using (var ms = new MemoryStream())
     {
         Serialize(ms, instance);
         return(ms.ToArray());
     }
 }
コード例 #6
0
        /// <summary>Helper: put the buffer into a MemoryStream and create a new instance to deserializing into</summary>
        public static KVRequest Deserialize(byte[] buffer)
        {
            KVRequest instance = new KVRequest();

            using (var ms = new MemoryStream(buffer))
                Deserialize(ms, instance);
            return(instance);
        }
コード例 #7
0
    public MemoryStream Item(string command)
    {
        Example.KVRequest request = new Example.KVRequest();
        request.Type         = Example.KVRequest.RequestType.ITEM;
        request.Item         = new Example.KVItem();
        request.Item.Command = command;

        return(RequestToMemoryStream(request));
    }
コード例 #8
0
 public MemoryStream Login(string user, string pass)
 {
     Example.KVRequest request = new Example.KVRequest();
     request.Type           = Example.KVRequest.RequestType.LOGIN;
     request.Login          = new Example.KVLogin();
     request.Login.Username = user;
     request.Login.Password = pass;
     return(RequestToMemoryStream(request));
 }
コード例 #9
0
        /// <summary>Serialize the instance into the stream</summary>
        public static void Serialize(Stream stream, KVRequest instance)
        {
            // Key for field: 1, Varint
            stream.WriteByte(8);
            global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt64(stream, (ulong)instance.Type);
            if (instance.Item != null)
            {
                // Key for field: 2, LengthDelimited
                stream.WriteByte(18);
                using(var ms2 = new MemoryStream())

                {
                    Example.KVItem.Serialize(ms2, instance.Item);

                    // Length delimited byte array

                    uint ms2Length = (uint)ms2.Length;

                    global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt32(stream, ms2Length);

                    stream.Write(ms2.GetBuffer(), 0, (int)ms2Length);
                }
            }
            if (instance.Login != null)
            {
                // Key for field: 3, LengthDelimited
                stream.WriteByte(26);
                using(var ms3 = new MemoryStream())

                {
                    Example.KVLogin.Serialize(ms3, instance.Login);

                    // Length delimited byte array

                    uint ms3Length = (uint)ms3.Length;

                    global::SilentOrbit.ProtocolBuffers.ProtocolParser.WriteUInt32(stream, ms3Length);

                    stream.Write(ms3.GetBuffer(), 0, (int)ms3Length);
                }
            }
        }