/// <summary> /// Decodes the "data_base64" property provided within a structured-mode message, /// populating the <see cref="CloudEvent.Data"/> property accordingly. /// </summary> /// <param name="cloudEvent"></param> /// <remarks> /// <para> /// This implementation converts JSON string tokens to byte arrays, and fails for any other token type. /// </para> /// <para> /// Override this method to provide more specialized conversions. /// </para> /// </remarks> /// <param name="dataBase64Element">The "data_base64" property value within the structured-mode message. Will not be null, and will /// not have a null token type.</param> /// <param name="cloudEvent">The event being decoded. This should not be modified except to /// populate the <see cref="CloudEvent.Data"/> property, but may be used to provide extra /// information such as the data content type. Will not be null.</param> /// <returns>The data to populate in the <see cref="CloudEvent.Data"/> property.</returns> protected virtual void DecodeStructuredModeDataBase64Property(JsonElement dataBase64Element, CloudEvent cloudEvent) { if (dataBase64Element.ValueKind != JsonValueKind.String) { throw new ArgumentException($"Structured mode property '{DataBase64PropertyName}' must be a string, when present."); } cloudEvent.Data = dataBase64Element.GetBytesFromBase64(); }
protected override void DecodeStructuredModeDataBase64Property(JsonElement dataBase64Element, CloudEvent cloudEvent) { if (cloudEvent.DataContentType == TextBinaryContentType && dataBase64Element.ValueKind == JsonValueKind.String) { cloudEvent.Data = Encoding.UTF8.GetString(dataBase64Element.GetBytesFromBase64()); } else { base.DecodeStructuredModeDataBase64Property(dataBase64Element, cloudEvent); } }
public static object Cast(this JsonElement fromValue, Field field) { switch (field.DataType) { case DataTypeEnum.Booelan: return(fromValue.GetBoolean()); case DataTypeEnum.Integer: case DataTypeEnum.Float: return(fromValue.GetDouble()); case DataTypeEnum.String: case DataTypeEnum.GUID: return(fromValue.GetString()); case DataTypeEnum.DateTime: case DataTypeEnum.Date: return(fromValue.GetDateTime()); case DataTypeEnum.Time: var val = fromValue.GetDateTime(); return(new TimeSpan(val.Hour, val.Minute, val.Second)); case DataTypeEnum.Binary: return(fromValue.GetBytesFromBase64()); case DataTypeEnum.Void: case DataTypeEnum.Array: throw new NotImplementedException(); case DataTypeEnum.Object: throw new NotImplementedException(); default: throw new NotImplementedException(); } }
public BinaryContent(JsonElement jsonElement) { _content = new MemoryStream(jsonElement.GetBytesFromBase64()); }
public override void SerializeBytes(ref byte[] val) { val = currentNode.GetBytesFromBase64(); }