Coder Social home page Coder Social logo

cs-libp2p-utils's Introduction

LibP2P.Utilities (cs-libp2p-utils)

Travis CI AppVeyor NuGet Codecov Libraries.io

Various utilities used in C# LibP2P.

Table of Contents

Install

PM> Install-Package LibP2P.Utilities

Usage

Extensions

Array

  • T[] Slice<T>(this T[] array, int offset, int? count = null)

    Returns a slice of an array, from offset and count (or the remaining lengt).

  • T[] Append<T>(this T[] array, params T[] items)

    Returns a new array containing the given array and all the items in sequential order.

  • int Copy<T>(this T[] src, T[] dst, int offset, int? count = null)

    Copies count items from src at given offset and returns the actual count of items copied.

Byte Array

  • byte[] Append(this byte[] bytes, params byte[][] arrays)

    Returns a new byte array containing the given array and all the arrays in sequential order.

  • int Compare(this byte[] a, byte[] b)

    Compare a to b by length and content.

  • byte[] XOR(this byte[] a, byte[] b)

    Returns a new byte array of the xor'ed result of a and b.

  • byte[] ComputeHash(this byte[] bytes)

    Returns the hash digest of the given bytes using the default algorithm (SHA2_256).

Multiaddress

  • bool IsIPLoopback(this Multiaddress addr)

    Is the given Multiaddress pointing to a loopback address? Catches both IPv4 and IPv6.

  • bool IsFDCostlyTransport(this Multiaddress addr)

    Does the given Multiaddress contain a transport that require file descriptors, like sockets? Catches only TCP for now.

Multihash

  • int Compare(this Multihash a, Multihash b)

    Compares two Multihashes by length and content.

Protocol Buffers

  • byte[] SerializeToBytes<T>(this T obj)

    Serializes the given object to a byte array using Protocol Buffers. The given object must be a valid protobuf-net contract.

  • T Deserialize<T>(this byte[] bytes)

    Deserializes the given byte array to an instance of T. The given type must be a valid protobuf-net contract type.

ReaderWriterLockSlim

  • void Read(this ReaderWriterLockSlim rwls, Action action, int timeout = Timeout.Infinite)

    Aqcuire a read lock with optional timeout.

  • T Read<T>(this ReaderWriterLockSlim rwls, Func<T> func, int timeout = TImeout.Infinite)

    Acquire a read lock and return a value with optional timeout.

  • void Write(this ReaderWriterLockSlim rwls, Action action, int timeout = Timeout.Infinite)

    Acquire a write lock with optional timeout.

  • T Write<T>(this ReaderWriterLockSlim rwls, Func<T> func, int timeout = TImeout.Infinite)

    Acquire a write lock and return a value with optional timeout.

SemaphoreSlim

  • void Lock(this SemaphoreSlim sl, Action action)

    Acquire a lock and perform an action.

  • Task LockAsync(this SemaphoreSlim sl, Action action, CancellationToken cancellationToken

    Acquire a lock and perform an action asynchronously.

  • T Lock<T>(this SemaphoreSim sl, Func<T> func)

    Acquire a lock and return a value.

  • Task<T> LockAsync<T>(this SemaphoreSlim sl, Func<T> func, CancellationToken cancellationToken)

    Acquire a lock and return a value asynchronously.

Stream

  • IReader AsReader(this Stream stream)

    Get an IReader from a Stream.

  • IWriter AsWriter(this Stream stream)

    Get an IWriter from a Stream.

  • Stream AsSystemStream(this IReader)

  • Stream AsSystemStream(this IWriter)

  • Stream AsSystemStream(this ISeeker)

  • Stream AsSystemStream(this IReadWriter)

  • Stream AsSystemStream(this IReadWriteSeeker)

  • Stream AsSystemStream(this IReadWriteCloser)

    Get a Stream from a LibP2P interface reader/writer/seeker/etc.

  • int CopyTo(this IReader reader, IWriter writer, int bufferSize = 4096)

    Copy everything from reader to writer with a given buffer size. Returns bytes copied.

  • Task<int> CopyToAsync(this IReader reader, IWriter writer, int bufferSize = 4096, CancellationToken cancellationToken = default(CancellationToken))

    Copy everything from reader to writer with a given buffer size asynchronously. Returns bytes copied.

  • int ReadFull(this IReader reader, byte[] buffer, int offset = 0, int count = -1)

    Read from reader until given count is reached or the size of the buffer minus offset.

  • Task<int> ReadFullAsync(this IReader reader, byte[] buffer, int offset = 0, int count = -1, CancellationToken cancellationToken = default(CancellationToken))

    Read from reader until given count is reached or the size of the buffer minus offset asynchronously.

Tuple

  • Tuple<T, T> Swap<T>(this Tuple<T, T> tuple)

    Swaps the values of a tuple.

Classes

ConcurrentList

  • ConcurrentList<T> : IList<T>, IDisposable

    IList with built in ReaderWriterLockSlim.

SyncMutex

  • abstract class SyncMutex : IDisposable

    Base class for usage with one ReaderWriterLockSlim.

Maintainers

Captain: @tabrath.

Contribute

Contributions welcome. Please check out the issues.

Check out our contributing document for more information on how we work, and about contributing in general. Please be aware that all interactions related to multiformats are subject to the IPFS Code of Conduct.

Small note: If editing the README, please conform to the standard-readme specification.

License

MIT � 2016 Trond Br�then

cs-libp2p-utils's People

Contributors

libp2p-mgmt-read-write[bot] avatar tabrath avatar web-flow avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.