Thanks to visit codestin.com
Credit goes to github.com

Skip to content

danilovd/yabencoder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 

Repository files navigation

YaBEncoder

Description

Yet another library for encoding and decoding data in b-encode format. The format is described here

Quick start

How to create entries

Entries are defined by interface Entry and represent b-encode format entity. Entries can be created using EntryFactory interface.

EntryFactory entryFactory = new EntryFactoryImpl()

StringEntry strEntry = entryFactory.createStringEntry("sampleStringEntry");
IntegerEntry intEntry = entryFactory.createIntegerEntry(42);
ListEntry listEntry = entryFactory.createListEntry(strEntry, intEntry);
    
// create map first
Map<StringEntry,Entry> map = new HashMap<>();
map.put(strEntry, intEntry);
DictionaryEntry dictionary = entryFactory.createDictionaryEntry(map);

or using CompositeEntryBuilder for dictionaries and lists

DictionaryEntry entry = dictionary()
    .entry("name", "Arthur")
    .entry("number", 42L)
    .entry("picture", "")
    .entry("planets", list("Earth", "Somewhere else", "Old Earth"))
    .create();

How to encode data

Encoding is done using BEncoder interface. It takes output stream and collection of entries to be encoded.

BEncoder bencoder = new BEncoderImpl();
bencoder.encode(outStream, entriesToEncode);

Entries will be written to output stream.

How to decode data

Decoding is done using BDecoder. BDecoder reads data from input stream, creates entries from it, and puts them into a given collection.

BDecoder bdecoder = new BDecoderImpl();
bdecoder.decode(inStream, decodedEntries);

About

b-encode serializer/deserializer sample

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages