Esempio n. 1
0
    // Use this for initialization
    void Start()
    {
        trialNumber      = 0;
        totalTrials      = 10;
        messageText.text = "Trial No: " + trialNumber;
        image            = Google.Protobuf.ByteString.Empty;

        SpawnCar();

        thread = new Thread(new ThreadStart(ThreadMethod));
        thread.Start();
        StartCoroutine(GameLoop());
    }
Esempio n. 2
0
        public void MergeFrom(pb.CodedInputStream input)
        {
    #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
            input.ReadRawMessage(this);
    #else
            uint tag;
            while ((tag = input.ReadTag()) != 0)
            {
                switch (tag)
                {
                default:
                    _unknownFields = pb.UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
                    break;

                case 10: {
                    ClientId = input.ReadString();
                    break;
                }

                case 18: {
                    MessageId = input.ReadString();
                    break;
                }

                case 24: {
                    Type = (MessageType)input.ReadEnum();
                    break;
                }

                case 34: {
                    if (time_ == null)
                    {
                        Time = new global.Google.Protobuf.WellKnownTypes.Timestamp();
                    }
                    input.ReadMessage(Time);
                    break;
                }

                case 40: {
                    Status = (MessageStatus)input.ReadEnum();
                    break;
                }

                case 50: {
                    Payload = input.ReadBytes();
                    break;
                }
                }
            }
    #endif
        }
 private void ReadHeadings()
 {
     foreach (var item in pose_readers)
     {
         RefID         refID  = item.Key;
         BinaryReaderX reader = item.Value;
         //send heading bytes to GRPC
         byte[] byteArray = reader.ReadBytes((int)reader.BaseStream.Length);
         Google.Protobuf.ByteString byteString = Google.Protobuf.ByteString.CopyFrom(byteArray, 0, byteArray.Length);
         client.SendHeadingBytes(new Heading {
             RefId = refID.ToString(), Data = byteString
         });
     }
 }
Esempio n. 4
0
        void pb.IBufferMessage.InternalMergeFrom(ref pb.ParseContext input)
        {
            uint tag;

            while ((tag = input.ReadTag()) != 0)
            {
                switch (tag)
                {
                default:
                    _unknownFields = pb.UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
                    break;

                case 10: {
                    ClientId = input.ReadString();
                    break;
                }

                case 18: {
                    MessageId = input.ReadString();
                    break;
                }

                case 24: {
                    Type = (MessageType)input.ReadEnum();
                    break;
                }

                case 34: {
                    if (time_ == null)
                    {
                        Time = new Google.Protobuf.WellKnownTypes.Timestamp();
                    }
                    input.ReadMessage(Time);
                    break;
                }

                case 40: {
                    Status = (MessageStatus)input.ReadEnum();
                    break;
                }

                case 50: {
                    Payload = input.ReadBytes();
                    break;
                }
                }
            }
        }
 public void InteractPoseStreams(float deltaT)
 {
     if (channel.State != ChannelState.Ready)
     {
         return;
     }
     try
     {
         //UniLog.Log("InteractPoseStreams");
         foreach (var item in pose_writers)
         {
             RefID        refID  = item.Key;
             BinaryWriter writer = item.Value;
             //read heading bytes from GRPC
             //byte[] bs = null;
             ByteString bs1 = client.GetFrameBytes(new RefIDMessage {
                 RefId = refID.ToString()
             }).Data;
             //writer.Write(bs1.ToByteArray());
             //writer.BaseStream.Write(bs1.ToByteArray(),(int) writer.BaseStream.Position, bs1.Length);
             UniLog.Log(writer.BaseStream.Position);
             writer.Write(bs1.ToByteArray());
             UniLog.Log(writer.BaseStream.Position);
             UniLog.Log(bs1.Length);
             writer.BaseStream.Position -= bs1.Length;
             //writer.Write(frame_bs);
         }
         metagen_comp.streamPlayer.PlayStreams();
         metagen_comp.metaRecorder.streamRecorder.RecordStreams(deltaT);
         foreach (var item in pose_readers)
         {
             RefID         refID  = item.Key;
             BinaryReaderX reader = item.Value;
             //send heading bytes to GRPC
             byte[] byteArray = reader.ReadBytes((int)reader.BaseStream.Length);
             Google.Protobuf.ByteString byteString = Google.Protobuf.ByteString.CopyFrom(byteArray, 0, byteArray.Length);
             client.SendFrameBytes(new Frame {
                 RefId = refID.ToString(), Data = byteString
             });
         }
     }
     catch (Exception e)
     {
         UniLog.Log("OwO: " + e.Message);
     }
 }
