Skip to content

Bytes Operations

ResIOT has many Lua 5.1 functions to operate with Bytes and Bytes Array. Here's a quick example.

    -- Append a Byte at the end of a Bytes Array | return = {0xB3, 0xC2, 0xFF, 0xC5}
    result = resiot_appbyte({0xB3, 0xC2, 0xFF}, 0xC5)

    -- Append a String at the end of a Bytes Array | result = {0x61, 0x62, 0x63, 0x64}  
    result = resiot_apps2ba({0x61, 0x62, 0x63}, "d")

    -- Encode a Bytes Array into a base64 String | result = {"UFJV"}
    result = resiot_base64encode({0x50, 0x52, 0x55})

    -- Decode a base64 String into a Bytes Array
    -- result = { 0x48 0x65 0x6c 0x6c 0x6f 0x20 0x77 0x6f 0x72 0x6c 0x64 0x21 }
    -- err = ""
    result, err = resiot_base64decode("SGVsbG8gd29ybGQh")

    -- Slice a Bytes Array at given Indexes | result = {0x50}
    result = resiot_baslice({0x50, 0x52, 0x55, 0x33, 0x97, 0x85}, 0, 1)

    -- Get the length of the Bytes Array | result = 3
    result = resiot_byarrlen({0x50, 0x43, 0x31})

    -- Concat N Bytes to the main Bytes Array | result = {0x50, 0x54, 0x12, 0x76}
    result = resiot_bytearrayconcat({0x50}, {0x54}, {0x12}, {0x76})