public static BlueprintRoot GetBlueprintWithIcon() { var root = new BlueprintRoot(); root.Blueprint = new BlueprintBO { Icons = new[] { new IconBO { Index = 1, Signal = new SignalIdBO { Type = SignalTypes.Item, Name = EntityNames.SmallLamp } } }, Item = "blueprint", Version = 1 }; return(root); }
public static string Encode(BlueprintRoot blueprint) { var contractResolver = new DefaultContractResolver { NamingStrategy = new SnakeCaseNamingStrategy() }; string json = JsonConvert.SerializeObject(blueprint, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore, ContractResolver = contractResolver, Formatting = Formatting.None, Converters = new List <JsonConverter> { new FloatJsonConverter() } }); byte[] compressedData2 = null; byte[] data = Encoding.UTF8.GetBytes(json); using (var inputStream = new MemoryStream(data)) using (var ms = new MemoryStream()) { using (var ds = new ZlibStream(ms, CompressionMode.Compress)) { inputStream.CopyTo(ds); } compressedData2 = ms.ToArray(); } string encodedString2 = Convert.ToBase64String(compressedData2); var sb = new StringBuilder("0"); sb.Append(encodedString2); string result = sb.ToString(); return(result); }