Example #1
0
 public static SerializaType[] SerializeBondObject(this IBondSerializable value)
 {
     byte[] result;
     using (MemoryStream memoryStream = new MemoryStream())
     {
         using (CompactBinaryProtocolWriter compactBinaryProtocolWriter = new CompactBinaryProtocolWriter(memoryStream))
         {
             ((IBondSerializable)value).Write(compactBinaryProtocolWriter);
             result = memoryStream.ToArray();
         }
     }
     return(result);
 }
Example #2
0
        public static string TsvBase64BondEncode(
            IBondSerializable key,
            IBondSerializable value)
        {
            var keyStream = new MemoryStream();

            key.Write(new SimpleProtocolWriter(keyStream));

            var valueStream = new MemoryStream();

            value.Write(new CompactBinaryProtocolWriter(valueStream));

            return(Convert.ToBase64String(keyStream.ToArray()) + "\t" +
                   Convert.ToBase64String(valueStream.ToArray()));
        }
Example #3
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            if (reader.TokenType != JsonToken.String)
            {
                return(null);
            }

            var payload           = Convert.FromBase64String(reader.Value.ToString());
            IBondSerializable scd = (IBondSerializable)Activator.CreateInstance(objectType);

            using (var ms = new MemoryStream(payload))
            {
                using (var protocolReader = new CompactBinaryProtocolReader(ms))
                {
                    scd.Read(protocolReader);
                }
            }
            return(scd);
        }
Example #4
0
 /// <summary>
 /// Read
 /// </summary>
 public virtual void Read(global::Microsoft.Bond.IProtocolReader reader, IBondSerializable schema)
 {
     Read(ProtocolHelper.CreateReader(reader, schema));
 }
Example #5
0
 /// <summary>
 /// Unmarshal
 /// </summary>
 public virtual void Unmarshal(System.IO.Stream input, IBondSerializable schema)
 {
     global::Microsoft.Bond.Marshaler.Unmarshal(input, schema as SchemaDef, this);
 }