Beispiel #1
0
    void HandlerData(byte[] data)
    {
        DataModel model = DataCodec.Decode(data);

        switch (model.Type)
        {
        case ChatProtocolType.TYPE_NONE:
            break;

        case ChatProtocolType.TYPE_MYSQL:
            mySqlHandler.MessageReceive(model);
            break;

        case ChatProtocolType.TYPE_IM:
            imHandler.MessageReceive(model);
            break;

        case ChatProtocolType.TYPE_MESSAGE:
            messageHandler.MessageReceive(model);
            break;

        case ChatProtocolType.TYPE_CHATDATA:
            videoDataHandler.MessageReceive(model);
            break;

        case ChatProtocolType.TYPE_OTHER:
            HandlerOther(model.Request, model.Message);
            break;
        }
    }
Beispiel #2
0
        public static RequestParameters DecodeRequest(ClientMessage clientMessage)
        {
            using var iterator = clientMessage.GetEnumerator();
            var request = new RequestParameters();

            iterator.Take(); // empty initial frame
            request.Name = StringCodec.Decode(iterator);
            request.Key  = DataCodec.Decode(iterator);
            return(request);
        }
Beispiel #3
0
        public static RequestParameters DecodeRequest(ClientMessage clientMessage)
        {
            using var iterator = clientMessage.GetEnumerator();
            var request      = new RequestParameters();
            var initialFrame = iterator.Take();

            request.OverflowPolicy = initialFrame.Bytes.ReadIntL(RequestOverflowPolicyFieldOffset);
            request.Name           = StringCodec.Decode(iterator);
            request.Value          = DataCodec.Decode(iterator);
            return(request);
        }
        public static RequestParameters DecodeRequest(ClientMessage clientMessage)
        {
            using var iterator = clientMessage.GetEnumerator();
            var request      = new RequestParameters();
            var initialFrame = iterator.Take();

            request.ThreadId = initialFrame.Bytes.ReadLongL(RequestThreadIdFieldOffset);
            request.Name     = StringCodec.Decode(iterator);
            request.Key      = DataCodec.Decode(iterator);
            return(request);
        }
Beispiel #5
0
        public static RequestParameters DecodeRequest(ClientMessage clientMessage)
        {
            using var iterator = clientMessage.GetEnumerator();
            var request      = new RequestParameters();
            var initialFrame = iterator.Take();

            request.LocalOnly = initialFrame.Bytes.ReadBoolL(RequestLocalOnlyFieldOffset);
            request.Name      = StringCodec.Decode(iterator);
            request.Predicate = DataCodec.Decode(iterator);
            return(request);
        }
