/// <summary> /// Read the message header structure and cache the meta data for finding the key fields for decoding messages. /// </summary> /// <param name="headerStructure"> for the meta data describing the message header. </param> public OtfHeaderDecoder(HeaderStructure headerStructure) { _size = headerStructure.Tokens[0].Size; foreach (Token token in headerStructure.Tokens) { switch (token.Name) { case HeaderStructure.BlockLength: _blockLengthOffset = token.Offset; _blockLengthType = token.Encoding.PrimitiveType; _blockLengthByteOrder = token.Encoding.ByteOrder; break; case HeaderStructure.TemplateId: _templateIdOffset = token.Offset; _templateIdType = token.Encoding.PrimitiveType; _templateIdByteOrder = token.Encoding.ByteOrder; break; case HeaderStructure.SchemaId: _schemaIdOffset = token.Offset; _schemaIdType = token.Encoding.PrimitiveType; _schemaIdByteOrder = token.Encoding.ByteOrder; break; case HeaderStructure.SchemaVersion: _schemaVersionOffset = token.Offset; _schemaVersionType = token.Encoding.PrimitiveType; _schemaVersionByteOrder = token.Encoding.ByteOrder; break; } } }
/// <summary> /// Splits number into the byte array /// </summary> /// <param name="number">Value to split</param> /// <param name="outputArray">Array where the bytes be stored</param> /// <param name="byteOrder">Byte order of the array</param> public static void GetBytes(long number, byte[] outputArray, ByteOrder byteOrder) { if (byteOrder == ByteOrder.BigEndian) ToBigEndian(number, outputArray); else throw new NotImplementedException(Resources.StringResources.NotImplementedLittleEndian.ToString()); }
public static int BytesToInt32(byte[] bytes, ByteOrder byteOrder) { if (byteOrder == ByteOrder.BigEndian) Array.Reverse(bytes); return BitConverter.ToInt32(bytes, 0); }
public DataReader(Stream stream) { mStream = new BinaryReader(stream); if (!BitConverter.IsLittleEndian) { byteOrder = ByteOrder.Big; } }
/// <summary> /// Get value from the byte array /// </summary> /// <param name="byteArray">Byte array</param> /// <param name="startIndex">Start index in array</param> /// <param name="length">Number of bytes to parse</param> /// <param name="byteOrder">Byte order</param> /// <returns>Long value</returns> public static long GetValue(byte[] byteArray, int startIndex, int length, ByteOrder byteOrder) { if (byteOrder == ByteOrder.BigEndian) return FromBigEndian(byteArray, startIndex, length); else throw new NotImplementedException(Resources.StringResources.NotImplementedLittleEndian.ToString()); }
public PrimitiveElementAttribute(int serializationOrder, ByteOrder dataByteOrder) { Require.That("serializationOrder", serializationOrder >= 0); SerializationOrder = serializationOrder; DataByteOrder = dataByteOrder; }
public static UInt16 Read16Bits(I2cDevice device, byte reg, ByteOrder byteOrder, string exceptionMessage) { try { byte[] addr = { reg }; byte[] data = new byte[2]; device.WriteRead(addr, data); switch (byteOrder) { case ByteOrder.BigEndian: return (UInt16)((data[0] << 8) | data[1]); case ByteOrder.LittleEndian: return (UInt16)((data[1] << 8) | data[0]); default: throw new SensorException($"Unsupported byte order {byteOrder}"); } } catch (Exception exception) { throw new SensorException(exceptionMessage, exception); } }
EmptyByteBuffer(IByteBufferAllocator allocator, ByteOrder order) { Contract.Requires(allocator != null); this.allocator = allocator; this.order = order; this.str = this.GetType().Name + (order == ByteOrder.BigEndian ? "BE" : "LE"); }
/// <summary> /// Initializes a new instance of the <see cref="DataBuffer"/> class. /// </summary> /// <param name="capacity">The capacity of the new instance.</param> /// <param name="mode">The endianness mode of the new instance.</param> public DataBuffer(int capacity, ByteOrder mode) { Contract.Requires(capacity > 0); Contract.Ensures(this.Position == 0); this.data = new byte[capacity]; this.Mode = mode; }
/// <summary> /// Returns an unsigned rational number converted from the first /// eight bytes of the given byte array. The first four bytes are /// assumed to be the numerator and the next four bytes are the /// denumerator. /// Numbers are converted from the given byte-order to platform byte-order. /// </summary> public static MathEx.UFraction32 ToURational(byte[] data, ByteOrder frombyteorder) { byte[] num = new byte[4]; byte[] den = new byte[4]; Array.Copy(data, 0, num, 0, 4); Array.Copy(data, 4, den, 0, 4); return new MathEx.UFraction32(ToUInt32(num, 0, frombyteorder, ByteOrder.System), ToUInt32(den, 0, frombyteorder, ByteOrder.System)); }
/// <summary> /// Creates a new instance of ByteReader with UTF-8 encoding. /// </summary> /// <param name="message">The bytes to read from</param> public ByteReader(byte[] message) { _message = message; _position = 0; if (_byteOrder == ByteOrder.Default) _byteOrder = _defaultByteOrder; }
public CoalescedFileXml(List<FileEntry> files = null, IEnumerable<int> compileTypes = null, ByteOrder byteOrder = ByteOrder.LittleEndian, int overrideCompileValueTypes = -1, uint version = 0) { ByteOrder = byteOrder; Files = files ?? new List<FileEntry>(); OverrideCompileValueTypes = overrideCompileValueTypes; Version = version; CompileTypes = compileTypes ?? new[] { 0, 1, 2, 3, 4 }; }
/// <summary>Create a <see cref="BinaryReader"/> or a <see cref="BigEndianBinaryReader"/> based upon a <see cref="ByteOrder"/>.</summary> /// <param name="byteOrder"></param> /// <param name="input"></param> /// <returns></returns> public static BinaryReader Create(ByteOrder byteOrder, Stream input) { switch (byteOrder) { case ByteOrder.LittleEndian: return new BinaryReader(input); case ByteOrder.BigEndian: return new BigEndianBinaryReader(input); default: throw new NotSupportedException(); } }
public ByteReader(byte[] message, ByteOrder byteOrder, Encoding encoding) : this(message) { _byteOrder = byteOrder; _encoding = encoding; if (_byteOrder == ByteOrder.Default) _byteOrder = _defaultByteOrder; }
public BNegotiate(BNegotiate rhs) { protocols = rhs.protocols; bversion = rhs.bversion; version = rhs.version; byteOrder = rhs.byteOrder; targetId = rhs.targetId; sessionId = rhs.sessionId; }
/// <summary> /// Converts the given signed rational number to an array of bytes. /// Numbers are converted from the platform byte-order to the given byte-order. /// </summary> public static byte[] GetBytes(MathEx.Fraction32 value, ByteOrder tobyteorder) { byte[] num = GetBytes(value.Numerator, ByteOrder.System, tobyteorder); byte[] den = GetBytes(value.Denominator, ByteOrder.System, tobyteorder); byte[] data = new byte[8]; Array.Copy(num, 0, data, 0, 4); Array.Copy(den, 0, data, 4, 4); return data; }
/// <summary> /// Initializes a new instance of the <see cref="DataBuffer"/> class. /// </summary> /// <param name="contents">The byte array to initialize the new instance with.</param> /// <param name="mode">The endianness mode of the new instance.</param> public DataBuffer(byte[] contents, ByteOrder mode) { Contract.Requires(contents != null); Contract.Requires(contents.Length > 0); Contract.Ensures(this.Position == 0); this.data = contents; this.Mode = mode; }
public static byte[] ToHostOrder(this byte[] src, ByteOrder srcOrder) { if (src == null) return null; return src.Length > 1 && !srcOrder.IsHostOrder() ? src.CopyReverse() : src; }
public static ByteOrderCodec MapByteOrder(ByteOrder byteOrder) { if (byteOrder == ByteOrder.BigEndian) { return ByteOrderCodec.SBE_BIG_ENDIAN; } return ByteOrderCodec.SBE_LITTLE_ENDIAN; }
public ByteWriter(Stream s, ByteOrder byteOrder, Encoding encoding) : this(s) { _byteOrder = byteOrder; _encoding = encoding; if (_byteOrder == ByteOrder.Default) _byteOrder = _defaultByteOrder; }
public ByteWriter(int capacity) { _byteOrder = ByteOrder.Default; #if(MF) _stream = new MemoryStream(); #else //_stream = new MemoryStream(capacity); #endif }
/// <summary> /// Converts the given array of 16-bit unsigned integers to an array of bytes. /// Numbers are converted from the platform byte-order to the given byte-order. /// </summary> public static byte[] GetBytes(ushort[] value, ByteOrder tobyteorder) { byte[] data = new byte[2 * value.Length]; for (int i = 0; i < value.Length; i++) { byte[] num = GetBytes(value[i], ByteOrder.System, tobyteorder); Array.Copy(num, 0, data, i * 2, 2); } return data; }
public BOutput(BTransport transport, BRegistry registry, int streamHeaderMagic, int negotiatedBypsVersion, long negotiatedVersion, ByteOrder negotiatedByteOrder) { this.objMap = transport.getApiDesc().uniqueObjects ? null : new BObjMap(); this.header = new BMessageHeader(streamHeaderMagic, negotiatedBypsVersion, negotiatedVersion, negotiatedByteOrder, transport.getWire().makeMessageId()); this.header.targetId = transport.getTargetId(); this.header.sessionId = transport.getSessionId(); this.transport = transport; this.registry = registry; this.streams = null; }
public BinaryFile(byte[] byteArray, ByteOrder byteOrder) { this.memStream = new MemoryStream(byteArray); this.binaryReader = new BinaryReader(memStream); // Set position to the beginning of the stream. this.memStream.Position = 0; this.byteOrder = byteOrder; }
public BinaryFile(MemoryStream stream, ByteOrder byteOrder) { this.memStream = stream; this.binaryWriter = new BinaryWriter(memStream, Encoding.Default); // Set position to the beginning of the stream. this.memStream.Position = 0; this.byteOrder = byteOrder; }
/// <summary> /// Initializes new instance of WitSpeechRequestTask class /// </summary> /// <param name="accessToken">Access Token</param> /// <param name="witPipedStream">Audio stream</param> /// <param name="type">Type</param> /// <param name="encoding">Encoding</param> /// <param name="bits">Bits per sample</param> /// <param name="rate">Samples per second</param> /// <param name="order">Bytes order</param> public WitSpeechRequestTask(string accessToken, WitPipedStream witPipedStream, string type, string encoding, int bits, int rate, ByteOrder order) { this.accessToken = accessToken; this.witPipedStream = witPipedStream; this.type = type; this.encoding = encoding; this.bits = bits; this.rate = rate; this.order = order; }
public BinaryStreamWriter(Stream s, ByteOrder outputEndian) { if (null == s) { throw new ArgumentNullException(); } OutputEndian = outputEndian; Stream = s; }
public static bool ReadBool32(BinaryReader reader, ByteOrder byteOrder) { if (byteOrder == ByteOrder.LittleEndian) { return Convert.ToBoolean(reader.ReadUInt32()); } else // Big-Endian { return Convert.ToBoolean(BitConverter.ToUInt32(ReadBytes(reader, 4, ByteOrder.BigEndian), 0)); } }
protected CoalesceFile(string source = "", string name = "", string id = "", IList<CoalesceAsset> assets = null, CoalesceSettings settings = null, ByteOrder byteOrder = ByteOrder.LittleEndian) { Assets = assets ?? new List<CoalesceAsset>(); ByteOrder = byteOrder; Id = id ?? ""; Name = name ?? ""; Settings = settings ?? new CoalesceSettings(); Source = source ?? ""; }
public static float ReadFloat(BinaryReader reader, ByteOrder byteOrder) { if (byteOrder == ByteOrder.LittleEndian) { return reader.ReadSingle(); } else // Big-Endian { return BitConverter.ToSingle(ReadBytes(reader, 4, ByteOrder.BigEndian), 0); } }
/// <summary> /// Creates a new IOBuffer instance from a byte array, using a specified byte order. /// </summary> /// <param name="bytes">The byte array to use.</param> /// <param name="order">Byte order to use.</param> /// <returns>A new IOBuffer instance.</returns> public static IoWriter FromBytes(byte[] bytes, ByteOrder order) { return(FromStream(new MemoryStream(bytes), order)); }
private StageList(string filename, List <World> worlds, ByteOrder byteOrder) { Worlds = worlds; Filename = filename; ByteOrder = byteOrder; }
public static void WriteValues(this BinaryWriter writer, byte[] values, int fieldSize, ByteOrder byteOrder) { if (byteOrder == ByteOrder.LittleEndian) { writer.Write(values); } else { for (int i = 0; i < values.Length; i += fieldSize) { for (int j = i + fieldSize - 1; j >= i; j--) { writer.Write(values[j]); } } } }
public void Order(ByteOrder byteOrder) { _order = byteOrder; }
public static TiffHelper.TiffIfd_Stream_Tuple GenerateIfd(ushort tag, TiffType type, string value, ByteOrder byteOrder) { return(new TiffIfdBuilder(byteOrder).WithIfdEntry(tag, type, value).ToIfdStreamTuple()); }
public string GetStringUtf8(int index, ByteOrder byteOrder) { var stringLength = GetInt(index, byteOrder); return(Encoding.UTF8.GetString(byteArray, index + 4, stringLength)); }
public void TestByte(ByteOrder order) { AssertSerialization(TestSupport.RandomByte(), order); }
private ISerializationService CreateSerializationService(ByteOrder order) { return(new SerializationServiceBuilder(). SetByteOrder(order).SetUseNativeByteOrder(false).SetPortableVersion(1).Build()); }
// byte.Utf32... -> Rune public static IEnumerable <Rune> AsUtf32Runes(this IEnumerable <byte> bytes, ByteOrder endianness = ByteOrder.LittleEndian) { var decoder = new Utf32.ByteDecoder(endianness); return(DecodeValues(bytes, decoder, "Ill-formed Utf32.")); }
public void TestStringArray(ByteOrder order) { AssertSerialization(TestSupport.RandomArray(TestSupport.RandomString), order); }
public static void Write(this BinaryWriter writer, Double[] buffer, int offset, int count, ByteOrder byteOrder = ByteOrder.LittleEndian) { var byteBuffer = new byte[count * sizeof(Double)]; Buffer.BlockCopy(buffer, offset, byteBuffer, 0, byteBuffer.Length); writer.WriteValues(byteBuffer, sizeof(Double), byteOrder); }
/// <summary> /// Initializes writer with the specified byte order. /// </summary> /// <param name="encodingType">Encoding type</param> /// <param name="handleSRID">SRID values, present or not, should be emitted.</param> /// <param name="emitZ">Z values, present or not, should be emitted</param> public WKBWriter(ByteOrder encodingType, bool handleSRID, bool emitZ) : this(encodingType, handleSRID, emitZ, false) { }
/// <summary> /// Initializes writer with the specified byte order. /// </summary> /// <param name="encodingType">Encoding type</param> public WKBWriter(ByteOrder encodingType) : this(encodingType, false) { }
// ---- METHODS ------------------------------------------------------------------------------------------------ public void ChangePlatform(bool isSwitch, int alignment, byte versionA, byte versionB, byte versionC, byte versionD, PlatformConverters.ConverterHandle handle) { if (IsPlatformSwitch && isSwitch || (!IsPlatformSwitch && !isSwitch)) { return; } //Shaders cannot be converted, remove them for (int i = 0; i < ExternalFiles.Count; i++) { if (ExternalFiles.Keys.ElementAt(i).Contains(".bfsha")) { ExternalFiles.RemoveAt(i); } } if (!IsPlatformSwitch && isSwitch) { ConvertTexturesToBntx(Textures.Values.ToList()); } else { List <TextureShared> textures = new List <TextureShared>(); foreach (var tex in this.Textures.Values) { var textureU = new WiiU.Texture(); textureU.FromSwitch((Switch.SwitchTexture)tex); textures.Add(textureU); } Textures.Clear(); foreach (var tex in textures) { Textures.Add(tex.Name, tex); } foreach (var mdl in Models.Values) { foreach (var mat in mdl.Materials.Values) { mat.RenderState = new RenderState(); } } for (int i = 0; i < ExternalFiles.Count; i++) { if (ExternalFiles.Keys.ElementAt(i).Contains(".bntx")) { ExternalFiles.RemoveAt(i); } } } //Order to read the existing data ByteOrder byteOrder = IsPlatformSwitch ? ByteOrder.LittleEndian : ByteOrder.BigEndian; //Order to set the target data ByteOrder targetOrder = isSwitch ? ByteOrder.LittleEndian : ByteOrder.BigEndian; IsPlatformSwitch = isSwitch; DataAlignment = alignment; VersionMajor = versionA; VersionMajor2 = versionB; VersionMinor = versionC; VersionMinor2 = versionD; this.ByteOrder = targetOrder; foreach (var model in Models.Values) { UpdateVertexBufferByteOrder(model, byteOrder, targetOrder); foreach (var shp in model.Shapes.Values) { foreach (var mesh in shp.Meshes) { mesh.UpdateIndexBufferByteOrder(targetOrder); } } foreach (var mat in model.Materials.Values) { if (IsPlatformSwitch) { PlatformConverters.MaterialConverter.ConvertToSwitchMaterial(mat, handle); } else { PlatformConverters.MaterialConverter.ConvertToWiiUMaterial(mat, handle); } } } if (IsPlatformSwitch) { foreach (var anim in ShaderParamAnims.Values) { anim.Name = $"{anim.Name}_fsp"; } foreach (var anim in TexSrtAnims.Values) { anim.Name = $"{anim.Name}_fts"; } foreach (var anim in ColorAnims.Values) { anim.Name = $"{anim.Name}_fcl"; } foreach (var anim in TexPatternAnims.Values) { anim.Name = $"{anim.Name}_ftp"; } foreach (var anim in MatVisibilityAnims.Values) { anim.Name = $"{anim.Name}_fvs"; } } else { this.TexPatternAnims = new ResDict <MaterialAnim>(); this.ShaderParamAnims = new ResDict <MaterialAnim>(); this.ColorAnims = new ResDict <MaterialAnim>(); this.TexSrtAnims = new ResDict <MaterialAnim>(); this.MatVisibilityAnims = new ResDict <MaterialAnim>(); } }
public void TestCharArray(ByteOrder order) { AssertSerialization(TestSupport.RandomArray(TestSupport.RandomChar), order); }
public void TestBigInteger(ByteOrder order) { var bigInt = BigInteger.Parse("123456789012345678901234567890123456789012345678901234567890"); AssertSerialization(bigInt, order); }
public string GetStringAscii(int index, ByteOrder byteOrder) { var stringLength = GetInt(index, byteOrder); return(Encoding.ASCII.GetString(byteArray, index + 4, stringLength)); }
public TiffIfdBuilder(ByteOrder byteOrder) { _byteOrder = byteOrder; }
public void TestBooleanArray(ByteOrder order) { AssertSerialization(TestSupport.RandomArray(TestSupport.RandomBool), order); }
public void TestFloatArray(ByteOrder order) { AssertSerialization(TestSupport.RandomArray(TestSupport.RandomFloat), order); }
public ExifBitConverter(ByteOrder from, ByteOrder to) : base(from, to) { ; }
public static int ReadValues(this BinaryReader reader, byte[] buffer, int fieldSize, ByteOrder byteOrder) { var bytesRead = reader.Read(buffer, 0, buffer.Length); if (byteOrder == ByteOrder.BigEndian && fieldSize > 1) { for (int i = 0; i < bytesRead; i += fieldSize) { for (int j = 0; j < fieldSize / 2; j++) { buffer.Swap(i + j, i + fieldSize - j - 1); } } } return(bytesRead); }
public void TestDoubleArray(ByteOrder order) { AssertSerialization(TestSupport.RandomArray(TestSupport.RandomDouble), order); }
public static int Read(this BinaryReader reader, Boolean[] buffer, int offset, int count, ByteOrder byteOrder = ByteOrder.LittleEndian) { var byteBuffer = new byte[count * sizeof(Boolean)]; var itemsRead = reader.ReadValues(byteBuffer, sizeof(Boolean), byteOrder); Buffer.BlockCopy(byteBuffer, 0, buffer, offset, itemsRead); return(itemsRead / sizeof(Boolean)); }
public void WriteShort(int v, ByteOrder byteOrder) { EnsureAvailable(Bits.ShortSizeInBytes); Bits.WriteShort(Buffer, Pos, (short)v, byteOrder == ByteOrder.BigEndian); Pos += Bits.ShortSizeInBytes; }
public void TestJavaClass(ByteOrder order) { var javaEnum = new JavaClass(TestSupport.RandomString()); AssertSerialization(javaEnum, order); }
public void WriteShort(int position, int v, ByteOrder byteOrder) { Bits.WriteShort(Buffer, position, (short)v, byteOrder == ByteOrder.BigEndian); }
public void TestIntegerArray(ByteOrder order) { AssertSerialization(TestSupport.RandomArray(TestSupport.RandomInt), order); }
public ColorCodecI4(ByteOrder order) : base(order) { }
public void TestNull(ByteOrder order) { AssertSerialization <object>(null, order); }