[feature] support processing of (many) more media types (#3090)

* initial work replacing our media decoding / encoding pipeline with ffprobe + ffmpeg

* specify the video codec to use when generating static image from emoji

* update go-storage library (fixes incompatibility after updating go-iotools)

* maintain image aspect ratio when generating a thumbnail for it

* update readme to show go-ffmpreg

* fix a bunch of media tests, move filesize checking to callers of media manager for more flexibility

* remove extra debug from error message

* fix up incorrect function signatures

* update PutFile to just use regular file copy, as changes are file is on separate partition

* fix remaining tests, remove some unneeded tests now we're working with ffmpeg/ffprobe

* update more tests, add more code comments

* add utilities to generate processed emoji / media outputs

* fix remaining tests

* add test for opus media file, add license header to utility cmds

* limit the number of concurrently available ffmpeg / ffprobe instances

* reduce number of instances

* further reduce number of instances

* fix envparsing test with configuration variables

* update docs and configuration with new media-{local,remote}-max-size variables
This commit is contained in:
kim
2024-07-12 09:39:47 +00:00
committed by GitHub
parent 5bc567196b
commit cde2fb6244
376 changed files with 8026 additions and 54091 deletions

View File

@ -0,0 +1,6 @@
package wasip1
const (
ArgsGetName = "args_get"
ArgsSizesGetName = "args_sizes_get"
)

View File

@ -0,0 +1,16 @@
package wasip1
const (
ClockResGetName = "clock_res_get"
ClockTimeGetName = "clock_time_get"
)
// https://github.com/WebAssembly/WASI/blob/snapshot-01/phases/snapshot/docs.md#-clockid-enumu32
const (
// ClockIDRealtime is the name ID named "realtime" like sys.Walltime
ClockIDRealtime = iota
// ClockIDMonotonic is the name ID named "monotonic" like sys.Nanotime
ClockIDMonotonic
// Note: clockIDProcessCputime and clockIDThreadCputime were removed by
// WASI maintainers: https://github.com/WebAssembly/wasi-libc/pull/294
)

View File

@ -0,0 +1,6 @@
package wasip1
const (
EnvironGetName = "environ_get"
EnvironSizesGetName = "environ_sizes_get"
)

View File

@ -0,0 +1,314 @@
package wasip1
import (
"fmt"
"github.com/tetratelabs/wazero/experimental/sys"
)
// Errno is neither uint16 nor an alias for parity with wasm.ValueType.
type Errno = uint32
// ErrnoName returns the POSIX error code name, except ErrnoSuccess, which is
// not an error. e.g. Errno2big -> "E2BIG"
func ErrnoName(errno uint32) string {
if int(errno) < len(errnoToString) {
return errnoToString[errno]
}
return fmt.Sprintf("errno(%d)", errno)
}
// Note: Below prefers POSIX symbol names over WASI ones, even if the docs are from WASI.
// See https://linux.die.net/man/3/errno
// See https://github.com/WebAssembly/WASI/blob/snapshot-01/phases/snapshot/docs.md#variants-1
const (
// ErrnoSuccess No error occurred. System call completed successfully.
ErrnoSuccess Errno = iota
// Errno2big Argument list too long.
Errno2big
// ErrnoAcces Permission denied.
ErrnoAcces
// ErrnoAddrinuse Address in use.
ErrnoAddrinuse
// ErrnoAddrnotavail Address not available.
ErrnoAddrnotavail
// ErrnoAfnosupport Address family not supported.
ErrnoAfnosupport
// ErrnoAgain Resource unavailable, or operation would block.
ErrnoAgain
// ErrnoAlready Connection already in progress.
ErrnoAlready
// ErrnoBadf Bad file descriptor.
ErrnoBadf
// ErrnoBadmsg Bad message.
ErrnoBadmsg
// ErrnoBusy Device or resource busy.
ErrnoBusy
// ErrnoCanceled Operation canceled.
ErrnoCanceled
// ErrnoChild No child processes.
ErrnoChild
// ErrnoConnaborted Connection aborted.
ErrnoConnaborted
// ErrnoConnrefused Connection refused.
ErrnoConnrefused
// ErrnoConnreset Connection reset.
ErrnoConnreset
// ErrnoDeadlk Resource deadlock would occur.
ErrnoDeadlk
// ErrnoDestaddrreq Destination address required.
ErrnoDestaddrreq
// ErrnoDom Mathematics argument out of domain of function.
ErrnoDom
// ErrnoDquot Reserved.
ErrnoDquot
// ErrnoExist File exists.
ErrnoExist
// ErrnoFault Bad address.
ErrnoFault
// ErrnoFbig File too large.
ErrnoFbig
// ErrnoHostunreach Host is unreachable.
ErrnoHostunreach
// ErrnoIdrm Identifier removed.
ErrnoIdrm
// ErrnoIlseq Illegal byte sequence.
ErrnoIlseq
// ErrnoInprogress Operation in progress.
ErrnoInprogress
// ErrnoIntr Interrupted function.
ErrnoIntr
// ErrnoInval Invalid argument.
ErrnoInval
// ErrnoIo I/O error.
ErrnoIo
// ErrnoIsconn Socket is connected.
ErrnoIsconn
// ErrnoIsdir Is a directory.
ErrnoIsdir
// ErrnoLoop Too many levels of symbolic links.
ErrnoLoop
// ErrnoMfile File descriptor value too large.
ErrnoMfile
// ErrnoMlink Too many links.
ErrnoMlink
// ErrnoMsgsize Message too large.
ErrnoMsgsize
// ErrnoMultihop Reserved.
ErrnoMultihop
// ErrnoNametoolong Filename too long.
ErrnoNametoolong
// ErrnoNetdown Network is down.
ErrnoNetdown
// ErrnoNetreset Connection aborted by network.
ErrnoNetreset
// ErrnoNetunreach Network unreachable.
ErrnoNetunreach
// ErrnoNfile Too many files open in system.
ErrnoNfile
// ErrnoNobufs No buffer space available.
ErrnoNobufs
// ErrnoNodev No such device.
ErrnoNodev
// ErrnoNoent No such file or directory.
ErrnoNoent
// ErrnoNoexec Executable file format error.
ErrnoNoexec
// ErrnoNolck No locks available.
ErrnoNolck
// ErrnoNolink Reserved.
ErrnoNolink
// ErrnoNomem Not enough space.
ErrnoNomem
// ErrnoNomsg No message of the desired type.
ErrnoNomsg
// ErrnoNoprotoopt No message of the desired type.
ErrnoNoprotoopt
// ErrnoNospc No space left on device.
ErrnoNospc
// ErrnoNosys function not supported.
ErrnoNosys
// ErrnoNotconn The socket is not connected.
ErrnoNotconn
// ErrnoNotdir Not a directory or a symbolic link to a directory.
ErrnoNotdir
// ErrnoNotempty Directory not empty.
ErrnoNotempty
// ErrnoNotrecoverable State not recoverable.
ErrnoNotrecoverable
// ErrnoNotsock Not a socket.
ErrnoNotsock
// ErrnoNotsup Not supported, or operation not supported on socket.
ErrnoNotsup
// ErrnoNotty Inappropriate I/O control operation.
ErrnoNotty
// ErrnoNxio No such device or address.
ErrnoNxio
// ErrnoOverflow Value too large to be stored in data type.
ErrnoOverflow
// ErrnoOwnerdead Previous owner died.
ErrnoOwnerdead
// ErrnoPerm Operation not permitted.
ErrnoPerm
// ErrnoPipe Broken pipe.
ErrnoPipe
// ErrnoProto Protocol error.
ErrnoProto
// ErrnoProtonosupport Protocol error.
ErrnoProtonosupport
// ErrnoPrototype Protocol wrong type for socket.
ErrnoPrototype
// ErrnoRange Result too large.
ErrnoRange
// ErrnoRofs Read-only file system.
ErrnoRofs
// ErrnoSpipe Invalid seek.
ErrnoSpipe
// ErrnoSrch No such process.
ErrnoSrch
// ErrnoStale Reserved.
ErrnoStale
// ErrnoTimedout Connection timed out.
ErrnoTimedout
// ErrnoTxtbsy Text file busy.
ErrnoTxtbsy
// ErrnoXdev Cross-device link.
ErrnoXdev
// Note: ErrnoNotcapable was removed by WASI maintainers.
// See https://github.com/WebAssembly/wasi-libc/pull/294
)
var errnoToString = [...]string{
"ESUCCESS",
"E2BIG",
"EACCES",
"EADDRINUSE",
"EADDRNOTAVAIL",
"EAFNOSUPPORT",
"EAGAIN",
"EALREADY",
"EBADF",
"EBADMSG",
"EBUSY",
"ECANCELED",
"ECHILD",
"ECONNABORTED",
"ECONNREFUSED",
"ECONNRESET",
"EDEADLK",
"EDESTADDRREQ",
"EDOM",
"EDQUOT",
"EEXIST",
"EFAULT",
"EFBIG",
"EHOSTUNREACH",
"EIDRM",
"EILSEQ",
"EINPROGRESS",
"EINTR",
"EINVAL",
"EIO",
"EISCONN",
"EISDIR",
"ELOOP",
"EMFILE",
"EMLINK",
"EMSGSIZE",
"EMULTIHOP",
"ENAMETOOLONG",
"ENETDOWN",
"ENETRESET",
"ENETUNREACH",
"ENFILE",
"ENOBUFS",
"ENODEV",
"ENOENT",
"ENOEXEC",
"ENOLCK",
"ENOLINK",
"ENOMEM",
"ENOMSG",
"ENOPROTOOPT",
"ENOSPC",
"ENOSYS",
"ENOTCONN",
"ENOTDIR",
"ENOTEMPTY",
"ENOTRECOVERABLE",
"ENOTSOCK",
"ENOTSUP",
"ENOTTY",
"ENXIO",
"EOVERFLOW",
"EOWNERDEAD",
"EPERM",
"EPIPE",
"EPROTO",
"EPROTONOSUPPORT",
"EPROTOTYPE",
"ERANGE",
"EROFS",
"ESPIPE",
"ESRCH",
"ESTALE",
"ETIMEDOUT",
"ETXTBSY",
"EXDEV",
"ENOTCAPABLE",
}
// ToErrno coerces the error to a WASI Errno.
//
// Note: Coercion isn't centralized in sys.FSContext because ABI use different
// error codes. For example, wasi-filesystem doesn't map to these
// Errno.
func ToErrno(errno sys.Errno) Errno {
switch errno {
case 0:
return ErrnoSuccess
case sys.EACCES:
return ErrnoAcces
case sys.EAGAIN:
return ErrnoAgain
case sys.EBADF:
return ErrnoBadf
case sys.EEXIST:
return ErrnoExist
case sys.EFAULT:
return ErrnoFault
case sys.EINTR:
return ErrnoIntr
case sys.EINVAL:
return ErrnoInval
case sys.EIO:
return ErrnoIo
case sys.EISDIR:
return ErrnoIsdir
case sys.ELOOP:
return ErrnoLoop
case sys.ENAMETOOLONG:
return ErrnoNametoolong
case sys.ENOENT:
return ErrnoNoent
case sys.ENOSYS:
return ErrnoNosys
case sys.ENOTDIR:
return ErrnoNotdir
case sys.ERANGE:
return ErrnoRange
case sys.ENOTEMPTY:
return ErrnoNotempty
case sys.ENOTSOCK:
return ErrnoNotsock
case sys.ENOTSUP:
return ErrnoNotsup
case sys.EPERM:
return ErrnoPerm
case sys.EROFS:
return ErrnoRofs
default:
return ErrnoIo
}
}

View File

@ -0,0 +1,164 @@
package wasip1
import (
"fmt"
)
const (
FdAdviseName = "fd_advise"
FdAllocateName = "fd_allocate"
FdCloseName = "fd_close"
FdDatasyncName = "fd_datasync"
FdFdstatGetName = "fd_fdstat_get"
FdFdstatSetFlagsName = "fd_fdstat_set_flags"
FdFdstatSetRightsName = "fd_fdstat_set_rights"
FdFilestatGetName = "fd_filestat_get"
FdFilestatSetSizeName = "fd_filestat_set_size"
FdFilestatSetTimesName = "fd_filestat_set_times"
FdPreadName = "fd_pread"
FdPrestatGetName = "fd_prestat_get"
FdPrestatDirNameName = "fd_prestat_dir_name"
FdPwriteName = "fd_pwrite"
FdReadName = "fd_read"
FdReaddirName = "fd_readdir"
FdRenumberName = "fd_renumber"
FdSeekName = "fd_seek"
FdSyncName = "fd_sync"
FdTellName = "fd_tell"
FdWriteName = "fd_write"
PathCreateDirectoryName = "path_create_directory"
PathFilestatGetName = "path_filestat_get"
PathFilestatSetTimesName = "path_filestat_set_times"
PathLinkName = "path_link"
PathOpenName = "path_open"
PathReadlinkName = "path_readlink"
PathRemoveDirectoryName = "path_remove_directory"
PathRenameName = "path_rename"
PathSymlinkName = "path_symlink"
PathUnlinkFileName = "path_unlink_file"
)
// oflags are open flags used by path_open
// See https://github.com/WebAssembly/WASI/blob/snapshot-01/phases/snapshot/docs.md#-oflags-flagsu16
const (
// O_CREAT creates a file if it does not exist.
O_CREAT uint16 = 1 << iota //nolint
// O_DIRECTORY fails if not a directory.
O_DIRECTORY
// O_EXCL fails if file already exists.
O_EXCL //nolint
// O_TRUNC truncates the file to size 0.
O_TRUNC //nolint
)
func OflagsString(oflags int) string {
return flagsString(oflagNames[:], oflags)
}
var oflagNames = [...]string{
"CREAT",
"DIRECTORY",
"EXCL",
"TRUNC",
}
// file descriptor flags
// See https://github.com/WebAssembly/WASI/blob/snapshot-01/phases/snapshot/docs.md#fdflags
const (
FD_APPEND uint16 = 1 << iota //nolint
FD_DSYNC
FD_NONBLOCK
FD_RSYNC
FD_SYNC
)
func FdFlagsString(fdflags int) string {
return flagsString(fdflagNames[:], fdflags)
}
var fdflagNames = [...]string{
"APPEND",
"DSYNC",
"NONBLOCK",
"RSYNC",
"SYNC",
}
// See https://github.com/WebAssembly/WASI/blob/snapshot-01/phases/snapshot/docs.md#lookupflags
const (
// LOOKUP_SYMLINK_FOLLOW expands a path if it resolves into a symbolic
// link.
LOOKUP_SYMLINK_FOLLOW uint16 = 1 << iota //nolint
)
var lookupflagNames = [...]string{
"SYMLINK_FOLLOW",
}
func LookupflagsString(lookupflags int) string {
return flagsString(lookupflagNames[:], lookupflags)
}
// DirentSize is the size of the dirent struct, which should be followed by the
// length of a file name.
const DirentSize = uint32(24)
const (
FILETYPE_UNKNOWN uint8 = iota
FILETYPE_BLOCK_DEVICE
FILETYPE_CHARACTER_DEVICE
FILETYPE_DIRECTORY
FILETYPE_REGULAR_FILE
FILETYPE_SOCKET_DGRAM
FILETYPE_SOCKET_STREAM
FILETYPE_SYMBOLIC_LINK
)
// FiletypeName returns string name of the file type.
func FiletypeName(filetype uint8) string {
if int(filetype) < len(filetypeToString) {
return filetypeToString[filetype]
}
return fmt.Sprintf("filetype(%d)", filetype)
}
var filetypeToString = [...]string{
"UNKNOWN",
"BLOCK_DEVICE",
"CHARACTER_DEVICE",
"DIRECTORY",
"REGULAR_FILE",
"SOCKET_DGRAM",
"SOCKET_STREAM",
"SYMBOLIC_LINK",
}
// https://github.com/WebAssembly/WASI/blob/snapshot-01/phases/snapshot/docs.md#fstflags
const (
FstflagsAtim uint16 = 1 << iota
FstflagsAtimNow
FstflagsMtim
FstflagsMtimNow
)
var fstflagNames = [...]string{
"ATIM",
"ATIM_NOW",
"MTIM",
"MTIM_NOW",
}
func FstflagsString(fdflags int) string {
return flagsString(fstflagNames[:], fdflags)
}
// https://github.com/WebAssembly/WASI/blob/snapshot-01/phases/snapshot/docs.md#-advice-enumu8
const (
FdAdviceNormal byte = iota
FdAdviceSequential
FdAdviceRandom
FdAdviceWillNeed
FdAdviceDontNeed
FdAdviceNoReuse
)

View File

@ -0,0 +1,15 @@
package wasip1
// https://github.com/WebAssembly/WASI/blob/snapshot-01/phases/snapshot/docs.md#-eventtype-enumu8
const (
// EventTypeClock is the timeout event named "name".
EventTypeClock = iota
// EventTypeFdRead is the data available event named "fd_read".
EventTypeFdRead
// EventTypeFdWrite is the capacity available event named "fd_write".
EventTypeFdWrite
)
const (
PollOneoffName = "poll_oneoff"
)

View File

@ -0,0 +1,6 @@
package wasip1
const (
ProcExitName = "proc_exit"
ProcRaiseName = "proc_raise"
)

View File

@ -0,0 +1,3 @@
package wasip1
const RandomGetName = "random_get"

View File

@ -0,0 +1,148 @@
package wasip1
// See https://github.com/WebAssembly/WASI/blob/snapshot-01/phases/snapshot/docs.md#-rights-flagsu64
const (
// RIGHT_FD_DATASYNC is the right to invoke fd_datasync. If RIGHT_PATH_OPEN
// is set, includes the right to invoke path_open with FD_DSYNC.
RIGHT_FD_DATASYNC uint32 = 1 << iota //nolint
// RIGHT_FD_READ is he right to invoke fd_read and sock_recv. If
// RIGHT_FD_SYNC is set, includes the right to invoke fd_pread.
RIGHT_FD_READ
// RIGHT_FD_SEEK is the right to invoke fd_seek. This flag implies
// RIGHT_FD_TELL.
RIGHT_FD_SEEK
// RIGHT_FDSTAT_SET_FLAGS is the right to invoke fd_fdstat_set_flags.
RIGHT_FDSTAT_SET_FLAGS
// RIGHT_FD_SYNC The right to invoke fd_sync. If path_open is set, includes
// the right to invoke path_open with FD_RSYNC and FD_DSYNC.
RIGHT_FD_SYNC
// RIGHT_FD_TELL is the right to invoke fd_seek in such a way that the file
// offset remains unaltered (i.e., whence::cur with offset zero), or to
// invoke fd_tell.
RIGHT_FD_TELL
// RIGHT_FD_WRITE is the right to invoke fd_write and sock_send. If
// RIGHT_FD_SEEK is set, includes the right to invoke fd_pwrite.
RIGHT_FD_WRITE
// RIGHT_FD_ADVISE is the right to invoke fd_advise.
RIGHT_FD_ADVISE
// RIGHT_FD_ALLOCATE is the right to invoke fd_allocate.
RIGHT_FD_ALLOCATE
// RIGHT_PATH_CREATE_DIRECTORY is the right to invoke
// path_create_directory.
RIGHT_PATH_CREATE_DIRECTORY
// RIGHT_PATH_CREATE_FILE when RIGHT_PATH_OPEN is set, the right to invoke
// path_open with O_CREAT.
RIGHT_PATH_CREATE_FILE
// RIGHT_PATH_LINK_SOURCE is the right to invoke path_link with the file
// descriptor as the source directory.
RIGHT_PATH_LINK_SOURCE
// RIGHT_PATH_LINK_TARGET is the right to invoke path_link with the file
// descriptor as the target directory.
RIGHT_PATH_LINK_TARGET
// RIGHT_PATH_OPEN is the right to invoke path_open.
RIGHT_PATH_OPEN
// RIGHT_FD_READDIR is the right to invoke fd_readdir.
RIGHT_FD_READDIR
// RIGHT_PATH_READLINK is the right to invoke path_readlink.
RIGHT_PATH_READLINK
// RIGHT_PATH_RENAME_SOURCE is the right to invoke path_rename with the
// file descriptor as the source directory.
RIGHT_PATH_RENAME_SOURCE
// RIGHT_PATH_RENAME_TARGET is the right to invoke path_rename with the
// file descriptor as the target directory.
RIGHT_PATH_RENAME_TARGET
// RIGHT_PATH_FILESTAT_GET is the right to invoke path_filestat_get.
RIGHT_PATH_FILESTAT_GET
// RIGHT_PATH_FILESTAT_SET_SIZE is the right to change a file's size (there
// is no path_filestat_set_size). If RIGHT_PATH_OPEN is set, includes the
// right to invoke path_open with O_TRUNC.
RIGHT_PATH_FILESTAT_SET_SIZE
// RIGHT_PATH_FILESTAT_SET_TIMES is the right to invoke
// path_filestat_set_times.
RIGHT_PATH_FILESTAT_SET_TIMES
// RIGHT_FD_FILESTAT_GET is the right to invoke fd_filestat_get.
RIGHT_FD_FILESTAT_GET
// RIGHT_FD_FILESTAT_SET_SIZE is the right to invoke fd_filestat_set_size.
RIGHT_FD_FILESTAT_SET_SIZE
// RIGHT_FD_FILESTAT_SET_TIMES is the right to invoke
// fd_filestat_set_times.
RIGHT_FD_FILESTAT_SET_TIMES
// RIGHT_PATH_SYMLINK is the right to invoke path_symlink.
RIGHT_PATH_SYMLINK
// RIGHT_PATH_REMOVE_DIRECTORY is the right to invoke
// path_remove_directory.
RIGHT_PATH_REMOVE_DIRECTORY
// RIGHT_PATH_UNLINK_FILE is the right to invoke path_unlink_file.
RIGHT_PATH_UNLINK_FILE
// RIGHT_POLL_FD_READWRITE when RIGHT_FD_READ is set, includes the right to
// invoke poll_oneoff to subscribe to eventtype::fd_read. If RIGHT_FD_WRITE
// is set, includes the right to invoke poll_oneoff to subscribe to
// eventtype::fd_write.
RIGHT_POLL_FD_READWRITE
// RIGHT_SOCK_SHUTDOWN is the right to invoke sock_shutdown.
RIGHT_SOCK_SHUTDOWN
)
func RightsString(rights int) string {
return flagsString(rightNames[:], rights)
}
var rightNames = [...]string{
"FD_DATASYNC",
"FD_READ",
"FD_SEEK",
"FDSTAT_SET_FLAGS",
"FD_SYNC",
"FD_TELL",
"FD_WRITE",
"FD_ADVISE",
"FD_ALLOCATE",
"PATH_CREATE_DIRECTORY",
"PATH_CREATE_FILE",
"PATH_LINK_SOURCE",
"PATH_LINK_TARGET",
"PATH_OPEN",
"FD_READDIR",
"PATH_READLINK",
"PATH_RENAME_SOURCE",
"PATH_RENAME_TARGET",
"PATH_FILESTAT_GET",
"PATH_FILESTAT_SET_SIZE",
"PATH_FILESTAT_SET_TIMES",
"FD_FILESTAT_GET",
"FD_FILESTAT_SET_SIZE",
"FD_FILESTAT_SET_TIMES",
"PATH_SYMLINK",
"PATH_REMOVE_DIRECTORY",
"PATH_UNLINK_FILE",
"POLL_FD_READWRITE",
"SOCK_SHUTDOWN",
}

View File

@ -0,0 +1,3 @@
package wasip1
const SchedYieldName = "sched_yield"

View File

@ -0,0 +1,71 @@
package wasip1
import "strconv"
const (
SockAcceptName = "sock_accept"
SockRecvName = "sock_recv"
SockSendName = "sock_send"
SockShutdownName = "sock_shutdown"
)
// SD Flags indicate which channels on a socket to shut down.
// https://github.com/WebAssembly/WASI/blob/snapshot-01/phases/snapshot/docs.md#-sdflags-flagsu8
const (
// SD_RD disables further receive operations.
SD_RD uint8 = 1 << iota //nolint
// SD_WR disables further send operations.
SD_WR
)
func SdFlagsString(sdflags int) string {
return flagsString(sdflagNames[:], sdflags)
}
var sdflagNames = [...]string{
"RD",
"WR",
}
// SI Flags are flags provided to sock_send. As there are currently no flags defined, it must be set to zero.
// https://github.com/WebAssembly/WASI/blob/snapshot-01/phases/snapshot/docs.md#-siflags-u16
func SiFlagsString(siflags int) string {
if siflags == 0 {
return ""
}
return strconv.Itoa(siflags)
}
// RI Flags are flags provided to sock_recv.
// https://github.com/WebAssembly/WASI/blob/snapshot-01/phases/snapshot/docs.md#-riflags-flagsu16
const (
// RI_RECV_PEEK returns the message without removing it from the socket's receive queue
RI_RECV_PEEK uint8 = 1 << iota //nolint
// RI_RECV_WAITALL on byte-stream sockets, block until the full amount of data can be returned.
RI_RECV_WAITALL
)
func RiFlagsString(riflags int) string {
return flagsString(riflagNames[:], riflags)
}
var riflagNames = [...]string{
"RECV_PEEK",
"RECV_WAITALL",
}
// RO Flags are flags returned by sock_recv.
// https://github.com/WebAssembly/WASI/blob/snapshot-01/phases/snapshot/docs.md#-roflags-flagsu16
const (
// RO_RECV_DATA_TRUNCATED is returned by sock_recv when message data has been truncated.
RO_RECV_DATA_TRUNCATED uint8 = 1 << iota //nolint
)
func RoFlagsString(roflags int) string {
return flagsString(roflagNames[:], roflags)
}
var roflagNames = [...]string{
"RECV_DATA_TRUNCATED",
}

View File

@ -0,0 +1,26 @@
// Package wasip1 is a helper to remove package cycles re-using constants.
package wasip1
import (
"strings"
)
// InternalModuleName is not named ModuleName, to avoid a clash on dot imports.
const InternalModuleName = "wasi_snapshot_preview1"
func flagsString(names []string, f int) string {
var builder strings.Builder
first := true
for i, sf := range names {
target := 1 << i
if target&f != 0 {
if !first {
builder.WriteByte('|')
} else {
first = false
}
builder.WriteString(sf)
}
}
return builder.String()
}