public static byte[] SingleValue(bool value) { var buffer = new FlexBuffer(3); buffer.Add(value); return(buffer.Finish()); }
public static byte[] SingleValue(string value) { var buffer = new FlexBuffer((ulong)value.Length + 2); buffer.Add(value); return(buffer.Finish()); }
public static byte[] SingleValue(byte[] blob) { var buffer = new FlexBuffer((ulong)blob.Length + 10); buffer.Add(blob); return(buffer.Finish()); }
public static byte[] Null() { var buffer = new FlexBuffer(3); buffer.AddNull(); return(buffer.Finish()); }
public static byte[] SingleValue(long x, long y) { var buffer = new FlexBuffer(20); var start = buffer.StartVector(); buffer.Add(x); buffer.Add(y); buffer.EndVector(start, true, true); return(buffer.Finish()); }
public static byte[] Map(Action <IFlexBufferMapBuilder> map) { var buffer = new FlexBuffer(); var start = buffer.StartVector(); var builder = new FlexBufferMapBuilder(buffer); map(builder); buffer.SortAndEndMap(start); return(buffer.Finish()); }
public static byte[] Vector(Action <IFlexBufferVectorBuilder> vector) { var buffer = new FlexBuffer(); var start = buffer.StartVector(); var builder = new FlexBufferVectorBuilder(buffer); vector(builder); buffer.EndVector(start, false, false); return(buffer.Finish()); }
public static byte[] Convert(TextReader reader, FlexBuffer.Options options = FlexBuffer.Options.ShareKeys | FlexBuffer.Options.ShareStrings | FlexBuffer.Options.ShareKeyVectors) { if (reader == null) { throw new ArgumentNullException(nameof(reader)); } var flx = new FlexBuffer(options: options); new JsonToFlexBufferConverter(reader).ReadJsonValue(flx); return(flx.Finish()); }
public static byte[] SingleValue(double x, double y, double z) { var buffer = new FlexBuffer(28); var start = buffer.StartVector(); buffer.Add(x); buffer.Add(y); buffer.Add(z); buffer.EndVector(start, true, true); return(buffer.Finish()); }
public static byte[] SingleValue(ulong x, ulong y, ulong z, ulong w) { var buffer = new FlexBuffer(36); var start = buffer.StartVector(); buffer.Add(x); buffer.Add(y); buffer.Add(z); buffer.Add(w); buffer.EndVector(start, true, true); return(buffer.Finish()); }
public static byte[] Convert(string xmlData) { XmlDocument doc = new XmlDocument(); doc.Load(new StringReader(xmlData)); var flx = new FlexBuffer(); Process(flx, doc.DocumentElement); return(flx.Finish()); }
public static byte[] From(IEnumerable value, Options options = Options.ShareKeys | Options.ShareStrings | Options.ShareKeyVectors) { var buffer = new FlexBuffer(options: options); if (value is IDictionary dictionary) { buffer.AddDynamicMap(dictionary); } else { buffer.AddDynamicVector(value); } return(buffer.Finish()); }
public static byte[] Convert(string csv, char separator = ',') { var flx = new FlexBuffer(); var sb = new StringBuilder(); var outerVec = flx.StartVector(); var innerVec = -1; var isInDoubleQuotes = false; for (var offset = 0; offset < csv.Length;) { if (innerVec == -1) { innerVec = flx.StartVector(); } if (csv[offset] == '"') { if (isInDoubleQuotes == false) { isInDoubleQuotes = true; offset++; } else { if (csv.Length > offset + 1 && csv[offset + 1] == '"') { sb.Append('"'); offset += 2; } else { isInDoubleQuotes = false; offset++; } } } else if (csv[offset] == separator && isInDoubleQuotes == false) { flx.Add(sb.ToString()); sb.Clear(); offset++; } else if (csv[offset] == '\n' && isInDoubleQuotes == false) { flx.Add(sb.ToString()); flx.EndVector(innerVec, false, false); innerVec = -1; sb.Clear(); offset++; } else if (csv[offset] == '\r' && csv.Length > offset + 1 && csv[offset + 1] == '\n' && isInDoubleQuotes == false) { flx.Add(sb.ToString()); flx.EndVector(innerVec, false, false); innerVec = -1; sb.Clear(); offset += 2; } else { sb.Append(csv[offset]); offset++; } } if (innerVec != -1) { flx.Add(sb.ToString()); flx.EndVector(innerVec, false, false); } flx.EndVector(outerVec, false, false); return(flx.Finish()); }