コード例 #1
0
ファイル: Program.cs プロジェクト: thexdesk/cs-multicodec
        private static void Wrap(StreamWriter w, StreamReader r, string path)
        {
            var mcc = CodecWithPath(path);

            if (mcc == null)
            {
                throw new Exception($"unknown codec {path}");
            }

            var hdrs = Encoding.UTF8.GetString(mcc.Header);

            Action <ICodec, ICodec> wrapRT = (c, mc) =>
            {
                var v = c.Decoder(r.BaseStream).Decode <dynamic>();
                mc.Encoder(w.BaseStream).Encode(v);
            };

            if (hdrs == JsonCodec.HeaderMsgioPath)
            {
                wrapRT(JsonCodec.CreateCodec(true), mcc);
            }
            else if (hdrs == JsonCodec.HeaderPath)
            {
                wrapRT(JsonCodec.CreateCodec(false), mcc);
            }
            else if (hdrs == CborCodec.HeaderPath)
            {
                wrapRT(CborCodec.CreateCodec(), mcc);
            }
            else
            {
                throw new Exception($"wrap unsupported for codec {hdrs}");
            }
        }
コード例 #2
0
 public void JsonCodecWithoutMsgIoRoundTrip() => MulticodecRoundTrip(JsonCodec.CreateCodec(false));
コード例 #3
0
 public void JsonCodecWithMsgIoRoundTrip() => MulticodecRoundTrip(JsonCodec.CreateCodec(true));
コード例 #4
0
 public Task JsonCodecWithoutMsgIoRoundTripMany_Async() => MulticodecRoundTripManyAsync(JsonCodec.CreateCodec(false));
コード例 #5
0
 public Task JsonCodecWithMsgIoRoundTrip_Async() => MulticodecRoundTripAsync(JsonCodec.CreateCodec(true));