public void LoadSingleGlyphWithInt16Offset_signed_short() { var writer = new BigEndianBinaryWriter(); writer.WriteUInt16((ushort)(CompositeFlags.ArgsAreWords /* 16bit */ | CompositeFlags.ArgsAreXYValues /* signed */)); // flags writer.WriteUInt16(1); // glyph id writer.WriteInt16(short.MinValue + 1); // dx writer.WriteInt16(short.MinValue + 2); // dy writer.GetReader(); var bounds = new Bounds(0, 0, 100, 100); var glyph = CompositeGlyphLoader.LoadCompositeGlyph(writer.GetReader(), in bounds); var tbl = new GlyphTable(new[] { new SimpleGlyphLoader(bounds), // padding new SimpleGlyphLoader(new short[] { 20 }, new short[] { 21 }, new[] { true }, new ushort[] { 1 }, bounds) }); GlyphVector finalGlyph = glyph.CreateGlyph(tbl); Vector2 point = Assert.Single(finalGlyph.ControlPoints); Assert.Equal(new Vector2(short.MinValue + 1 + 20, short.MinValue + 2 + 21), point); }
/// <summary> /// The serialize event. /// </summary> /// <param name="eventData">The event data.</param> /// <returns> The serialized event</returns> public byte[] SerializeEventData(EventData eventData) { using (ReusableMemoryStream stream = new ReusableMemoryStream()) { BigEndianBinaryWriter binaryWriter = new BigEndianBinaryWriter(stream); stream.Position = this.headerSize; stream.WriteByte(eventData.Code); if ((eventData.Parameters == null) || (eventData.Parameters.Count == 0)) { binaryWriter.WriteInt16(0); } else { binaryWriter.WriteInt16((short)eventData.Parameters.Count); Amf3Writer writer2 = new Amf3Writer(binaryWriter); foreach (KeyValuePair <byte, object> pair in eventData.Parameters) { writer2.WriteInteger((long)((ulong)pair.Key)); writer2.Write(pair.Value); } } stream.Position = 0L; this.headerWriter.WriteHeader(stream, RtsMessageType.Event, false); return(stream.ToArray()); } }
/// <summary> /// Serializes an operation request. /// </summary> /// <param name="stream">The stream.</param> /// <param name="operationRequest"> The operation request.</param> /// <exception cref="T:System.IO.InvalidDataException"> /// A value can not be serialized. ///</exception> ///<exception cref="T:System.ArrayTypeMismatchException"> /// A collection with different types can not be serialized. ///</exception> private static void SerializeOperationRequest(Stream stream, OperationRequest operationRequest) { IBinaryWriter writer = new BigEndianBinaryWriter(stream); writer.WriteByte(operationRequest.OperationCode); writer.WriteBoolean(false); if (operationRequest.Parameters != null) { writer.WriteInt16((short)operationRequest.Parameters.Count); foreach (KeyValuePair <byte, object> pair in operationRequest.Parameters) { writer.WriteByte(pair.Key); GpBinaryByteWriter.Write(writer, pair.Value); } } else { writer.WriteInt16(0); } }
/// <summary> /// Serializes an <see cref="T:Photon.SocketServer.OperationResponse"/>. /// </summary> /// <param name="operationResponse">The operation response to serialize.</param> /// <returns>The serialized operation response.</returns> public byte[] SerializeOperationResponse(OperationResponse operationResponse) { using (ReusableMemoryStream stream = new ReusableMemoryStream()) { BigEndianBinaryWriter binaryWriter = new BigEndianBinaryWriter(stream); stream.Position = this.headerSize; binaryWriter.WriteByte(operationResponse.OperationCode); binaryWriter.WriteInt16(operationResponse.ReturnCode); if (string.IsNullOrEmpty(operationResponse.DebugMessage)) { binaryWriter.WriteByte(0x2a); } else { binaryWriter.WriteByte(0x73); binaryWriter.WriteUTF(operationResponse.DebugMessage); } if ((operationResponse.Parameters == null) || (operationResponse.Parameters.Count == 0)) { binaryWriter.WriteInt16(0); } else { binaryWriter.WriteInt16((short)operationResponse.Parameters.Count); Amf3Writer writer2 = new Amf3Writer(binaryWriter); foreach (KeyValuePair <byte, object> pair in operationResponse.Parameters) { writer2.WriteInteger((long)((ulong)pair.Key)); writer2.Write(pair.Value); } } stream.Position = 0L; this.headerWriter.WriteHeader(stream, RtsMessageType.OperationResponse, false); return(stream.ToArray()); } }
public static void SendMessage(Socket udp, byte id, params byte[] payload) { byte[] msg = new byte[payload.Length + 4]; uint innerLen = (uint)payload.Length; // bridge message format (all numbers big endian) // bridge command - UINT8 (0 = transmit) // --start payload-- // inner command - UINT8 // inner payload length - UINT16 // payload msg[0] = BRIDGE_CMD_TX; msg[1] = id; msg[2] = (byte)((innerLen >> 8) & 0xff); msg[3] = (byte)(innerLen & 0xff); // copy over the payload Buffer.BlockCopy(payload, 0, msg, 4, payload.Length); // send that ish out udp.SendTo(msg, ControllerEP); if (payload.Length == 8) { msg = new byte[payload.Length + 9]; BigEndianBinaryWriter writer = new BigEndianBinaryWriter(msg); // write a slot for the timestamp (zero as we don't have any timestamp) writer.WriteUInt16(0); writer.WriteInt32(0); // write message type writer.WriteByte(ACT_FEEDBACK_CMDRECEIVED); // write the length as bullstuff writer.WriteInt16(0); // only send for all message // change the message ID, only send a subset of the stuffs writer.WriteBytes(payload); // set the stuff stuff udp.SendTo(msg, MulticastEP); } }
/// <summary> /// Serializes an <see cref="T:Photon.SocketServer.OperationRequest"/>. /// </summary> /// <param name="operationRequest">The operation request.</param> /// <returns>The serialized operation request.</returns> public byte[] SerializeOperationRequest(OperationRequest operationRequest) { using (ReusableMemoryStream stream = new ReusableMemoryStream()) { IBinaryWriter binaryWriter = new BigEndianBinaryWriter(stream); stream.Position = this.headerSize; binaryWriter.WriteByte(operationRequest.OperationCode); binaryWriter.WriteInt16((short)operationRequest.Parameters.Count); Amf3Writer writer2 = new Amf3Writer(binaryWriter); foreach (KeyValuePair <byte, object> pair in operationRequest.Parameters) { writer2.WriteInteger((long)((ulong)pair.Key)); writer2.Write(pair.Value); } stream.Position = 0L; this.headerWriter.WriteHeader(stream, RtsMessageType.Operation, false); return(stream.ToArray()); } }
/// <summary> /// Serializes an operation response. /// </summary> /// <param name="stream">The stream.</param> /// <param name="operationResponse"> The operation response.</param> /// <exception cref="T:System.IO.InvalidDataException"> /// A value can not be serialized. ///</exception> ///<exception cref="T:System.ArrayTypeMismatchException"> /// A collection with different types can not be serialized. ///</exception> private static void SerializeOperationResponse(Stream stream, OperationResponse operationResponse) { if (operationResponse.Parameters != null) { if (operationResponse.Parameters.Remove(0xf4)) { log.WarnFormat("SendOperationResponse - removed reserved parameter {1} from operation response {0}", new object[] { operationResponse.OperationCode, (byte)0xf4 }); } if (operationResponse.Parameters.Remove(0)) { log.WarnFormat("SendOperationResponse - removed reserved parameter {1} from operation response {0}", new object[] { operationResponse.OperationCode, (byte)0 }); } if (operationResponse.Parameters.Remove(1)) { log.WarnFormat("SendOperationResponse - removed reserved parameter {1} from operation response {0}", new object[] { operationResponse.OperationCode, (byte)1 }); } } IBinaryWriter writer = new BigEndianBinaryWriter(stream); bool flag = !string.IsNullOrEmpty(operationResponse.DebugMessage); bool flag2 = operationResponse.Parameters != null; int num = flag2 ? operationResponse.Parameters.Count : 0; num += flag ? 3 : 2; writer.WriteInt16((short)num); writer.WriteByte(0xf4); GpBinaryByteWriter.Write(writer, operationResponse.OperationCode); writer.WriteByte(0); GpBinaryByteWriter.Write(writer, (int)operationResponse.ReturnCode); if (flag) { writer.WriteByte(1); GpBinaryByteWriter.Write(writer, operationResponse.DebugMessage); } if (flag2) { foreach (KeyValuePair <byte, object> pair in operationResponse.Parameters) { writer.WriteByte(pair.Key); GpBinaryByteWriter.Write(writer, pair.Value); } } }
/// <summary> /// serializes the event data to a stream. /// </summary> /// <param name="stream">The stream.</param> /// <param name="eventData">The event data.</param> private void SerializeEventData(ReusableMemoryStream stream, IEventData eventData) { if ((eventData.Parameters != null) && eventData.Parameters.Remove(0xf4)) { log.WarnFormat("SendEvent - removed reserved parameter {1} from event {0}", new object[] { eventData.Code, (byte)0xf4 }); } BigEndianBinaryWriter writer = new BigEndianBinaryWriter(stream); stream.Seek((long)this.headerSize, SeekOrigin.Begin); bool flag = eventData.Parameters != null; int num = flag ? (eventData.Parameters.Count + 1) : 1; writer.WriteInt16((short)num); writer.WriteByte(0xf4); GpBinaryByteWriter.Write(writer, eventData.Code); if (flag) { foreach (KeyValuePair <byte, object> pair in eventData.Parameters) { writer.WriteByte(pair.Key); GpBinaryByteWriter.Write(writer, pair.Value); } } }