Exemplo n.º 1
0
        /// <summary>
        /// Encode key & value into schema into a KeyValue schema.
        /// </summary>
        /// <param name="schemaName"> the final schema name </param>
        /// <param name="keySchemaInfo"> the key schema info </param>
        /// <param name="valueSchemaInfo"> the value schema info </param>
        /// <param name="keyValueEncodingType"> the encoding type to encode and decode key value pair </param>
        /// <returns> the final schema info </returns>
        public static ISchemaInfo EncodeKeyValueSchemaInfo(string schemaName, ISchemaInfo keySchemaInfo, ISchemaInfo valueSchemaInfo, KeyValueEncodingType keyValueEncodingType)
        {
            Condition.CheckNotNull(keyValueEncodingType, "Null encoding type is provided");

            if (keySchemaInfo == null || valueSchemaInfo == null)
            {
                // schema is not ready
                return(null);
            }

            // process key/value schema data
            byte[] schemaData = KeyValue <ISchemaInfo, ISchemaInfo> .Encode(keySchemaInfo, _schemaInfoWriter, valueSchemaInfo, _schemaInfoWriter);

            // process key/value schema properties
            IDictionary <string, string> Properties = new Dictionary <string, string>();

            EncodeSubSchemaInfoToParentSchemaProperties(keySchemaInfo, KEY_SCHEMA_NAME, KEY_SCHEMA_TYPE, KEY_SCHEMA_PROPS, Properties);

            EncodeSubSchemaInfoToParentSchemaProperties(valueSchemaInfo, VALUE_SCHEMA_NAME, VALUE_SCHEMA_TYPE, VALUE_SCHEMA_PROPS, Properties);
            Properties[KV_ENCODING_TYPE] = keyValueEncodingType.ToString();

            // generate the final schema info
            return(new SchemaInfo
            {
                Name = schemaName,
                Type = SchemaType.KeyValue,
                Schema = schemaData,
                Properties = Properties
            });
        }
Exemplo n.º 2
0
 // encode as bytes: [key.length][key.bytes][value.length][value.bytes] or [value.bytes]
 public virtual byte[] Encode(KeyValue <K, V> Message)
 {
     if (_keyValueEncodingType == KeyValueEncodingType.INLINE)
     {
         return(KeyValue <K, V> .Encode(Message.Key, _keySchema, Message.Value, _valueSchema));
     }
     else
     {
         if (Message.Value == null)
         {
             return(null);
         }
         return(_valueSchema.Encode(Message.Value));
     }
 }