public static Envelope Get(TypeDescription desc, POCOBuilder mapper, object payload) { using (var mem = new MemoryStream()) { // null *can* be serialized, it just has no value if (payload != null) { // A lot of models can skip the whole "create shadow type" operation, so let's squeeze those savings out if (!desc.NeedsMapping) { var model = desc.TypeModel ?? RuntimeTypeModel.Default; model.Serialize(mem, payload); } else { payload = mapper.GetMapper()(payload); ProtoBuf.Serializer.NonGeneric.Serialize(mem, payload); } } return(new Envelope(desc, mem.ToArray())); } }
public static Envelope Get(TypeDescription desc, POCOBuilder mapper, object payload) { using(var mem = new MemoryStream()) { // null *can* be serialized, it just has no value if (payload != null) { // A lot of models can skip the whole "create shadow type" operation, so let's squeeze those savings out if (!desc.NeedsMapping) { var model = desc.TypeModel ?? RuntimeTypeModel.Default; model.Serialize(mem, payload); } else { payload = mapper.GetMapper()(payload); ProtoBuf.Serializer.NonGeneric.Serialize(mem, payload); } } return new Envelope(desc, mem.ToArray()); } }