示例#1
0
        /* Private API */

        internal void SerializeTo(INameTableProvider nameTable, byte[] buffer, int bufferPos)
        {
            //Write count
            BitConverter.GetBytes((int)values.Count).CopyTo(buffer, bufferPos);
            bufferPos += 4;

            //Loop through
            foreach (var v in values)
            {
                //Lookup key name and write it's index
                short keyIndex = nameTable.GetNameTableIndex(v.Key);
                BitConverter.GetBytes(keyIndex).CopyTo(buffer, bufferPos + 0);

                //Get the type ID and write it
                short typeId = v.Value.SerTypeId;
                BitConverter.GetBytes(typeId).CopyTo(buffer, bufferPos + 2);

                //Get the length and write it
                int length = v.Value.GetLength();
                BitConverter.GetBytes(length).CopyTo(buffer, bufferPos + 4);

                //Now serialize to the buffer
                v.Value.Serialize(buffer, bufferPos + ENTRY_HEADER_BYTES, nameTable);

                //Update
                bufferPos += length + ENTRY_HEADER_BYTES;
            }
        }
示例#2
0
        public override void Serialize(byte[] buffer, int bufferPos, INameTableProvider nameTable)
        {
            //Ensure this is inside the possible options.
            //We check this because otherwise an attacker could flood our name table and cause slowdowns
            string realValue = value;

            if (!possibleOptions.Contains(value))
            {
                realValue = possibleOptions[0];
            }

            //Look up name table entry
            short entry = nameTable.GetNameTableIndex(realValue);

            //Write
            BitConverter.GetBytes(entry).CopyTo(buffer, bufferPos);
        }