Beispiel #6
0
        public static RequestParameters DecodeRequest(ClientMessage clientMessage)
        {
            using var iterator = clientMessage.GetEnumerator();
            var request      = new RequestParameters();
            var initialFrame = iterator.Take();

            request.IncludeValue  = initialFrame.Bytes.ReadBoolL(RequestIncludeValueFieldOffset);
            request.ListenerFlags = initialFrame.Bytes.ReadIntL(RequestListenerFlagsFieldOffset);
            request.LocalOnly     = initialFrame.Bytes.ReadBoolL(RequestLocalOnlyFieldOffset);
            request.Name          = StringCodec.Decode(iterator);
            request.Key           = DataCodec.Decode(iterator);
            return(request);
        }
        public static RequestParameters DecodeRequest(ClientMessage clientMessage)
        {
            using var iterator = clientMessage.GetEnumerator();
            var request      = new RequestParameters();
            var initialFrame = iterator.Take();

            request.Batch             = initialFrame.Bytes.ReadIntL(RequestBatchFieldOffset);
            request.Name              = StringCodec.Decode(iterator);
            request.IterationPointers = EntryListIntegerIntegerCodec.Decode(iterator);
            request.Projection        = DataCodec.Decode(iterator);
            request.Predicate         = DataCodec.Decode(iterator);
            return(request);
        }
        // Decodes a texture
        private byte[] DecodeTexture()
        {
            if (m_paletteOffset != -1) // The texture contains an embedded palette
            {
                DataCodec.SetPalette(m_encodedData, m_paletteOffset, m_paletteEntries);
            }

            if (HasMipmaps)
            {
                return(DataCodec.Decode(m_encodedData, m_dataOffset + m_mipmapOffsets[0], TextureWidth, TextureHeight, PixelCodec));
            }

            return(DataCodec.Decode(m_encodedData, m_dataOffset, TextureWidth, TextureHeight, PixelCodec));
        }
        public static ValueTask HandleEventAsync(ClientMessage clientMessage, HandleTopicEventAsync handleTopicEventAsync, ILoggerFactory loggerFactory)
        {
            using var iterator = clientMessage.GetEnumerator();
            var messageType = clientMessage.MessageType;

            if (messageType == EventTopicMessageType)
            {
                var initialFrame = iterator.Take();
                var publishTime  = initialFrame.Bytes.ReadLongL(EventTopicPublishTimeFieldOffset);
                var uuid         = initialFrame.Bytes.ReadGuidL(EventTopicUuidFieldOffset);
                var item         = DataCodec.Decode(iterator);
                return(handleTopicEventAsync(item, publishTime, uuid));
            }
            loggerFactory.CreateLogger(typeof(EventHandler)).LogDebug("Unknown message type received on event handler :" + messageType);
            return(default);
        // Decodes mipmaps
        private byte[][] DecodeMipmaps()
        {
            if (m_paletteOffset != -1) // The texture contains an embedded palette
            {
                DataCodec.SetPalette(m_encodedData, m_paletteOffset, m_paletteEntries);
            }

            byte[][] mipmaps = new byte[m_mipmapOffsets.Length][];
            for (int i = 0, size = TextureWidth; i < mipmaps.Length; i++, size >>= 1)
            {
                mipmaps[i] = DataCodec.Decode(m_encodedData, m_dataOffset + m_mipmapOffsets[i], size, size, PixelCodec);
            }

            return(mipmaps);
        }
Beispiel #11
0
            public static void HandleEvent(ClientMessage clientMessage, HandleTopicEvent handleTopicEvent)
            {
                var messageType = clientMessage.MessageType;
                var iterator    = clientMessage.GetIterator();

                if (messageType == EventTopicMessageType)
                {
                    var   initialFrame = iterator.Next();
                    long  publishTime  = DecodeLong(initialFrame.Content, EventTopicPublishTimeFieldOffset);
                    Guid  uuid         = DecodeGuid(initialFrame.Content, EventTopicUuidFieldOffset);
                    IData item         = DataCodec.Decode(iterator);
                    handleTopicEvent(item, publishTime, uuid);
                    return;
                }
                Logger.GetLogger(typeof(EventHandler)).Finest("Unknown message type received on event handler :" + messageType);
            }
Beispiel #12
0
    void HandlerData(byte[] data)
    {
        DataModel model = DataCodec.Decode(data);

        switch (model.Type)
        {
        case ChatProtocolType.TYPE_NONE:
            print("NONE:" + Encoding.UTF8.GetString(model.Message));
            break;

        case ChatProtocolType.TYPE_MYSQL:
            mySqlHandler.MessageReceive(model);
            break;

        case ChatProtocolType.TYPE_IM:
            imHandler.MessageReceive(model);
            break;

        case ChatProtocolType.TYPE_MESSAGE:
            messageHandler.MessageReceive(model);
            break;
        }
    }
Beispiel #13
0
        public static Hazelcast.Data.HDictionaryEntry <IData, IData> Decode(IEnumerator <Frame> iterator)
        {
            // begin frame
            iterator.Take();

            var initialFrame = iterator.Take();
            var cost         = initialFrame.Bytes.ReadLongL(CostFieldOffset);

            var creationTime   = initialFrame.Bytes.ReadLongL(CreationTimeFieldOffset);
            var expirationTime = initialFrame.Bytes.ReadLongL(ExpirationTimeFieldOffset);
            var hits           = initialFrame.Bytes.ReadLongL(HitsFieldOffset);
            var lastAccessTime = initialFrame.Bytes.ReadLongL(LastAccessTimeFieldOffset);
            var lastStoredTime = initialFrame.Bytes.ReadLongL(LastStoredTimeFieldOffset);
            var lastUpdateTime = initialFrame.Bytes.ReadLongL(LastUpdateTimeFieldOffset);
            var version        = initialFrame.Bytes.ReadLongL(VersionFieldOffset);
            var ttl            = initialFrame.Bytes.ReadLongL(TtlFieldOffset);
            var maxIdle        = initialFrame.Bytes.ReadLongL(MaxIdleFieldOffset);
            var key            = DataCodec.Decode(iterator);
            var @value         = DataCodec.Decode(iterator);

            iterator.SkipToStructEnd();
            return(CustomTypeFactory.CreateSimpleEntryView(key, @value, cost, creationTime, expirationTime, hits, lastAccessTime, lastStoredTime, lastUpdateTime, version, ttl, maxIdle));
        }
Beispiel #14
0
        public static Hazelcast.Map.SimpleEntryView <IData, IData> Decode(FrameIterator iterator)
        {
            // begin frame
            iterator.Next();

            var initialFrame   = iterator.Next();
            var cost           = DecodeLong(initialFrame.Content, CostFieldOffset);
            var creationTime   = DecodeLong(initialFrame.Content, CreationTimeFieldOffset);
            var expirationTime = DecodeLong(initialFrame.Content, ExpirationTimeFieldOffset);
            var hits           = DecodeLong(initialFrame.Content, HitsFieldOffset);
            var lastAccessTime = DecodeLong(initialFrame.Content, LastAccessTimeFieldOffset);
            var lastStoredTime = DecodeLong(initialFrame.Content, LastStoredTimeFieldOffset);
            var lastUpdateTime = DecodeLong(initialFrame.Content, LastUpdateTimeFieldOffset);
            var version        = DecodeLong(initialFrame.Content, VersionFieldOffset);
            var ttl            = DecodeLong(initialFrame.Content, TtlFieldOffset);
            var maxIdle        = DecodeLong(initialFrame.Content, MaxIdleFieldOffset);

            var key    = DataCodec.Decode(iterator);
            var @value = DataCodec.Decode(iterator);

            CodecUtil.FastForwardToEndFrame(iterator);

            return(CustomTypeFactory.CreateSimpleEntryView(key, @value, cost, creationTime, expirationTime, hits, lastAccessTime, lastStoredTime, lastUpdateTime, version, ttl, maxIdle));
        }
Beispiel #15
0
        /// <summary>
        /// Internal read implementation of the sub classes.
        /// </summary>
        /// <param name="reader"></param>
        /// <exception cref="Exception">Expected DDS RGB24 or RGBA32 color format!</exception>
        /// <exception cref="NotImplementedException">TODO</exception>
        protected override void _Read(BinaryReader reader)
        {
            long baseOffset = reader.BaseStream.Position;

            int gbixOffset = 0;
            int pvrtOffset = 0;

            uint identifier = reader.ReadUInt32();

            if (identifier == m_gbix) //"GBIX"
            {
                HasGlobalIndex  = true;
                GlobalIndexSize = reader.ReadUInt32();
                GlobalIndex     = reader.ReadBytes((int)GlobalIndexSize);

                reader.BaseStream.Seek(4, SeekOrigin.Current); //Skip "PVRT"
                gbixOffset = 0x00;
                pvrtOffset = 0x08 + (int)GlobalIndexSize;
            }
            else
            {
                identifier = reader.ReadUInt32();
                if (identifier == m_gbix)
                {
                    HasGlobalIndex  = true;
                    GlobalIndexSize = reader.ReadUInt32();
                    GlobalIndex     = reader.ReadBytes((int)GlobalIndexSize);
                    gbixOffset      = 0x04;
                    pvrtOffset      = 0x0C + (int)GlobalIndexSize;
                }
                else if (identifier == m_pvrt)
                {
                    gbixOffset = -1;
                    pvrtOffset = 0x04;
                }
                else
                {
                    gbixOffset = -1;
                    pvrtOffset = 0x00;
                    reader.BaseStream.Seek(-4, SeekOrigin.Current);
                }
            }

            // Read information about the texture
            ContentSize = reader.ReadUInt32();
            PixelFormat = (PvrPixelFormat)reader.ReadByte();
            DataFormat  = (PvrDataFormat)reader.ReadByte();
            reader.BaseStream.Seek(2, SeekOrigin.Current);
            Width  = reader.ReadUInt16();
            Height = reader.ReadUInt16();

            if (DataFormat == PvrDataFormat.DDS || DataFormat == PvrDataFormat.DDS_2)
            {
                if (!(PixelFormat == PvrPixelFormat.DDS_DXT1_RGB24 || PixelFormat == PvrPixelFormat.DDS_DXT3_RGBA32))
                {
                    throw new Exception("Expected DDS RGB24 or RGBA32 color format!");
                }

                long             ddsOffset = reader.BaseStream.Position;
                DDS_Header       header    = new DDS_Header(reader.BaseStream);
                DDSFormatDetails format    = new DDSFormatDetails(header.Format, header.DX10_DXGI_AdditionalHeader.dxgiFormat);
                reader.BaseStream.Seek(ddsOffset, SeekOrigin.Begin);

                byte[] ddsBuffer = reader.ReadBytes(header.dwPitchOrLinearSize + header.dwSize + 128);

                MemoryStream memoryStream = new MemoryStream(ddsBuffer, 0, ddsBuffer.Length, true, true);
                MipMaps = DDSGeneral.LoadDDS(memoryStream, header, 0, format);
                memoryStream.Close();

                Width  = header.Width;
                Height = header.Height;
            }
            else
            {
                // Get the codecs and make sure we can decode using them
                PixelCodec = PvrPixelCodec.GetPixelCodec(PixelFormat);
                DataCodec  = PvrDataCodec.GetDataCodec(DataFormat);
                if (DataCodec != null && PixelCodec != null)
                {
                    DataCodec.PixelCodec = PixelCodec;
                }

                // Set the number of palette entries
                int paletteEntries = DataCodec.PaletteEntries;
                if (DataFormat == PvrDataFormat.VECTOR_QUANTIZATION_SMALL || DataFormat == PvrDataFormat.VECTOR_QUANTIZATION_SMALL_MIPMAP)
                {
                    if (Width <= 16)
                    {
                        paletteEntries = 64; // Actually 16
                    }
                    else if (Width <= 32)
                    {
                        paletteEntries = 256; // Actually 64
                    }
                    else if (Width <= 64)
                    {
                        paletteEntries = 512; // Actually 128
                    }
                    else
                    {
                        paletteEntries = 1024; // Actually 256
                    }
                }

                // Set the palette and data offsets
                int paletteOffset = 0;
                int dataOffset    = 0;
                if (paletteEntries == 0 || DataCodec.NeedsExternalPalette)
                {
                    paletteOffset = -1;
                    dataOffset    = pvrtOffset + 0x10;
                }
                else
                {
                    paletteOffset = pvrtOffset + 0x10;
                    dataOffset    = paletteOffset + (paletteEntries * (PixelCodec.Bpp >> 3));
                }

                // Get the compression format and determine if we need to decompress this texture
                reader.BaseStream.Seek(baseOffset, SeekOrigin.Begin);
                uint first = reader.ReadUInt32();
                reader.BaseStream.Seek(baseOffset + pvrtOffset + 4, SeekOrigin.Begin);
                uint second = reader.ReadUInt32();
                if (first == second - pvrtOffset + dataOffset + 8)
                {
                    CompressionFormat = PvrCompressionFormat.RLE;
                }
                else
                {
                    CompressionFormat = PvrCompressionFormat.NONE;
                }
                CompressionCodec = PvrCompressionCodec.GetCompressionCodec(CompressionFormat);

                if (CompressionFormat != PvrCompressionFormat.NONE && CompressionCodec != null)
                {
                    //TODO: Convert to stream compatible code
                    throw new NotImplementedException("TODO");
                    //m_encodedData = CompressionCodec.Decompress(m_encodedData, dataOffset, PixelCodec, DataCodec);

                    // Now place the offsets in the appropiate area
                    if (CompressionFormat == PvrCompressionFormat.RLE)
                    {
                        if (gbixOffset != -1)
                        {
                            gbixOffset -= 4;
                        }
                        pvrtOffset -= 4;
                        if (paletteOffset != -1)
                        {
                            paletteOffset -= 4;
                        }
                        dataOffset -= 4;
                    }
                }

                // If the texture contains mipmaps, gets the offsets of them
                int[] mipmapOffsets;
                if (DataCodec.HasMipmaps)
                {
                    int mipmapOffset = 0;
                    mipmapOffsets = new int[(int)Math.Log(Width, 2) + 1];

                    // Calculate the padding for the first mipmap offset
                    if (DataFormat == PvrDataFormat.SQUARE_TWIDDLED_MIPMAP)
                    {
                        mipmapOffset = (DataCodec.Bpp) >> 3; // A 1x1 mipmap takes up as much space as a 2x1 mipmap
                    }
                    else if (DataFormat == PvrDataFormat.SQUARE_TWIDDLED_MIPMAP_ALT)
                    {
                        mipmapOffset = (3 * DataCodec.Bpp) >> 3; // A 1x1 mipmap takes up as much space as a 2x2 mipmap
                    }
                    for (int i = mipmapOffsets.Length - 1, size = 1; i >= 0; i--, size <<= 1)
                    {
                        mipmapOffsets[i] = mipmapOffset;
                        mipmapOffset    += Math.Max((size * size * DataCodec.Bpp) >> 3, 1);
                    }
                }
                else
                {
                    mipmapOffsets = new int[1] {
                        0
                    };
                }

                //DecodeMipmaps()
                if (paletteOffset != -1) // The texture contains an embedded palette
                {
                    reader.BaseStream.Seek(baseOffset + paletteOffset, SeekOrigin.Begin);
                    DataCodec.SetPalette(reader, paletteEntries);
                }

                MipMaps = new List <MipMap>();
                if (DataCodec.HasMipmaps)
                {
                    for (int i = 0, size = Width; i < mipmapOffsets.Length; i++, size >>= 1)
                    {
                        reader.BaseStream.Seek(baseOffset + dataOffset + mipmapOffsets[i], SeekOrigin.Begin);
                        byte[] pixels = DataCodec.Decode(reader, size, size, PixelCodec);
                        MipMaps.Add(new MipMap(pixels, size, size));
                    }
                }
                else
                {
                    reader.BaseStream.Seek(baseOffset + dataOffset + mipmapOffsets[0], SeekOrigin.Begin);
                    byte[] pixels = DataCodec.Decode(reader, Width, Height, PixelCodec);
                    MipMaps.Add(new MipMap(pixels, Width, Height));
                }
            }
            if (HasGlobalIndex)
            {
                reader.BaseStream.Seek(baseOffset + ContentSize + 0xC, SeekOrigin.Begin);
            }
            else
            {
                reader.BaseStream.Seek(baseOffset + ContentSize, SeekOrigin.Begin);
            }
        }