Skip to content

Commit

Permalink
System.Formats.Cbor package's readme (#93021)
Browse files Browse the repository at this point in the history
* Remove conceptual docummentation item

Removed since is not applicable

* List types library provides

Add list of types which library provides. Listed
public types, means exposed types.

* Add description and usage examples

Add library description. Add few code examples
showing basic functionality for CBOR wirter and reader
types.

* Add related packages section

Since different targets have different dependencies
so I have divided for each section.

* Improve short description

Add 'format' word after abbreviation to have an object
in sentence.

* Remove related packages section

Since there are no related packages.

* Improve array reading/writing example
  • Loading branch information
illialarka authored and ViktorHofer committed Oct 20, 2023
1 parent 93f0952 commit 998e118
Showing 1 changed file with 64 additions and 13 deletions.
77 changes: 64 additions & 13 deletions src/libraries/System.Formats.Cbor/src/PACKAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,91 @@

<!-- A description of the package and where one can find more documentation -->

Provides support for reading and writing values in Concise Binary Object Representation (CBOR) format, as originally defined in [IETF RFC 7049](https://www.ietf.org/rfc/rfc7049.html).


## Key Features

<!-- The key features of this package -->

*
*
*
* Reader and writer types for the CBOR format.
* Built-in support for different CBOR conformance modes.

## How to Use

<!-- A compelling example on how to use this package with code, as well as any specific guidelines for when to use the package -->

Write and read primitives:

```csharp
using System.Formats.Cbor;

var cborWriter = new CborWriter(CborConformanceMode.Lax);
cborWriter.WriteTextString("Hello World");

var cborReader = new CborReader(cborWriter.Encode(), CborConformanceMode.Lax);
Console.WriteLine(cborReader.ReadTextString());
// Hello World
```

Write and read an array:

```csharp
var cborWriter = new CborWriter(CborConformanceMode.Lax);
cborWriter.WriteStartArray(5);
for (var index = 0; index < 5; index++)
{
cborWriter.WriteInt32(index);
}
cborWriter.WriteEndArray();

var cborReader = new CborReader(cborWriter.Encode(), CborConformanceMode.Lax);
var arrayLength = cborReader.ReadStartArray();
for (var index = 0; index < arrayLength; index++)
{
Console.Write(cborReader.ReadInt32());
}
// 01234
cborReader.ReadEndArray();
```

Inspect writer and reader state:

```csharp
var cborWriter = new CborWriter(CborConformanceMode.Lax);
cborWriter.WriteTextString("SomeArray");
Console.WriteLine(cborWriter.BytesWritten);
// 10
Console.WriteLine(cborWriter.IsWriteCompleted);
// True
var cborReader = new CborReader(cborWriter.Encode(), CborConformanceMode.Lax);
Console.WriteLine(cborReader.BytesRemaining);
// 10
Console.WriteLine(cborReader.ReadTextString());
// SomeArray
Console.WriteLine(cborReader.BytesRemaining);
// 0
```

## Main Types

<!-- The main types provided in this library -->

The main types provided by this library are:

* ``
* ``
* ``
* `System.Formats.Cbor.CborReader`
* `System.Formats.Cbor.CborWriter`
* `System.Formats.Cbor.CborReaderState`
* `System.Formats.Cbor.CborConformanceMode`
* `System.Formats.Cbor.CborContentException`
* `System.Formats.Cbor.CborTag`

## Addtional Documentation
## Additional Documentation

<!-- Links to further documentation. Remove conceptual documentation if not available for the library. -->

* [Conceptual documentation](https://learn.microsoft.com/en-us/dotnet/standard/serialization/**LIBRARYNAME**/overview)
* [API documentation](https://learn.microsoft.com/en-us/dotnet/api/**LIBRARYNAME**)

## Related Packages

<!-- The related packages associated with this package -->
* [API documentation](https://learn.microsoft.com/en-us/dotnet/api/system.formats.cbor)

## Feedback & Contributing

Expand Down

0 comments on commit 998e118

Please sign in to comment.