Esempio n. 6
0
    private IEnumerator TrialRunning()
    {
        while (!carManager.HasFailed())
        {
            if (processData)
            {
                lock (lockObject)
                {
                    if (dataReceived == "FD")
                    {
                        carManager.MoveForward();
                    }
                    else if (dataReceived == "BK")
                    {
                        carManager.MoveBackward();
                    }
                    else if (dataReceived == "RT")
                    {
                        carManager.TurnRight();
                    }
                    else if (dataReceived == "LT")
                    {
                        carManager.TurnLeft();
                    }
                    else
                    {
                        carManager.Stop();
                    }
                    processData = false;
                    image       = Google.Protobuf.ByteString.CopyFrom(carManager.GetImage(256, 256));
                    sensorData  = carManager.PollSensors();

                    /*
                     * Debug.Log("data: ");
                     * for(int i=0; i<10; i++)
                     * {
                     *  Debug.Log("Sensor " + i + " : " + sensorData[i]);
                     * }
                     */
                }
            }
            yield return(null);
        }
    }
Esempio n. 7
0
    private void Auth()
    {
        channel = new Channel(ip + ":" + port, ChannelCredentials.Insecure);
        client  = new Chat.ChatClient(channel);

        var req = new RequestAuthorize();

        req.Name = userName;

        try {
            var res = client.Authorize(req);
            sid = res.SessionId;
        }
        catch (RpcException e) {
            Debug.Log(ExceptionMsg(e));
            return;
        }


        Task.Run(() => Connect());
    }
Esempio n. 8
0
 public void MergeFrom(ResponseMessage other)
 {
     if (other == null)
     {
         return;
     }
     if (other.ClientId.Length != 0)
     {
         ClientId = other.ClientId;
     }
     if (other.MessageId.Length != 0)
     {
         MessageId = other.MessageId;
     }
     if (other.Type != MessageType.Undefined)
     {
         Type = other.Type;
     }
     if (other.time_ != null)
     {
         if (time_ == null)
         {
             Time = new Google.Protobuf.WellKnownTypes.Timestamp();
         }
         Time.MergeFrom(other.Time);
     }
     if (other.Status != MessageStatus.Undefined)
     {
         Status = other.Status;
     }
     if (other.Payload.Length != 0)
     {
         Payload = other.Payload;
     }
     _unknownFields = pb.UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
 }
 /// <summary>
 /// Write a byte string, without a tag, to the stream.
 /// The data is length-prefixed.
 /// </summary>
 /// <param name="value">The value to write</param>
 public void WriteBytes(ByteString value)
 {
     WriteLength(value.Length);
     value.WriteRawBytesTo(this);
 }
        public void AllSingleFields()
        {
            var message = new TestAllTypes
            {
                SingleBool           = true,
                SingleBytes          = ByteString.CopyFrom(1, 2, 3, 4),
                SingleDouble         = 23.5,
                SingleFixed32        = 23,
                SingleFixed64        = 1234567890123,
                SingleFloat          = 12.25f,
                SingleForeignEnum    = ForeignEnum.ForeignBar,
                SingleForeignMessage = new ForeignMessage {
                    C = 10
                },
                SingleImportEnum    = ImportEnum.ImportBaz,
                SingleImportMessage = new ImportMessage {
                    D = 20
                },
                SingleInt32         = 100,
                SingleInt64         = 3210987654321,
                SingleNestedEnum    = TestAllTypes.Types.NestedEnum.Foo,
                SingleNestedMessage = new TestAllTypes.Types.NestedMessage {
                    Bb = 35
                },
                SinglePublicImportMessage = new PublicImportMessage {
                    E = 54
                },
                SingleSfixed32 = -123,
                SingleSfixed64 = -12345678901234,
                SingleSint32   = -456,
                SingleSint64   = -12345678901235,
                SingleString   = "test\twith\ttabs",
                SingleUint32   = uint.MaxValue,
                SingleUint64   = ulong.MaxValue,
            };
            var actualText = JsonFormatter.Default.Format(message);

            // Fields in numeric order
            var expectedText = "{ " +
                               "'singleInt32': 100, " +
                               "'singleInt64': '3210987654321', " +
                               "'singleUint32': 4294967295, " +
                               "'singleUint64': '18446744073709551615', " +
                               "'singleSint32': -456, " +
                               "'singleSint64': '-12345678901235', " +
                               "'singleFixed32': 23, " +
                               "'singleFixed64': '1234567890123', " +
                               "'singleSfixed32': -123, " +
                               "'singleSfixed64': '-12345678901234', " +
                               "'singleFloat': 12.25, " +
                               "'singleDouble': 23.5, " +
                               "'singleBool': true, " +
                               "'singleString': 'test\\twith\\ttabs', " +
                               "'singleBytes': 'AQIDBA==', " +
                               "'singleNestedMessage': { 'bb': 35 }, " +
                               "'singleForeignMessage': { 'c': 10 }, " +
                               "'singleImportMessage': { 'd': 20 }, " +
                               "'singleNestedEnum': 'FOO', " +
                               "'singleForeignEnum': 'FOREIGN_BAR', " +
                               "'singleImportEnum': 'IMPORT_BAZ', " +
                               "'singlePublicImportMessage': { 'e': 54 }" +
                               " }";

            AssertJson(expectedText, actualText);
        }
