Skip to content

Commit

Permalink
add FromMap and FromOrderedMap
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles Roddie committed Jan 22, 2024
1 parent b45ae36 commit 7e31d06
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions CBOR/PeterO/Cbor/CBORObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3236,6 +3236,20 @@ public static CBORObject NewMap() {
new SortedDictionary<CBORObject, CBORObject>());
}

/// <summary>Creates a new CBOR map that stores its keys in an
/// undefined order.</summary>
/// <param name='keysAndValues'>A sequence of key-value pairs.</param>
/// <returns>A new CBOR map.</returns>
public static CBORObject FromMap(IEnumerable<Tuple<CBORObject, CBORObject>> keysAndValues) {
var sd = new SortedDictionary<CBORObject, CBORObject>();
foreach (Tuple<CBORObject, CBORObject> kv in keysAndValues) {
sd.Add(kv.Item1, kv.Item2);
}
return new CBORObject(
CBORObjectTypeMap,
sd);
}

/// <summary>Creates a new empty CBOR map that ensures that keys are
/// stored in the order in which they are first inserted.</summary>
/// <returns>A new CBOR map.</returns>
Expand All @@ -3245,6 +3259,20 @@ public static CBORObject NewOrderedMap() {
PropertyMap.NewOrderedDict());
}

/// <summary>Creates a new CBOR map that ensures that keys are
/// stored in order.</summary>
/// <param name='keysAndValues'>A sequence of key-value pairs.</param>
/// <returns>A new CBOR map.</returns>
public static CBORObject FromOrderedMap(IEnumerable<Tuple<CBORObject, CBORObject>> keysAndValues) {
var oDict = PropertyMap.NewOrderedDict();
foreach (Tuple<CBORObject, CBORObject> kv in keysAndValues) {
oDict.Add(kv.Item1, kv.Item2);
}
return new CBORObject(
CBORObjectTypeMap,
oDict);
}

/// <summary>
/// <para>Reads a sequence of objects in CBOR format from a data
/// stream. This method will read CBOR objects from the stream until
Expand Down

0 comments on commit 7e31d06

Please sign in to comment.