CheckNoSpaceLeft() public method

Verifies that SpaceLeft returns zero. It's common to create a byte array that is exactly big enough to hold a message, then write to it with a CodedOutputStream. Calling CheckNoSpaceLeft after writing verifies that the message was actually as big as expected, which can help bugs.
public CheckNoSpaceLeft ( ) : void
return void
Esempio n. 1
1
 public static byte[] ToByteArray(this IMessage message)
 {
     Preconditions.CheckNotNull(message, "message");
     byte[] result = new byte[message.CalculateSize()];
     CodedOutputStream output = new CodedOutputStream(result);
     message.WriteTo(output);
     output.CheckNoSpaceLeft();
     return result;
 }
Esempio n. 2
0
        /// <summary>
        /// Converts the given message into a byte array in protobuf encoding.
        /// </summary>
        /// <param name="message">The message to convert.</param>
        /// <returns>The message data as a byte array.</returns>
        public static byte[] ToByteArray(this IMessage message)
        {
            ProtoPreconditions.CheckNotNull(message, "message");
            byte[]            result = new byte[message.CalculateSize()];
            CodedOutputStream output = new CodedOutputStream(result);

            message.WriteTo(output);
            output.CheckNoSpaceLeft();
            return(result);
        }
Esempio n. 3
0
        public static byte[] ToByteArray(this IMessage message)
        {
            Preconditions.CheckNotNull <IMessage>(message, Module.smethod_33 <string>(879293356u));
            byte[]            expr_1C           = new byte[message.CalculateSize()];
            CodedOutputStream codedOutputStream = new CodedOutputStream(expr_1C);

            message.WriteTo(codedOutputStream);
            codedOutputStream.CheckNoSpaceLeft();
            return(expr_1C);
        }
Esempio n. 4
0
        /// <summary>
        /// Converts the given message into a byte array in protobuf encoding.
        /// </summary>
        /// <param name="message">The message to convert.</param>
        /// <returns>The message data as a byte array.</returns>
        public static byte[] ToByteArray(this IMessage message)
        {
            ProtoPreconditions.CheckNotNull(message, "message");

            byte[]            result = null;
            CodedOutputStream output = GetOutSteam(message, out result);

            message.WriteTo(output);
            output.CheckNoSpaceLeft();
            return(result);
        }
Esempio n. 5
0
    public void SendReq(GameState request, out String response)
    {
        byte[] bytes = new byte[request.CalculateSize()];
        Google.Protobuf.CodedOutputStream codedOutputStream = new Google.Protobuf.CodedOutputStream(bytes);
        request.WriteTo(codedOutputStream);
        codedOutputStream.Flush();
        codedOutputStream.CheckNoSpaceLeft();
        networkStream.Write(bytes, 0, bytes.Length);
        networkStream.Flush();
        byte[] toRead    = new byte[tcpClient.ReceiveBufferSize];
        int    bytesRead = networkStream.Read(toRead, 0, tcpClient.ReceiveBufferSize);

        response = Encoding.UTF8.GetString(toRead, 0, bytesRead);
    }