Esempio n. 11
0
        public void AllSingleFields()
        {
            var message = new TestAllTypes
            {
                SingleBool           = true,
                SingleBytes          = ByteString.CopyFrom(1, 2, 3, 4),
                SingleDouble         = 23.5,
                SingleFixed32        = 23,
                SingleFixed64        = 1234567890123,
                SingleFloat          = 12.25f,
                SingleForeignEnum    = ForeignEnum.FOREIGN_BAR,
                SingleForeignMessage = new ForeignMessage {
                    C = 10
                },
                SingleImportEnum    = ImportEnum.IMPORT_BAZ,
                SingleImportMessage = new ImportMessage {
                    D = 20
                },
                SingleInt32         = 100,
                SingleInt64         = 3210987654321,
                SingleNestedEnum    = TestAllTypes.Types.NestedEnum.FOO,
                SingleNestedMessage = new TestAllTypes.Types.NestedMessage {
                    Bb = 35
                },
                SinglePublicImportMessage = new PublicImportMessage {
                    E = 54
                },
                SingleSfixed32 = -123,
                SingleSfixed64 = -12345678901234,
                SingleSint32   = -456,
                SingleSint64   = -12345678901235,
                SingleString   = "test\twith\ttabs",
                SingleUint32   = uint.MaxValue,
                SingleUint64   = ulong.MaxValue,
            };
            var actualText = JsonFormatter.Default.Format(message);

            // Fields in declaration order, which matches numeric order.
            var expectedText = "{ " +
                               "\"singleInt32\": 100, " +
                               "\"singleInt64\": \"3210987654321\", " +
                               "\"singleUint32\": 4294967295, " +
                               "\"singleUint64\": \"18446744073709551615\", " +
                               "\"singleSint32\": -456, " +
                               "\"singleSint64\": \"-12345678901235\", " +
                               "\"singleFixed32\": 23, " +
                               "\"singleFixed64\": \"1234567890123\", " +
                               "\"singleSfixed32\": -123, " +
                               "\"singleSfixed64\": \"-12345678901234\", " +
                               "\"singleFloat\": 12.25, " +
                               "\"singleDouble\": 23.5, " +
                               "\"singleBool\": true, " +
                               "\"singleString\": \"test\\twith\\ttabs\", " +
                               "\"singleBytes\": \"AQIDBA==\", " +
                               "\"singleNestedMessage\": { \"bb\": 35 }, " +
                               "\"singleForeignMessage\": { \"c\": 10 }, " +
                               "\"singleImportMessage\": { \"d\": 20 }, " +
                               "\"singleNestedEnum\": \"FOO\", " +
                               "\"singleForeignEnum\": \"FOREIGN_BAR\", " +
                               "\"singleImportEnum\": \"IMPORT_BAZ\", " +
                               "\"singlePublicImportMessage\": { \"e\": 54 }" +
                               " }";

            Assert.AreEqual(expectedText, actualText);
        }
