amf.bend checks
raw source on the hub · import 0xd6fc55bf65b187fec4175f80d08c165a/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. Writing has them: AArr{n} opens an array of the n values that follow.
2 imports
import Base import ./bytes.bend as B
Types
type Tok source · line 16 · raw
Data
ANum@n:U32 -> Tok
AStr@s:String -> Tok
AFlag@b:Bool -> Tok
ANullTok
AObjTok
AKey@s:String -> Tok
AEndTok
AArr@n:U32 -> Tok
Definitions
def Amf.log2 source · line 30 · 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 39 · 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 48 · raw
@+e:Nat -> @+hi:U32 -> @lo:U32 -> U32
def Amf.whole source · line 55 · 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 64 · raw
@+s:String -> @rest:List<&2, U32> -> List<&2, U32>
def Amf.tok source · line 68 · raw
@t:Tok -> @rest:List<&2, U32> -> List<&2, U32>
def Amf.rev source · line 87 · raw
@ts:List<&2, Tok> -> @acc:List<&2, Tok> -> List<&2, Tok>
def Amf.put source · line 94 · raw
@rev:List<&2, Tok> -> @acc:List<&2, U32> -> List<&2, U32>
def Amf.bytes source · line 102 · raw
@ts:List<&2, Tok> -> List<&2, U32>
The bytes of a message's tokens.
def Amf.done source · line 108 · raw
@acc:List<&2, Tok> -> List<&2, Tok>
def Amf.num source · line 111 · raw
@c:0xd6fc55bf65b187fec4175f80d08c165a/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 119 · raw
@c:0xd6fc55bf65b187fec4175f80d08c165a/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 129 · 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 151 · raw
@empty:Bool -> @c:0xd6fc55bf65b187fec4175f80d08c165a/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 161 · 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 165 · 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 176 · 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 185 · raw
@+bs:List<&2, U32> -> List<&2, Tok>
The tokens of a message's bytes.
def Amf.at source · line 192 · 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 201 · raw
@t:Tok -> String
def Amf.number source · line 208 · raw
@t:Tok -> U32
def Amf.get source · line 216 · raw
@ts:List<&2, Tok> -> @+key:String -> String
The string under a key, at any depth; "" when there is none.