/// <inheritdoc /> public override void Write(string value, IWireStreamWriterStrategy dest) { if (dest == null) { throw new ArgumentNullException(nameof(dest)); } //Review the source for Trinitycore's string reading for their ByteBuffer (payload/packet) Type. //(ctr+f << for std::string): http://www.trinitycore.net/d1/d17/ByteBuffer_8h_source.html //They use 0 byte to terminate the string in the stream //We should check this so we don't try to decode //or write null. Null should be considered empty. if (!String.IsNullOrEmpty(value)) { //TODO: Pointer hack for speed //Convert the string to bytes //Not sure about encoding yet byte[] stringBytes = EncodingStrategy.GetBytes(value); dest.Write(stringBytes); } //Write the null terminator; Client expects it. for (int i = 0; i < CharacterSize; i++) { dest.Write(0); } }
/// <inheritdoc /> public override async Task WriteAsync(string value, IWireStreamWriterStrategyAsync dest) { if (dest == null) { throw new ArgumentNullException(nameof(dest)); } //We should check this so we don't try to decode //or write null. Null should be considered empty. if (!String.IsNullOrEmpty(value)) { //See sync method for doc byte[] stringBytes = EncodingStrategy.GetBytes(value); await dest.WriteAsync(stringBytes) .ConfigureAwait(false); } //TODO: Make this more efficient instead of multiple wrtie calls //Write the null terminator; Client expects it. for (int i = 0; i < CharacterSize; i++) { await dest.WriteAsync(0) .ConfigureAwait(false); } }
/// <summary> /// Perform the steps necessary to deserialize a string. /// </summary> /// <param name="source">The reader providing the input data.</param> /// <returns>A string value from the reader.</returns> public override string Read(IWireStreamReaderStrategy source) { if (source == null) { throw new ArgumentNullException(nameof(source)); } //Review the source for Trinitycore's string reading for their ByteBuffer (payload/packet) Type. //(ctr+f >> for std::string): http://www.trinitycore.net/d1/d17/ByteBuffer_8h_source.html //They use 0 byte to terminate the string in the stream //TODO: We can likely do some fancy pointer stuff to make this much cheaper. //Read a byte from the stream; Stop when we find a 0 List <byte> stringBytes = new List <byte>(); //This is used to track larger than 1 char null terminators int zeroByteCountFound = 0; //How many characters have been counted int currentCharCount = 0; do { byte currentByte = source.ReadByte(); currentCharCount++; stringBytes.Add(currentByte); //If we find a 0 byte we need to track it //char could be 1 byte or even 4 so we need to reset //if we encounter an actual character before we find all //null terminator bytes if (currentByte == 0) { zeroByteCountFound++; } else { zeroByteCountFound = 0; } //if we found 4 0 bytes in arow but we didn't find a full char set of CharacterSize //then we should reset. This can happen if you have {5 0 0 0} {0 0 0 0} it will stop after the first 4 //But with this is will read the whole {0 0 0 0}. if (currentCharCount % CharacterSize == 0 && zeroByteCountFound < CharacterSize) { zeroByteCountFound = 0; } } while(zeroByteCountFound < CharacterSize); //TODO: Invesitgate expected WoW/TC behavior for strings of length 0. Currently violates contract for return type. //I have decided to support empty strings instead of null return(stringBytes.Count - CharacterSize <= 0 ? "" : EncodingStrategy.GetString(stringBytes.ToArray(), 0, Math.Max(0, stringBytes.Count - CharacterSize))); }
/// <inheritdoc /> public override Task WriteAsync(string value, IWireStreamWriterStrategyAsync dest) { if (dest == null) { throw new ArgumentNullException(nameof(dest)); } //TODO: Pointer hack for speed byte[] stringBytes = EncodingStrategy.GetBytes(value); return(dest.WriteAsync(stringBytes)); //Just don't write terminator. Very simple. }
/// <inheritdoc /> public override async Task <string> ReadAsync(IWireStreamReaderStrategyAsync source) { if (source == null) { throw new ArgumentNullException(nameof(source)); } //See sync method for doc //TODO: Find an average size for WoW strings List <byte> stringBytes = new List <byte>(); //This is used to track larger than 1 char null terminators int zeroByteCountFound = 0; //How many characters have been counted int currentCharCount = 0; do { byte currentByte = await source.ReadByteAsync() .ConfigureAwait(false); currentCharCount++; stringBytes.Add(currentByte); //If we find a 0 byte we need to track it //char could be 1 byte or even 4 so we need to reset //if we encounter an actual character before we find all //null terminator bytes if (currentByte == 0) { zeroByteCountFound++; } else { zeroByteCountFound = 0; } //if we found 4 0 bytes in arow but we didn't find a full char set of CharacterSize //then we should reset. This can happen if you have {5 0 0 0} {0 0 0 0} it will stop after the first 4 //But with this is will read the whole {0 0 0 0}. if (currentCharCount % CharacterSize == 0 && zeroByteCountFound < CharacterSize) { zeroByteCountFound = 0; } } while(zeroByteCountFound < CharacterSize); //TODO: Invesitgate expected WoW/TC behavior for strings of length 0. Currently violates contract for return type. //I have decided to support empty strings instead of null return(stringBytes.Count - CharacterSize <= 0 ? "" : EncodingStrategy.GetString(stringBytes.ToArray(), 0, Math.Max(0, stringBytes.Count - CharacterSize))); }
/// <inheritdoc /> public override async Task <string> ReadAsync(IWireStreamReaderStrategyAsync source) { if (source == null) { throw new ArgumentNullException(nameof(source)); } //The size must come from the strategy provided int size = CharacterSize * await sizeProvider.SizeAsync(source) .ConfigureAwait(false); byte[] bytes = await source.ReadBytesAsync(size) .ConfigureAwait(false); return(EncodingStrategy.GetString(bytes).TrimEnd(NullTermincatorCharacterArray)); }
/// <inheritdoc /> public override string Read(IWireStreamReaderStrategy source) { if (source == null) { throw new ArgumentNullException(nameof(source)); } //The size must come from the strategy provided //TODO: Should we expect char size or byte size? int size = CharacterSize * sizeProvider.Size(source); byte[] bytes = source.ReadBytes(size); //TODO: Pointer hack for preformance //This is the only way to remove padding that I know of //There may be a more efficient way of removing the padding //There is actually an unsafe pointer hack to improve preformance here too. //profile and add later. return(EncodingStrategy.GetString(bytes).TrimEnd(NullTermincatorCharacterArray)); }
private static Stream Encode(SKSurface surface, int width, int height, EncodingStrategy encodingStrategy, ImageFormat format, int q, Conf.PdfMetadata pdfMetadata, ushort horizontalResolution, ushort verticalResolution) { switch (encodingStrategy) { case EncodingStrategy.Skia: FormatLookup.TryGetValue(format, out SKEncodedImageFormat formatType); return(EncodeSkiaImage(surface, formatType, q, horizontalResolution, verticalResolution)); case EncodingStrategy.PDF: return(EncodePdf(surface, width, height, q, pdfMetadata)); case EncodingStrategy.JPEG2000: return(Jpeg2000.Compressor.Compress(surface.Snapshot())); case EncodingStrategy.Tifflib: return(Image.Tiff.TiffEncoder.Encode(surface.Snapshot())); default: throw new ArgumentException("Unsupported format", "format"); } }
public WriterOptions(Properties tableProperties, Configuration conf) { configuration = conf; memoryManagerValue = getMemoryManager(conf); stripeSizeValue = OrcConf.STRIPE_SIZE.getLong(tableProperties, conf); blockSizeValue = OrcConf.BLOCK_SIZE.getLong(tableProperties, conf); rowIndexStrideValue = (int)OrcConf.ROW_INDEX_STRIDE.getLong(tableProperties, conf); bufferSizeValue = (int)OrcConf.BUFFER_SIZE.getLong(tableProperties, conf); blockPaddingValue = OrcConf.BLOCK_PADDING.getBoolean(tableProperties, conf); compressValue = (CompressionKind)Enum.Parse( typeof(CompressionKind), OrcConf.COMPRESS.getString(tableProperties, conf), true); string versionName = OrcConf.WRITE_FORMAT.getString(tableProperties, conf); versionValue = VersionHelper.byName(versionName); string enString = OrcConf.ENCODING_STRATEGY.getString(tableProperties, conf); _encodingStrategy = (EncodingStrategy)Enum.Parse(typeof(EncodingStrategy), enString, true); string compString = OrcConf.COMPRESSION_STRATEGY.getString(tableProperties, conf); compressionStrategy = (CompressionStrategy)Enum.Parse(typeof(CompressionStrategy), compString, true); _paddingTolerance = OrcConf.BLOCK_PADDING_TOLERANCE.getDouble(tableProperties, conf); _bloomFilterColumns = OrcConf.BLOOM_FILTER_COLUMNS.getString(tableProperties, conf); _bloomFilterFpp = OrcConf.BLOOM_FILTER_FPP.getDouble(tableProperties, conf); timeZone = TimeZoneInfo.Local.Id; }
protected virtual unsafe string ReadEncodedString(byte *bytes, int trueStringSize) { return(EncodingStrategy.GetString(bytes, trueStringSize)); }
protected virtual unsafe int WriteEncodedString(char *chars, int charsLength, byte *bytes, int byteLength) { return(EncodingStrategy.GetBytes(chars, charsLength, bytes, byteLength)); }
/** * Sets the encoding strategy that is used to encode the data. */ public WriterOptions encodingStrategy(EncodingStrategy strategy) { _encodingStrategy = strategy; return(this); }
/** * Sets the encoding strategy that is used to encode the data. */ public WriterOptions encodingStrategy(EncodingStrategy strategy) { _encodingStrategy = strategy; return this; }