Esempio n. 12
0
 /// <summary>
 /// Adds a length-delimited value.
 /// </summary>
 internal UnknownField AddLengthDelimited(ByteString value)
 {
     lengthDelimitedList = Add(lengthDelimitedList, value);
     return(this);
 }
Esempio n. 13
0
 /// <summary>
 /// Write a byte string, without a tag, to the stream.
 /// The data is length-prefixed.
 /// </summary>
 public static void WriteBytes(ref Span <byte> buffer, ref WriterInternalState state, ByteString value)
 {
     WriteLength(ref buffer, ref state, value.Length);
     WriteRawBytes(ref buffer, ref state, value.Span);
 }
Esempio n. 14
0
        public void ToBase64_Array()
        {
            ByteString bs = ByteString.CopyFrom(Encoding.UTF8.GetBytes("Hello world"));

            Assert.AreEqual("SGVsbG8gd29ybGQ=", bs.ToBase64());
        }
 /// <summary>
 /// Computes the number of bytes that would be needed to encode a
 /// bytes field, including the tag.
 /// </summary>
 public static int ComputeBytesSize(ByteString value)
 {
     return(ComputeLengthSize(value.Length) + value.Length);
 }
Esempio n. 16
0
        public void ToStringUtf8()
        {
            ByteString bs = ByteString.CopyFromUtf8("\u20ac");

            Assert.AreEqual("\u20ac", bs.ToStringUtf8());
        }
Esempio n. 17
0
 public void IsEmptyWhenNotEmpty()
 {
     Assert.IsFalse(ByteString.CopyFromUtf8("X").IsEmpty);
 }
Esempio n. 18
0
 public void IsEmptyWhenEmpty()
 {
     Assert.IsTrue(ByteString.CopyFromUtf8("").IsEmpty);
 }
