Skip to content
This repository has been archived by the owner on Oct 31, 2021. It is now read-only.

Encoding and Decoding BERT in F#

theburningmonk edited this page Aug 22, 2012 · 1 revision

The full example is available in the F# example project here.

Encoding

To encode a BERT, simply call the Filbert.Encoder.encode function with the output stream and an instance of one of the Bert types above:

let mysterWord = [| 131uy; 107uy; 0uy; 8uy; 104uy; 97uy; 122uy; 101uy; 108uy; 110uy; 117uy; 116uy |]
let bert = Dictionary(Map.ofList [(Atom "Filbert", Atom "means"); (ByteList mysterWord, Atom "!")])    

// encode this BERT
use memStream = new MemoryStream()
Filbert.Encoder.encode bert memStream

Decoding

To decode a stream of bytes, call the Filbert.Decoder.decode function with the input stream and you'll get back an instance of one of the Bert types:

// now decode it
memStream.Position <- 0L
let bert' = Filbert.Decoder.decode memStream

and that's all there is to it encoding/decoding a BERT! Simple, eh?

Clone this wiki locally