~/bend-docscommunity

amf.bend checks

raw source on the hub · import 0xfbc4773809086afacef84e7fba6d620c/amf.bend as Amf

AMF0, the encoding of RTMP's commands (connect, play, _result...): a value is a marker byte and its data. Here a message is a flat list of tokens, an object being AObj, then AKey and value pairs, then AEnd; that is enough to write the commands and to find a field of a reply, and it keeps the decoder one loop.

Numbers are IEEE 754 doubles on the wire; the ones RTMP's commands carry are small whole numbers (a transaction, a stream id), so ANum holds a U32: the whole part of the double, 0 for a negative one. Arrays (marker 10) and the rest end the decoding: the tokens before them are what is given.

2 imports
import Base
import ./bytes.bend as B

Types

type Tok source · line 15 · raw

Data

Definitions

def Amf.log2 source · line 28 · raw

@fuel:Nat -> @+x:U32 -> @+e:Nat -> Nat

The position of n's highest set bit (0 for 0 and 1).

def Amf.double source · line 37 · raw

@+n:U32 -> @rest:List<&2, U32> -> List<&2, U32>

n as the 8 bytes of a double, in front of rest: the exponent is the highest bit's position, the fraction the bits below it.

def Amf.whole.at source · line 46 · raw

@+e:Nat -> @+hi:U32 -> @lo:U32 -> U32

def Amf.whole source · line 53 · raw

@+hi:U32 -> @lo:U32 -> U32

The whole part of the double in hi and lo: 0 below 1 and for a negative one, the largest U32 for what does not fit.

def Amf.str source · line 62 · raw

@+s:String -> @rest:List<&2, U32> -> List<&2, U32>

def Amf.tok source · line 66 · raw

@t:Tok -> @rest:List<&2, U32> -> List<&2, U32>

def Amf.rev source · line 83 · raw

@ts:List<&2, Tok> -> @acc:List<&2, Tok> -> List<&2, Tok>

def Amf.put source · line 90 · raw

@rev:List<&2, Tok> -> @acc:List<&2, U32> -> List<&2, U32>

def Amf.bytes source · line 98 · raw

@ts:List<&2, Tok> -> List<&2, U32>

The bytes of a message's tokens.

def Amf.done source · line 104 · raw

@acc:List<&2, Tok> -> List<&2, Tok>

def Amf.num source · line 107 · raw

@c:0xfbc4773809086afacef84e7fba6d620c/bytes.Cut -> @depth:Nat -> @acc:List<&2, Tok> -> @k:(@_:List<&2, U32> -> @_:Nat -> @_:List<&2, Tok> -> List<&2, Tok>) -> List<&2, Tok>

def Amf.text source · line 115 · raw

@c:0xfbc4773809086afacef84e7fba6d620c/bytes.Cut -> @depth:Nat -> @acc:List<&2, Tok> -> @k:(@_:List<&2, U32> -> @_:Nat -> @_:List<&2, Tok> -> List<&2, Tok>) -> List<&2, Tok>

def Amf.val source · line 125 · raw

@m:Nat -> @t:List<&2, U32> -> @depth:Nat -> @acc:List<&2, Tok> -> @k:(@_:List<&2, U32> -> @_:Nat -> @_:List<&2, Tok> -> List<&2, Tok>) -> List<&2, Tok>

A value after its marker m: 0 a number, 1 a boolean, 2 a string, 3 an object, 5 and 6 null and undefined, 8 an object after a 4-byte count.

def Amf.key source · line 147 · raw

@empty:Bool -> @c:0xfbc4773809086afacef84e7fba6d620c/bytes.Cut -> @depth:Nat -> @acc:List<&2, Tok> -> @k:(@_:List<&2, U32> -> @_:Nat -> @_:List<&2, Tok> -> List<&2, Tok>) -> List<&2, Tok>

Inside an object: a key (16-bit size, the text) and its value, or the empty key and the marker 9 that end it.

def Amf.key.of source · line 157 · raw

@+n:U32 -> @t:List<&2, U32> -> @depth:Nat -> @acc:List<&2, Tok> -> @k:(@_:List<&2, U32> -> @_:Nat -> @_:List<&2, Tok> -> List<&2, Tok>) -> List<&2, Tok>

def Amf.step source · line 161 · raw

@top:Bool -> @bs:List<&2, U32> -> @depth:Nat -> @acc:List<&2, Tok> -> @k:(@_:List<&2, U32> -> @_:Nat -> @_:List<&2, Tok> -> List<&2, Tok>) -> List<&2, Tok>

def Amf.toks source · line 172 · raw

@fuel:Nat -> @bs:List<&2, U32> -> @+depth:Nat -> @acc:List<&2, Tok> -> List<&2, Tok>

Every turn takes at least a byte, so the fuel is the byte count.

def Amf.of source · line 181 · raw

@+bs:List<&2, U32> -> List<&2, Tok>

The tokens of a message's bytes.

def Amf.at source · line 188 · raw

@ts:List<&2, Tok> -> @n:Nat -> Tok

The n-th token (0 the first), Null when there is none.

def Amf.string source · line 197 · raw

@t:Tok -> String

def Amf.number source · line 204 · raw

@t:Tok -> U32

def Amf.get source · line 212 · raw

@ts:List<&2, Tok> -> @+key:String -> String

The string under a key, at any depth; "" when there is none.