Esempio n. 19
0
 /// <summary>
 /// Creates a new sample TestAllTypes message with all fields populated.
 /// The "oneof" field is populated with the string property (OneofString).
 /// </summary>
 public static TestAllTypes CreateFullTestAllTypes()
 {
     return(new TestAllTypes
     {
         SingleBool = true,
         SingleBytes = ByteString.CopyFrom(1, 2, 3, 4),
         SingleDouble = 23.5,
         SingleFixed32 = 23,
         SingleFixed64 = 1234567890123,
         SingleFloat = 12.25f,
         SingleForeignEnum = ForeignEnum.ForeignBar,
         SingleForeignMessage = new ForeignMessage {
             C = 10
         },
         SingleImportEnum = ImportEnum.ImportBaz,
         SingleImportMessage = new ImportMessage {
             D = 20
         },
         SingleInt32 = 100,
         SingleInt64 = 3210987654321,
         SingleNestedEnum = TestAllTypes.Types.NestedEnum.Foo,
         SingleNestedMessage = new TestAllTypes.Types.NestedMessage {
             Bb = 35
         },
         SinglePublicImportMessage = new PublicImportMessage {
             E = 54
         },
         SingleSfixed32 = -123,
         SingleSfixed64 = -12345678901234,
         SingleSint32 = -456,
         SingleSint64 = -12345678901235,
         SingleString = "test",
         SingleUint32 = UInt32.MaxValue,
         SingleUint64 = UInt64.MaxValue,
         RepeatedBool = { true, false },
         RepeatedBytes = { ByteString.CopyFrom(1, 2, 3, 4), ByteString.CopyFrom(5, 6), ByteString.CopyFrom(new byte[1000]) },
         RepeatedDouble = { -12.25, 23.5 },
         RepeatedFixed32 = { UInt32.MaxValue, 23 },
         RepeatedFixed64 = { UInt64.MaxValue, 1234567890123 },
         RepeatedFloat = { 100f, 12.25f },
         RepeatedForeignEnum = { ForeignEnum.ForeignFoo, ForeignEnum.ForeignBar },
         RepeatedForeignMessage = { new ForeignMessage(), new ForeignMessage {
                                        C = 10
                                    } },
         RepeatedImportEnum = { ImportEnum.ImportBaz, ImportEnum.Unspecified },
         RepeatedImportMessage = { new ImportMessage {
                                       D = 20
                                   }, new ImportMessage{
                                       D = 25
                                   } },
         RepeatedInt32 = { 100, 200 },
         RepeatedInt64 = { 3210987654321, Int64.MaxValue },
         RepeatedNestedEnum = { TestAllTypes.Types.NestedEnum.Foo, TestAllTypes.Types.NestedEnum.Neg },
         RepeatedNestedMessage = { new TestAllTypes.Types.NestedMessage {
                                       Bb = 35
                                   }, new TestAllTypes.Types.NestedMessage{
                                       Bb = 10
                                   } },
         RepeatedPublicImportMessage = { new PublicImportMessage {
                                             E = 54
                                         }, new PublicImportMessage{
                                             E = -1
                                         } },
         RepeatedSfixed32 = { -123, 123 },
         RepeatedSfixed64 = { -12345678901234, 12345678901234 },
         RepeatedSint32 = { -456, 100 },
         RepeatedSint64 = { -12345678901235, 123 },
         RepeatedString = { "foo", "bar" },
         RepeatedUint32 = { UInt32.MaxValue, UInt32.MinValue },
         RepeatedUint64 = { UInt64.MaxValue, UInt32.MinValue },
         OneofString = "Oneof string"
     });
 }
Esempio n. 20
0
 /// <summary>
 /// Converts the given message into a byte string in protobuf encoding.
 /// </summary>
 /// <param name="message">The message to convert.</param>
 /// <returns>The message data as a byte string.</returns>
 public static ByteString ToByteString(this IMessage message)
 {
     ProtoPreconditions.CheckNotNull(message, nameof(message));
     return(ByteString.AttachBytes(message.ToByteArray()));
 }
Esempio n. 21
0
        public void ToStringWithExplicitEncoding()
        {
            ByteString bs = ByteString.CopyFrom("\u20ac", Encoding.Unicode);

            Assert.AreEqual("\u20ac", bs.ToString(Encoding.Unicode));
        }
Esempio n. 22
0
 /// <summary>
 /// Merges data from the given byte string into an existing message.
 /// </summary>
 /// <param name="message">The message to merge the data into.</param>
 /// <param name="data">The data to merge, which must be protobuf-encoded binary data.</param>
 public static void MergeFrom(this IMessage message, ByteString data) =>
 MergeFrom(message, data, false, null);
Esempio n. 23
0
 public void FromBase64_Empty()
 {
     // Optimization which also fixes issue 61.
     Assert.AreSame(ByteString.Empty, ByteString.FromBase64(""));
 }
        public void TestCodedInputOutputPosition()
        {
            byte[] content = new byte[110];
            for (int i = 0; i < content.Length; i++)
            {
                content[i] = (byte)i;
            }

            byte[] child = new byte[120];
            {
                MemoryStream      ms   = new MemoryStream(child);
                CodedOutputStream cout = new CodedOutputStream(ms, 20);
                // Field 11: numeric value: 500
                cout.WriteTag(11, WireFormat.WireType.Varint);
                Assert.AreEqual(1, cout.Position);
                cout.WriteInt32(500);
                Assert.AreEqual(3, cout.Position);
                //Field 12: length delimited 120 bytes
                cout.WriteTag(12, WireFormat.WireType.LengthDelimited);
                Assert.AreEqual(4, cout.Position);
                cout.WriteBytes(ByteString.CopyFrom(content));
                Assert.AreEqual(115, cout.Position);
                // Field 13: fixed numeric value: 501
                cout.WriteTag(13, WireFormat.WireType.Fixed32);
                Assert.AreEqual(116, cout.Position);
                cout.WriteSFixed32(501);
                Assert.AreEqual(120, cout.Position);
                cout.Flush();
            }

            byte[] bytes = new byte[130];
            {
                CodedOutputStream cout = new CodedOutputStream(bytes);
                // Field 1: numeric value: 500
                cout.WriteTag(1, WireFormat.WireType.Varint);
                Assert.AreEqual(1, cout.Position);
                cout.WriteInt32(500);
                Assert.AreEqual(3, cout.Position);
                //Field 2: length delimited 120 bytes
                cout.WriteTag(2, WireFormat.WireType.LengthDelimited);
                Assert.AreEqual(4, cout.Position);
                cout.WriteBytes(ByteString.CopyFrom(child));
                Assert.AreEqual(125, cout.Position);
                // Field 3: fixed numeric value: 500
                cout.WriteTag(3, WireFormat.WireType.Fixed32);
                Assert.AreEqual(126, cout.Position);
                cout.WriteSFixed32(501);
                Assert.AreEqual(130, cout.Position);
                cout.Flush();
            }
            // Now test Input stream:
            {
                CodedInputStream cin = new CodedInputStream(new MemoryStream(bytes), new byte[50], 0, 0, false);
                Assert.AreEqual(0, cin.Position);
                // Field 1:
                uint tag = cin.ReadTag();
                Assert.AreEqual(1, tag >> 3);
                Assert.AreEqual(1, cin.Position);
                Assert.AreEqual(500, cin.ReadInt32());
                Assert.AreEqual(3, cin.Position);
                //Field 2:
                tag = cin.ReadTag();
                Assert.AreEqual(2, tag >> 3);
                Assert.AreEqual(4, cin.Position);
                int childlen = cin.ReadLength();
                Assert.AreEqual(120, childlen);
                Assert.AreEqual(5, cin.Position);
                int oldlimit = cin.PushLimit((int)childlen);
                Assert.AreEqual(5, cin.Position);
                // Now we are reading child message
                {
                    // Field 11: numeric value: 500
                    tag = cin.ReadTag();
                    Assert.AreEqual(11, tag >> 3);
                    Assert.AreEqual(6, cin.Position);
                    Assert.AreEqual(500, cin.ReadInt32());
                    Assert.AreEqual(8, cin.Position);
                    //Field 12: length delimited 120 bytes
                    tag = cin.ReadTag();
                    Assert.AreEqual(12, tag >> 3);
                    Assert.AreEqual(9, cin.Position);
                    ByteString bstr = cin.ReadBytes();
                    Assert.AreEqual(110, bstr.Length);
                    Assert.AreEqual((byte)109, bstr[109]);
                    Assert.AreEqual(120, cin.Position);
                    // Field 13: fixed numeric value: 501
                    tag = cin.ReadTag();
                    Assert.AreEqual(13, tag >> 3);
                    // ROK - Previously broken here, this returned 126 failing to account for bufferSizeAfterLimit
                    Assert.AreEqual(121, cin.Position);
                    Assert.AreEqual(501, cin.ReadSFixed32());
                    Assert.AreEqual(125, cin.Position);
                    Assert.IsTrue(cin.IsAtEnd);
                }
                cin.PopLimit(oldlimit);
                Assert.AreEqual(125, cin.Position);
                // Field 3: fixed numeric value: 501
                tag = cin.ReadTag();
                Assert.AreEqual(3, tag >> 3);
                Assert.AreEqual(126, cin.Position);
                Assert.AreEqual(501, cin.ReadSFixed32());
                Assert.AreEqual(130, cin.Position);
                Assert.IsTrue(cin.IsAtEnd);
            }
        }