...
This commit is contained in:
785
aiprompts/v_core/array/arrays.md
Normal file
785
aiprompts/v_core/array/arrays.md
Normal file
@@ -0,0 +1,785 @@
|
||||
# module arrays
|
||||
|
||||
|
||||
## Contents
|
||||
- [append](#append)
|
||||
- [binary_search](#binary_search)
|
||||
- [carray_to_varray](#carray_to_varray)
|
||||
- [chunk](#chunk)
|
||||
- [chunk_while](#chunk_while)
|
||||
- [concat](#concat)
|
||||
- [copy](#copy)
|
||||
- [distinct](#distinct)
|
||||
- [each](#each)
|
||||
- [each_indexed](#each_indexed)
|
||||
- [filter_indexed](#filter_indexed)
|
||||
- [find_first](#find_first)
|
||||
- [find_last](#find_last)
|
||||
- [flat_map](#flat_map)
|
||||
- [flat_map_indexed](#flat_map_indexed)
|
||||
- [flatten](#flatten)
|
||||
- [fold](#fold)
|
||||
- [fold_indexed](#fold_indexed)
|
||||
- [group](#group)
|
||||
- [group_by](#group_by)
|
||||
- [idx_max](#idx_max)
|
||||
- [idx_min](#idx_min)
|
||||
- [index_of_first](#index_of_first)
|
||||
- [index_of_last](#index_of_last)
|
||||
- [join_to_string](#join_to_string)
|
||||
- [lower_bound](#lower_bound)
|
||||
- [map_indexed](#map_indexed)
|
||||
- [map_of_counts](#map_of_counts)
|
||||
- [map_of_indexes](#map_of_indexes)
|
||||
- [max](#max)
|
||||
- [merge](#merge)
|
||||
- [min](#min)
|
||||
- [partition](#partition)
|
||||
- [reduce](#reduce)
|
||||
- [reduce_indexed](#reduce_indexed)
|
||||
- [reverse_iterator](#reverse_iterator)
|
||||
- [rotate_left](#rotate_left)
|
||||
- [rotate_right](#rotate_right)
|
||||
- [sum](#sum)
|
||||
- [uniq](#uniq)
|
||||
- [uniq_all_repeated](#uniq_all_repeated)
|
||||
- [uniq_only](#uniq_only)
|
||||
- [uniq_only_repeated](#uniq_only_repeated)
|
||||
- [upper_bound](#upper_bound)
|
||||
- [window](#window)
|
||||
- [ReverseIterator[T]](#ReverseIterator[T])
|
||||
- [next](#next)
|
||||
- [free](#free)
|
||||
- [ReverseIterator](#ReverseIterator)
|
||||
- [WindowAttribute](#WindowAttribute)
|
||||
|
||||
## append
|
||||
```v
|
||||
fn append[T](a []T, b []T) []T
|
||||
```
|
||||
|
||||
append the second array `b` to the first array `a`, and return the result. Note, that unlike arrays.concat, arrays.append is less flexible, but more efficient, since it does not require you to use ...a for the second parameter.
|
||||
|
||||
Example
|
||||
```v
|
||||
|
||||
arrays.append([1, 3, 5, 7], [2, 4, 6, 8]) // => [1, 3, 5, 7, 2, 4, 6, 8]
|
||||
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## binary_search
|
||||
```v
|
||||
fn binary_search[T](array []T, target T) !int
|
||||
```
|
||||
|
||||
binary_search, requires `array` to be sorted, returns index of found item or error. Binary searches on sorted lists can be faster than other array searches because at maximum the algorithm only has to traverse log N elements
|
||||
|
||||
Example
|
||||
```v
|
||||
|
||||
arrays.binary_search([1, 2, 3, 4], 4)! // => 3
|
||||
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## carray_to_varray
|
||||
```v
|
||||
fn carray_to_varray[T](c_array_data voidptr, items int) []T
|
||||
```
|
||||
|
||||
carray_to_varray copies a C byte array into a V array of type `T`. See also: `cstring_to_vstring`
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## chunk
|
||||
```v
|
||||
fn chunk[T](array []T, size int) [][]T
|
||||
```
|
||||
|
||||
chunk array into a single array of arrays where each element is the next `size` elements of the original.
|
||||
|
||||
Example
|
||||
```v
|
||||
|
||||
arrays.chunk([1, 2, 3, 4, 5, 6, 7, 8, 9], 2) // => [[1, 2], [3, 4], [5, 6], [7, 8], [9]]
|
||||
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## chunk_while
|
||||
```v
|
||||
fn chunk_while[T](a []T, predicate fn (before T, after T) bool) [][]T
|
||||
```
|
||||
|
||||
chunk_while splits the input array `a` into chunks of varying length, using the `predicate`, passing to it pairs of adjacent elements `before` and `after`. Each chunk, will contain all ajdacent elements, for which the `predicate` returned true. The chunks are split *between* the `before` and `after` elements, for which the `predicate` returned false.
|
||||
|
||||
Examples
|
||||
```v
|
||||
|
||||
assert arrays.chunk_while([0,9,2,2,3,2,7,5,9,5],fn(x int,y int)bool{return x<=y})==[[0,9],[2,2,3],[2,7],[5,9],[5]]
|
||||
|
||||
assert arrays.chunk_while('aaaabbbcca'.runes(),fn(x rune,y rune)bool{return x==y})==[[`a`,`a`,`a`,`a`],[`b`,`b`,`b`],[`c`,`c`],[`a`]]
|
||||
|
||||
assert arrays.chunk_while('aaaabbbcca'.runes(),fn(x rune,y rune)bool{return x==y}).map({it[0]:it.len})==[{`a`:4},{`b`:3},{`c`:2},{`a`:1}]
|
||||
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## concat
|
||||
```v
|
||||
fn concat[T](a []T, b ...T) []T
|
||||
```
|
||||
|
||||
concatenate an array with an arbitrary number of additional values.
|
||||
|
||||
Note: if you have two arrays, you should simply use the `<<` operator directly.
|
||||
|
||||
Examples
|
||||
```v
|
||||
|
||||
assert arrays.concat([1, 2, 3], 4, 5, 6) == [1, 2, 3, 4, 5, 6]
|
||||
|
||||
assert arrays.concat([1, 2, 3], ...[4, 5, 6]) == [1, 2, 3, 4, 5, 6]
|
||||
|
||||
mut arr := arrays.concat([1, 2, 3], 4); arr << [10,20]; assert arr == [1,2,3,4,10,20] // note: arr is mutable
|
||||
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## copy
|
||||
```v
|
||||
fn copy[T](mut dst []T, src []T) int
|
||||
```
|
||||
|
||||
copy copies the `src` array elements to the `dst` array. The number of the elements copied is the minimum of the length of both arrays. Returns the number of elements copied.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## distinct
|
||||
```v
|
||||
fn distinct[T](a []T) []T
|
||||
```
|
||||
|
||||
distinct returns all distinct elements from the given array a. The results are guaranteed to be unique, i.e. not have duplicates. See also arrays.uniq, which can be used to achieve the same goal, but needs you to first sort the array.
|
||||
|
||||
Example
|
||||
```v
|
||||
|
||||
assert arrays.distinct( [5, 5, 1, 5, 2, 1, 1, 9] ) == [1, 2, 5, 9]
|
||||
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## each
|
||||
```v
|
||||
fn each[T](a []T, cb fn (elem T))
|
||||
```
|
||||
|
||||
each calls the callback fn `cb`, for each element of the given array `a`.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## each_indexed
|
||||
```v
|
||||
fn each_indexed[T](a []T, cb fn (i int, e T))
|
||||
```
|
||||
|
||||
each_indexed calls the callback fn `cb`, for each element of the given array `a`. It passes the callback both the index of the current element, and the element itself.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## filter_indexed
|
||||
```v
|
||||
fn filter_indexed[T](array []T, predicate fn (idx int, elem T) bool) []T
|
||||
```
|
||||
|
||||
filter_indexed filters elements based on `predicate` function being invoked on each element with its index in the original array.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## find_first
|
||||
```v
|
||||
fn find_first[T](array []T, predicate fn (elem T) bool) ?T
|
||||
```
|
||||
|
||||
find_first returns the first element that matches the given predicate. Returns `none` if no match is found.
|
||||
|
||||
Example
|
||||
```v
|
||||
|
||||
arrays.find_first([1, 2, 3, 4, 5], fn (i int) bool { return i == 3 })? // => 3
|
||||
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## find_last
|
||||
```v
|
||||
fn find_last[T](array []T, predicate fn (elem T) bool) ?T
|
||||
```
|
||||
|
||||
find_last returns the last element that matches the given predicate. Returns `none` if no match is found.
|
||||
|
||||
Example
|
||||
```v
|
||||
|
||||
arrays.find_last([1, 2, 3, 4, 5], fn (i int) bool { return i == 3})? // => 3
|
||||
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## flat_map
|
||||
```v
|
||||
fn flat_map[T, R](array []T, transform fn (elem T) []R) []R
|
||||
```
|
||||
|
||||
flat_map creates a new array populated with the flattened result of calling transform function being invoked on each element of `list`.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## flat_map_indexed
|
||||
```v
|
||||
fn flat_map_indexed[T, R](array []T, transform fn (idx int, elem T) []R) []R
|
||||
```
|
||||
|
||||
flat_map_indexed creates a new array with the flattened result of calling the `transform` fn, invoked on each idx,elem pair from the original.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## flatten
|
||||
```v
|
||||
fn flatten[T](array [][]T) []T
|
||||
```
|
||||
|
||||
flatten flattens n + 1 dimensional array into n dimensional array.
|
||||
|
||||
Example
|
||||
```v
|
||||
|
||||
arrays.flatten[int]([[1, 2, 3], [4, 5]]) // => [1, 2, 3, 4, 5]
|
||||
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## fold
|
||||
```v
|
||||
fn fold[T, R](array []T, init R, fold_op fn (acc R, elem T) R) R
|
||||
```
|
||||
|
||||
fold sets `acc = init`, then successively calls `acc = fold_op(acc, elem)` for each element in `array`. returns `acc`.
|
||||
|
||||
Example
|
||||
```v
|
||||
|
||||
// Sum the length of each string in an array
|
||||
a := ['Hi', 'all']
|
||||
r := arrays.fold[string, int](a, 0,
|
||||
fn (r int, t string) int { return r + t.len })
|
||||
assert r == 5
|
||||
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## fold_indexed
|
||||
```v
|
||||
fn fold_indexed[T, R](array []T, init R, fold_op fn (idx int, acc R, elem T) R) R
|
||||
```
|
||||
|
||||
fold_indexed sets `acc = init`, then successively calls `acc = fold_op(idx, acc, elem)` for each element in `array`. returns `acc`.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## group
|
||||
```v
|
||||
fn group[T](arrs ...[]T) [][]T
|
||||
```
|
||||
|
||||
group n arrays into a single array of arrays with n elements. This function is analogous to the "zip" function of other languages. To fully interleave two arrays, follow this function with a call to `flatten`.
|
||||
|
||||
Note: An error will be generated if the type annotation is omitted.
|
||||
|
||||
Example
|
||||
```v
|
||||
|
||||
arrays.group[int]([1, 2, 3], [4, 5, 6]) // => [[1, 4], [2, 5], [3, 6]]
|
||||
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## group_by
|
||||
```v
|
||||
fn group_by[K, V](array []V, grouping_op fn (val V) K) map[K][]V
|
||||
```
|
||||
|
||||
group_by groups together elements, for which the `grouping_op` callback produced the same result.
|
||||
|
||||
Example
|
||||
```v
|
||||
|
||||
arrays.group_by[int, string](['H', 'el', 'lo'], fn (v string) int { return v.len }) // => {1: ['H'], 2: ['el', 'lo']}
|
||||
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## idx_max
|
||||
```v
|
||||
fn idx_max[T](array []T) !int
|
||||
```
|
||||
|
||||
idx_max returns the index of the maximum value in the array.
|
||||
|
||||
Example
|
||||
```v
|
||||
|
||||
arrays.idx_max([1, 2, 3, 0, 9])! // => 4
|
||||
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## idx_min
|
||||
```v
|
||||
fn idx_min[T](array []T) !int
|
||||
```
|
||||
|
||||
idx_min returns the index of the minimum value in the array.
|
||||
|
||||
Example
|
||||
```v
|
||||
|
||||
arrays.idx_min([1, 2, 3, 0, 9])! // => 3
|
||||
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## index_of_first
|
||||
```v
|
||||
fn index_of_first[T](array []T, predicate fn (idx int, elem T) bool) int
|
||||
```
|
||||
|
||||
index_of_first returns the index of the first element of `array`, for which the predicate fn returns true. If predicate does not return true for any of the elements, then index_of_first will return -1.
|
||||
|
||||
Example
|
||||
```v
|
||||
|
||||
assert arrays.index_of_first([4,5,0,7,0,9], fn(idx int, x int) bool { return x == 0 }) == 2
|
||||
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## index_of_last
|
||||
```v
|
||||
fn index_of_last[T](array []T, predicate fn (idx int, elem T) bool) int
|
||||
```
|
||||
|
||||
index_of_last returns the index of the last element of `array`, for which the predicate fn returns true. If predicate does not return true for any of the elements, then index_of_last will return -1.
|
||||
|
||||
Example
|
||||
```v
|
||||
|
||||
assert arrays.index_of_last([4,5,0,7,0,9], fn(idx int, x int) bool { return x == 0 }) == 4
|
||||
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## join_to_string
|
||||
```v
|
||||
fn join_to_string[T](array []T, separator string, transform fn (elem T) string) string
|
||||
```
|
||||
|
||||
join_to_string takes in a custom transform function and joins all elements into a string with the specified separator
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## lower_bound
|
||||
```v
|
||||
fn lower_bound[T](array []T, val T) !T
|
||||
```
|
||||
|
||||
returns the smallest element >= val, requires `array` to be sorted.
|
||||
|
||||
Example
|
||||
```v
|
||||
|
||||
arrays.lower_bound([2, 4, 6, 8], 3)! // => 4
|
||||
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## map_indexed
|
||||
```v
|
||||
fn map_indexed[T, R](array []T, transform fn (idx int, elem T) R) []R
|
||||
```
|
||||
|
||||
map_indexed creates a new array with the result of calling the `transform` fn, invoked on each idx,elem pair from the original.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## map_of_counts
|
||||
```v
|
||||
fn map_of_counts[T](array []T) map[T]int
|
||||
```
|
||||
|
||||
map_of_counts returns a map, where each key is an unique value in `array`. Each value in that map for that key, is how many times that value occurs in `array`. It can be useful for building histograms of discrete measurements.
|
||||
|
||||
Example
|
||||
```v
|
||||
|
||||
assert arrays.map_of_counts([1,2,3,4,4,2,1,4,4]) == {1: 2, 2: 2, 3: 1, 4: 4}
|
||||
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## map_of_indexes
|
||||
```v
|
||||
fn map_of_indexes[T](array []T) map[T][]int
|
||||
```
|
||||
|
||||
map_of_indexes returns a map, where each key is an unique value in `array`. Each value in that map for that key, is an array, containing the indexes in `array`, where that value has been found.
|
||||
|
||||
Example
|
||||
```v
|
||||
|
||||
assert arrays.map_of_indexes([1,2,3,4,4,2,1,4,4,999]) == {1: [0, 6], 2: [1, 5], 3: [2], 4: [3, 4, 7, 8], 999: [9]}
|
||||
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## max
|
||||
```v
|
||||
fn max[T](array []T) !T
|
||||
```
|
||||
|
||||
max returns the maximum value in the array.
|
||||
|
||||
Example
|
||||
```v
|
||||
|
||||
arrays.max([1, 2, 3, 0, 9])! // => 9
|
||||
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## merge
|
||||
```v
|
||||
fn merge[T](a []T, b []T) []T
|
||||
```
|
||||
|
||||
merge two sorted arrays (ascending) and maintain sorted order.
|
||||
|
||||
Example
|
||||
```v
|
||||
|
||||
arrays.merge([1, 3, 5, 7], [2, 4, 6, 8]) // => [1, 2, 3, 4, 5, 6, 7, 8]
|
||||
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## min
|
||||
```v
|
||||
fn min[T](array []T) !T
|
||||
```
|
||||
|
||||
min returns the minimum value in the array.
|
||||
|
||||
Example
|
||||
```v
|
||||
|
||||
arrays.min([1, 2, 3, 0, 9])! // => 0
|
||||
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## partition
|
||||
```v
|
||||
fn partition[T](array []T, predicate fn (elem T) bool) ([]T, []T)
|
||||
```
|
||||
|
||||
partition splits the original array into pair of lists. The first list contains elements for which the predicate fn returned true, while the second list contains elements for which the predicate fn returned false.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## reduce
|
||||
```v
|
||||
fn reduce[T](array []T, reduce_op fn (acc T, elem T) T) !T
|
||||
```
|
||||
|
||||
reduce sets `acc = array[0]`, then successively calls `acc = reduce_op(acc, elem)` for each remaining element in `array`. returns the accumulated value in `acc`. returns an error if the array is empty. See also: [fold](#fold).
|
||||
|
||||
Example
|
||||
```v
|
||||
|
||||
arrays.reduce([1, 2, 3, 4, 5], fn (t1 int, t2 int) int { return t1 * t2 })! // => 120
|
||||
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## reduce_indexed
|
||||
```v
|
||||
fn reduce_indexed[T](array []T, reduce_op fn (idx int, acc T, elem T) T) !T
|
||||
```
|
||||
|
||||
reduce_indexed sets `acc = array[0]`, then successively calls `acc = reduce_op(idx, acc, elem)` for each remaining element in `array`. returns the accumulated value in `acc`. returns an error if the array is empty. See also: [fold_indexed](#fold_indexed).
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## reverse_iterator
|
||||
```v
|
||||
fn reverse_iterator[T](a []T) ReverseIterator[T]
|
||||
```
|
||||
|
||||
reverse_iterator can be used to iterate over the elements in an array. i.e. you can use this syntax: `for elem in arrays.reverse_iterator(a) {` .
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## rotate_left
|
||||
```v
|
||||
fn rotate_left[T](mut array []T, mid int)
|
||||
```
|
||||
|
||||
rotate_left rotates the array in-place. It does it in such a way, that the first `mid` elements of the array, move to the end, while the last `array.len - mid` elements move to the front. After calling `rotate_left`, the element previously at index `mid` will become the first element in the array.
|
||||
|
||||
Example
|
||||
```v
|
||||
|
||||
mut x := [1,2,3,4,5,6]
|
||||
arrays.rotate_left(mut x, 2)
|
||||
println(x) // [3, 4, 5, 6, 1, 2]
|
||||
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## rotate_right
|
||||
```v
|
||||
fn rotate_right[T](mut array []T, k int)
|
||||
```
|
||||
|
||||
rotate_right rotates the array in-place. It does it in such a way, that the first `array.len - k` elements of the array, move to the end, while the last `k` elements move to the front. After calling `rotate_right`, the element previously at index `array.len - k` will become the first element in the array.
|
||||
|
||||
Example
|
||||
```v
|
||||
|
||||
mut x := [1,2,3,4,5,6]
|
||||
arrays.rotate_right(mut x, 2)
|
||||
println(x) // [5, 6, 1, 2, 3, 4]
|
||||
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## sum
|
||||
```v
|
||||
fn sum[T](array []T) !T
|
||||
```
|
||||
|
||||
sum up array, return an error, when the array has no elements.
|
||||
|
||||
Example
|
||||
```v
|
||||
|
||||
arrays.sum([1, 2, 3, 4, 5])! // => 15
|
||||
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## uniq
|
||||
```v
|
||||
fn uniq[T](a []T) []T
|
||||
```
|
||||
|
||||
uniq filters the adjacent matching elements from the given array. All adjacent matching elements, are merged to their first occurrence, so the output will have no repeating elements.
|
||||
|
||||
Note: `uniq` does not detect repeats, unless they are adjacent. You may want to call a.sorted() on your array, before passing the result to arrays.uniq(). See also arrays.distinct, which is essentially arrays.uniq(a.sorted()) .
|
||||
|
||||
Examples
|
||||
```v
|
||||
|
||||
assert arrays.uniq( []int{} ) == []
|
||||
|
||||
assert arrays.uniq( [1, 1] ) == [1]
|
||||
|
||||
assert arrays.uniq( [2, 1] ) == [2, 1]
|
||||
|
||||
assert arrays.uniq( [5, 5, 1, 5, 2, 1, 1, 9] ) == [5, 1, 5, 2, 1, 9]
|
||||
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## uniq_all_repeated
|
||||
```v
|
||||
fn uniq_all_repeated[T](a []T) []T
|
||||
```
|
||||
|
||||
uniq_all_repeated produces all adjacent matching elements from the given array. Unique elements, with no duplicates are removed. The output will contain all the duplicated elements, repeated just like they were in the original.
|
||||
|
||||
Note: `uniq_all_repeated` does not detect repeats, unless they are adjacent. You may want to call a.sorted() on your array, before passing the result to arrays.uniq_all_repeated().
|
||||
|
||||
Examples
|
||||
```v
|
||||
|
||||
assert arrays.uniq_all_repeated( []int{} ) == []
|
||||
|
||||
assert arrays.uniq_all_repeated( [1, 5] ) == []
|
||||
|
||||
assert arrays.uniq_all_repeated( [5, 5] ) == [5,5]
|
||||
|
||||
assert arrays.uniq_all_repeated( [5, 5, 1, 5, 2, 1, 1, 9] ) == [5, 5, 1, 1]
|
||||
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## uniq_only
|
||||
```v
|
||||
fn uniq_only[T](a []T) []T
|
||||
```
|
||||
|
||||
uniq_only filters the adjacent matching elements from the given array. All adjacent matching elements, are removed. The output will contain only the elements that *did not have* any adjacent matches.
|
||||
|
||||
Note: `uniq_only` does not detect repeats, unless they are adjacent. You may want to call a.sorted() on your array, before passing the result to arrays.uniq_only().
|
||||
|
||||
Examples
|
||||
```v
|
||||
|
||||
assert arrays.uniq_only( []int{} ) == []
|
||||
|
||||
assert arrays.uniq_only( [1, 1] ) == []
|
||||
|
||||
assert arrays.uniq_only( [2, 1] ) == [2, 1]
|
||||
|
||||
assert arrays.uniq_only( [1, 5, 5, 1, 5, 2, 1, 1, 9] ) == [1, 1, 5, 2, 9]
|
||||
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## uniq_only_repeated
|
||||
```v
|
||||
fn uniq_only_repeated[T](a []T) []T
|
||||
```
|
||||
|
||||
uniq_only_repeated produces the adjacent matching elements from the given array. Unique elements, with no duplicates are removed. Adjacent matching elements, are reduced to just 1 element per repeat group.
|
||||
|
||||
Note: `uniq_only_repeated` does not detect repeats, unless they are adjacent. You may want to call a.sorted() on your array, before passing the result to arrays.uniq_only_repeated().
|
||||
|
||||
Examples
|
||||
```v
|
||||
|
||||
assert arrays.uniq_only_repeated( []int{} ) == []
|
||||
|
||||
assert arrays.uniq_only_repeated( [1, 5] ) == []
|
||||
|
||||
assert arrays.uniq_only_repeated( [5, 5] ) == [5]
|
||||
|
||||
assert arrays.uniq_only_repeated( [5, 5, 1, 5, 2, 1, 1, 9] ) == [5, 1]
|
||||
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## upper_bound
|
||||
```v
|
||||
fn upper_bound[T](array []T, val T) !T
|
||||
```
|
||||
|
||||
returns the largest element <= val, requires `array` to be sorted.
|
||||
|
||||
Example
|
||||
```v
|
||||
|
||||
arrays.upper_bound([2, 4, 6, 8], 3)! // => 2
|
||||
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## window
|
||||
```v
|
||||
fn window[T](array []T, attr WindowAttribute) [][]T
|
||||
```
|
||||
|
||||
get snapshots of the window of the given size sliding along array with the given step, where each snapshot is an array.- `size` - snapshot size
|
||||
- `step` - gap size between each snapshot, default is 1.
|
||||
|
||||
|
||||
|
||||
Examples
|
||||
```v
|
||||
|
||||
arrays.window([1, 2, 3, 4], size: 2) // => [[1, 2], [2, 3], [3, 4]]
|
||||
|
||||
arrays.window([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], size: 3, step: 2) // => [[1, 2, 3], [3, 4, 5], [5, 6, 7], [7, 8, 9]]
|
||||
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## ReverseIterator[T]
|
||||
## next
|
||||
```v
|
||||
fn (mut iter ReverseIterator[T]) next() ?&T
|
||||
```
|
||||
|
||||
next is the required method, to implement an iterator in V. It returns none when the iteration should stop. Otherwise it returns the current element of the array.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## free
|
||||
```v
|
||||
fn (iter &ReverseIterator[T]) free()
|
||||
```
|
||||
|
||||
free frees the iterator resources.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## ReverseIterator
|
||||
```v
|
||||
struct ReverseIterator[T] {
|
||||
mut:
|
||||
a []T
|
||||
i int
|
||||
}
|
||||
```
|
||||
|
||||
ReverseIterator provides a convenient way to iterate in reverse over all elements of an array without allocations. I.e. it allows you to use this syntax: `for elem in arrays.reverse_iterator(a) {` .
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## WindowAttribute
|
||||
```v
|
||||
struct WindowAttribute {
|
||||
pub:
|
||||
size int
|
||||
step int = 1
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:19:06
|
||||
76
aiprompts/v_core/array/diff.md
Normal file
76
aiprompts/v_core/array/diff.md
Normal file
@@ -0,0 +1,76 @@
|
||||
# module diff
|
||||
|
||||
|
||||
## Contents
|
||||
- [diff](#diff)
|
||||
- [DiffContext[T]](#DiffContext[T])
|
||||
- [generate_patch](#generate_patch)
|
||||
- [DiffChange](#DiffChange)
|
||||
- [DiffContext](#DiffContext)
|
||||
- [DiffGenStrParam](#DiffGenStrParam)
|
||||
|
||||
## diff
|
||||
```v
|
||||
fn diff[T](a []T, b []T) &DiffContext[T]
|
||||
```
|
||||
|
||||
diff returns the difference of two arrays.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## DiffContext[T]
|
||||
## generate_patch
|
||||
```v
|
||||
fn (mut c DiffContext[T]) generate_patch(param DiffGenStrParam) string
|
||||
```
|
||||
|
||||
generate_patch generate a diff string of two arrays.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## DiffChange
|
||||
```v
|
||||
struct DiffChange {
|
||||
pub mut:
|
||||
a int // position in input a []T
|
||||
b int // position in input b []T
|
||||
del int // delete Del elements from input a
|
||||
ins int // insert Ins elements from input b
|
||||
}
|
||||
```
|
||||
|
||||
DiffChange contains one or more deletions or inserts at one position in two arrays.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## DiffContext
|
||||
```v
|
||||
struct DiffContext[T] {
|
||||
mut:
|
||||
a []T
|
||||
b []T
|
||||
flags []DiffContextFlag
|
||||
max int
|
||||
// forward and reverse d-path endpoint x components
|
||||
forward []int
|
||||
reverse []int
|
||||
pub mut:
|
||||
changes []DiffChange
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## DiffGenStrParam
|
||||
```v
|
||||
struct DiffGenStrParam {
|
||||
pub mut:
|
||||
colorful bool
|
||||
unified int = 3 // how many context lines before/after diff block
|
||||
block_header bool // output `@@ -3,4 +3,5 @@` or not
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:19:06
|
||||
53
aiprompts/v_core/array/parallel.md
Normal file
53
aiprompts/v_core/array/parallel.md
Normal file
@@ -0,0 +1,53 @@
|
||||
# module parallel
|
||||
|
||||
|
||||
## Contents
|
||||
- [amap](#amap)
|
||||
- [run](#run)
|
||||
- [Params](#Params)
|
||||
|
||||
## amap
|
||||
```v
|
||||
fn amap[T, R](input []T, worker fn (T) R, opt Params) []R
|
||||
```
|
||||
|
||||
amap lets the user run an array of input with a user provided function in parallel. It limits the number of worker threads to max number of cpus. The worker function can return a value. The returning array maintains the input order. Any error handling should have happened within the worker function.
|
||||
|
||||
Example
|
||||
```v
|
||||
|
||||
squares := parallel.amap([1, 2, 3, 4, 5], |i| i * i); assert squares == [1, 4, 9, 16, 25]
|
||||
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## run
|
||||
```v
|
||||
fn run[T](input []T, worker fn (T), opt Params)
|
||||
```
|
||||
|
||||
run lets the user run an array of input with a user provided function in parallel. It limits the number of worker threads to min(num_workers, num_cpu). The function aborts if an error is encountered.
|
||||
|
||||
Example
|
||||
```v
|
||||
|
||||
parallel.run([1, 2, 3, 4, 5], |i| println(i))
|
||||
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Params
|
||||
```v
|
||||
struct Params {
|
||||
pub mut:
|
||||
workers int // 0 by default, so that VJOBS will be used, through runtime.nr_jobs()
|
||||
}
|
||||
```
|
||||
|
||||
Params contains the optional parameters that can be passed to `run` and `amap`.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:19:06
|
||||
321
aiprompts/v_core/benchmark/benchmark.md
Normal file
321
aiprompts/v_core/benchmark/benchmark.md
Normal file
@@ -0,0 +1,321 @@
|
||||
# module benchmark
|
||||
|
||||
|
||||
## Contents
|
||||
- [Constants](#Constants)
|
||||
- [new_benchmark](#new_benchmark)
|
||||
- [new_benchmark_no_cstep](#new_benchmark_no_cstep)
|
||||
- [new_benchmark_pointer](#new_benchmark_pointer)
|
||||
- [start](#start)
|
||||
- [Benchmark](#Benchmark)
|
||||
- [set_total_expected_steps](#set_total_expected_steps)
|
||||
- [stop](#stop)
|
||||
- [step](#step)
|
||||
- [step_restart](#step_restart)
|
||||
- [fail](#fail)
|
||||
- [ok](#ok)
|
||||
- [skip](#skip)
|
||||
- [fail_many](#fail_many)
|
||||
- [ok_many](#ok_many)
|
||||
- [neither_fail_nor_ok](#neither_fail_nor_ok)
|
||||
- [measure](#measure)
|
||||
- [record_measure](#record_measure)
|
||||
- [step_message_with_label_and_duration](#step_message_with_label_and_duration)
|
||||
- [step_message_with_label](#step_message_with_label)
|
||||
- [step_message](#step_message)
|
||||
- [step_message_ok](#step_message_ok)
|
||||
- [step_message_fail](#step_message_fail)
|
||||
- [step_message_skip](#step_message_skip)
|
||||
- [total_message](#total_message)
|
||||
- [all_recorded_measures](#all_recorded_measures)
|
||||
- [total_duration](#total_duration)
|
||||
- [MessageOptions](#MessageOptions)
|
||||
|
||||
## Constants
|
||||
```v
|
||||
const b_ok = term.ok_message('OK ')
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const b_fail = term.fail_message('FAIL')
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const b_skip = term.warn_message('SKIP')
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const b_spent = term.ok_message('SPENT')
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new_benchmark
|
||||
```v
|
||||
fn new_benchmark() Benchmark
|
||||
```
|
||||
|
||||
new_benchmark returns a `Benchmark` instance on the stack.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new_benchmark_no_cstep
|
||||
```v
|
||||
fn new_benchmark_no_cstep() Benchmark
|
||||
```
|
||||
|
||||
new_benchmark_no_cstep returns a new `Benchmark` instance with step counting disabled.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new_benchmark_pointer
|
||||
```v
|
||||
fn new_benchmark_pointer() &Benchmark
|
||||
```
|
||||
|
||||
new_benchmark_pointer returns a new `Benchmark` instance allocated on the heap. This is useful for long-lived use of `Benchmark` instances.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## start
|
||||
```v
|
||||
fn start() Benchmark
|
||||
```
|
||||
|
||||
start returns a new, running, instance of `Benchmark`. This is a shorthand for calling `new_benchmark().step()`.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Benchmark
|
||||
```v
|
||||
struct Benchmark {
|
||||
pub mut:
|
||||
bench_timer time.StopWatch
|
||||
verbose bool
|
||||
no_cstep bool
|
||||
step_timer time.StopWatch
|
||||
ntotal int
|
||||
nok int
|
||||
nfail int
|
||||
nskip int
|
||||
nexpected_steps int
|
||||
njobs int
|
||||
cstep int
|
||||
bok string
|
||||
bfail string
|
||||
measured_steps []string
|
||||
step_data map[string][]f64
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## set_total_expected_steps
|
||||
```v
|
||||
fn (mut b Benchmark) set_total_expected_steps(n int)
|
||||
```
|
||||
|
||||
set_total_expected_steps sets the total amount of steps the benchmark is expected to take.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## stop
|
||||
```v
|
||||
fn (mut b Benchmark) stop()
|
||||
```
|
||||
|
||||
stop stops the internal benchmark timer.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## step
|
||||
```v
|
||||
fn (mut b Benchmark) step()
|
||||
```
|
||||
|
||||
step increases the step count by 1 and restarts the internal timer.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## step_restart
|
||||
```v
|
||||
fn (mut b Benchmark) step_restart()
|
||||
```
|
||||
|
||||
step_restart will restart the internal step timer. Note that the step count will *stay the same*. This method is useful, when you want to do some optional preparation after you have called .step(), so that the time for that optional preparation will *not* be added to the duration of the step.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## fail
|
||||
```v
|
||||
fn (mut b Benchmark) fail()
|
||||
```
|
||||
|
||||
fail increases the fail count by 1 and stops the internal timer.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## ok
|
||||
```v
|
||||
fn (mut b Benchmark) ok()
|
||||
```
|
||||
|
||||
ok increases the ok count by 1 and stops the internal timer.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## skip
|
||||
```v
|
||||
fn (mut b Benchmark) skip()
|
||||
```
|
||||
|
||||
skip increases the skip count by 1 and stops the internal timer.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## fail_many
|
||||
```v
|
||||
fn (mut b Benchmark) fail_many(n int)
|
||||
```
|
||||
|
||||
fail_many increases the fail count by `n` and stops the internal timer.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## ok_many
|
||||
```v
|
||||
fn (mut b Benchmark) ok_many(n int)
|
||||
```
|
||||
|
||||
ok_many increases the ok count by `n` and stops the internal timer.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## neither_fail_nor_ok
|
||||
```v
|
||||
fn (mut b Benchmark) neither_fail_nor_ok()
|
||||
```
|
||||
|
||||
neither_fail_nor_ok stops the internal timer.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## measure
|
||||
```v
|
||||
fn (mut b Benchmark) measure(label string) i64
|
||||
```
|
||||
|
||||
measure prints the current time spent doing `label`, since the benchmark was started, or since its last call.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## record_measure
|
||||
```v
|
||||
fn (mut b Benchmark) record_measure(label string) i64
|
||||
```
|
||||
|
||||
record_measure stores the current time doing `label`, since the benchmark was started, or since the last call to `b.record_measure`. It is similar to `b.measure`, but unlike it, will not print the measurement immediately, just record it for later. You can call `b.all_recorded_measures` to retrieve all measures stored by `b.record_measure` calls.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## step_message_with_label_and_duration
|
||||
```v
|
||||
fn (b &Benchmark) step_message_with_label_and_duration(label string, msg string, sduration time.Duration,
|
||||
opts MessageOptions) string
|
||||
```
|
||||
|
||||
step_message_with_label_and_duration returns a string describing the current step.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## step_message_with_label
|
||||
```v
|
||||
fn (b &Benchmark) step_message_with_label(label string, msg string, opts MessageOptions) string
|
||||
```
|
||||
|
||||
step_message_with_label returns a string describing the current step using current time as duration.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## step_message
|
||||
```v
|
||||
fn (b &Benchmark) step_message(msg string, opts MessageOptions) string
|
||||
```
|
||||
|
||||
step_message returns a string describing the current step.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## step_message_ok
|
||||
```v
|
||||
fn (b &Benchmark) step_message_ok(msg string, opts MessageOptions) string
|
||||
```
|
||||
|
||||
step_message_ok returns a string describing the current step with an standard "OK" label.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## step_message_fail
|
||||
```v
|
||||
fn (b &Benchmark) step_message_fail(msg string, opts MessageOptions) string
|
||||
```
|
||||
|
||||
step_message_fail returns a string describing the current step with an standard "FAIL" label.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## step_message_skip
|
||||
```v
|
||||
fn (b &Benchmark) step_message_skip(msg string, opts MessageOptions) string
|
||||
```
|
||||
|
||||
step_message_skip returns a string describing the current step with an standard "SKIP" label.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## total_message
|
||||
```v
|
||||
fn (b &Benchmark) total_message(msg string) string
|
||||
```
|
||||
|
||||
total_message returns a string with total summary of the benchmark run.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## all_recorded_measures
|
||||
```v
|
||||
fn (b &Benchmark) all_recorded_measures() string
|
||||
```
|
||||
|
||||
all_recorded_measures returns a string, that contains all the recorded measure messages, done by individual calls to `b.record_measure`.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## total_duration
|
||||
```v
|
||||
fn (b &Benchmark) total_duration() i64
|
||||
```
|
||||
|
||||
total_duration returns the duration in ms.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## MessageOptions
|
||||
```v
|
||||
struct MessageOptions {
|
||||
pub:
|
||||
preparation time.Duration // the duration of the preparation time for the step
|
||||
}
|
||||
```
|
||||
|
||||
MessageOptions allows passing an optional preparation time too to each label method. If it is set, the preparation time (compile time) will be shown before the measured runtime.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:21:08
|
||||
@@ -0,0 +1,22 @@
|
||||
# module builtin.linux_bare.old..checks.forkedtest
|
||||
|
||||
|
||||
## Contents
|
||||
- [normal_run](#normal_run)
|
||||
- [run](#run)
|
||||
|
||||
## normal_run
|
||||
```v
|
||||
fn normal_run(op fn (), label string) int
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## run
|
||||
```v
|
||||
fn run(op fn (), label string, code Wi_si_code, status int) int
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:18:39
|
||||
5417
aiprompts/v_core/builtin/builtin.md
Normal file
5417
aiprompts/v_core/builtin/builtin.md
Normal file
File diff suppressed because it is too large
Load Diff
220
aiprompts/v_core/builtin/closure.md
Normal file
220
aiprompts/v_core/builtin/closure.md
Normal file
@@ -0,0 +1,220 @@
|
||||
# module closure
|
||||
|
||||
|
||||
## Contents
|
||||
- [Constants](#Constants)
|
||||
- [C.pthread_mutex_t](#C.pthread_mutex_t)
|
||||
|
||||
## Constants
|
||||
```v
|
||||
const closure_thunk = $if amd64 {
|
||||
[
|
||||
u8(0xF3),
|
||||
0x44,
|
||||
0x0F,
|
||||
0x7E,
|
||||
0x3D,
|
||||
0xF7,
|
||||
0xBF,
|
||||
0xFF,
|
||||
0xFF, // movq xmm15, QWORD PTR [rip - userdata]
|
||||
0xFF,
|
||||
0x25,
|
||||
0xF9,
|
||||
0xBF,
|
||||
0xFF,
|
||||
0xFF, // jmp QWORD PTR [rip - fn]
|
||||
]
|
||||
} $else $if i386 {
|
||||
[
|
||||
u8(0xe8),
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00, // call here
|
||||
// here:
|
||||
0x59, // pop ecx
|
||||
0x66,
|
||||
0x0F,
|
||||
0x6E,
|
||||
0xF9, // movd xmm7, ecx
|
||||
0xff,
|
||||
0xA1,
|
||||
0xff,
|
||||
0xbf,
|
||||
0xff,
|
||||
0xff, // jmp DWORD PTR [ecx - 0x4001] # <fn>
|
||||
]
|
||||
} $else $if arm64 {
|
||||
[
|
||||
u8(0x11),
|
||||
0x00,
|
||||
0xFE,
|
||||
0x5C, // ldr d17, userdata
|
||||
0x30,
|
||||
0x00,
|
||||
0xFE,
|
||||
0x58, // ldr x16, fn
|
||||
0x00,
|
||||
0x02,
|
||||
0x1F,
|
||||
0xD6, // br x16
|
||||
]
|
||||
} $else $if arm32 {
|
||||
[
|
||||
u8(0x04),
|
||||
0xC0,
|
||||
0x4F,
|
||||
0xE2, // adr ip, here
|
||||
// here:
|
||||
0x01,
|
||||
0xC9,
|
||||
0x4C,
|
||||
0xE2, // sub ip, ip, #0x4000
|
||||
0x90,
|
||||
0xCA,
|
||||
0x07,
|
||||
0xEE, // vmov s15, ip
|
||||
0x00,
|
||||
0xC0,
|
||||
0x9C,
|
||||
0xE5, // ldr ip, [ip, 0]
|
||||
0x1C,
|
||||
0xFF,
|
||||
0x2F,
|
||||
0xE1, // bx ip
|
||||
]
|
||||
} $else $if rv64 {
|
||||
[
|
||||
u8(0x97),
|
||||
0xCF,
|
||||
0xFF,
|
||||
0xFF, // auipc t6, 0xffffc
|
||||
0x03,
|
||||
0xBF,
|
||||
0x8F,
|
||||
0x00, // ld t5, 8(t6)
|
||||
0x07,
|
||||
0xB3,
|
||||
0x0F,
|
||||
0x00, // fld ft6, 0(t6)
|
||||
0x67,
|
||||
0x00,
|
||||
0x0F,
|
||||
0x00, // jr t5
|
||||
]
|
||||
} $else $if rv32 {
|
||||
[
|
||||
u8(0x97),
|
||||
0xCF,
|
||||
0xFF,
|
||||
0xFF, // auipc t6, 0xffffc
|
||||
0x03,
|
||||
0xAF,
|
||||
0x4F,
|
||||
0x00, // lw t5, 4(t6)
|
||||
0x07,
|
||||
0xAB,
|
||||
0x0F,
|
||||
0x00, // flw fs6, 0(t6)
|
||||
0x67,
|
||||
0x00,
|
||||
0x0F,
|
||||
0x00, // jr t5
|
||||
]
|
||||
} $else $if s390x {
|
||||
[
|
||||
u8(0xC0),
|
||||
0x70,
|
||||
0xFF,
|
||||
0xFF,
|
||||
0xE0,
|
||||
0x00, // larl %r7, -16384
|
||||
0x68,
|
||||
0xF0,
|
||||
0x70,
|
||||
0x00, // ld %f15, 0(%r7)
|
||||
0xE3,
|
||||
0x70,
|
||||
0x70,
|
||||
0x08,
|
||||
0x00,
|
||||
0x04, // lg %r7, 8(%r7)
|
||||
0x07,
|
||||
0xF7, // br %r7
|
||||
]
|
||||
} $else $if ppc64le {
|
||||
[
|
||||
u8(0xa6),
|
||||
0x02,
|
||||
0x08,
|
||||
0x7c, // mflr %r0
|
||||
0x05,
|
||||
0x00,
|
||||
0x00,
|
||||
0x48, // bl here
|
||||
0xa6,
|
||||
0x02,
|
||||
0xc8,
|
||||
0x7d, // here: mflr %r14
|
||||
0xf8,
|
||||
0xbf,
|
||||
0xce,
|
||||
0x39, // addi %r14, %r14, -16392
|
||||
0x00,
|
||||
0x00,
|
||||
0xce,
|
||||
0xc9, // lfd %f14, 0(%r14)
|
||||
0x08,
|
||||
0x00,
|
||||
0xce,
|
||||
0xe9, // ld %r14, 8(%r14)
|
||||
0xa6,
|
||||
0x03,
|
||||
0x08,
|
||||
0x7c, // mtlr %r0
|
||||
0xa6,
|
||||
0x03,
|
||||
0xc9,
|
||||
0x7d, // mtctr %r14
|
||||
0x20,
|
||||
0x04,
|
||||
0x80,
|
||||
0x4e, // bctr
|
||||
]
|
||||
} $else $if loongarch64 {
|
||||
[
|
||||
u8(0x92),
|
||||
0xFF,
|
||||
0xFF,
|
||||
0x1D, // pcaddu12i t6, -4
|
||||
0x48,
|
||||
0x02,
|
||||
0x80,
|
||||
0x2B, // fld.d f8, t6, 0
|
||||
0x51,
|
||||
0x22,
|
||||
0xC0,
|
||||
0x28, // ld.d t5, t6, 8
|
||||
0x20,
|
||||
0x02,
|
||||
0x00,
|
||||
0x4C, // jr t5
|
||||
]
|
||||
} $else {
|
||||
[]u8{}
|
||||
}
|
||||
```
|
||||
|
||||
refer to https://godbolt.org/z/r7P3EYv6c for a complete assembly vfmt off
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## C.pthread_mutex_t
|
||||
```v
|
||||
struct C.pthread_mutex_t {}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:18:39
|
||||
135
aiprompts/v_core/builtin/wchar.md
Normal file
135
aiprompts/v_core/builtin/wchar.md
Normal file
@@ -0,0 +1,135 @@
|
||||
# module wchar
|
||||
|
||||
|
||||
## Contents
|
||||
- [Constants](#Constants)
|
||||
- [from_rune](#from_rune)
|
||||
- [from_string](#from_string)
|
||||
- [length_in_bytes](#length_in_bytes)
|
||||
- [length_in_characters](#length_in_characters)
|
||||
- [to_string](#to_string)
|
||||
- [to_string2](#to_string2)
|
||||
- [Character](#Character)
|
||||
- [str](#str)
|
||||
- [==](#==)
|
||||
- [to_rune](#to_rune)
|
||||
- [C.wchar_t](#C.wchar_t)
|
||||
|
||||
## Constants
|
||||
```v
|
||||
const zero = from_rune(0)
|
||||
```
|
||||
|
||||
zero is a Character, that in C L"" strings represents the string end character (terminator).
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## from_rune
|
||||
```v
|
||||
fn from_rune(r rune) Character
|
||||
```
|
||||
|
||||
from_rune creates a Character, given a V rune
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## from_string
|
||||
```v
|
||||
fn from_string(s string) &Character
|
||||
```
|
||||
|
||||
from_string converts the V string (in UTF-8 encoding), into a newly allocated platform specific buffer of C.wchar_t . The conversion is done by processing each rune of the input string 1 by 1.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## length_in_bytes
|
||||
```v
|
||||
fn length_in_bytes(p voidptr) int
|
||||
```
|
||||
|
||||
length_in_bytes returns the length of the given wchar_t* wide C style L"" string in bytes. Note that the size of wchar_t is different on the different platforms, thus the length in bytes for the same data converted from UTF-8 to a &Character buffer, will be different as well. i.e. unsafe { wchar.length_in_bytes(wchar.from_string('abc')) } will be 12 on unix, but 6 on windows.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## length_in_characters
|
||||
```v
|
||||
fn length_in_characters(p voidptr) int
|
||||
```
|
||||
|
||||
See also `length_in_bytes` .
|
||||
|
||||
Example
|
||||
```v
|
||||
|
||||
assert unsafe { wchar.length_in_characters(wchar.from_string('abc')) } == 3
|
||||
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## to_string
|
||||
```v
|
||||
fn to_string(p voidptr) string
|
||||
```
|
||||
|
||||
to_string creates a V string, encoded in UTF-8, given a wchar_t* wide C style L"" string. It relies that the string has a 0 terminator at its end, to determine the string's length. Note, that the size of wchar_t is platform-dependent, and is *2 bytes* on windows, while it is *4 bytes* on most everything else. Unless you are interfacing with a C library, that does specifically use `wchar_t`, consider using `string_from_wide` instead, which will always assume that the input data is in an UTF-16 encoding, no matter what the platform is.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## to_string2
|
||||
```v
|
||||
fn to_string2(p voidptr, len int) string
|
||||
```
|
||||
|
||||
to_string2 creates a V string, encoded in UTF-8, given a `C.wchar_t*` wide C style L"" string. Note, that the size of `C.wchar_t` is platform-dependent, and is *2 bytes* on windows, while *4* on most everything else. Unless you are interfacing with a C library, that does specifically use wchar_t, consider using string_from_wide2 instead, which will always assume that the input data is in an UTF-16 encoding, no matter what the platform is.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Character
|
||||
```v
|
||||
type Character = C.wchar_t
|
||||
```
|
||||
|
||||
Character is a type, that eases working with the platform dependent C.wchar_t type.
|
||||
|
||||
Note: the size of C.wchar_t varies between platforms, it is 2 bytes on windows, and usually 4 bytes elsewhere.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## str
|
||||
```v
|
||||
fn (a Character) str() string
|
||||
```
|
||||
|
||||
return a string representation of the given Character
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## ==
|
||||
```v
|
||||
fn (a Character) == (b Character) bool
|
||||
```
|
||||
|
||||
== is an equality operator, to ease comparing Characters
|
||||
|
||||
Todo: the default == operator, that V generates, does not work for C.wchar_t .
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## to_rune
|
||||
```v
|
||||
fn (c Character) to_rune() rune
|
||||
```
|
||||
|
||||
to_rune creates a V rune, given a Character
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## C.wchar_t
|
||||
```v
|
||||
struct C.wchar_t {}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:18:39
|
||||
80
aiprompts/v_core/crypto/aes.md
Normal file
80
aiprompts/v_core/crypto/aes.md
Normal file
@@ -0,0 +1,80 @@
|
||||
# module aes
|
||||
|
||||
|
||||
## Contents
|
||||
- [Constants](#Constants)
|
||||
- [new_cipher](#new_cipher)
|
||||
- [AesCipher](#AesCipher)
|
||||
- [free](#free)
|
||||
- [block_size](#block_size)
|
||||
- [encrypt](#encrypt)
|
||||
- [decrypt](#decrypt)
|
||||
|
||||
## Constants
|
||||
```v
|
||||
const block_size = 16
|
||||
```
|
||||
|
||||
The AES block size in bytes.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new_cipher
|
||||
```v
|
||||
fn new_cipher(key []u8) cipher.Block
|
||||
```
|
||||
|
||||
new_cipher creates and returns a new [[AesCipher](#AesCipher)]. The key argument should be the AES key, either 16, 24, or 32 bytes to select AES-128, AES-192, or AES-256.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## AesCipher
|
||||
## free
|
||||
```v
|
||||
fn (mut c AesCipher) free()
|
||||
```
|
||||
|
||||
free the resources taken by the AesCipher `c`
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## block_size
|
||||
```v
|
||||
fn (c &AesCipher) block_size() int
|
||||
```
|
||||
|
||||
block_size returns the block size of the checksum in bytes.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## encrypt
|
||||
```v
|
||||
fn (c &AesCipher) encrypt(mut dst []u8, src []u8)
|
||||
```
|
||||
|
||||
encrypt encrypts the first block of data in `src` to `dst`.
|
||||
|
||||
Note: `dst` and `src` are both mutable for performance reasons.
|
||||
|
||||
Note: `dst` and `src` must both be pre-allocated to the correct length.
|
||||
|
||||
Note: `dst` and `src` may be the same (overlapping entirely).
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## decrypt
|
||||
```v
|
||||
fn (c &AesCipher) decrypt(mut dst []u8, src []u8)
|
||||
```
|
||||
|
||||
decrypt decrypts the first block of data in `src` to `dst`.
|
||||
|
||||
Note: `dst` and `src` are both mutable for performance reasons.
|
||||
|
||||
Note: `dst` and `src` must both be pre-allocated to the correct length.
|
||||
|
||||
Note: `dst` and `src` may be the same (overlapping entirely).
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:18:17
|
||||
123
aiprompts/v_core/crypto/bcrypt.md
Normal file
123
aiprompts/v_core/crypto/bcrypt.md
Normal file
@@ -0,0 +1,123 @@
|
||||
# module bcrypt
|
||||
|
||||
|
||||
## Contents
|
||||
- [Constants](#Constants)
|
||||
- [compare_hash_and_password](#compare_hash_and_password)
|
||||
- [generate_from_password](#generate_from_password)
|
||||
- [generate_salt](#generate_salt)
|
||||
- [Hashed](#Hashed)
|
||||
- [free](#free)
|
||||
|
||||
## Constants
|
||||
```v
|
||||
const min_cost = 4
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const max_cost = 31
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const default_cost = 10
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const salt_length = 16
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const max_crypted_hash_size = 23
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const encoded_salt_size = 22
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const encoded_hash_size = 31
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const min_hash_size = 59
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const major_version = '2'
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const minor_version = 'a'
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## compare_hash_and_password
|
||||
```v
|
||||
fn compare_hash_and_password(password []u8, hashed_password []u8) !
|
||||
```
|
||||
|
||||
compare_hash_and_password compares a bcrypt hashed password with its possible hashed version.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## generate_from_password
|
||||
```v
|
||||
fn generate_from_password(password []u8, cost int) !string
|
||||
```
|
||||
|
||||
generate_from_password return a bcrypt string from Hashed struct.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## generate_salt
|
||||
```v
|
||||
fn generate_salt() string
|
||||
```
|
||||
|
||||
generate_salt generate a string to be treated as a salt.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Hashed
|
||||
```v
|
||||
struct Hashed {
|
||||
mut:
|
||||
hash []u8
|
||||
salt []u8
|
||||
cost int
|
||||
major string
|
||||
minor string
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## free
|
||||
```v
|
||||
fn (mut h Hashed) free()
|
||||
```
|
||||
|
||||
free the resources taken by the Hashed `h`
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:18:17
|
||||
254
aiprompts/v_core/crypto/blake2b.md
Normal file
254
aiprompts/v_core/crypto/blake2b.md
Normal file
@@ -0,0 +1,254 @@
|
||||
# module blake2b
|
||||
|
||||
|
||||
## Contents
|
||||
- [Constants](#Constants)
|
||||
- [new160](#new160)
|
||||
- [new256](#new256)
|
||||
- [new384](#new384)
|
||||
- [new512](#new512)
|
||||
- [new_digest](#new_digest)
|
||||
- [new_pmac160](#new_pmac160)
|
||||
- [new_pmac256](#new_pmac256)
|
||||
- [new_pmac384](#new_pmac384)
|
||||
- [new_pmac512](#new_pmac512)
|
||||
- [pmac160](#pmac160)
|
||||
- [pmac256](#pmac256)
|
||||
- [pmac384](#pmac384)
|
||||
- [pmac512](#pmac512)
|
||||
- [sum160](#sum160)
|
||||
- [sum256](#sum256)
|
||||
- [sum384](#sum384)
|
||||
- [sum512](#sum512)
|
||||
- [Digest](#Digest)
|
||||
- [str](#str)
|
||||
- [write](#write)
|
||||
- [checksum](#checksum)
|
||||
|
||||
## Constants
|
||||
```v
|
||||
const size160 = 20
|
||||
```
|
||||
|
||||
size160 is the size, in bytes, of a Blake2b 160 checksum.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const size256 = 32
|
||||
```
|
||||
|
||||
size256 is the size, in bytes, of a Blake2b 256 checksum.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const size384 = 48
|
||||
```
|
||||
|
||||
size384 is the size, in bytes, of a Blake2b 384 checksum.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const size512 = 64
|
||||
```
|
||||
|
||||
size512 is the size, in bytes, of a Blake2b 512 checksum.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const block_size = 128
|
||||
```
|
||||
|
||||
block_size is the block size, in bytes, of the Blake2b hash functions.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new160
|
||||
```v
|
||||
fn new160() !&Digest
|
||||
```
|
||||
|
||||
new160 initializes the digest structure for a Blake2b 160 bit hash
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new256
|
||||
```v
|
||||
fn new256() !&Digest
|
||||
```
|
||||
|
||||
new256 initializes the digest structure for a Blake2b 256 bit hash
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new384
|
||||
```v
|
||||
fn new384() !&Digest
|
||||
```
|
||||
|
||||
new384 initializes the digest structure for a Blake2b 384 bit hash
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new512
|
||||
```v
|
||||
fn new512() !&Digest
|
||||
```
|
||||
|
||||
new512 initializes the digest structure for a Blake2b 512 bit hash
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new_digest
|
||||
```v
|
||||
fn new_digest(hash_size u8, key []u8) !&Digest
|
||||
```
|
||||
|
||||
new_digest creates an initialized digest structure based on the hash size and whether or not you specify a MAC key.
|
||||
|
||||
hash_size - the number of bytes in the generated hash. Legal values are between 1 and 64.
|
||||
|
||||
key - key used for generating a prefix MAC. A zero length key is used for just generating a hash. A key of 1 to 64 bytes can be used for generating a prefix MAC.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new_pmac160
|
||||
```v
|
||||
fn new_pmac160(key []u8) !&Digest
|
||||
```
|
||||
|
||||
new_pmac160 initializes the digest structure for a Blake2b 160 bit prefix MAC
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new_pmac256
|
||||
```v
|
||||
fn new_pmac256(key []u8) !&Digest
|
||||
```
|
||||
|
||||
new_pmac256 initializes the digest structure for a Blake2b 256 bit prefix MAC
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new_pmac384
|
||||
```v
|
||||
fn new_pmac384(key []u8) !&Digest
|
||||
```
|
||||
|
||||
new_pmac384 initializes the digest structure for a Blake2b 384 bit prefix MAC
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new_pmac512
|
||||
```v
|
||||
fn new_pmac512(key []u8) !&Digest
|
||||
```
|
||||
|
||||
new_pmac512 initializes the digest structure for a Blake2b 512 bit prefix MAC
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## pmac160
|
||||
```v
|
||||
fn pmac160(data []u8, key []u8) []u8
|
||||
```
|
||||
|
||||
pmac160 returns the Blake2b 160 bit prefix MAC of the data.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## pmac256
|
||||
```v
|
||||
fn pmac256(data []u8, key []u8) []u8
|
||||
```
|
||||
|
||||
pmac256 returns the Blake2b 256 bit prefix MAC of the data.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## pmac384
|
||||
```v
|
||||
fn pmac384(data []u8, key []u8) []u8
|
||||
```
|
||||
|
||||
pmac384 returns the Blake2b 384 bit prefix MAC of the data.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## pmac512
|
||||
```v
|
||||
fn pmac512(data []u8, key []u8) []u8
|
||||
```
|
||||
|
||||
pmac512 returns the Blake2b 512 bit prefix MAC of the data.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## sum160
|
||||
```v
|
||||
fn sum160(data []u8) []u8
|
||||
```
|
||||
|
||||
sum160 returns the Blake2b 160 bit checksum of the data.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## sum256
|
||||
```v
|
||||
fn sum256(data []u8) []u8
|
||||
```
|
||||
|
||||
sum256 returns the Blake2b 256 bit checksum of the data.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## sum384
|
||||
```v
|
||||
fn sum384(data []u8) []u8
|
||||
```
|
||||
|
||||
sum384 returns the Blake2b 384 bit checksum of the data.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## sum512
|
||||
```v
|
||||
fn sum512(data []u8) []u8
|
||||
```
|
||||
|
||||
sum512 returns the Blake2b 512 bit checksum of the data.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Digest
|
||||
## str
|
||||
```v
|
||||
fn (d Digest) str() string
|
||||
```
|
||||
|
||||
string makes a formatted string representation of a Digest structure
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## write
|
||||
```v
|
||||
fn (mut d Digest) write(data []u8) !
|
||||
```
|
||||
|
||||
write adds bytes to the hash
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## checksum
|
||||
```v
|
||||
fn (mut d Digest) checksum() []u8
|
||||
```
|
||||
|
||||
checksum finalizes the hash and returns the generated bytes.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:18:17
|
||||
254
aiprompts/v_core/crypto/blake2s.md
Normal file
254
aiprompts/v_core/crypto/blake2s.md
Normal file
@@ -0,0 +1,254 @@
|
||||
# module blake2s
|
||||
|
||||
|
||||
## Contents
|
||||
- [Constants](#Constants)
|
||||
- [new128](#new128)
|
||||
- [new160](#new160)
|
||||
- [new224](#new224)
|
||||
- [new256](#new256)
|
||||
- [new_digest](#new_digest)
|
||||
- [new_pmac128](#new_pmac128)
|
||||
- [new_pmac160](#new_pmac160)
|
||||
- [new_pmac224](#new_pmac224)
|
||||
- [new_pmac256](#new_pmac256)
|
||||
- [pmac128](#pmac128)
|
||||
- [pmac160](#pmac160)
|
||||
- [pmac224](#pmac224)
|
||||
- [pmac256](#pmac256)
|
||||
- [sum128](#sum128)
|
||||
- [sum160](#sum160)
|
||||
- [sum224](#sum224)
|
||||
- [sum256](#sum256)
|
||||
- [Digest](#Digest)
|
||||
- [str](#str)
|
||||
- [write](#write)
|
||||
- [checksum](#checksum)
|
||||
|
||||
## Constants
|
||||
```v
|
||||
const size128 = 16
|
||||
```
|
||||
|
||||
size128 is the size, in bytes, of a Blake2s 128 checksum.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const size160 = 20
|
||||
```
|
||||
|
||||
size160 is the size, in bytes, of a Blake2s 160 checksum.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const size224 = 28
|
||||
```
|
||||
|
||||
size224 is the size, in bytes, of a Blake2s 224 checksum.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const size256 = 32
|
||||
```
|
||||
|
||||
size256 is the size, in bytes, of a Blake2s 256 checksum.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const block_size = 64
|
||||
```
|
||||
|
||||
block_size is the block size, in bytes, of the Blake2s hash functions.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new128
|
||||
```v
|
||||
fn new128() !&Digest
|
||||
```
|
||||
|
||||
new126 initializes the digest structure for a Blake2s 128 bit hash
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new160
|
||||
```v
|
||||
fn new160() !&Digest
|
||||
```
|
||||
|
||||
new160 initializes the digest structure for a Blake2s 160 bit hash
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new224
|
||||
```v
|
||||
fn new224() !&Digest
|
||||
```
|
||||
|
||||
new224 initializes the digest structure for a Blake2s 224 bit hash
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new256
|
||||
```v
|
||||
fn new256() !&Digest
|
||||
```
|
||||
|
||||
new256 initializes the digest structure for a Blake2s 256 bit hash
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new_digest
|
||||
```v
|
||||
fn new_digest(hash_size u8, key []u8) !&Digest
|
||||
```
|
||||
|
||||
new_digest creates an initialized digest structure based on the hash size and whether or not you specify a MAC key.
|
||||
|
||||
hash_size - the number of bytes in the generated hash. Legal values are between 1 and 32.
|
||||
|
||||
key - key used for generating a prefix MAC. A zero length key is used for just generating a hash. A key of 1 to 32 bytes can be used for generating a prefix MAC.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new_pmac128
|
||||
```v
|
||||
fn new_pmac128(key []u8) !&Digest
|
||||
```
|
||||
|
||||
new_pmac128 initializes the digest structure for a Blake2s 128 bit prefix MAC
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new_pmac160
|
||||
```v
|
||||
fn new_pmac160(key []u8) !&Digest
|
||||
```
|
||||
|
||||
new_pmac160 initializes the digest structure for a Blake2s 160 bit prefix MAC
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new_pmac224
|
||||
```v
|
||||
fn new_pmac224(key []u8) !&Digest
|
||||
```
|
||||
|
||||
new_pmac224 initializes the digest structure for a Blake2s 224 bit prefix MAC
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new_pmac256
|
||||
```v
|
||||
fn new_pmac256(key []u8) !&Digest
|
||||
```
|
||||
|
||||
new_pmac256 initializes the digest structure for a Blake2s 256 bit prefix MAC
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## pmac128
|
||||
```v
|
||||
fn pmac128(data []u8, key []u8) []u8
|
||||
```
|
||||
|
||||
pmac128 returns the Blake2s 128 bit prefix MAC of the data.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## pmac160
|
||||
```v
|
||||
fn pmac160(data []u8, key []u8) []u8
|
||||
```
|
||||
|
||||
pmac160 returns the Blake2s 160 bit prefix MAC of the data.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## pmac224
|
||||
```v
|
||||
fn pmac224(data []u8, key []u8) []u8
|
||||
```
|
||||
|
||||
pmac224 returns the Blake2s 224 bit prefix MAC of the data.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## pmac256
|
||||
```v
|
||||
fn pmac256(data []u8, key []u8) []u8
|
||||
```
|
||||
|
||||
pmac256 returns the Blake2s 256 bit prefix MAC of the data.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## sum128
|
||||
```v
|
||||
fn sum128(data []u8) []u8
|
||||
```
|
||||
|
||||
sum128 returns the Blake2s 128 bit checksum of the data.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## sum160
|
||||
```v
|
||||
fn sum160(data []u8) []u8
|
||||
```
|
||||
|
||||
sum160 returns the Blake2s 160 bit checksum of the data.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## sum224
|
||||
```v
|
||||
fn sum224(data []u8) []u8
|
||||
```
|
||||
|
||||
sum224 returns the Blake2s 224 bit checksum of the data.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## sum256
|
||||
```v
|
||||
fn sum256(data []u8) []u8
|
||||
```
|
||||
|
||||
sum256 returns the Blake2s 256 bit checksum of the data.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Digest
|
||||
## str
|
||||
```v
|
||||
fn (d Digest) str() string
|
||||
```
|
||||
|
||||
string makes a formatted string representation of a Digest structure
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## write
|
||||
```v
|
||||
fn (mut d Digest) write(data []u8) !
|
||||
```
|
||||
|
||||
write adds bytes to the hash
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## checksum
|
||||
```v
|
||||
fn (mut d Digest) checksum() []u8
|
||||
```
|
||||
|
||||
checksum finalizes the hash and returns the generated bytes.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:18:17
|
||||
124
aiprompts/v_core/crypto/blake3.md
Normal file
124
aiprompts/v_core/crypto/blake3.md
Normal file
@@ -0,0 +1,124 @@
|
||||
# module blake3
|
||||
|
||||
|
||||
## Contents
|
||||
- [Constants](#Constants)
|
||||
- [sum256](#sum256)
|
||||
- [sum_derive_key256](#sum_derive_key256)
|
||||
- [sum_keyed256](#sum_keyed256)
|
||||
- [Digest.new_derive_key_hash](#Digest.new_derive_key_hash)
|
||||
- [Digest.new_hash](#Digest.new_hash)
|
||||
- [Digest.new_keyed_hash](#Digest.new_keyed_hash)
|
||||
- [Digest](#Digest)
|
||||
- [write](#write)
|
||||
- [checksum](#checksum)
|
||||
|
||||
## Constants
|
||||
```v
|
||||
const size256 = 32
|
||||
```
|
||||
|
||||
size256 is the size, in bytes, of a Blake3 256 checksum.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const key_length = 32
|
||||
```
|
||||
|
||||
key_length is the length, in bytes, of a Blake3 key
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const block_size = 64
|
||||
```
|
||||
|
||||
block_size is the block size, in bytes, of the Blake3 hash functions.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const chunk_size = 1024
|
||||
```
|
||||
|
||||
chunk_size is the chunk size, in bytes, of the Blake3 hash functions. A chunk consists of 16 blocks.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## sum256
|
||||
```v
|
||||
fn sum256(data []u8) []u8
|
||||
```
|
||||
|
||||
sum256 returns the Blake3 256 bit hash of the data.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## sum_derive_key256
|
||||
```v
|
||||
fn sum_derive_key256(context []u8, key_material []u8) []u8
|
||||
```
|
||||
|
||||
sum_derived_key256 returns the Blake3 256 bit derived key hash of the key material
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## sum_keyed256
|
||||
```v
|
||||
fn sum_keyed256(data []u8, key []u8) []u8
|
||||
```
|
||||
|
||||
sum_keyed256 returns the Blake3 256 bit keyed hash of the data.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Digest.new_derive_key_hash
|
||||
```v
|
||||
fn Digest.new_derive_key_hash(context []u8) !Digest
|
||||
```
|
||||
|
||||
Digest.new_derive_key_hash initializes a Digest structure for deriving a Blake3 key
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Digest.new_hash
|
||||
```v
|
||||
fn Digest.new_hash() !Digest
|
||||
```
|
||||
|
||||
Digest.new_hash initializes a Digest structure for a Blake3 hash
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Digest.new_keyed_hash
|
||||
```v
|
||||
fn Digest.new_keyed_hash(key []u8) !Digest
|
||||
```
|
||||
|
||||
Digest.new_keyed_hash initializes a Digest structure for a Blake3 keyed hash
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Digest
|
||||
## write
|
||||
```v
|
||||
fn (mut d Digest) write(data []u8) !
|
||||
```
|
||||
|
||||
write adds bytes to the hash
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## checksum
|
||||
```v
|
||||
fn (mut d Digest) checksum(size u64) []u8
|
||||
```
|
||||
|
||||
checksum finalizes the hash and returns the generated bytes.
|
||||
|
||||
This is the point in the hashing operation that we need to know how many bytes of hash to generate. Normally this is 32 but can be any size up to 2**64.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:18:17
|
||||
1134
aiprompts/v_core/crypto/blowfish.md
Normal file
1134
aiprompts/v_core/crypto/blowfish.md
Normal file
File diff suppressed because it is too large
Load Diff
238
aiprompts/v_core/crypto/cipher.md
Normal file
238
aiprompts/v_core/crypto/cipher.md
Normal file
@@ -0,0 +1,238 @@
|
||||
# module cipher
|
||||
|
||||
|
||||
## Contents
|
||||
- [new_cbc](#new_cbc)
|
||||
- [new_cfb_decrypter](#new_cfb_decrypter)
|
||||
- [new_cfb_encrypter](#new_cfb_encrypter)
|
||||
- [new_ctr](#new_ctr)
|
||||
- [new_ofb](#new_ofb)
|
||||
- [safe_xor_bytes](#safe_xor_bytes)
|
||||
- [xor_bytes](#xor_bytes)
|
||||
- [xor_words](#xor_words)
|
||||
- [Block](#Block)
|
||||
- [BlockMode](#BlockMode)
|
||||
- [Stream](#Stream)
|
||||
- [Cbc](#Cbc)
|
||||
- [free](#free)
|
||||
- [encrypt_blocks](#encrypt_blocks)
|
||||
- [decrypt_blocks](#decrypt_blocks)
|
||||
- [Cfb](#Cfb)
|
||||
- [free](#free)
|
||||
- [xor_key_stream](#xor_key_stream)
|
||||
- [Ctr](#Ctr)
|
||||
- [free](#free)
|
||||
- [xor_key_stream](#xor_key_stream)
|
||||
- [Ofb](#Ofb)
|
||||
- [xor_key_stream](#xor_key_stream)
|
||||
|
||||
## new_cbc
|
||||
```v
|
||||
fn new_cbc(b Block, iv []u8) Cbc
|
||||
```
|
||||
|
||||
new_cbc returns a `DesCbc` which encrypts in cipher block chaining mode, using the given Block. The length of iv must be the same as the Block's block size.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new_cfb_decrypter
|
||||
```v
|
||||
fn new_cfb_decrypter(b Block, iv []u8) Cfb
|
||||
```
|
||||
|
||||
new_cfb_decrypter returns a `Cfb` which decrypts with cipher feedback mode, using the given Block. The iv must be the same length as the Block's block size
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new_cfb_encrypter
|
||||
```v
|
||||
fn new_cfb_encrypter(b Block, iv []u8) Cfb
|
||||
```
|
||||
|
||||
new_cfb_encrypter returns a `Cfb` which encrypts with cipher feedback mode, using the given Block. The iv must be the same length as the Block's block size
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new_ctr
|
||||
```v
|
||||
fn new_ctr(b Block, iv []u8) Ctr
|
||||
```
|
||||
|
||||
new_ctr returns a Ctr which encrypts/decrypts using the given Block in counter mode. The length of iv must be the same as the Block's block size.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new_ofb
|
||||
```v
|
||||
fn new_ofb(b Block, iv []u8) Ofb
|
||||
```
|
||||
|
||||
new_ofb returns a Ofb that encrypts or decrypts using the block cipher b in output feedback mode. The initialization vector iv's length must be equal to b's block size.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## safe_xor_bytes
|
||||
```v
|
||||
fn safe_xor_bytes(mut dst []u8, a []u8, b []u8, n int)
|
||||
```
|
||||
|
||||
safe_xor_bytes XORs the bytes in `a` and `b` into `dst` it does so `n` times. Please note: `n` needs to be smaller or equal than the length of `a` and `b`.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## xor_bytes
|
||||
```v
|
||||
fn xor_bytes(mut dst []u8, a []u8, b []u8) int
|
||||
```
|
||||
|
||||
|
||||
|
||||
Note: Implement other versions (joe-c)xor_bytes xors the bytes in a and b. The destination should have enough space, otherwise xor_bytes will panic. Returns the number of bytes xor'd.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## xor_words
|
||||
```v
|
||||
fn xor_words(mut dst []u8, a []u8, b []u8)
|
||||
```
|
||||
|
||||
xor_words XORs multiples of 4 or 8 bytes (depending on architecture.) The slice arguments `a` and `b` are assumed to be of equal length.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Block
|
||||
```v
|
||||
interface Block {
|
||||
block_size int // block_size returns the cipher's block size.
|
||||
encrypt(mut dst []u8, src []u8) // Encrypt encrypts the first block in src into dst.
|
||||
// Dst and src must overlap entirely or not at all.
|
||||
decrypt(mut dst []u8, src []u8) // Decrypt decrypts the first block in src into dst.
|
||||
// Dst and src must overlap entirely or not at all.
|
||||
}
|
||||
```
|
||||
|
||||
A Block represents an implementation of block cipher using a given key. It provides the capability to encrypt or decrypt individual blocks. The mode implementations extend that capability to streams of blocks.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## BlockMode
|
||||
```v
|
||||
interface BlockMode {
|
||||
block_size int // block_size returns the mode's block size.
|
||||
crypt_blocks(mut dst []u8, src []u8) // crypt_blocks encrypts or decrypts a number of blocks. The length of
|
||||
// src must be a multiple of the block size. Dst and src must overlap
|
||||
// entirely or not at all.
|
||||
//
|
||||
// If len(dst) < len(src), crypt_blocks should panic. It is acceptable
|
||||
// to pass a dst bigger than src, and in that case, crypt_blocks will
|
||||
// only update dst[:len(src)] and will not touch the rest of dst.
|
||||
//
|
||||
// Multiple calls to crypt_blocks behave as if the concatenation of
|
||||
// the src buffers was passed in a single run. That is, BlockMode
|
||||
// maintains state and does not reset at each crypt_blocks call.
|
||||
}
|
||||
```
|
||||
|
||||
A BlockMode represents a block cipher running in a block-based mode (CBC, ECB etc).
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Stream
|
||||
```v
|
||||
interface Stream {
|
||||
mut:
|
||||
// xor_key_stream XORs each byte in the given slice with a byte from the
|
||||
// cipher's key stream. Dst and src must overlap entirely or not at all.
|
||||
//
|
||||
// If len(dst) < len(src), xor_key_stream should panic. It is acceptable
|
||||
// to pass a dst bigger than src, and in that case, xor_key_stream will
|
||||
// only update dst[:len(src)] and will not touch the rest of dst.
|
||||
//
|
||||
// Multiple calls to xor_key_stream behave as if the concatenation of
|
||||
// the src buffers was passed in a single run. That is, Stream
|
||||
// maintains state and does not reset at each xor_key_stream call.
|
||||
xor_key_stream(mut dst []u8, src []u8)
|
||||
}
|
||||
```
|
||||
|
||||
A Stream represents a stream cipher.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Cbc
|
||||
## free
|
||||
```v
|
||||
fn (mut x Cbc) free()
|
||||
```
|
||||
|
||||
free the resources taken by the Cbc `x`
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## encrypt_blocks
|
||||
```v
|
||||
fn (mut x Cbc) encrypt_blocks(mut dst_ []u8, src_ []u8)
|
||||
```
|
||||
|
||||
encrypt_blocks encrypts the blocks in `src_` to `dst_`. Please note: `dst_` is mutable for performance reasons.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## decrypt_blocks
|
||||
```v
|
||||
fn (mut x Cbc) decrypt_blocks(mut dst []u8, src []u8)
|
||||
```
|
||||
|
||||
decrypt_blocks decrypts the blocks in `src` to `dst`. Please note: `dst` is mutable for performance reasons.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Cfb
|
||||
## free
|
||||
```v
|
||||
fn (mut x Cfb) free()
|
||||
```
|
||||
|
||||
free the resources taken by the Cfb `x`
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## xor_key_stream
|
||||
```v
|
||||
fn (mut x Cfb) xor_key_stream(mut dst []u8, src []u8)
|
||||
```
|
||||
|
||||
xor_key_stream xors each byte in the given slice with a byte from the key stream.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Ctr
|
||||
## free
|
||||
```v
|
||||
fn (mut x Ctr) free()
|
||||
```
|
||||
|
||||
free the resources taken by the Ctr `c`
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## xor_key_stream
|
||||
```v
|
||||
fn (mut x Ctr) xor_key_stream(mut dst []u8, src []u8)
|
||||
```
|
||||
|
||||
xor_key_stream xors each byte in the given slice with a byte from the key stream.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Ofb
|
||||
## xor_key_stream
|
||||
```v
|
||||
fn (mut x Ofb) xor_key_stream(mut dst []u8, src []u8)
|
||||
```
|
||||
|
||||
xor_key_stream xors each byte in the given slice with a byte from the key stream.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:18:17
|
||||
613
aiprompts/v_core/crypto/crypto.ed25519.internal.edwards25519.md
Normal file
613
aiprompts/v_core/crypto/crypto.ed25519.internal.edwards25519.md
Normal file
@@ -0,0 +1,613 @@
|
||||
# module crypto.ed25519.internal.edwards25519
|
||||
|
||||
|
||||
## Contents
|
||||
- [Constants](#Constants)
|
||||
- [new_generator_point](#new_generator_point)
|
||||
- [new_identity_point](#new_identity_point)
|
||||
- [new_scalar](#new_scalar)
|
||||
- [Scalar](#Scalar)
|
||||
- [add](#add)
|
||||
- [bytes](#bytes)
|
||||
- [equal](#equal)
|
||||
- [invert](#invert)
|
||||
- [multiply](#multiply)
|
||||
- [multiply_add](#multiply_add)
|
||||
- [negate](#negate)
|
||||
- [non_adjacent_form](#non_adjacent_form)
|
||||
- [set](#set)
|
||||
- [set_bytes_with_clamping](#set_bytes_with_clamping)
|
||||
- [set_canonical_bytes](#set_canonical_bytes)
|
||||
- [set_uniform_bytes](#set_uniform_bytes)
|
||||
- [subtract](#subtract)
|
||||
- [Element](#Element)
|
||||
- [zero](#zero)
|
||||
- [one](#one)
|
||||
- [reduce](#reduce)
|
||||
- [add](#add)
|
||||
- [subtract](#subtract)
|
||||
- [negate](#negate)
|
||||
- [invert](#invert)
|
||||
- [square](#square)
|
||||
- [multiply](#multiply)
|
||||
- [pow_22523](#pow_22523)
|
||||
- [sqrt_ratio](#sqrt_ratio)
|
||||
- [selected](#selected)
|
||||
- [is_negative](#is_negative)
|
||||
- [absolute](#absolute)
|
||||
- [set](#set)
|
||||
- [set_bytes](#set_bytes)
|
||||
- [bytes](#bytes)
|
||||
- [equal](#equal)
|
||||
- [swap](#swap)
|
||||
- [mult_32](#mult_32)
|
||||
- [Point](#Point)
|
||||
- [add](#add)
|
||||
- [bytes](#bytes)
|
||||
- [bytes_montgomery](#bytes_montgomery)
|
||||
- [equal](#equal)
|
||||
- [mult_by_cofactor](#mult_by_cofactor)
|
||||
- [multi_scalar_mult](#multi_scalar_mult)
|
||||
- [negate](#negate)
|
||||
- [scalar_base_mult](#scalar_base_mult)
|
||||
- [scalar_mult](#scalar_mult)
|
||||
- [set](#set)
|
||||
- [set_bytes](#set_bytes)
|
||||
- [subtract](#subtract)
|
||||
- [vartime_double_scalar_base_mult](#vartime_double_scalar_base_mult)
|
||||
- [vartime_multiscalar_mult](#vartime_multiscalar_mult)
|
||||
|
||||
## Constants
|
||||
```v
|
||||
const sc_zero = Scalar{
|
||||
s: [u8(0), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0]!
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const sc_one = Scalar{
|
||||
s: [u8(1), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0]!
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const sc_minus_one = Scalar{
|
||||
s: [u8(236), 211, 245, 92, 26, 99, 18, 88, 214, 156, 247, 162, 222, 249, 222, 20, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16]!
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new_generator_point
|
||||
```v
|
||||
fn new_generator_point() Point
|
||||
```
|
||||
|
||||
new_generator_point returns a new Point set to the canonical generator.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new_identity_point
|
||||
```v
|
||||
fn new_identity_point() Point
|
||||
```
|
||||
|
||||
new_identity_point returns a new Point set to the identity.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new_scalar
|
||||
```v
|
||||
fn new_scalar() Scalar
|
||||
```
|
||||
|
||||
new_scalar return new zero scalar
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Scalar
|
||||
## add
|
||||
```v
|
||||
fn (mut s Scalar) add(x Scalar, y Scalar) Scalar
|
||||
```
|
||||
|
||||
add sets s = x + y mod l, and returns s.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## bytes
|
||||
```v
|
||||
fn (mut s Scalar) bytes() []u8
|
||||
```
|
||||
|
||||
bytes returns the canonical 32-byte little-endian encoding of s.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## equal
|
||||
```v
|
||||
fn (s Scalar) equal(t Scalar) int
|
||||
```
|
||||
|
||||
equal returns 1 if s and t are equal, and 0 otherwise.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## invert
|
||||
```v
|
||||
fn (mut s Scalar) invert(t Scalar) Scalar
|
||||
```
|
||||
|
||||
invert sets s to the inverse of a nonzero scalar v, and returns s.
|
||||
|
||||
If t is zero, invert returns zero.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## multiply
|
||||
```v
|
||||
fn (mut s Scalar) multiply(x Scalar, y Scalar) Scalar
|
||||
```
|
||||
|
||||
multiply sets s = x * y mod l, and returns s.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## multiply_add
|
||||
```v
|
||||
fn (mut s Scalar) multiply_add(x Scalar, y Scalar, z Scalar) Scalar
|
||||
```
|
||||
|
||||
multiply_add sets s = x * y + z mod l, and returns s.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## negate
|
||||
```v
|
||||
fn (mut s Scalar) negate(x Scalar) Scalar
|
||||
```
|
||||
|
||||
negate sets s = -x mod l, and returns s.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## non_adjacent_form
|
||||
```v
|
||||
fn (mut s Scalar) non_adjacent_form(w u32) []i8
|
||||
```
|
||||
|
||||
non_adjacent_form computes a width-w non-adjacent form for this scalar.
|
||||
|
||||
w must be between 2 and 8, or non_adjacent_form will panic.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## set
|
||||
```v
|
||||
fn (mut s Scalar) set(x Scalar) Scalar
|
||||
```
|
||||
|
||||
set sets s = x, and returns s.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## set_bytes_with_clamping
|
||||
```v
|
||||
fn (mut s Scalar) set_bytes_with_clamping(x []u8) !Scalar
|
||||
```
|
||||
|
||||
set_bytes_with_clamping applies the buffer pruning described in RFC 8032, Section 5.1.5 (also known as clamping) and sets s to the result. The input must be 32 bytes, and it is not modified. If x is not of the right length, `set_bytes_with_clamping` returns an error, and the receiver is unchanged.
|
||||
|
||||
Note that since Scalar values are always reduced modulo the prime order of the curve, the resulting value will not preserve any of the cofactor-clearing properties that clamping is meant to provide. It will however work as expected as long as it is applied to points on the prime order subgroup, like in Ed25519. In fact, it is lost to history why RFC 8032 adopted the irrelevant RFC 7748 clamping, but it is now required for compatibility.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## set_canonical_bytes
|
||||
```v
|
||||
fn (mut s Scalar) set_canonical_bytes(x []u8) !Scalar
|
||||
```
|
||||
|
||||
set_canonical_bytes sets s = x, where x is a 32-byte little-endian encoding of s, and returns s. If x is not a canonical encoding of s, set_canonical_bytes returns an error, and the receiver is unchanged.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## set_uniform_bytes
|
||||
```v
|
||||
fn (mut s Scalar) set_uniform_bytes(x []u8) !Scalar
|
||||
```
|
||||
|
||||
set_uniform_bytes sets s to an uniformly distributed value given 64 uniformly distributed random bytes. If x is not of the right length, set_uniform_bytes returns an error, and the receiver is unchanged.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## subtract
|
||||
```v
|
||||
fn (mut s Scalar) subtract(x Scalar, y Scalar) Scalar
|
||||
```
|
||||
|
||||
subtract sets s = x - y mod l, and returns s.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Element
|
||||
```v
|
||||
struct Element {
|
||||
mut:
|
||||
// An element t represents the integer
|
||||
// t.l0 + t.l1*2^51 + t.l2*2^102 + t.l3*2^153 + t.l4*2^204
|
||||
//
|
||||
// Between operations, all limbs are expected to be lower than 2^52.
|
||||
l0 u64
|
||||
l1 u64
|
||||
l2 u64
|
||||
l3 u64
|
||||
l4 u64
|
||||
}
|
||||
```
|
||||
|
||||
Element represents an element of the edwards25519 GF(2^255-19). Note that this is not a cryptographically secure group, and should only be used to interact with edwards25519.Point coordinates.
|
||||
|
||||
This type works similarly to math/big.Int, and all arguments and receivers are allowed to alias.
|
||||
|
||||
The zero value is a valid zero element.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## zero
|
||||
```v
|
||||
fn (mut v Element) zero() Element
|
||||
```
|
||||
|
||||
zero sets v = 0, and returns v.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## one
|
||||
```v
|
||||
fn (mut v Element) one() Element
|
||||
```
|
||||
|
||||
one sets v = 1, and returns v.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## reduce
|
||||
```v
|
||||
fn (mut v Element) reduce() Element
|
||||
```
|
||||
|
||||
reduce reduces v modulo 2^255 - 19 and returns it.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## add
|
||||
```v
|
||||
fn (mut v Element) add(a Element, b Element) Element
|
||||
```
|
||||
|
||||
add sets v = a + b, and returns v.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## subtract
|
||||
```v
|
||||
fn (mut v Element) subtract(a Element, b Element) Element
|
||||
```
|
||||
|
||||
subtract sets v = a - b, and returns v.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## negate
|
||||
```v
|
||||
fn (mut v Element) negate(a Element) Element
|
||||
```
|
||||
|
||||
negate sets v = -a, and returns v.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## invert
|
||||
```v
|
||||
fn (mut v Element) invert(z Element) Element
|
||||
```
|
||||
|
||||
invert sets v = 1/z mod p, and returns v.
|
||||
|
||||
If z == 0, invert returns v = 0.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## square
|
||||
```v
|
||||
fn (mut v Element) square(x Element) Element
|
||||
```
|
||||
|
||||
square sets v = x * x, and returns v.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## multiply
|
||||
```v
|
||||
fn (mut v Element) multiply(x Element, y Element) Element
|
||||
```
|
||||
|
||||
multiply sets v = x * y, and returns v.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## pow_22523
|
||||
```v
|
||||
fn (mut v Element) pow_22523(x Element) Element
|
||||
```
|
||||
|
||||
pow_22523 set v = x^((p-5)/8), and returns v. (p-5)/8 is 2^252-3.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## sqrt_ratio
|
||||
```v
|
||||
fn (mut r Element) sqrt_ratio(u Element, v Element) (Element, int)
|
||||
```
|
||||
|
||||
sqrt_ratio sets r to the non-negative square root of the ratio of u and v.
|
||||
|
||||
If u/v is square, sqrt_ratio returns r and 1. If u/v is not square, sqrt_ratio sets r according to Section 4.3 of draft-irtf-cfrg-ristretto255-decaf448-00, and returns r and 0.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## selected
|
||||
```v
|
||||
fn (mut v Element) selected(a Element, b Element, cond int) Element
|
||||
```
|
||||
|
||||
selected sets v to a if cond == 1, and to b if cond == 0.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## is_negative
|
||||
```v
|
||||
fn (mut v Element) is_negative() int
|
||||
```
|
||||
|
||||
is_negative returns 1 if v is negative, and 0 otherwise.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## absolute
|
||||
```v
|
||||
fn (mut v Element) absolute(u Element) Element
|
||||
```
|
||||
|
||||
absolute sets v to |u|, and returns v.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## set
|
||||
```v
|
||||
fn (mut v Element) set(a Element) Element
|
||||
```
|
||||
|
||||
set sets v = a, and returns v.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## set_bytes
|
||||
```v
|
||||
fn (mut v Element) set_bytes(x []u8) !Element
|
||||
```
|
||||
|
||||
set_bytes sets v to x, where x is a 32-byte little-endian encoding. If x is not of the right length, SetUniformBytes returns an error, and the receiver is unchanged.
|
||||
|
||||
Consistent with RFC 7748, the most significant bit (the high bit of the last byte) is ignored, and non-canonical values (2^255-19 through 2^255-1) are accepted. Note that this is laxer than specified by RFC 8032.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## bytes
|
||||
```v
|
||||
fn (mut v Element) bytes() []u8
|
||||
```
|
||||
|
||||
bytes returns the canonical 32-byte little-endian encoding of v.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## equal
|
||||
```v
|
||||
fn (mut v Element) equal(ue Element) int
|
||||
```
|
||||
|
||||
equal returns 1 if v and u are equal, and 0 otherwise.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## swap
|
||||
```v
|
||||
fn (mut v Element) swap(mut u Element, cond int)
|
||||
```
|
||||
|
||||
swap swaps v and u if cond == 1 or leaves them unchanged if cond == 0, and returns v.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## mult_32
|
||||
```v
|
||||
fn (mut v Element) mult_32(x Element, y u32) Element
|
||||
```
|
||||
|
||||
mult_32 sets v = x * y, and returns v.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Point
|
||||
```v
|
||||
struct Point {
|
||||
mut:
|
||||
// The point is internally represented in extended coordinates (x, y, z, T)
|
||||
// where x = x/z, y = y/z, and xy = T/z per https://eprint.iacr.org/2008/522.
|
||||
x Element
|
||||
y Element
|
||||
z Element
|
||||
t Element
|
||||
// Make the type not comparable (i.e. used with == or as a map key), as
|
||||
// equivalent points can be represented by different values.
|
||||
// _ incomparable
|
||||
}
|
||||
```
|
||||
|
||||
Point represents a point on the edwards25519 curve.
|
||||
|
||||
This type works similarly to math/big.Int, and all arguments and receivers are allowed to alias.
|
||||
|
||||
The zero value is NOT valid, and it may be used only as a receiver.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## add
|
||||
```v
|
||||
fn (mut v Point) add(p Point, q Point) Point
|
||||
```
|
||||
|
||||
add sets v = p + q, and returns v.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## bytes
|
||||
```v
|
||||
fn (mut v Point) bytes() []u8
|
||||
```
|
||||
|
||||
bytes returns the canonical 32-byte encoding of v, according to RFC 8032, Section 5.1.2.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## bytes_montgomery
|
||||
```v
|
||||
fn (mut v Point) bytes_montgomery() []u8
|
||||
```
|
||||
|
||||
bytes_montgomery converts v to a point on the birationally-equivalent Curve25519 Montgomery curve, and returns its canonical 32 bytes encoding according to RFC 7748.
|
||||
|
||||
Note that bytes_montgomery only encodes the u-coordinate, so v and -v encode to the same value. If v is the identity point, bytes_montgomery returns 32 zero bytes, analogously to the X25519 function.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## equal
|
||||
```v
|
||||
fn (mut v Point) equal(u Point) int
|
||||
```
|
||||
|
||||
equal returns 1 if v is equivalent to u, and 0 otherwise.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## mult_by_cofactor
|
||||
```v
|
||||
fn (mut v Point) mult_by_cofactor(p Point) Point
|
||||
```
|
||||
|
||||
mult_by_cofactor sets v = 8 * p, and returns v.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## multi_scalar_mult
|
||||
```v
|
||||
fn (mut v Point) multi_scalar_mult(scalars []Scalar, points []Point) Point
|
||||
```
|
||||
|
||||
multi_scalar_mult sets v = sum(scalars[i] * points[i]), and returns v.
|
||||
|
||||
Execution time depends only on the lengths of the two slices, which must match.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## negate
|
||||
```v
|
||||
fn (mut v Point) negate(p Point) Point
|
||||
```
|
||||
|
||||
negate sets v = -p, and returns v.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## scalar_base_mult
|
||||
```v
|
||||
fn (mut v Point) scalar_base_mult(mut x Scalar) Point
|
||||
```
|
||||
|
||||
scalar_base_mult sets v = x * B, where B is the canonical generator, and returns v.
|
||||
|
||||
The scalar multiplication is done in constant time.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## scalar_mult
|
||||
```v
|
||||
fn (mut v Point) scalar_mult(mut x Scalar, q Point) Point
|
||||
```
|
||||
|
||||
scalar_mult sets v = x * q, and returns v.
|
||||
|
||||
The scalar multiplication is done in constant time.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## set
|
||||
```v
|
||||
fn (mut v Point) set(u Point) Point
|
||||
```
|
||||
|
||||
set sets v = u, and returns v.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## set_bytes
|
||||
```v
|
||||
fn (mut v Point) set_bytes(x []u8) !Point
|
||||
```
|
||||
|
||||
set_bytes sets v = x, where x is a 32-byte encoding of v. If x does not represent a valid point on the curve, set_bytes returns an error and the receiver is unchanged. Otherwise, set_bytes returns v.
|
||||
|
||||
Note that set_bytes accepts all non-canonical encodings of valid points. That is, it follows decoding rules that match most implementations in the ecosystem rather than RFC 8032.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## subtract
|
||||
```v
|
||||
fn (mut v Point) subtract(p Point, q Point) Point
|
||||
```
|
||||
|
||||
subtract sets v = p - q, and returns v.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## vartime_double_scalar_base_mult
|
||||
```v
|
||||
fn (mut v Point) vartime_double_scalar_base_mult(xa Scalar, aa Point, xb Scalar) Point
|
||||
```
|
||||
|
||||
vartime_double_scalar_base_mult sets v = a * A + b * B, where B is the canonical generator, and returns v.
|
||||
|
||||
Execution time depends on the inputs.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## vartime_multiscalar_mult
|
||||
```v
|
||||
fn (mut v Point) vartime_multiscalar_mult(scalars []Scalar, points []Point) Point
|
||||
```
|
||||
|
||||
vartime_multiscalar_mult sets v = sum(scalars[i] * points[i]), and returns v.
|
||||
|
||||
Execution time depends on the inputs.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:18:17
|
||||
90
aiprompts/v_core/crypto/crypto.internal.subtle.md
Normal file
90
aiprompts/v_core/crypto/crypto.internal.subtle.md
Normal file
@@ -0,0 +1,90 @@
|
||||
# module crypto.internal.subtle
|
||||
|
||||
|
||||
## Contents
|
||||
- [any_overlap](#any_overlap)
|
||||
- [constant_time_byte_eq](#constant_time_byte_eq)
|
||||
- [constant_time_compare](#constant_time_compare)
|
||||
- [constant_time_copy](#constant_time_copy)
|
||||
- [constant_time_eq](#constant_time_eq)
|
||||
- [constant_time_less_or_eq](#constant_time_less_or_eq)
|
||||
- [constant_time_select](#constant_time_select)
|
||||
- [inexact_overlap](#inexact_overlap)
|
||||
|
||||
## any_overlap
|
||||
```v
|
||||
fn any_overlap(x []u8, y []u8) bool
|
||||
```
|
||||
|
||||
|
||||
|
||||
Note: require unsafe in futureany_overlap reports whether x and y share memory at any (not necessarily corresponding) index. The memory beyond the slice length is ignored.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## constant_time_byte_eq
|
||||
```v
|
||||
fn constant_time_byte_eq(x u8, y u8) int
|
||||
```
|
||||
|
||||
constant_time_byte_eq returns 1 when x == y.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## constant_time_compare
|
||||
```v
|
||||
fn constant_time_compare(x []u8, y []u8) int
|
||||
```
|
||||
|
||||
constant_time_compare returns 1 when x and y have equal contents. The runtime of this function is proportional of the length of x and y. It is *NOT* dependent on their content.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## constant_time_copy
|
||||
```v
|
||||
fn constant_time_copy(v int, mut x []u8, y []u8)
|
||||
```
|
||||
|
||||
constant_time_copy copies the contents of y into x, when v == 1. When v == 0, x is left unchanged. this function is undefined, when v takes any other value
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## constant_time_eq
|
||||
```v
|
||||
fn constant_time_eq(x int, y int) int
|
||||
```
|
||||
|
||||
constant_time_eq returns 1 when x == y.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## constant_time_less_or_eq
|
||||
```v
|
||||
fn constant_time_less_or_eq(x int, y int) int
|
||||
```
|
||||
|
||||
constant_time_less_or_eq returns 1 if x <= y, and 0 otherwise. it is undefined when x or y are negative, or > (2^32 - 1)
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## constant_time_select
|
||||
```v
|
||||
fn constant_time_select(v int, x int, y int) int
|
||||
```
|
||||
|
||||
constant_time_select returns x when v == 1, and y when v == 0. it is undefined when v is any other value
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## inexact_overlap
|
||||
```v
|
||||
fn inexact_overlap(x []u8, y []u8) bool
|
||||
```
|
||||
|
||||
inexact_overlap reports whether x and y share memory at any non-corresponding index. The memory beyond the slice length is ignored. Note that x and y can have different lengths and still not have any inexact overlap.
|
||||
|
||||
inexact_overlap can be used to implement the requirements of the crypto/cipher AEAD, Block, BlockMode and Stream interfaces.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:18:17
|
||||
34
aiprompts/v_core/crypto/crypto.md
Normal file
34
aiprompts/v_core/crypto/crypto.md
Normal file
@@ -0,0 +1,34 @@
|
||||
# module crypto
|
||||
|
||||
|
||||
## Contents
|
||||
- [Hash](#Hash)
|
||||
|
||||
## Hash
|
||||
```v
|
||||
enum Hash {
|
||||
md4
|
||||
md5
|
||||
sha1
|
||||
sha224
|
||||
sha256
|
||||
sha384
|
||||
sha512
|
||||
md5sha1
|
||||
ripemd160
|
||||
sha3_224
|
||||
sha3_256
|
||||
sha3_384
|
||||
sha3_512
|
||||
sha512_224
|
||||
sha512_256
|
||||
blake2s_256
|
||||
blake2b_256
|
||||
blake2b_384
|
||||
blake2b_512
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:18:17
|
||||
80
aiprompts/v_core/crypto/des.md
Normal file
80
aiprompts/v_core/crypto/des.md
Normal file
@@ -0,0 +1,80 @@
|
||||
# module des
|
||||
|
||||
|
||||
## Contents
|
||||
- [encrypt_block](#encrypt_block)
|
||||
- [new_cipher](#new_cipher)
|
||||
- [new_triple_des_cipher](#new_triple_des_cipher)
|
||||
- [DesCipher](#DesCipher)
|
||||
- [encrypt](#encrypt)
|
||||
- [decrypt](#decrypt)
|
||||
- [TripleDesCipher](#TripleDesCipher)
|
||||
- [encrypt](#encrypt)
|
||||
- [decrypt](#decrypt)
|
||||
|
||||
## encrypt_block
|
||||
```v
|
||||
fn encrypt_block(subkeys []u64, mut dst []u8, src []u8)
|
||||
```
|
||||
|
||||
Encrypt one block from src into dst, using the subkeys.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new_cipher
|
||||
```v
|
||||
fn new_cipher(key []u8) cipher.Block
|
||||
```
|
||||
|
||||
NewCipher creates and returns a new cipher.Block.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new_triple_des_cipher
|
||||
```v
|
||||
fn new_triple_des_cipher(key []u8) cipher.Block
|
||||
```
|
||||
|
||||
NewTripleDesCipher creates and returns a new cipher.Block.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## DesCipher
|
||||
## encrypt
|
||||
```v
|
||||
fn (c &DesCipher) encrypt(mut dst []u8, src []u8)
|
||||
```
|
||||
|
||||
encrypt a block of data using the DES algorithm
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## decrypt
|
||||
```v
|
||||
fn (c &DesCipher) decrypt(mut dst []u8, src []u8)
|
||||
```
|
||||
|
||||
decrypt a block of data using the DES algorithm
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## TripleDesCipher
|
||||
## encrypt
|
||||
```v
|
||||
fn (c &TripleDesCipher) encrypt(mut dst []u8, src []u8)
|
||||
```
|
||||
|
||||
encrypt a block of data using the TripleDES algorithm
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## decrypt
|
||||
```v
|
||||
fn (c &TripleDesCipher) decrypt(mut dst []u8, src []u8)
|
||||
```
|
||||
|
||||
decrypt a block of data using the TripleDES algorithm
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:18:17
|
||||
304
aiprompts/v_core/crypto/ecdsa.md
Normal file
304
aiprompts/v_core/crypto/ecdsa.md
Normal file
@@ -0,0 +1,304 @@
|
||||
# module ecdsa
|
||||
|
||||
|
||||
## Contents
|
||||
- [generate_key](#generate_key)
|
||||
- [new_key_from_seed](#new_key_from_seed)
|
||||
- [privkey_from_string](#privkey_from_string)
|
||||
- [pubkey_from_bytes](#pubkey_from_bytes)
|
||||
- [pubkey_from_string](#pubkey_from_string)
|
||||
- [PrivateKey.new](#PrivateKey.new)
|
||||
- [HashConfig](#HashConfig)
|
||||
- [Nid](#Nid)
|
||||
- [C.BIO](#C.BIO)
|
||||
- [CurveOptions](#CurveOptions)
|
||||
- [PrivateKey](#PrivateKey)
|
||||
- [sign](#sign)
|
||||
- [sign_with_options](#sign_with_options)
|
||||
- [bytes](#bytes)
|
||||
- [seed](#seed)
|
||||
- [public_key](#public_key)
|
||||
- [equal](#equal)
|
||||
- [free](#free)
|
||||
- [PublicKey](#PublicKey)
|
||||
- [bytes](#bytes)
|
||||
- [equal](#equal)
|
||||
- [free](#free)
|
||||
- [verify](#verify)
|
||||
- [SignerOpts](#SignerOpts)
|
||||
|
||||
## generate_key
|
||||
```v
|
||||
fn generate_key(opt CurveOptions) !(PublicKey, PrivateKey)
|
||||
```
|
||||
|
||||
generate_key generates a new key pair. If opt was not provided, its default to prime256v1 curve. If you want another curve, use `pubkey, pivkey := ecdsa.generate_key(nid: .secp384r1)!` instead.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new_key_from_seed
|
||||
```v
|
||||
fn new_key_from_seed(seed []u8, opt CurveOptions) !PrivateKey
|
||||
```
|
||||
|
||||
new_key_from_seed creates a new private key from the seed bytes. If opt was not provided, its default to prime256v1 curve.
|
||||
|
||||
Notes on the seed:
|
||||
|
||||
You should make sure, the seed bytes come from a cryptographically secure random generator, likes the `crypto.rand` or other trusted sources. Internally, the seed size's would be checked to not exceed the key size of underlying curve, ie, 32 bytes length for p-256 and secp256k1, 48 bytes length for p-384 and 66 bytes length for p-521. Its recommended to use seed with bytes length matching with underlying curve key size.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## privkey_from_string
|
||||
```v
|
||||
fn privkey_from_string(s string) !PrivateKey
|
||||
```
|
||||
|
||||
privkey_from_string loads a PrivateKey from valid PEM-formatted string in s. Underlying wrapper support for old SECG and PKCS8 private key format, but this was not heavily tested. This routine does not support for the PKCS8 EncryptedPrivateKeyInfo format. See [ecdsa_seed_test.v](https://github.com/vlang/v/blob/master/vlib/crypto/ecdsa/example/ecdsa_seed_test.v) file for example of usage.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## pubkey_from_bytes
|
||||
```v
|
||||
fn pubkey_from_bytes(bytes []u8) !PublicKey
|
||||
```
|
||||
|
||||
pubkey_from_bytes loads ECDSA Public Key from bytes array. The bytes of data should be a valid of ASN.1 DER serialized SubjectPublicKeyInfo structrue of RFC 5480. Otherwise, its should an error. Typically, you can load the bytes from pem formatted of ecdsa public key.
|
||||
|
||||
Examples:
|
||||
```codeblock
|
||||
import crypto.pem
|
||||
import crypto.ecdsa
|
||||
|
||||
const pubkey_sample = '-----BEGIN PUBLIC KEY-----
|
||||
MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE+P3rhFkT1fXHYbY3CpcBdh6xTC74MQFx
|
||||
cftNVD3zEPVzo//OalIVatY162ksg8uRWBdvFFuHZ9OMVXkbjwWwhcXP7qmI9rOS
|
||||
LR3AGUldy+bBpV2nT306qCIwgUAMeOJP
|
||||
-----END PUBLIC KEY-----'
|
||||
|
||||
block, _ := pem.decode(pubkey_sample) or { panic(err) }
|
||||
pubkey := ecdsa.pubkey_from_bytes(block.data)!
|
||||
```
|
||||
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## pubkey_from_string
|
||||
```v
|
||||
fn pubkey_from_string(s string) !PublicKey
|
||||
```
|
||||
|
||||
pubkey_from_string loads a PublicKey from valid PEM-formatted string in s.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## PrivateKey.new
|
||||
```v
|
||||
fn PrivateKey.new(opt CurveOptions) !PrivateKey
|
||||
```
|
||||
|
||||
PrivateKey.new creates a new key pair. By default, it would create a prime256v1 based key. Dont forget to call `.free()` after finish with your key.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## HashConfig
|
||||
```v
|
||||
enum HashConfig {
|
||||
with_recommended_hash
|
||||
with_no_hash
|
||||
with_custom_hash
|
||||
}
|
||||
```
|
||||
|
||||
HashConfig is an enumeration of the possible options for key signing (verifying).
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Nid
|
||||
```v
|
||||
enum Nid {
|
||||
prime256v1 = C.NID_X9_62_prime256v1
|
||||
secp384r1 = C.NID_secp384r1
|
||||
secp521r1 = C.NID_secp521r1
|
||||
secp256k1 = C.NID_secp256k1
|
||||
}
|
||||
```
|
||||
|
||||
Nid is an enumeration of the supported curves
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## C.BIO
|
||||
```v
|
||||
struct C.BIO {}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## CurveOptions
|
||||
```v
|
||||
struct CurveOptions {
|
||||
pub mut:
|
||||
// default to NIST P-256 curve
|
||||
nid Nid = .prime256v1
|
||||
// by default, allow arbitrary size of seed bytes as key.
|
||||
// Set it to `true` when you need fixed size, using the curve key size.
|
||||
// Its main purposes is to support the `.new_key_from_seed` call.
|
||||
fixed_size bool
|
||||
}
|
||||
```
|
||||
|
||||
CurveOptions represents configuration options to drive keypair generation.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## PrivateKey
|
||||
```v
|
||||
struct PrivateKey {
|
||||
// The new high level of keypair opaque
|
||||
evpkey &C.EVP_PKEY
|
||||
mut:
|
||||
// ks_flag with .flexible value allowing
|
||||
// flexible-size seed bytes as key.
|
||||
// When it is `.fixed`, it will use the underlying key size.
|
||||
ks_flag KeyFlag = .flexible
|
||||
// ks_size stores size of the seed bytes when ks_flag was .flexible.
|
||||
// You should set it to a non zero value
|
||||
ks_size int
|
||||
}
|
||||
```
|
||||
|
||||
PrivateKey represents ECDSA private key. Actually its a key pair, contains private key and public key parts.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## sign
|
||||
```v
|
||||
fn (pv PrivateKey) sign(message []u8, opt SignerOpts) ![]u8
|
||||
```
|
||||
|
||||
sign performs signing the message with the options. By default options, it will perform hashing before signing the message.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## sign_with_options
|
||||
```v
|
||||
fn (pv PrivateKey) sign_with_options(message []u8, opt SignerOpts) ![]u8
|
||||
```
|
||||
|
||||
sign_with_options signs message with the options. It will be deprecated, Use `PrivateKey.sign()` instead.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## bytes
|
||||
```v
|
||||
fn (pv PrivateKey) bytes() ![]u8
|
||||
```
|
||||
|
||||
bytes represent private key as bytes.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## seed
|
||||
```v
|
||||
fn (pv PrivateKey) seed() ![]u8
|
||||
```
|
||||
|
||||
seed gets the seed (private key bytes). It will be deprecated. Use `PrivateKey.bytes()` instead.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## public_key
|
||||
```v
|
||||
fn (pv PrivateKey) public_key() !PublicKey
|
||||
```
|
||||
|
||||
public_key gets the PublicKey from private key.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## equal
|
||||
```v
|
||||
fn (priv_key PrivateKey) equal(other PrivateKey) bool
|
||||
```
|
||||
|
||||
equal compares two private keys was equal.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## free
|
||||
```v
|
||||
fn (pv &PrivateKey) free()
|
||||
```
|
||||
|
||||
free clears out allocated memory for PrivateKey. Dont use PrivateKey after calling `.free()`
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## PublicKey
|
||||
```v
|
||||
struct PublicKey {
|
||||
// The new high level of keypair opaque
|
||||
evpkey &C.EVP_PKEY
|
||||
}
|
||||
```
|
||||
|
||||
PublicKey represents ECDSA public key for verifying message.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## bytes
|
||||
```v
|
||||
fn (pbk PublicKey) bytes() ![]u8
|
||||
```
|
||||
|
||||
bytes gets the bytes of public key.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## equal
|
||||
```v
|
||||
fn (pub_key PublicKey) equal(other PublicKey) bool
|
||||
```
|
||||
|
||||
equal compares two public keys was equal.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## free
|
||||
```v
|
||||
fn (pb &PublicKey) free()
|
||||
```
|
||||
|
||||
free clears out allocated memory for PublicKey. Dont use PublicKey after calling `.free()`
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## verify
|
||||
```v
|
||||
fn (pb PublicKey) verify(message []u8, sig []u8, opt SignerOpts) !bool
|
||||
```
|
||||
|
||||
verify verifies a message with the signature are valid with public key provided . You should provide it with the same SignerOpts used with the `.sign()` call. or verify would fail (false).
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## SignerOpts
|
||||
```v
|
||||
struct SignerOpts {
|
||||
pub mut:
|
||||
// default to .with_recommended_hash
|
||||
hash_config HashConfig = .with_recommended_hash
|
||||
// make sense when HashConfig != with_recommended_hash
|
||||
allow_smaller_size bool
|
||||
allow_custom_hash bool
|
||||
// set to non-nil if allow_custom_hash was true
|
||||
custom_hash &hash.Hash = unsafe { nil }
|
||||
}
|
||||
```
|
||||
|
||||
SignerOpts represents configuration options to drive signing and verifying process.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:18:17
|
||||
150
aiprompts/v_core/crypto/ed25519.md
Normal file
150
aiprompts/v_core/crypto/ed25519.md
Normal file
@@ -0,0 +1,150 @@
|
||||
# module ed25519
|
||||
|
||||
|
||||
## Contents
|
||||
- [Constants](#Constants)
|
||||
- [generate_key](#generate_key)
|
||||
- [new_key_from_seed](#new_key_from_seed)
|
||||
- [sign](#sign)
|
||||
- [verify](#verify)
|
||||
- [PrivateKey](#PrivateKey)
|
||||
- [seed](#seed)
|
||||
- [public_key](#public_key)
|
||||
- [equal](#equal)
|
||||
- [sign](#sign)
|
||||
- [PublicKey](#PublicKey)
|
||||
- [equal](#equal)
|
||||
|
||||
## Constants
|
||||
```v
|
||||
const public_key_size = 32
|
||||
```
|
||||
|
||||
public_key_size is the sizeof public keys in bytes
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const private_key_size = 64
|
||||
```
|
||||
|
||||
private_key_size is the sizeof private keys in bytes
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const signature_size = 64
|
||||
```
|
||||
|
||||
signature_size is the size of signatures generated and verified by this modules, in bytes.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const seed_size = 32
|
||||
```
|
||||
|
||||
seed_size is the size of private key seeds in bytes
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## generate_key
|
||||
```v
|
||||
fn generate_key() !(PublicKey, PrivateKey)
|
||||
```
|
||||
|
||||
generate_key generates a public/private key pair entropy using `crypto.rand`.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new_key_from_seed
|
||||
```v
|
||||
fn new_key_from_seed(seed []u8) PrivateKey
|
||||
```
|
||||
|
||||
new_key_from_seed calculates a private key from a seed. private keys of RFC 8032 correspond to seeds in this module
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## sign
|
||||
```v
|
||||
fn sign(privatekey PrivateKey, message []u8) ![]u8
|
||||
```
|
||||
|
||||
sign`signs the message with privatekey and returns a signature
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## verify
|
||||
```v
|
||||
fn verify(publickey PublicKey, message []u8, sig []u8) !bool
|
||||
```
|
||||
|
||||
verify reports whether sig is a valid signature of message by publickey.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## PrivateKey
|
||||
```v
|
||||
type PrivateKey = []u8
|
||||
```
|
||||
|
||||
PrivateKey is Ed25519 private keys
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## seed
|
||||
```v
|
||||
fn (priv PrivateKey) seed() []u8
|
||||
```
|
||||
|
||||
seed returns the private key seed corresponding to priv. RFC 8032's private keys correspond to seeds in this module.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## public_key
|
||||
```v
|
||||
fn (priv PrivateKey) public_key() PublicKey
|
||||
```
|
||||
|
||||
public_key returns the []u8 corresponding to priv.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## equal
|
||||
```v
|
||||
fn (priv PrivateKey) equal(x []u8) bool
|
||||
```
|
||||
|
||||
currentyly x not `crypto.PrivateKey`
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## sign
|
||||
```v
|
||||
fn (priv PrivateKey) sign(message []u8) ![]u8
|
||||
```
|
||||
|
||||
sign signs the given message with priv.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## PublicKey
|
||||
```v
|
||||
type PublicKey = []u8
|
||||
```
|
||||
|
||||
`PublicKey` is Ed25519 public keys.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## equal
|
||||
```v
|
||||
fn (p PublicKey) equal(x []u8) bool
|
||||
```
|
||||
|
||||
equal reports whether p and x have the same value.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:18:17
|
||||
28
aiprompts/v_core/crypto/hmac.md
Normal file
28
aiprompts/v_core/crypto/hmac.md
Normal file
@@ -0,0 +1,28 @@
|
||||
# module hmac
|
||||
|
||||
|
||||
## Contents
|
||||
- [equal](#equal)
|
||||
- [new](#new)
|
||||
|
||||
## equal
|
||||
```v
|
||||
fn equal(mac1 []u8, mac2 []u8) bool
|
||||
```
|
||||
|
||||
equal compares 2 MACs for equality, without leaking timing info.
|
||||
|
||||
Note: if the lengths of the 2 MACs are different, probably a completely different hash function was used to generate them => no useful timing information.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new
|
||||
```v
|
||||
fn new(key []u8, data []u8, hash_func fn ([]u8) []u8, blocksize int) []u8
|
||||
```
|
||||
|
||||
new returns a HMAC byte array, depending on the hash algorithm used.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:18:17
|
||||
123
aiprompts/v_core/crypto/md5.md
Normal file
123
aiprompts/v_core/crypto/md5.md
Normal file
@@ -0,0 +1,123 @@
|
||||
# module md5
|
||||
|
||||
|
||||
## Contents
|
||||
- [Constants](#Constants)
|
||||
- [hexhash](#hexhash)
|
||||
- [new](#new)
|
||||
- [sum](#sum)
|
||||
- [Digest](#Digest)
|
||||
- [free](#free)
|
||||
- [reset](#reset)
|
||||
- [write](#write)
|
||||
- [sum](#sum)
|
||||
- [size](#size)
|
||||
- [block_size](#block_size)
|
||||
|
||||
## Constants
|
||||
```v
|
||||
const size = 16
|
||||
```
|
||||
|
||||
The size of an MD5 checksum in bytes.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const block_size = 64
|
||||
```
|
||||
|
||||
The blocksize of MD5 in bytes.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## hexhash
|
||||
```v
|
||||
fn hexhash(s string) string
|
||||
```
|
||||
|
||||
hexhash returns a hexadecimal MD5 hash sum `string` of `s`.
|
||||
|
||||
Example
|
||||
```v
|
||||
|
||||
assert md5.hexhash('V') == '5206560a306a2e085a437fd258eb57ce'
|
||||
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new
|
||||
```v
|
||||
fn new() &Digest
|
||||
```
|
||||
|
||||
new returns a new Digest (implementing hash.Hash) computing the MD5 checksum.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## sum
|
||||
```v
|
||||
fn sum(data []u8) []u8
|
||||
```
|
||||
|
||||
sum returns the MD5 checksum of the data.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Digest
|
||||
## free
|
||||
```v
|
||||
fn (mut d Digest) free()
|
||||
```
|
||||
|
||||
free the resources taken by the Digest `d`
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## reset
|
||||
```v
|
||||
fn (mut d Digest) reset()
|
||||
```
|
||||
|
||||
reset the state of the Digest `d`
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## write
|
||||
```v
|
||||
fn (mut d Digest) write(p_ []u8) !int
|
||||
```
|
||||
|
||||
write writes the contents of `p_` to the internal hash representation.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## sum
|
||||
```v
|
||||
fn (d &Digest) sum(b_in []u8) []u8
|
||||
```
|
||||
|
||||
sum returns the md5 sum of the bytes in `b_in`.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## size
|
||||
```v
|
||||
fn (d &Digest) size() int
|
||||
```
|
||||
|
||||
size returns the size of the checksum in bytes.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## block_size
|
||||
```v
|
||||
fn (d &Digest) block_size() int
|
||||
```
|
||||
|
||||
block_size returns the block size of the checksum in bytes.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:18:17
|
||||
16
aiprompts/v_core/crypto/pbkdf2.md
Normal file
16
aiprompts/v_core/crypto/pbkdf2.md
Normal file
@@ -0,0 +1,16 @@
|
||||
# module pbkdf2
|
||||
|
||||
|
||||
## Contents
|
||||
- [key](#key)
|
||||
|
||||
## key
|
||||
```v
|
||||
fn key(password []u8, salt []u8, count int, key_length int, h hash.Hash) ![]u8
|
||||
```
|
||||
|
||||
key derives a key from the password, salt and iteration count example pbkdf2.key('test'.bytes(), '123456'.bytes(), 1000, 64, sha512.new())
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:18:17
|
||||
137
aiprompts/v_core/crypto/pem.md
Normal file
137
aiprompts/v_core/crypto/pem.md
Normal file
@@ -0,0 +1,137 @@
|
||||
# module pem
|
||||
|
||||
|
||||
## Contents
|
||||
- [decode](#decode)
|
||||
- [decode_only](#decode_only)
|
||||
- [Block.new](#Block.new)
|
||||
- [Header](#Header)
|
||||
- [str](#str)
|
||||
- [Block](#Block)
|
||||
- [encode](#encode)
|
||||
- [free](#free)
|
||||
- [header_by_key](#header_by_key)
|
||||
- [EncodeConfig](#EncodeConfig)
|
||||
|
||||
## decode
|
||||
```v
|
||||
fn decode(data string) ?(Block, string)
|
||||
```
|
||||
|
||||
decode reads `data` and returns the first parsed PEM Block along with the rest of the string. `none` is returned when a header is expected, but not present or when a start of '-----BEGIN' or end of '-----END' can't be found.
|
||||
|
||||
use decode_only if you do not need the unparsed rest of the string.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## decode_only
|
||||
```v
|
||||
fn decode_only(data string) ?Block
|
||||
```
|
||||
|
||||
decode_only reads `data` and returns the first parsed PEM Block. `none` is returned when a header is expected, but not present or when a start of '-----BEGIN' or end of '-----END' can't be found.
|
||||
|
||||
use decode if you still need the unparsed rest of the string.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Block.new
|
||||
```v
|
||||
fn Block.new(block_type string) Block
|
||||
```
|
||||
|
||||
Block.new returns a new `Block` with the specified block_type
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Header
|
||||
```v
|
||||
enum Header {
|
||||
proctype
|
||||
contentdomain
|
||||
dekinfo
|
||||
origid_asymm
|
||||
origid_symm
|
||||
recipid_asymm
|
||||
recipid_symm
|
||||
cert
|
||||
issuercert
|
||||
micinfo
|
||||
keyinfo
|
||||
crl
|
||||
}
|
||||
```
|
||||
|
||||
Headers as described in RFC 1421 Section 9
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## str
|
||||
```v
|
||||
fn (header Header) str() string
|
||||
```
|
||||
|
||||
str returns the string representation of the header
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Block
|
||||
```v
|
||||
struct Block {
|
||||
pub mut:
|
||||
// from preamble
|
||||
block_type string
|
||||
// optional headers
|
||||
headers map[string][]string
|
||||
// decoded contents
|
||||
data []u8
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## encode
|
||||
```v
|
||||
fn (block Block) encode(config EncodeConfig) !string
|
||||
```
|
||||
|
||||
encode encodes the given block into a string using the EncodeConfig. It returns an error if `block_type` is undefined or if a value in `headers` contains an invalid character ':'
|
||||
|
||||
default EncodeConfig values wrap lines at 64 bytes and use '\n' for newlines
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## free
|
||||
```v
|
||||
fn (mut block Block) free()
|
||||
```
|
||||
|
||||
free the resources taken by the Block `block`
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## header_by_key
|
||||
```v
|
||||
fn (block Block) header_by_key(key Header) []string
|
||||
```
|
||||
|
||||
header_by_key returns the selected key using the Header enum
|
||||
|
||||
same as `block.headers[key.str()]`
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## EncodeConfig
|
||||
```v
|
||||
struct EncodeConfig {
|
||||
pub mut:
|
||||
// inner text wrap around
|
||||
line_length int = 64
|
||||
// line ending (alternatively '\r\n')
|
||||
line_ending string = '\n'
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:18:17
|
||||
60
aiprompts/v_core/crypto/rand.md
Normal file
60
aiprompts/v_core/crypto/rand.md
Normal file
@@ -0,0 +1,60 @@
|
||||
# module rand
|
||||
|
||||
|
||||
## Contents
|
||||
- [bytes](#bytes)
|
||||
- [int_big](#int_big)
|
||||
- [int_u64](#int_u64)
|
||||
- [read](#read)
|
||||
- [ReadError](#ReadError)
|
||||
- [msg](#msg)
|
||||
|
||||
## bytes
|
||||
```v
|
||||
fn bytes(bytes_needed int) ![]u8
|
||||
```
|
||||
|
||||
bytes returns an array of `bytes_needed` random bytes.
|
||||
|
||||
Note: this call can block your program for a long period of time, if your system does not have access to enough entropy. See also rand.bytes(), if you do not need really random bytes, but instead pseudo random ones, from a pseudo random generator that can be seeded, and that is usually faster.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## int_big
|
||||
```v
|
||||
fn int_big(n big.Integer) !big.Integer
|
||||
```
|
||||
|
||||
int_big creates a random `big.Integer` with range [0, n) returns an error if `n` is 0 or negative.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## int_u64
|
||||
```v
|
||||
fn int_u64(max u64) !u64
|
||||
```
|
||||
|
||||
int_u64 returns a random unsigned 64-bit integer `u64` read from a real OS source of entropy.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## read
|
||||
```v
|
||||
fn read(bytes_needed int) ![]u8
|
||||
```
|
||||
|
||||
read returns an array of `bytes_needed` random bytes read from the OS.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## ReadError
|
||||
## msg
|
||||
```v
|
||||
fn (err ReadError) msg() string
|
||||
```
|
||||
|
||||
msg returns the error message.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:18:17
|
||||
50
aiprompts/v_core/crypto/rc4.md
Normal file
50
aiprompts/v_core/crypto/rc4.md
Normal file
@@ -0,0 +1,50 @@
|
||||
# module rc4
|
||||
|
||||
|
||||
## Contents
|
||||
- [new_cipher](#new_cipher)
|
||||
- [Cipher](#Cipher)
|
||||
- [free](#free)
|
||||
- [reset](#reset)
|
||||
- [xor_key_stream](#xor_key_stream)
|
||||
|
||||
## new_cipher
|
||||
```v
|
||||
fn new_cipher(key []u8) !&Cipher
|
||||
```
|
||||
|
||||
new_cipher creates and returns a new Cipher. The key argument should be the RC4 key, at least 1 byte and at most 256 bytes.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Cipher
|
||||
## free
|
||||
```v
|
||||
fn (mut c Cipher) free()
|
||||
```
|
||||
|
||||
free the resources taken by the Cipher `c`
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## reset
|
||||
```v
|
||||
fn (mut c Cipher) reset()
|
||||
```
|
||||
|
||||
reset zeros the key data and makes the Cipher unusable.good to com
|
||||
|
||||
Deprecated: Reset can't guarantee that the key will be entirely removed from the process's memory.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## xor_key_stream
|
||||
```v
|
||||
fn (mut c Cipher) xor_key_stream(mut dst []u8, src []u8)
|
||||
```
|
||||
|
||||
xor_key_stream sets dst to the result of XORing src with the key stream. Dst and src must overlap entirely or not at all.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:18:17
|
||||
88
aiprompts/v_core/crypto/ripemd160.md
Normal file
88
aiprompts/v_core/crypto/ripemd160.md
Normal file
@@ -0,0 +1,88 @@
|
||||
# module ripemd160
|
||||
|
||||
|
||||
## Contents
|
||||
- [hexhash](#hexhash)
|
||||
- [new](#new)
|
||||
- [Digest](#Digest)
|
||||
- [free](#free)
|
||||
- [reset](#reset)
|
||||
- [size](#size)
|
||||
- [block_size](#block_size)
|
||||
- [write](#write)
|
||||
- [sum](#sum)
|
||||
|
||||
## hexhash
|
||||
```v
|
||||
fn hexhash(s string) string
|
||||
```
|
||||
|
||||
hexhash returns a hexadecimal RIPEMD-160 hash sum `string` of `s`.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new
|
||||
```v
|
||||
fn new() &Digest
|
||||
```
|
||||
|
||||
new returns a new Digest (implementing hash.Hash) computing the MD5 checksum.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Digest
|
||||
## free
|
||||
```v
|
||||
fn (mut d Digest) free()
|
||||
```
|
||||
|
||||
free the resources taken by the Digest `d`
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## reset
|
||||
```v
|
||||
fn (mut d Digest) reset()
|
||||
```
|
||||
|
||||
reset the state of the Digest `d`
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## size
|
||||
```v
|
||||
fn (d &Digest) size() int
|
||||
```
|
||||
|
||||
size returns the size of the checksum in bytes.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## block_size
|
||||
```v
|
||||
fn (d &Digest) block_size() int
|
||||
```
|
||||
|
||||
block_size returns the block size of the checksum in bytes.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## write
|
||||
```v
|
||||
fn (mut d Digest) write(p_ []u8) !int
|
||||
```
|
||||
|
||||
write writes the contents of `p_` to the internal hash representation.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## sum
|
||||
```v
|
||||
fn (d0 &Digest) sum(inp []u8) []u8
|
||||
```
|
||||
|
||||
sum returns the RIPEMD-160 sum of the bytes in `inp`.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:18:17
|
||||
36
aiprompts/v_core/crypto/scrypt.md
Normal file
36
aiprompts/v_core/crypto/scrypt.md
Normal file
@@ -0,0 +1,36 @@
|
||||
# module scrypt
|
||||
|
||||
|
||||
## Contents
|
||||
- [Constants](#Constants)
|
||||
- [scrypt](#scrypt)
|
||||
|
||||
## Constants
|
||||
```v
|
||||
const max_buffer_length = ((u64(1) << 32) - 1) * 32
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const max_blocksize_parallal_product = u64(1 << 30)
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## scrypt
|
||||
```v
|
||||
fn scrypt(password []u8, salt []u8, n u64, r u32, p u32, dk_len u64) ![]u8
|
||||
```
|
||||
|
||||
scrypt performs password based key derivation using the scrypt algorithm.
|
||||
|
||||
The input parameters are:
|
||||
|
||||
password - a slice of bytes which is the password being used to derive the key. Don't leak this value to anybody. salt - a slice of bytes used to make it harder to crack the key. n - CPU/Memory cost parameter, must be larger than 0, a power of 2, and less than 2^(128 * r / 8). r - block size parameter. p - parallelization parameter, a positive integer less than or equal to ((2^32-1) * hLen) / MFLen where hLen is 32 and MFlen is 128 * r. dk_len - intended output length in octets of the derived key; a positive integer less than or equal to (2^32 - 1) * hLen where hLen is 32.
|
||||
|
||||
Reasonable values for n, r, and p are n = 1024, r = 8, p = 16.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:18:17
|
||||
116
aiprompts/v_core/crypto/sha1.md
Normal file
116
aiprompts/v_core/crypto/sha1.md
Normal file
@@ -0,0 +1,116 @@
|
||||
# module sha1
|
||||
|
||||
|
||||
## Contents
|
||||
- [Constants](#Constants)
|
||||
- [hexhash](#hexhash)
|
||||
- [new](#new)
|
||||
- [sum](#sum)
|
||||
- [Digest](#Digest)
|
||||
- [free](#free)
|
||||
- [reset](#reset)
|
||||
- [write](#write)
|
||||
- [sum](#sum)
|
||||
- [size](#size)
|
||||
- [block_size](#block_size)
|
||||
|
||||
## Constants
|
||||
```v
|
||||
const size = 20
|
||||
```
|
||||
|
||||
The size of a SHA-1 checksum in bytes.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const block_size = 64
|
||||
```
|
||||
|
||||
The blocksize of SHA-1 in bytes.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## hexhash
|
||||
```v
|
||||
fn hexhash(s string) string
|
||||
```
|
||||
|
||||
hexhash returns a hexadecimal SHA1 hash sum `string` of `s`.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new
|
||||
```v
|
||||
fn new() &Digest
|
||||
```
|
||||
|
||||
new returns a new Digest (implementing hash.Hash) computing the SHA1 checksum.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## sum
|
||||
```v
|
||||
fn sum(data []u8) []u8
|
||||
```
|
||||
|
||||
sum returns the SHA-1 checksum of the bytes passed in `data`.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Digest
|
||||
## free
|
||||
```v
|
||||
fn (mut d Digest) free()
|
||||
```
|
||||
|
||||
free the resources taken by the Digest `d`
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## reset
|
||||
```v
|
||||
fn (mut d Digest) reset()
|
||||
```
|
||||
|
||||
reset the state of the Digest `d`
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## write
|
||||
```v
|
||||
fn (mut d Digest) write(p_ []u8) !int
|
||||
```
|
||||
|
||||
write writes the contents of `p_` to the internal hash representation.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## sum
|
||||
```v
|
||||
fn (d &Digest) sum(b_in []u8) []u8
|
||||
```
|
||||
|
||||
sum returns a copy of the generated sum of the bytes in `b_in`.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## size
|
||||
```v
|
||||
fn (d &Digest) size() int
|
||||
```
|
||||
|
||||
size returns the size of the checksum in bytes.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## block_size
|
||||
```v
|
||||
fn (d &Digest) block_size() int
|
||||
```
|
||||
|
||||
block_size returns the block size of the checksum in bytes.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:18:17
|
||||
178
aiprompts/v_core/crypto/sha256.md
Normal file
178
aiprompts/v_core/crypto/sha256.md
Normal file
@@ -0,0 +1,178 @@
|
||||
# module sha256
|
||||
|
||||
|
||||
## Contents
|
||||
- [Constants](#Constants)
|
||||
- [hexhash](#hexhash)
|
||||
- [hexhash_224](#hexhash_224)
|
||||
- [new](#new)
|
||||
- [new224](#new224)
|
||||
- [sum](#sum)
|
||||
- [sum224](#sum224)
|
||||
- [sum256](#sum256)
|
||||
- [Digest](#Digest)
|
||||
- [free](#free)
|
||||
- [reset](#reset)
|
||||
- [write](#write)
|
||||
- [sum](#sum)
|
||||
- [size](#size)
|
||||
- [block_size](#block_size)
|
||||
|
||||
## Constants
|
||||
```v
|
||||
const size = 32
|
||||
```
|
||||
|
||||
The size of a SHA256 checksum in bytes.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const size224 = 28
|
||||
```
|
||||
|
||||
The size of a SHA224 checksum in bytes.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const block_size = 64
|
||||
```
|
||||
|
||||
The blocksize of SHA256 and SHA224 in bytes.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## hexhash
|
||||
```v
|
||||
fn hexhash(s string) string
|
||||
```
|
||||
|
||||
hexhash returns a hexadecimal SHA256 hash sum `string` of `s`.
|
||||
|
||||
Example
|
||||
```v
|
||||
|
||||
assert sha256.hexhash('V') == 'de5a6f78116eca62d7fc5ce159d23ae6b889b365a1739ad2cf36f925a140d0cc'
|
||||
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## hexhash_224
|
||||
```v
|
||||
fn hexhash_224(s string) string
|
||||
```
|
||||
|
||||
hexhash_224 returns a hexadecimal SHA224 hash sum `string` of `s`.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new
|
||||
```v
|
||||
fn new() &Digest
|
||||
```
|
||||
|
||||
new returns a new Digest (implementing hash.Hash) computing the SHA256 checksum.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new224
|
||||
```v
|
||||
fn new224() &Digest
|
||||
```
|
||||
|
||||
new224 returns a new Digest (implementing hash.Hash) computing the SHA224 checksum.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## sum
|
||||
```v
|
||||
fn sum(data []u8) []u8
|
||||
```
|
||||
|
||||
sum returns the SHA256 checksum of the bytes in `data`.
|
||||
|
||||
Example
|
||||
```v
|
||||
|
||||
assert sha256.sum('V'.bytes()).len > 0 == true
|
||||
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## sum224
|
||||
```v
|
||||
fn sum224(data []u8) []u8
|
||||
```
|
||||
|
||||
sum224 returns the SHA224 checksum of the data.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## sum256
|
||||
```v
|
||||
fn sum256(data []u8) []u8
|
||||
```
|
||||
|
||||
sum256 returns the SHA256 checksum of the data.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Digest
|
||||
## free
|
||||
```v
|
||||
fn (mut d Digest) free()
|
||||
```
|
||||
|
||||
free the resources taken by the Digest `d`
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## reset
|
||||
```v
|
||||
fn (mut d Digest) reset()
|
||||
```
|
||||
|
||||
reset the state of the Digest `d`
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## write
|
||||
```v
|
||||
fn (mut d Digest) write(p_ []u8) !int
|
||||
```
|
||||
|
||||
write writes the contents of `p_` to the internal hash representation.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## sum
|
||||
```v
|
||||
fn (d &Digest) sum(b_in []u8) []u8
|
||||
```
|
||||
|
||||
sum returns the SHA256 or SHA224 checksum of digest with the data.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## size
|
||||
```v
|
||||
fn (d &Digest) size() int
|
||||
```
|
||||
|
||||
size returns the size of the checksum in bytes.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## block_size
|
||||
```v
|
||||
fn (d &Digest) block_size() int
|
||||
```
|
||||
|
||||
block_size returns the block size of the checksum in bytes.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:18:17
|
||||
327
aiprompts/v_core/crypto/sha3.md
Normal file
327
aiprompts/v_core/crypto/sha3.md
Normal file
@@ -0,0 +1,327 @@
|
||||
# module sha3
|
||||
|
||||
|
||||
## Contents
|
||||
- [Constants](#Constants)
|
||||
- [keccak256](#keccak256)
|
||||
- [keccak512](#keccak512)
|
||||
- [new128xof](#new128xof)
|
||||
- [new224](#new224)
|
||||
- [new256](#new256)
|
||||
- [new256keccak](#new256keccak)
|
||||
- [new256xof](#new256xof)
|
||||
- [new384](#new384)
|
||||
- [new512](#new512)
|
||||
- [new512keccak](#new512keccak)
|
||||
- [new_digest](#new_digest)
|
||||
- [new_xof_digest](#new_xof_digest)
|
||||
- [shake128](#shake128)
|
||||
- [shake256](#shake256)
|
||||
- [sum224](#sum224)
|
||||
- [sum256](#sum256)
|
||||
- [sum384](#sum384)
|
||||
- [sum512](#sum512)
|
||||
- [Digest](#Digest)
|
||||
- [write](#write)
|
||||
- [checksum](#checksum)
|
||||
- [Padding](#Padding)
|
||||
- [PaddingConfig](#PaddingConfig)
|
||||
|
||||
## Constants
|
||||
```v
|
||||
const size_224 = 28
|
||||
```
|
||||
|
||||
size_224 is the size, in bytes, of a sha3 sum224 checksum.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const size_256 = 32
|
||||
```
|
||||
|
||||
size_256 is the size, in bytes, of a sha3 sum256 checksum.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const size_384 = 48
|
||||
```
|
||||
|
||||
size_384 is the size, in bytes, of a sha3 sum384 checksum.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const size_512 = 64
|
||||
```
|
||||
|
||||
size_512 is the size, in bytes, of a sha3 sum512 checksum.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const rate_224 = 144
|
||||
```
|
||||
|
||||
rate_224 is the rate, in bytes, absorbed into the sponge on every permutation
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const rate_256 = 136
|
||||
```
|
||||
|
||||
rate_256 is the rate, in bytes, absorbed into the sponge on every permutation
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const rate_384 = 104
|
||||
```
|
||||
|
||||
rate_384 is the rate, in bytes, absorbed into the sponge on every permutation
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const rate_512 = 72
|
||||
```
|
||||
|
||||
rate_512 is the rate, in bytes, absorbed into the sponge on every permutation
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const xof_rate_128 = 168
|
||||
```
|
||||
|
||||
xof_rate_128 is the capacity, in bytes, of a 128 bit extended output function sponge
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const xof_rate_256 = 136
|
||||
```
|
||||
|
||||
xof_rate_256 is the capacity, in bytes, of a 256 bit extended output function sponge
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## keccak256
|
||||
```v
|
||||
fn keccak256(data []u8) []u8
|
||||
```
|
||||
|
||||
keccak256 returns the keccak 256 bit checksum of the data.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## keccak512
|
||||
```v
|
||||
fn keccak512(data []u8) []u8
|
||||
```
|
||||
|
||||
keccak512 returns the keccak 512 bit checksum of the data.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new128xof
|
||||
```v
|
||||
fn new128xof(output_len int) !&Digest
|
||||
```
|
||||
|
||||
new128_xof initializes the digest structure for a sha3 128 bit extended output function
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new224
|
||||
```v
|
||||
fn new224() !&Digest
|
||||
```
|
||||
|
||||
new224 initializes the digest structure for a sha3 224 bit hash
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new256
|
||||
```v
|
||||
fn new256() !&Digest
|
||||
```
|
||||
|
||||
new256 initializes the digest structure for a sha3 256 bit hash
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new256keccak
|
||||
```v
|
||||
fn new256keccak() !&Digest
|
||||
```
|
||||
|
||||
new256keccak initializes the digest structure for a keccak 256 bit hash
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new256xof
|
||||
```v
|
||||
fn new256xof(output_len int) !&Digest
|
||||
```
|
||||
|
||||
new256_xof initializes the digest structure for a sha3 256 bit extended output function
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new384
|
||||
```v
|
||||
fn new384() !&Digest
|
||||
```
|
||||
|
||||
new384 initializes the digest structure for a sha3 384 bit hash
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new512
|
||||
```v
|
||||
fn new512() !&Digest
|
||||
```
|
||||
|
||||
new512 initializes the digest structure for a sha3 512 bit hash
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new512keccak
|
||||
```v
|
||||
fn new512keccak() !&Digest
|
||||
```
|
||||
|
||||
new512keccak initializes the digest structure for a keccak 512 bit hash
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new_digest
|
||||
```v
|
||||
fn new_digest(absorption_rate int, hash_size int, config PaddingConfig) !&Digest
|
||||
```
|
||||
|
||||
new_digest creates an initialized digest structure based on the hash size.
|
||||
|
||||
absorption_rate is the number of bytes to be absorbed into the sponge per permutation.
|
||||
|
||||
hash_size - the number if bytes in the generated hash. Legal values are 224, 256, 384, and 512.
|
||||
|
||||
config - the padding setting for hash generation. .sha3 should be used for FIPS PUB 202 compliant SHA3-224, SHA3-256, SHA3-384 and SHA3-512. Use .keccak if you want a legacy Keccak-224, Keccak-256, Keccak-384 or Keccak-512 algorithm. .xof is for extended output functions.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new_xof_digest
|
||||
```v
|
||||
fn new_xof_digest(absorption_rate int, hash_size int) !&Digest
|
||||
```
|
||||
|
||||
new_xof_digest creates an initialized digest structure based on the absorption rate and how many bytes of output you need
|
||||
|
||||
absorption_rate is the number of bytes to be absorbed into the sponge per permutation. Legal values are xof_rate_128 and xof_rate_256.
|
||||
|
||||
hash_size - the number if bytes in the generated hash. Legal values are positive integers.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## shake128
|
||||
```v
|
||||
fn shake128(data []u8, output_len int) []u8
|
||||
```
|
||||
|
||||
shake128 returns the sha3 shake128 bit extended output
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## shake256
|
||||
```v
|
||||
fn shake256(data []u8, output_len int) []u8
|
||||
```
|
||||
|
||||
shake256 returns the sha3 shake256 bit extended output
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## sum224
|
||||
```v
|
||||
fn sum224(data []u8) []u8
|
||||
```
|
||||
|
||||
sum224 returns the sha3 224 bit checksum of the data.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## sum256
|
||||
```v
|
||||
fn sum256(data []u8) []u8
|
||||
```
|
||||
|
||||
sum256 returns the sha3 256 bit checksum of the data.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## sum384
|
||||
```v
|
||||
fn sum384(data []u8) []u8
|
||||
```
|
||||
|
||||
sum384 returns the sha3 384 bit checksum of the data.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## sum512
|
||||
```v
|
||||
fn sum512(data []u8) []u8
|
||||
```
|
||||
|
||||
sum512 returns the sha3 512 bit checksum of the data.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Digest
|
||||
## write
|
||||
```v
|
||||
fn (mut d Digest) write(data []u8) !
|
||||
```
|
||||
|
||||
write adds bytes to the sponge.
|
||||
|
||||
This is the absorption phase of the computation.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## checksum
|
||||
```v
|
||||
fn (mut d Digest) checksum() []u8
|
||||
```
|
||||
|
||||
checksum finalizes the hash and returns the generated bytes.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Padding
|
||||
```v
|
||||
enum Padding as u8 {
|
||||
keccak = 0x01
|
||||
sha3 = 0x06
|
||||
xof = 0x1f
|
||||
}
|
||||
```
|
||||
|
||||
the low order pad bits for a hash function
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## PaddingConfig
|
||||
```v
|
||||
struct PaddingConfig {
|
||||
pub:
|
||||
padding Padding = .sha3
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:18:17
|
||||
230
aiprompts/v_core/crypto/sha512.md
Normal file
230
aiprompts/v_core/crypto/sha512.md
Normal file
@@ -0,0 +1,230 @@
|
||||
# module sha512
|
||||
|
||||
|
||||
## Contents
|
||||
- [Constants](#Constants)
|
||||
- [hexhash](#hexhash)
|
||||
- [hexhash_384](#hexhash_384)
|
||||
- [hexhash_512_224](#hexhash_512_224)
|
||||
- [hexhash_512_256](#hexhash_512_256)
|
||||
- [new](#new)
|
||||
- [new384](#new384)
|
||||
- [new512_224](#new512_224)
|
||||
- [new512_256](#new512_256)
|
||||
- [sum384](#sum384)
|
||||
- [sum512](#sum512)
|
||||
- [sum512_224](#sum512_224)
|
||||
- [sum512_256](#sum512_256)
|
||||
- [Digest](#Digest)
|
||||
- [free](#free)
|
||||
- [reset](#reset)
|
||||
- [write](#write)
|
||||
- [sum](#sum)
|
||||
- [size](#size)
|
||||
- [block_size](#block_size)
|
||||
|
||||
## Constants
|
||||
```v
|
||||
const size = 64
|
||||
```
|
||||
|
||||
size is the size, in bytes, of a SHA-512 checksum.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const size224 = 28
|
||||
```
|
||||
|
||||
size224 is the size, in bytes, of a SHA-512/224 checksum.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const size256 = 32
|
||||
```
|
||||
|
||||
size256 is the size, in bytes, of a SHA-512/256 checksum.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const size384 = 48
|
||||
```
|
||||
|
||||
size384 is the size, in bytes, of a SHA-384 checksum.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const block_size = 128
|
||||
```
|
||||
|
||||
block_size is the block size, in bytes, of the SHA-512/224, SHA-512/256, SHA-384 and SHA-512 hash functions.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## hexhash
|
||||
```v
|
||||
fn hexhash(s string) string
|
||||
```
|
||||
|
||||
hexhash returns a hexadecimal SHA512 hash sum `string` of `s`.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## hexhash_384
|
||||
```v
|
||||
fn hexhash_384(s string) string
|
||||
```
|
||||
|
||||
hexhash_384 returns a hexadecimal SHA384 hash sum `string` of `s`.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## hexhash_512_224
|
||||
```v
|
||||
fn hexhash_512_224(s string) string
|
||||
```
|
||||
|
||||
hexhash_512_224 returns a hexadecimal SHA512/224 hash sum `string` of `s`.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## hexhash_512_256
|
||||
```v
|
||||
fn hexhash_512_256(s string) string
|
||||
```
|
||||
|
||||
hexhash_512_256 returns a hexadecimal 512/256 hash sum `string` of `s`.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new
|
||||
```v
|
||||
fn new() &Digest
|
||||
```
|
||||
|
||||
new returns a new Digest (implementing hash.Hash) computing the SHA-512 checksum.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new384
|
||||
```v
|
||||
fn new384() &Digest
|
||||
```
|
||||
|
||||
new384 returns a new Digest (implementing hash.Hash) computing the SHA-384 checksum.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new512_224
|
||||
```v
|
||||
fn new512_224() &Digest
|
||||
```
|
||||
|
||||
new512_224 returns a new Digest (implementing hash.Hash) computing the SHA-512/224 checksum.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new512_256
|
||||
```v
|
||||
fn new512_256() &Digest
|
||||
```
|
||||
|
||||
new512_256 returns a new Digest (implementing hash.Hash) computing the SHA-512/256 checksum.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## sum384
|
||||
```v
|
||||
fn sum384(data []u8) []u8
|
||||
```
|
||||
|
||||
sum384 returns the SHA384 checksum of the data.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## sum512
|
||||
```v
|
||||
fn sum512(data []u8) []u8
|
||||
```
|
||||
|
||||
sum512 returns the SHA512 checksum of the data.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## sum512_224
|
||||
```v
|
||||
fn sum512_224(data []u8) []u8
|
||||
```
|
||||
|
||||
sum512_224 returns the Sum512/224 checksum of the data.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## sum512_256
|
||||
```v
|
||||
fn sum512_256(data []u8) []u8
|
||||
```
|
||||
|
||||
sum512_256 returns the Sum512/256 checksum of the data.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Digest
|
||||
## free
|
||||
```v
|
||||
fn (mut d Digest) free()
|
||||
```
|
||||
|
||||
free the resources taken by the Digest `d`
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## reset
|
||||
```v
|
||||
fn (mut d Digest) reset()
|
||||
```
|
||||
|
||||
reset the state of the Digest `d`
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## write
|
||||
```v
|
||||
fn (mut d Digest) write(p_ []u8) !int
|
||||
```
|
||||
|
||||
write writes the contents of `p_` to the internal hash representation.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## sum
|
||||
```v
|
||||
fn (d &Digest) sum(b_in []u8) []u8
|
||||
```
|
||||
|
||||
sum returns the SHA512 or SHA384 checksum of digest with the data bytes in `b_in`
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## size
|
||||
```v
|
||||
fn (d &Digest) size() int
|
||||
```
|
||||
|
||||
size returns the size of the checksum in bytes.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## block_size
|
||||
```v
|
||||
fn (d &Digest) block_size() int
|
||||
```
|
||||
|
||||
block_size returns the block size of the checksum in bytes.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:18:17
|
||||
184
aiprompts/v_core/encoding/base32.md
Normal file
184
aiprompts/v_core/encoding/base32.md
Normal file
@@ -0,0 +1,184 @@
|
||||
# module base32
|
||||
|
||||
|
||||
## Contents
|
||||
- [Constants](#Constants)
|
||||
- [decode](#decode)
|
||||
- [decode_string_to_string](#decode_string_to_string)
|
||||
- [decode_to_string](#decode_to_string)
|
||||
- [encode](#encode)
|
||||
- [encode_string_to_string](#encode_string_to_string)
|
||||
- [encode_to_string](#encode_to_string)
|
||||
- [new_encoding](#new_encoding)
|
||||
- [new_encoding_with_padding](#new_encoding_with_padding)
|
||||
- [new_std_encoding](#new_std_encoding)
|
||||
- [new_std_encoding_with_padding](#new_std_encoding_with_padding)
|
||||
- [Encoding](#Encoding)
|
||||
- [encode_to_string](#encode_to_string)
|
||||
- [encode_string_to_string](#encode_string_to_string)
|
||||
- [decode_string](#decode_string)
|
||||
- [decode_string_to_string](#decode_string_to_string)
|
||||
- [decode](#decode)
|
||||
|
||||
## Constants
|
||||
```v
|
||||
const std_padding = `=` // Standard padding character
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const no_padding = u8(-1) // No padding
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const std_alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567'.bytes()
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const hex_alphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUV'.bytes()
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## decode
|
||||
```v
|
||||
fn decode(src []u8) ![]u8
|
||||
```
|
||||
|
||||
decode decodes a byte array `src` using Base32 and returns the decoded bytes or a `corrupt_input_error_msg` error.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## decode_string_to_string
|
||||
```v
|
||||
fn decode_string_to_string(src string) !string
|
||||
```
|
||||
|
||||
decode_string_to_string decodes a V string `src` using Base32 and returns the decoded string or a `corrupt_input_error_msg` error.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## decode_to_string
|
||||
```v
|
||||
fn decode_to_string(src []u8) !string
|
||||
```
|
||||
|
||||
decode_to_string decodes a byte array `src` using Base32 and returns the decoded string or a `corrupt_input_error_msg` error.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## encode
|
||||
```v
|
||||
fn encode(src []u8) []u8
|
||||
```
|
||||
|
||||
encode encodes a byte array `src` using Base32 and returns the encoded bytes.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## encode_string_to_string
|
||||
```v
|
||||
fn encode_string_to_string(src string) string
|
||||
```
|
||||
|
||||
encode_string_to_string encodes the V string `src` using Base32 and returns the encoded bytes as a V string.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## encode_to_string
|
||||
```v
|
||||
fn encode_to_string(src []u8) string
|
||||
```
|
||||
|
||||
encode_to_string encodes a byte array `src` using Base32 and returns the encoded bytes as a V string.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new_encoding
|
||||
```v
|
||||
fn new_encoding(alphabet []u8) Encoding
|
||||
```
|
||||
|
||||
new_encoding returns a Base32 `Encoding` with standard `alphabet`s and standard padding.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new_encoding_with_padding
|
||||
```v
|
||||
fn new_encoding_with_padding(alphabet []u8, padding_char u8) Encoding
|
||||
```
|
||||
|
||||
new_encoding_with_padding returns a Base32 `Encoding` with specified encoding `alphabet`s and a specified `padding_char`. The `padding_char` must not be '\r' or '\n', must not be contained in the `Encoding`'s alphabet and must be a rune equal or below '\xff'.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new_std_encoding
|
||||
```v
|
||||
fn new_std_encoding() Encoding
|
||||
```
|
||||
|
||||
new_std_encoding creates a standard Base32 `Encoding` as defined in RFC 4648.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new_std_encoding_with_padding
|
||||
```v
|
||||
fn new_std_encoding_with_padding(padding u8) Encoding
|
||||
```
|
||||
|
||||
new_std_encoding creates a standard Base32 `Encoding` identical to `new_std_encoding` but with a specified character `padding`, or `no_padding` to disable padding. The `padding` character must not be '\r' or '\n', must not be contained in the `Encoding`'s alphabet and must be a rune equal or below '\xff'.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Encoding
|
||||
## encode_to_string
|
||||
```v
|
||||
fn (enc &Encoding) encode_to_string(src []u8) string
|
||||
```
|
||||
|
||||
encode_to_string encodes the Base32 encoding of `src` with the encoding `enc` and returns the encoded bytes as a V string.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## encode_string_to_string
|
||||
```v
|
||||
fn (enc &Encoding) encode_string_to_string(src string) string
|
||||
```
|
||||
|
||||
encode_string_to_string encodes a V string `src` using Base32 with the encoding `enc` and returns the encoded bytes as a V string.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## decode_string
|
||||
```v
|
||||
fn (enc &Encoding) decode_string(src string) ![]u8
|
||||
```
|
||||
|
||||
decode_string decodes a V string `src` using Base32 with the encoding `enc` and returns the decoded bytes or a `corrupt_input_error_msg` error.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## decode_string_to_string
|
||||
```v
|
||||
fn (enc &Encoding) decode_string_to_string(src string) !string
|
||||
```
|
||||
|
||||
decode_string_to_string decodes a V string `src` using Base32 with the encoding `enc` and returns the decoded V string or a `corrupt_input_error_msg` error.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## decode
|
||||
```v
|
||||
fn (enc &Encoding) decode(src []u8) ![]u8
|
||||
```
|
||||
|
||||
decode decodes `src` using the encoding `enc`. It returns the decoded bytes written or a `corrupt_input_error_msg` error. New line characters (\r and \n) are ignored.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:18:04
|
||||
186
aiprompts/v_core/encoding/base58.md
Normal file
186
aiprompts/v_core/encoding/base58.md
Normal file
@@ -0,0 +1,186 @@
|
||||
# module base58
|
||||
|
||||
|
||||
## Contents
|
||||
- [Constants](#Constants)
|
||||
- [decode](#decode)
|
||||
- [decode_bytes](#decode_bytes)
|
||||
- [decode_int](#decode_int)
|
||||
- [decode_int_walpha](#decode_int_walpha)
|
||||
- [decode_walpha](#decode_walpha)
|
||||
- [decode_walpha_bytes](#decode_walpha_bytes)
|
||||
- [encode](#encode)
|
||||
- [encode_bytes](#encode_bytes)
|
||||
- [encode_int](#encode_int)
|
||||
- [encode_int_walpha](#encode_int_walpha)
|
||||
- [encode_walpha](#encode_walpha)
|
||||
- [encode_walpha_bytes](#encode_walpha_bytes)
|
||||
- [new_alphabet](#new_alphabet)
|
||||
- [Alphabet](#Alphabet)
|
||||
- [str](#str)
|
||||
|
||||
## Constants
|
||||
```v
|
||||
const btc_alphabet = new_alphabet('123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz') or {
|
||||
panic(impossible)
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const flickr_alphabet = new_alphabet('123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ') or {
|
||||
panic(impossible)
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const ripple_alphabet = new_alphabet('rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz') or {
|
||||
panic(impossible)
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const alphabets = {
|
||||
'btc': btc_alphabet
|
||||
'flickr': flickr_alphabet
|
||||
'ripple': ripple_alphabet
|
||||
}
|
||||
```
|
||||
|
||||
alphabets is a map of common base58 alphabets:
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## decode
|
||||
```v
|
||||
fn decode(str string) !string
|
||||
```
|
||||
|
||||
decode decodes the base58 input string, using the Bitcoin alphabet
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## decode_bytes
|
||||
```v
|
||||
fn decode_bytes(input []u8) ![]u8
|
||||
```
|
||||
|
||||
decode_bytes decodes the base58 encoded input array, using the Bitcoin alphabet
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## decode_int
|
||||
```v
|
||||
fn decode_int(input string) !int
|
||||
```
|
||||
|
||||
decode_int decodes base58 string to an integer with Bitcoin alphabet
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## decode_int_walpha
|
||||
```v
|
||||
fn decode_int_walpha(input string, alphabet Alphabet) !int
|
||||
```
|
||||
|
||||
decode_int_walpha decodes base58 string to an integer with custom alphabet
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## decode_walpha
|
||||
```v
|
||||
fn decode_walpha(input string, alphabet Alphabet) !string
|
||||
```
|
||||
|
||||
decode_walpha decodes the base58 encoded input string, using custom alphabet
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## decode_walpha_bytes
|
||||
```v
|
||||
fn decode_walpha_bytes(input []u8, alphabet Alphabet) ![]u8
|
||||
```
|
||||
|
||||
decode_walpha_bytes decodes the base58 encoded input array using a custom alphabet
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## encode
|
||||
```v
|
||||
fn encode(input string) string
|
||||
```
|
||||
|
||||
encode encodes the input string to base58 with the Bitcoin alphabet
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## encode_bytes
|
||||
```v
|
||||
fn encode_bytes(input []u8) []u8
|
||||
```
|
||||
|
||||
encode_bytes encodes the input array to base58, with the Bitcoin alphabet
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## encode_int
|
||||
```v
|
||||
fn encode_int(input int) !string
|
||||
```
|
||||
|
||||
encode_int encodes any integer type to base58 string with Bitcoin alphabet
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## encode_int_walpha
|
||||
```v
|
||||
fn encode_int_walpha(input int, alphabet Alphabet) !string
|
||||
```
|
||||
|
||||
encode_int_walpha any integer type to base58 string with custom alphabet
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## encode_walpha
|
||||
```v
|
||||
fn encode_walpha(input string, alphabet Alphabet) string
|
||||
```
|
||||
|
||||
encode_walpha encodes the input string to base58 with a custom aplhabet
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## encode_walpha_bytes
|
||||
```v
|
||||
fn encode_walpha_bytes(input []u8, alphabet Alphabet) []u8
|
||||
```
|
||||
|
||||
encode_walpha encodes the input array to base58 with a custom aplhabet
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new_alphabet
|
||||
```v
|
||||
fn new_alphabet(str string) !Alphabet
|
||||
```
|
||||
|
||||
new_alphabet instantiates an Alphabet object based on the provided characters
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Alphabet
|
||||
## str
|
||||
```v
|
||||
fn (alphabet Alphabet) str() string
|
||||
```
|
||||
|
||||
str returns an Alphabet encode table byte array as a string
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:18:04
|
||||
130
aiprompts/v_core/encoding/base64.md
Normal file
130
aiprompts/v_core/encoding/base64.md
Normal file
@@ -0,0 +1,130 @@
|
||||
# module base64
|
||||
|
||||
|
||||
## Contents
|
||||
- [decode](#decode)
|
||||
- [decode_in_buffer](#decode_in_buffer)
|
||||
- [decode_in_buffer_bytes](#decode_in_buffer_bytes)
|
||||
- [decode_str](#decode_str)
|
||||
- [encode](#encode)
|
||||
- [encode_in_buffer](#encode_in_buffer)
|
||||
- [encode_str](#encode_str)
|
||||
- [url_decode](#url_decode)
|
||||
- [url_decode_str](#url_decode_str)
|
||||
- [url_encode](#url_encode)
|
||||
- [url_encode_str](#url_encode_str)
|
||||
|
||||
## decode
|
||||
```v
|
||||
fn decode(data string) []u8
|
||||
```
|
||||
|
||||
decode decodes the base64 encoded `string` value passed in `data`. Please note: If you need to decode many strings repeatedly, take a look at `decode_in_buffer`.
|
||||
|
||||
Example
|
||||
```v
|
||||
|
||||
assert base64.decode('ViBpbiBiYXNlIDY0') == 'V in base 64'.bytes()
|
||||
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## decode_in_buffer
|
||||
```v
|
||||
fn decode_in_buffer(data &string, buffer &u8) int
|
||||
```
|
||||
|
||||
decode_in_buffer decodes the base64 encoded `string` reference passed in `data` into `buffer`. decode_in_buffer returns the size of the decoded data in the buffer. Please note: The `buffer` should be large enough (i.e. 3/4 of the data.len, or larger) to hold the decoded data. Please note: This function does NOT allocate new memory, and is thus suitable for handling very large strings.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## decode_in_buffer_bytes
|
||||
```v
|
||||
fn decode_in_buffer_bytes(data []u8, buffer &u8) int
|
||||
```
|
||||
|
||||
decode_from_buffer decodes the base64 encoded ASCII bytes from `data` into `buffer`. decode_from_buffer returns the size of the decoded data in the buffer. Please note: The `buffer` should be large enough (i.e. 3/4 of the data.len, or larger) to hold the decoded data. Please note: This function does NOT allocate new memory, and is thus suitable for handling very large strings.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## decode_str
|
||||
```v
|
||||
fn decode_str(data string) string
|
||||
```
|
||||
|
||||
decode_str is the string variant of decode
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## encode
|
||||
```v
|
||||
fn encode(data []u8) string
|
||||
```
|
||||
|
||||
encode encodes the `[]u8` value passed in `data` to base64. Please note: base64 encoding returns a `string` that is ~ 4/3 larger than the input. Please note: If you need to encode many strings repeatedly, take a look at `encode_in_buffer`.
|
||||
|
||||
Example
|
||||
```v
|
||||
|
||||
assert base64.encode('V in base 64'.bytes()) == 'ViBpbiBiYXNlIDY0'
|
||||
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## encode_in_buffer
|
||||
```v
|
||||
fn encode_in_buffer(data []u8, buffer &u8) int
|
||||
```
|
||||
|
||||
encode_in_buffer base64 encodes the `[]u8` passed in `data` into `buffer`. encode_in_buffer returns the size of the encoded data in the buffer. Please note: The buffer should be large enough (i.e. 4/3 of the data.len, or larger) to hold the encoded data. Please note: The function does NOT allocate new memory, and is suitable for handling very large strings.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## encode_str
|
||||
```v
|
||||
fn encode_str(data string) string
|
||||
```
|
||||
|
||||
encode_str is the string variant of encode
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## url_decode
|
||||
```v
|
||||
fn url_decode(data string) []u8
|
||||
```
|
||||
|
||||
url_decode returns a decoded URL `string` version of the a base64 url encoded `string` passed in `data`.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## url_decode_str
|
||||
```v
|
||||
fn url_decode_str(data string) string
|
||||
```
|
||||
|
||||
url_decode_str is the string variant of url_decode
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## url_encode
|
||||
```v
|
||||
fn url_encode(data []u8) string
|
||||
```
|
||||
|
||||
url_encode returns a base64 URL encoded `string` version of the value passed in `data`.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## url_encode_str
|
||||
```v
|
||||
fn url_encode_str(data string) string
|
||||
```
|
||||
|
||||
url_encode_str is the string variant of url_encode
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:18:04
|
||||
598
aiprompts/v_core/encoding/binary.md
Normal file
598
aiprompts/v_core/encoding/binary.md
Normal file
@@ -0,0 +1,598 @@
|
||||
# module binary
|
||||
|
||||
|
||||
## Contents
|
||||
- [big_endian_get_u16](#big_endian_get_u16)
|
||||
- [big_endian_get_u32](#big_endian_get_u32)
|
||||
- [big_endian_get_u64](#big_endian_get_u64)
|
||||
- [big_endian_put_u16](#big_endian_put_u16)
|
||||
- [big_endian_put_u16_at](#big_endian_put_u16_at)
|
||||
- [big_endian_put_u16_end](#big_endian_put_u16_end)
|
||||
- [big_endian_put_u16_fixed](#big_endian_put_u16_fixed)
|
||||
- [big_endian_put_u32](#big_endian_put_u32)
|
||||
- [big_endian_put_u32_at](#big_endian_put_u32_at)
|
||||
- [big_endian_put_u32_end](#big_endian_put_u32_end)
|
||||
- [big_endian_put_u32_fixed](#big_endian_put_u32_fixed)
|
||||
- [big_endian_put_u64](#big_endian_put_u64)
|
||||
- [big_endian_put_u64_at](#big_endian_put_u64_at)
|
||||
- [big_endian_put_u64_end](#big_endian_put_u64_end)
|
||||
- [big_endian_put_u64_fixed](#big_endian_put_u64_fixed)
|
||||
- [big_endian_u16](#big_endian_u16)
|
||||
- [big_endian_u16_at](#big_endian_u16_at)
|
||||
- [big_endian_u16_end](#big_endian_u16_end)
|
||||
- [big_endian_u16_fixed](#big_endian_u16_fixed)
|
||||
- [big_endian_u32](#big_endian_u32)
|
||||
- [big_endian_u32_at](#big_endian_u32_at)
|
||||
- [big_endian_u32_end](#big_endian_u32_end)
|
||||
- [big_endian_u32_fixed](#big_endian_u32_fixed)
|
||||
- [big_endian_u64](#big_endian_u64)
|
||||
- [big_endian_u64_at](#big_endian_u64_at)
|
||||
- [big_endian_u64_end](#big_endian_u64_end)
|
||||
- [big_endian_u64_fixed](#big_endian_u64_fixed)
|
||||
- [decode_binary](#decode_binary)
|
||||
- [encode_binary](#encode_binary)
|
||||
- [little_endian_f32_at](#little_endian_f32_at)
|
||||
- [little_endian_get_u16](#little_endian_get_u16)
|
||||
- [little_endian_get_u32](#little_endian_get_u32)
|
||||
- [little_endian_get_u64](#little_endian_get_u64)
|
||||
- [little_endian_put_u16](#little_endian_put_u16)
|
||||
- [little_endian_put_u16_at](#little_endian_put_u16_at)
|
||||
- [little_endian_put_u16_end](#little_endian_put_u16_end)
|
||||
- [little_endian_put_u16_fixed](#little_endian_put_u16_fixed)
|
||||
- [little_endian_put_u32](#little_endian_put_u32)
|
||||
- [little_endian_put_u32_at](#little_endian_put_u32_at)
|
||||
- [little_endian_put_u32_end](#little_endian_put_u32_end)
|
||||
- [little_endian_put_u32_fixed](#little_endian_put_u32_fixed)
|
||||
- [little_endian_put_u64](#little_endian_put_u64)
|
||||
- [little_endian_put_u64_at](#little_endian_put_u64_at)
|
||||
- [little_endian_put_u64_end](#little_endian_put_u64_end)
|
||||
- [little_endian_put_u64_fixed](#little_endian_put_u64_fixed)
|
||||
- [little_endian_u16](#little_endian_u16)
|
||||
- [little_endian_u16_at](#little_endian_u16_at)
|
||||
- [little_endian_u16_end](#little_endian_u16_end)
|
||||
- [little_endian_u16_fixed](#little_endian_u16_fixed)
|
||||
- [little_endian_u32](#little_endian_u32)
|
||||
- [little_endian_u32_at](#little_endian_u32_at)
|
||||
- [little_endian_u32_end](#little_endian_u32_end)
|
||||
- [little_endian_u32_fixed](#little_endian_u32_fixed)
|
||||
- [little_endian_u64](#little_endian_u64)
|
||||
- [little_endian_u64_at](#little_endian_u64_at)
|
||||
- [little_endian_u64_end](#little_endian_u64_end)
|
||||
- [little_endian_u64_fixed](#little_endian_u64_fixed)
|
||||
- [DecodeConfig](#DecodeConfig)
|
||||
- [EncodeConfig](#EncodeConfig)
|
||||
|
||||
## big_endian_get_u16
|
||||
```v
|
||||
fn big_endian_get_u16(v u16) []u8
|
||||
```
|
||||
|
||||
big_endian_get_u16 creates u8 array from the unsigned 16-bit integer v in big endian order.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## big_endian_get_u32
|
||||
```v
|
||||
fn big_endian_get_u32(v u32) []u8
|
||||
```
|
||||
|
||||
big_endian_get_u32 creates u8 array from the unsigned 32-bit integer v in big endian order.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## big_endian_get_u64
|
||||
```v
|
||||
fn big_endian_get_u64(v u64) []u8
|
||||
```
|
||||
|
||||
big_endian_get_u64 creates u8 array from the unsigned 64-bit integer v in big endian order.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## big_endian_put_u16
|
||||
```v
|
||||
fn big_endian_put_u16(mut b []u8, v u16)
|
||||
```
|
||||
|
||||
big_endian_put_u16 writes a u16 to the first two bytes in the array b in big endian order.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## big_endian_put_u16_at
|
||||
```v
|
||||
fn big_endian_put_u16_at(mut b []u8, v u16, o int)
|
||||
```
|
||||
|
||||
big_endian_put_u16_at writes a u16 to the two bytes in the array b at the specified offset in big endian order.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## big_endian_put_u16_end
|
||||
```v
|
||||
fn big_endian_put_u16_end(mut b []u8, v u16)
|
||||
```
|
||||
|
||||
big_endian_put_u16_end writes a u16 to the last two bytes in the array b in big endian order.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## big_endian_put_u16_fixed
|
||||
```v
|
||||
fn big_endian_put_u16_fixed(mut b [2]u8, v u16)
|
||||
```
|
||||
|
||||
big_endian_put_u16_fixed writes a u16 to the fixed array b in big endian order.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## big_endian_put_u32
|
||||
```v
|
||||
fn big_endian_put_u32(mut b []u8, v u32)
|
||||
```
|
||||
|
||||
big_endian_put_u32 writes a u32 to the first four bytes in the array b in big endian order.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## big_endian_put_u32_at
|
||||
```v
|
||||
fn big_endian_put_u32_at(mut b []u8, v u32, o int)
|
||||
```
|
||||
|
||||
big_endian_put_u32_at writes a u32 to four bytes in the array b at the specified offset in big endian order.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## big_endian_put_u32_end
|
||||
```v
|
||||
fn big_endian_put_u32_end(mut b []u8, v u32)
|
||||
```
|
||||
|
||||
big_endian_put_u32_end writes a u32 to the last four bytes in the array b in big endian order.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## big_endian_put_u32_fixed
|
||||
```v
|
||||
fn big_endian_put_u32_fixed(mut b [4]u8, v u32)
|
||||
```
|
||||
|
||||
big_endian_put_u32_fixed writes a u32 to the fixed array b in big endian order.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## big_endian_put_u64
|
||||
```v
|
||||
fn big_endian_put_u64(mut b []u8, v u64)
|
||||
```
|
||||
|
||||
big_endian_put_u64 writes a u64 to the first eight bytes in the array b in big endian order.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## big_endian_put_u64_at
|
||||
```v
|
||||
fn big_endian_put_u64_at(mut b []u8, v u64, o int)
|
||||
```
|
||||
|
||||
big_endian_put_u64_at writes a u64 to eight bytes in the array b at the specified offset in big endian order.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## big_endian_put_u64_end
|
||||
```v
|
||||
fn big_endian_put_u64_end(mut b []u8, v u64)
|
||||
```
|
||||
|
||||
big_endian_put_u64_end writes a u64 to the last eight bytes in the array b at the specified offset in big endian order.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## big_endian_put_u64_fixed
|
||||
```v
|
||||
fn big_endian_put_u64_fixed(mut b [8]u8, v u64)
|
||||
```
|
||||
|
||||
big_endian_put_u64_fixed writes a u64 to the fixed array b in big endian order.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## big_endian_u16
|
||||
```v
|
||||
fn big_endian_u16(b []u8) u16
|
||||
```
|
||||
|
||||
big_endian_u16 creates a u16 from the first two bytes in the array b in big endian order.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## big_endian_u16_at
|
||||
```v
|
||||
fn big_endian_u16_at(b []u8, o int) u16
|
||||
```
|
||||
|
||||
big_endian_u16_at creates a u16 from two bytes in the array b at the specified offset in big endian order.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## big_endian_u16_end
|
||||
```v
|
||||
fn big_endian_u16_end(b []u8) u16
|
||||
```
|
||||
|
||||
big_endian_u16_end creates a u16 from two bytes in the array b at the specified offset in big endian order.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## big_endian_u16_fixed
|
||||
```v
|
||||
fn big_endian_u16_fixed(b [2]u8) u16
|
||||
```
|
||||
|
||||
big_endian_u16_fixed creates a u16 from the first two bytes in the fixed array b in big endian order.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## big_endian_u32
|
||||
```v
|
||||
fn big_endian_u32(b []u8) u32
|
||||
```
|
||||
|
||||
big_endian_u32 creates a u32 from four bytes in the array b in big endian order.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## big_endian_u32_at
|
||||
```v
|
||||
fn big_endian_u32_at(b []u8, o int) u32
|
||||
```
|
||||
|
||||
big_endian_u32_at creates a u32 from four bytes in the array b at the specified offset in big endian order.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## big_endian_u32_end
|
||||
```v
|
||||
fn big_endian_u32_end(b []u8) u32
|
||||
```
|
||||
|
||||
big_endian_u32_end creates a u32 from the last four bytes in the array b in big endian order.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## big_endian_u32_fixed
|
||||
```v
|
||||
fn big_endian_u32_fixed(b [4]u8) u32
|
||||
```
|
||||
|
||||
big_endian_u32_fixed creates a u32 from four bytes in the fixed array b in big endian order.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## big_endian_u64
|
||||
```v
|
||||
fn big_endian_u64(b []u8) u64
|
||||
```
|
||||
|
||||
big_endian_u64 creates a u64 from the first eight bytes in the array b in big endian order.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## big_endian_u64_at
|
||||
```v
|
||||
fn big_endian_u64_at(b []u8, o int) u64
|
||||
```
|
||||
|
||||
big_endian_u64_at creates a u64 from eight bytes in the array b at the specified offset in big endian order.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## big_endian_u64_end
|
||||
```v
|
||||
fn big_endian_u64_end(b []u8) u64
|
||||
```
|
||||
|
||||
big_endian_u64_end creates a u64 from the last eight bytes in the array b in big endian order.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## big_endian_u64_fixed
|
||||
```v
|
||||
fn big_endian_u64_fixed(b [8]u8) u64
|
||||
```
|
||||
|
||||
big_endian_u64_fixed creates a u64 from the fixed array b in big endian order.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## decode_binary
|
||||
```v
|
||||
fn decode_binary[T](b []u8, config DecodeConfig) !T
|
||||
```
|
||||
|
||||
decode_binary decode a u8 array into T type data. for decoding struct, you can use `@[serialize: '-']` to skip field.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## encode_binary
|
||||
```v
|
||||
fn encode_binary[T](obj T, config EncodeConfig) ![]u8
|
||||
```
|
||||
|
||||
encode_binary encode a T type data into u8 array. for encoding struct, you can use `@[serialize: '-']` to skip field.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## little_endian_f32_at
|
||||
```v
|
||||
fn little_endian_f32_at(b []u8, o int) f32
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## little_endian_get_u16
|
||||
```v
|
||||
fn little_endian_get_u16(v u16) []u8
|
||||
```
|
||||
|
||||
little_endian_get_u16 creates u8 array from the unsigned 16-bit integer v in little endian order.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## little_endian_get_u32
|
||||
```v
|
||||
fn little_endian_get_u32(v u32) []u8
|
||||
```
|
||||
|
||||
little_endian_get_u32 creates u8 array from the unsigned 32-bit integer v in little endian order.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## little_endian_get_u64
|
||||
```v
|
||||
fn little_endian_get_u64(v u64) []u8
|
||||
```
|
||||
|
||||
little_endian_get_u64 creates u8 array from the unsigned 64-bit integer v in little endian order.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## little_endian_put_u16
|
||||
```v
|
||||
fn little_endian_put_u16(mut b []u8, v u16)
|
||||
```
|
||||
|
||||
little_endian_put_u16 writes a u16 to the first two bytes in the array b in little endian order.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## little_endian_put_u16_at
|
||||
```v
|
||||
fn little_endian_put_u16_at(mut b []u8, v u16, o int)
|
||||
```
|
||||
|
||||
little_endian_put_u16_at writes a u16 to the two bytes in the array b at the specified offset in little endian order.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## little_endian_put_u16_end
|
||||
```v
|
||||
fn little_endian_put_u16_end(mut b []u8, v u16)
|
||||
```
|
||||
|
||||
little_endian_put_u16_end writes a u16 to the last two bytes of the array b in little endian order.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## little_endian_put_u16_fixed
|
||||
```v
|
||||
fn little_endian_put_u16_fixed(mut b [2]u8, v u16)
|
||||
```
|
||||
|
||||
little_endian_put_u16_fixed writes a u16 to the fixed array b in little endian order.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## little_endian_put_u32
|
||||
```v
|
||||
fn little_endian_put_u32(mut b []u8, v u32)
|
||||
```
|
||||
|
||||
little_endian_put_u32 writes a u32 to the first four bytes in the array b in little endian order.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## little_endian_put_u32_at
|
||||
```v
|
||||
fn little_endian_put_u32_at(mut b []u8, v u32, o int)
|
||||
```
|
||||
|
||||
little_endian_put_u32_at writes a u32 to the four bytes in the array b at the specified offset in little endian order.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## little_endian_put_u32_end
|
||||
```v
|
||||
fn little_endian_put_u32_end(mut b []u8, v u32)
|
||||
```
|
||||
|
||||
little_endian_put_u32_end writes a u32 to the last four bytes in the array b in little endian order.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## little_endian_put_u32_fixed
|
||||
```v
|
||||
fn little_endian_put_u32_fixed(mut b [4]u8, v u32)
|
||||
```
|
||||
|
||||
little_endian_put_u32_fixed writes a u32 to the fixed array b in little endian order.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## little_endian_put_u64
|
||||
```v
|
||||
fn little_endian_put_u64(mut b []u8, v u64)
|
||||
```
|
||||
|
||||
little_endian_put_u64 writes a u64 to the first eight bytes in the array b in little endian order.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## little_endian_put_u64_at
|
||||
```v
|
||||
fn little_endian_put_u64_at(mut b []u8, v u64, o int)
|
||||
```
|
||||
|
||||
little_endian_put_u64_at writes a u64 to the eight bytes in the array b at the specified offset in little endian order.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## little_endian_put_u64_end
|
||||
```v
|
||||
fn little_endian_put_u64_end(mut b []u8, v u64)
|
||||
```
|
||||
|
||||
little_endian_put_u64_end writes a u64 to the last eight bytes in the array b at in little endian order.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## little_endian_put_u64_fixed
|
||||
```v
|
||||
fn little_endian_put_u64_fixed(mut b [8]u8, v u64)
|
||||
```
|
||||
|
||||
little_endian_put_u64_fixed writes a u64 to the fixed array b in little endian order.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## little_endian_u16
|
||||
```v
|
||||
fn little_endian_u16(b []u8) u16
|
||||
```
|
||||
|
||||
little_endian_u16 creates a u16 from the first two bytes in the array b in little endian order.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## little_endian_u16_at
|
||||
```v
|
||||
fn little_endian_u16_at(b []u8, o int) u16
|
||||
```
|
||||
|
||||
little_endian_u16_at creates a u16 from two bytes in the array b at the specified offset in little endian order.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## little_endian_u16_end
|
||||
```v
|
||||
fn little_endian_u16_end(b []u8) u16
|
||||
```
|
||||
|
||||
little_endian_u16_end creates a u16 from the last two bytes of the array b in little endian order.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## little_endian_u16_fixed
|
||||
```v
|
||||
fn little_endian_u16_fixed(b [2]u8) u16
|
||||
```
|
||||
|
||||
little_endian_u16_fixed creates a u16 from the fixed array b in little endian order.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## little_endian_u32
|
||||
```v
|
||||
fn little_endian_u32(b []u8) u32
|
||||
```
|
||||
|
||||
little_endian_u32 creates a u32 from the first four bytes in the array b in little endian order.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## little_endian_u32_at
|
||||
```v
|
||||
fn little_endian_u32_at(b []u8, o int) u32
|
||||
```
|
||||
|
||||
little_endian_u32_at creates a u32 from four bytes in the array b at the specified offset in little endian order.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## little_endian_u32_end
|
||||
```v
|
||||
fn little_endian_u32_end(b []u8) u32
|
||||
```
|
||||
|
||||
little_endian_u32_end creates a u32 from the last four bytes in the array b in little endian order.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## little_endian_u32_fixed
|
||||
```v
|
||||
fn little_endian_u32_fixed(b [4]u8) u32
|
||||
```
|
||||
|
||||
little_endian_u32_fixed creates a u32 from the fixed array b in little endian order.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## little_endian_u64
|
||||
```v
|
||||
fn little_endian_u64(b []u8) u64
|
||||
```
|
||||
|
||||
little_endian_u64 creates a u64 from the first eight bytes in the array b in little endian order.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## little_endian_u64_at
|
||||
```v
|
||||
fn little_endian_u64_at(b []u8, o int) u64
|
||||
```
|
||||
|
||||
little_endian_u64_at creates a u64 from eight bytes in the array b at the specified offset in little endian order.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## little_endian_u64_end
|
||||
```v
|
||||
fn little_endian_u64_end(b []u8) u64
|
||||
```
|
||||
|
||||
little_endian_u64_end creates a u64 from the last eight bytes in the array b in little endian order.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## little_endian_u64_fixed
|
||||
```v
|
||||
fn little_endian_u64_fixed(b [8]u8) u64
|
||||
```
|
||||
|
||||
little_endian_u64_fixed creates a u64 from the fixed array b in little endian order.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## DecodeConfig
|
||||
```v
|
||||
struct DecodeConfig {
|
||||
pub mut:
|
||||
buffer_len int = 1024
|
||||
big_endian bool // use big endian decode the data
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## EncodeConfig
|
||||
```v
|
||||
struct EncodeConfig {
|
||||
pub mut:
|
||||
buffer_len int = 1024
|
||||
big_endian bool // use big endian encoding the data
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:18:04
|
||||
462
aiprompts/v_core/encoding/csv.md
Normal file
462
aiprompts/v_core/encoding/csv.md
Normal file
@@ -0,0 +1,462 @@
|
||||
# module csv
|
||||
|
||||
|
||||
## Contents
|
||||
- [Constants](#Constants)
|
||||
- [csv_reader](#csv_reader)
|
||||
- [csv_reader_from_string](#csv_reader_from_string)
|
||||
- [csv_sequential_reader](#csv_sequential_reader)
|
||||
- [decode](#decode)
|
||||
- [new_reader](#new_reader)
|
||||
- [new_reader_from_file](#new_reader_from_file)
|
||||
- [new_writer](#new_writer)
|
||||
- [CellValue](#CellValue)
|
||||
- [Reader](#Reader)
|
||||
- [read](#read)
|
||||
- [Writer](#Writer)
|
||||
- [write](#write)
|
||||
- [str](#str)
|
||||
- [ColumType](#ColumType)
|
||||
- [GetCellConfig](#GetCellConfig)
|
||||
- [GetHeaderConf](#GetHeaderConf)
|
||||
- [HeaderItem](#HeaderItem)
|
||||
- [RandomAccessReader](#RandomAccessReader)
|
||||
- [dispose_csv_reader](#dispose_csv_reader)
|
||||
- [copy_configuration](#copy_configuration)
|
||||
- [map_csv](#map_csv)
|
||||
- [get_row](#get_row)
|
||||
- [get_cell](#get_cell)
|
||||
- [get_cellt](#get_cellt)
|
||||
- [build_header_dict](#build_header_dict)
|
||||
- [rows_count](#rows_count)
|
||||
- [RandomAccessReaderConfig](#RandomAccessReaderConfig)
|
||||
- [ReaderConfig](#ReaderConfig)
|
||||
- [SequentialReader](#SequentialReader)
|
||||
- [dispose_csv_reader](#dispose_csv_reader)
|
||||
- [has_data](#has_data)
|
||||
- [get_next_row](#get_next_row)
|
||||
- [SequentialReaderConfig](#SequentialReaderConfig)
|
||||
- [WriterConfig](#WriterConfig)
|
||||
|
||||
## Constants
|
||||
```v
|
||||
const endline_cr_len = 1
|
||||
```
|
||||
|
||||
endline lengths
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const endline_crlf_len = 2
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const ram_csv = 1
|
||||
```
|
||||
|
||||
Type of read buffer
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const file_csv = 0
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## csv_reader
|
||||
```v
|
||||
fn csv_reader(cfg RandomAccessReaderConfig) !&RandomAccessReader
|
||||
```
|
||||
|
||||
csv_reader create a random access csv reader
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## csv_reader_from_string
|
||||
```v
|
||||
fn csv_reader_from_string(in_str string) !&RandomAccessReader
|
||||
```
|
||||
|
||||
csv_reader_from_string create a csv reader from a string
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## csv_sequential_reader
|
||||
```v
|
||||
fn csv_sequential_reader(cfg SequentialReaderConfig) !&SequentialReader
|
||||
```
|
||||
|
||||
csv_sequential_reader creates a sequential csv reader
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## decode
|
||||
```v
|
||||
fn decode[T](data string) []T
|
||||
```
|
||||
|
||||
decode csv to struct
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new_reader
|
||||
```v
|
||||
fn new_reader(data string, config ReaderConfig) &Reader
|
||||
```
|
||||
|
||||
new_reader initializes a Reader with string data to parse and, optionally, a custom delimiter.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new_reader_from_file
|
||||
```v
|
||||
fn new_reader_from_file(csv_file_path string, config ReaderConfig) !&Reader
|
||||
```
|
||||
|
||||
new_reader_from_file create a csv reader from a file
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new_writer
|
||||
```v
|
||||
fn new_writer(config WriterConfig) &Writer
|
||||
```
|
||||
|
||||
new_writer returns a reference to a Writer
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## CellValue
|
||||
```v
|
||||
type CellValue = f32 | int | string
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Reader
|
||||
## read
|
||||
```v
|
||||
fn (mut r Reader) read() ![]string
|
||||
```
|
||||
|
||||
read reads a row from the CSV data. If successful, the result holds an array of each column's data.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Writer
|
||||
## write
|
||||
```v
|
||||
fn (mut w Writer) write(record []string) !bool
|
||||
```
|
||||
|
||||
write writes a single record
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## str
|
||||
```v
|
||||
fn (mut w Writer) str() string
|
||||
```
|
||||
|
||||
str returns the writer contents
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## ColumType
|
||||
```v
|
||||
enum ColumType {
|
||||
string = 0
|
||||
int = 1
|
||||
f32 = 2
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## GetCellConfig
|
||||
```v
|
||||
struct GetCellConfig {
|
||||
pub:
|
||||
x int
|
||||
y int
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## GetHeaderConf
|
||||
```v
|
||||
struct GetHeaderConf {
|
||||
pub:
|
||||
header_row int // row where to inspect the header
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## HeaderItem
|
||||
```v
|
||||
struct HeaderItem {
|
||||
pub mut:
|
||||
label string
|
||||
column int
|
||||
htype ColumType = .string
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## RandomAccessReader
|
||||
```v
|
||||
struct RandomAccessReader {
|
||||
pub mut:
|
||||
index i64
|
||||
|
||||
f os.File
|
||||
f_len i64
|
||||
is_bom_present bool
|
||||
|
||||
start_index i64
|
||||
end_index i64 = -1
|
||||
|
||||
end_line u8 = `\n`
|
||||
end_line_len int = endline_cr_len // size of the endline rune \n = 1, \r\n = 2
|
||||
separator u8 = `,` // comma is the default separator
|
||||
separator_len int = 1 // size of the separator rune
|
||||
quote u8 = `"` // double quote is the standard quote char
|
||||
quote_remove bool // if true clear the cell from the quotes
|
||||
comment u8 = `#` // every line that start with the quote char is ignored
|
||||
|
||||
default_cell string = '*' // return this string if out of the csv boundaries
|
||||
empty_cell string = '#' // retunrn this if empty cell
|
||||
// ram buffer
|
||||
mem_buf_type u32 // buffer type 0=File,1=RAM
|
||||
mem_buf voidptr // buffer used to load chars from file
|
||||
mem_buf_size i64 // size of the buffer
|
||||
mem_buf_start i64 = -1 // start index in the file of the read buffer
|
||||
mem_buf_end i64 = -1 // end index in the file of the read buffer
|
||||
// csv map for quick access
|
||||
create_map_csv bool = true // flag to enable the csv map creation
|
||||
csv_map [][]i64
|
||||
// header
|
||||
header_row int = -1 // row index of the header in the csv_map
|
||||
header_list []HeaderItem // list of the header item
|
||||
header_map map[string]int // map from header label to column index
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## dispose_csv_reader
|
||||
```v
|
||||
fn (mut cr RandomAccessReader) dispose_csv_reader()
|
||||
```
|
||||
|
||||
dispose_csv_reader release the resources used by the csv_reader
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## copy_configuration
|
||||
```v
|
||||
fn (mut cr RandomAccessReader) copy_configuration(src_cr RandomAccessReader)
|
||||
```
|
||||
|
||||
copy_configuration copies the configuration from another csv RandomAccessReader this function is a helper for using the RandomAccessReader in multi threaded applications pay attention to the free process
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## map_csv
|
||||
```v
|
||||
fn (mut cr RandomAccessReader) map_csv() !
|
||||
```
|
||||
|
||||
map_csv create an index of whole csv file to consent random access to every cell in the file
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## get_row
|
||||
```v
|
||||
fn (mut cr RandomAccessReader) get_row(y int) ![]string
|
||||
```
|
||||
|
||||
get_row get a row from the CSV file as a string array
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## get_cell
|
||||
```v
|
||||
fn (mut cr RandomAccessReader) get_cell(cfg GetCellConfig) !string
|
||||
```
|
||||
|
||||
get_cell read a single cel nd return a string
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## get_cellt
|
||||
```v
|
||||
fn (mut cr RandomAccessReader) get_cellt(cfg GetCellConfig) !CellValue
|
||||
```
|
||||
|
||||
get_cellt read a single cell and return a sum type CellValue
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## build_header_dict
|
||||
```v
|
||||
fn (mut cr RandomAccessReader) build_header_dict(cfg GetHeaderConf) !
|
||||
```
|
||||
|
||||
build_header_dict infer the header, it use the first available row in not row number is passesd it try to infer the type of column using the first available row after the header By default all the column are of the string type
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## rows_count
|
||||
```v
|
||||
fn (mut cr RandomAccessReader) rows_count() !i64
|
||||
```
|
||||
|
||||
rows_count count the rows in the csv between start_index and end_index
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## RandomAccessReaderConfig
|
||||
```v
|
||||
struct RandomAccessReaderConfig {
|
||||
pub:
|
||||
scr_buf voidptr // pointer to the buffer of data
|
||||
scr_buf_len i64 // if > 0 use the RAM pointed from scr_buf as source of data
|
||||
file_path string
|
||||
start_index i64
|
||||
end_index i64 = -1
|
||||
mem_buf_size int = 1024 * 64 // default buffer size 64KByte
|
||||
separator u8 = `,`
|
||||
comment u8 = `#` // every line that start with the quote char is ignored
|
||||
default_cell string = '*' // return this string if out of the csv boundaries
|
||||
empty_cell string // return this string if empty cell
|
||||
end_line_len int = endline_cr_len // size of the endline rune
|
||||
quote u8 = `"` // double quote is the standard quote char
|
||||
quote_remove bool // if true clear the cell from the quotes
|
||||
create_map_csv bool = true // if true make the map of the csv file
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## ReaderConfig
|
||||
```v
|
||||
struct ReaderConfig {
|
||||
pub:
|
||||
delimiter u8 = `,`
|
||||
comment u8 = `#`
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## SequentialReader
|
||||
```v
|
||||
struct SequentialReader {
|
||||
pub mut:
|
||||
index i64
|
||||
|
||||
f os.File
|
||||
f_len i64
|
||||
is_bom_present bool
|
||||
|
||||
start_index i64
|
||||
end_index i64 = -1
|
||||
|
||||
end_line u8 = `\n`
|
||||
end_line_len int = endline_cr_len // size of the endline rune \n = 1, \r\n = 2
|
||||
separator u8 = `,` // comma is the default separator
|
||||
separator_len int = 1 // size of the separator rune
|
||||
quote u8 = `"` // double quote is the standard quote char
|
||||
|
||||
comment u8 = `#` // every line that start with the quote char is ignored
|
||||
|
||||
default_cell string = '*' // return this string if out of the csv boundaries
|
||||
empty_cell string = '#' // retunrn this if empty cell
|
||||
// ram buffer
|
||||
mem_buf_type u32 // buffer type 0=File,1=RAM
|
||||
mem_buf voidptr // buffer used to load chars from file
|
||||
mem_buf_size i64 // size of the buffer
|
||||
mem_buf_start i64 = -1 // start index in the file of the read buffer
|
||||
mem_buf_end i64 = -1 // end index in the file of the read buffer
|
||||
|
||||
ch_buf []u8 = []u8{cap: 1024}
|
||||
// error management
|
||||
row_count i64
|
||||
col_count i64
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## dispose_csv_reader
|
||||
```v
|
||||
fn (mut cr SequentialReader) dispose_csv_reader()
|
||||
```
|
||||
|
||||
dispose_csv_reader release the resources used by the csv_reader
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## has_data
|
||||
```v
|
||||
fn (mut cr SequentialReader) has_data() i64
|
||||
```
|
||||
|
||||
has_data return the bytes available for future readings
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## get_next_row
|
||||
```v
|
||||
fn (mut cr SequentialReader) get_next_row() ![]string
|
||||
```
|
||||
|
||||
get_next_row get the next row from the CSV file as a string array
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## SequentialReaderConfig
|
||||
```v
|
||||
struct SequentialReaderConfig {
|
||||
pub:
|
||||
scr_buf voidptr // pointer to the buffer of data
|
||||
scr_buf_len i64 // if > 0 use the RAM pointed by scr_buf as source of data
|
||||
file_path string
|
||||
start_index i64
|
||||
end_index i64 = -1
|
||||
mem_buf_size int = 1024 * 64 // default buffer size 64KByte
|
||||
separator u8 = `,`
|
||||
comment u8 = `#` // every line that start with the comment char is ignored
|
||||
default_cell string = '*' // return this string if out of the csv boundaries
|
||||
empty_cell string // return this string if empty cell
|
||||
end_line_len int = endline_cr_len // size of the endline rune
|
||||
quote u8 = `"` // double quote is the standard quote char
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## WriterConfig
|
||||
```v
|
||||
struct WriterConfig {
|
||||
pub:
|
||||
use_crlf bool
|
||||
delimiter u8 = `,`
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:18:04
|
||||
43
aiprompts/v_core/encoding/encoding.utf8.east_asian.md
Normal file
43
aiprompts/v_core/encoding/encoding.utf8.east_asian.md
Normal file
@@ -0,0 +1,43 @@
|
||||
# module encoding.utf8.east_asian
|
||||
|
||||
|
||||
## Contents
|
||||
- [display_width](#display_width)
|
||||
- [east_asian_width_property_at](#east_asian_width_property_at)
|
||||
- [EastAsianWidthProperty](#EastAsianWidthProperty)
|
||||
|
||||
## display_width
|
||||
```v
|
||||
fn display_width(s string, ambiguous_width int) int
|
||||
```
|
||||
|
||||
display_width return the display width as number of unicode chars from a string.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## east_asian_width_property_at
|
||||
```v
|
||||
fn east_asian_width_property_at(s string, index int) EastAsianWidthProperty
|
||||
```
|
||||
|
||||
width_property_at returns the East Asian Width properties at string[index]
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## EastAsianWidthProperty
|
||||
```v
|
||||
enum EastAsianWidthProperty {
|
||||
full
|
||||
half
|
||||
wide
|
||||
narrow
|
||||
ambiguous
|
||||
neutral
|
||||
}
|
||||
```
|
||||
|
||||
EastAsianWidthType represents East_Asian_Width informative prorperty
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:18:04
|
||||
26
aiprompts/v_core/encoding/encoding.utf8.validate.md
Normal file
26
aiprompts/v_core/encoding/encoding.utf8.validate.md
Normal file
@@ -0,0 +1,26 @@
|
||||
# module encoding.utf8.validate
|
||||
|
||||
|
||||
## Contents
|
||||
- [utf8_data](#utf8_data)
|
||||
- [utf8_string](#utf8_string)
|
||||
|
||||
## utf8_data
|
||||
```v
|
||||
fn utf8_data(data &u8, len int) bool
|
||||
```
|
||||
|
||||
utf8_data returns true, if the given `data` block, with length `len` bytes, consists only of valid UTF-8 runes
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## utf8_string
|
||||
```v
|
||||
fn utf8_string(s string) bool
|
||||
```
|
||||
|
||||
utf8_string returns true, if the given string `s` consists only of valid UTF-8 runes
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:18:04
|
||||
26
aiprompts/v_core/encoding/hex.md
Normal file
26
aiprompts/v_core/encoding/hex.md
Normal file
@@ -0,0 +1,26 @@
|
||||
# module hex
|
||||
|
||||
|
||||
## Contents
|
||||
- [decode](#decode)
|
||||
- [encode](#encode)
|
||||
|
||||
## decode
|
||||
```v
|
||||
fn decode(s string) ![]u8
|
||||
```
|
||||
|
||||
decode converts a hex string into an array of bytes. The expected input format is 2 ASCII characters for each output byte. If the provided string length is not a multiple of 2, an implicit `0` is prepended to it.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## encode
|
||||
```v
|
||||
fn encode(bytes []u8) string
|
||||
```
|
||||
|
||||
encode converts an array of bytes into a string of ASCII hex bytes. The output will always be a string with length a multiple of 2.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:18:04
|
||||
49
aiprompts/v_core/encoding/html.md
Normal file
49
aiprompts/v_core/encoding/html.md
Normal file
@@ -0,0 +1,49 @@
|
||||
# module html
|
||||
|
||||
|
||||
## Contents
|
||||
- [escape](#escape)
|
||||
- [unescape](#unescape)
|
||||
- [EscapeConfig](#EscapeConfig)
|
||||
- [UnescapeConfig](#UnescapeConfig)
|
||||
|
||||
## escape
|
||||
```v
|
||||
fn escape(input string, config EscapeConfig) string
|
||||
```
|
||||
|
||||
escape converts special characters in the input, specifically "<", ">", and "&" to HTML-safe sequences. If `quote` is set to true (which is default), quotes in HTML will also be translated. Both double and single quotes will be affected. **Note:** escape() supports funky accents by doing nothing about them. V's UTF-8 support through `string` is robust enough to deal with these cases.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## unescape
|
||||
```v
|
||||
fn unescape(input string, config UnescapeConfig) string
|
||||
```
|
||||
|
||||
unescape converts entities like "<" to "<". By default it is the converse of `escape`. If `all` is set to true, it handles named, numeric, and hex values - for example, `'''`, `'''`, and `'''` then unescape to "'".
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## EscapeConfig
|
||||
```v
|
||||
struct EscapeConfig {
|
||||
pub:
|
||||
quote bool = true
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## UnescapeConfig
|
||||
```v
|
||||
struct UnescapeConfig {
|
||||
EscapeConfig
|
||||
pub:
|
||||
all bool
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:18:04
|
||||
66
aiprompts/v_core/encoding/iconv.md
Normal file
66
aiprompts/v_core/encoding/iconv.md
Normal file
@@ -0,0 +1,66 @@
|
||||
# module iconv
|
||||
|
||||
|
||||
## Contents
|
||||
- [create_utf_string_with_bom](#create_utf_string_with_bom)
|
||||
- [encoding_to_vstring](#encoding_to_vstring)
|
||||
- [read_file_encoding](#read_file_encoding)
|
||||
- [remove_utf_string_with_bom](#remove_utf_string_with_bom)
|
||||
- [vstring_to_encoding](#vstring_to_encoding)
|
||||
- [write_file_encoding](#write_file_encoding)
|
||||
|
||||
## create_utf_string_with_bom
|
||||
```v
|
||||
fn create_utf_string_with_bom(src []u8, utf_type string) []u8
|
||||
```
|
||||
|
||||
create_utf_string_with_bom will create a utf8/utf16/utf32 string with BOM header for utf8, it will prepend 0xEFBBBF to the `src` for utf16le, it will prepend 0xFFFE to the `src` for utf16be, it will prepend 0xFEFF to the `src` for utf32le, it will prepend 0xFFFE0000 to the `src` for utf32be, it will prepend 0x0000FEFF to the `src`
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## encoding_to_vstring
|
||||
```v
|
||||
fn encoding_to_vstring(bytes []u8, fromcode string) !string
|
||||
```
|
||||
|
||||
encoding_to_vstring converts the given `bytes` using `fromcode` encoding, to a V string (encoded with UTF-8) tips: use `iconv --list` check for supported encodings
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## read_file_encoding
|
||||
```v
|
||||
fn read_file_encoding(path string, encoding string) !string
|
||||
```
|
||||
|
||||
read_file_encoding reads the file in `path` with `encoding` and returns the contents
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## remove_utf_string_with_bom
|
||||
```v
|
||||
fn remove_utf_string_with_bom(src []u8, utf_type string) []u8
|
||||
```
|
||||
|
||||
remove_utf_string_with_bom will remove a utf8/utf16/utf32 string's BOM header for utf8, it will remove 0xEFBBBF from the `src` for utf16le, it will remove 0xFFFE from the `src` for utf16be, it will remove 0xFEFF from the `src` for utf32le, it will remove 0xFFFE0000 from the `src` for utf32be, it will remove 0x0000FEFF from the `src`
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## vstring_to_encoding
|
||||
```v
|
||||
fn vstring_to_encoding(str string, tocode string) ![]u8
|
||||
```
|
||||
|
||||
vstring_to_encoding convert V string `str` to `tocode` encoding string tips: use `iconv --list` check for supported encodings
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## write_file_encoding
|
||||
```v
|
||||
fn write_file_encoding(path string, text string, encoding string, bom bool) !
|
||||
```
|
||||
|
||||
write_file_encoding write_file convert `text` into `encoding` and writes to a file with the given `path`. If `path` already exists, it will be overwritten. For `encoding` in UTF8/UTF16/UTF32, if `bom` is true, then a BOM header will write to the file.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:18:04
|
||||
86
aiprompts/v_core/encoding/leb128.md
Normal file
86
aiprompts/v_core/encoding/leb128.md
Normal file
@@ -0,0 +1,86 @@
|
||||
# module leb128
|
||||
|
||||
|
||||
## Contents
|
||||
- [decode_i32](#decode_i32)
|
||||
- [decode_i64](#decode_i64)
|
||||
- [decode_u32](#decode_u32)
|
||||
- [decode_u64](#decode_u64)
|
||||
- [encode_i32](#encode_i32)
|
||||
- [encode_i64](#encode_i64)
|
||||
- [encode_u32](#encode_u32)
|
||||
- [encode_u64](#encode_u64)
|
||||
|
||||
## decode_i32
|
||||
```v
|
||||
fn decode_i32(value []u8) (i32, int)
|
||||
```
|
||||
|
||||
decode_i32 decodes an i32 and returns the number of bytes used from the given leb128 encoded array `value`
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## decode_i64
|
||||
```v
|
||||
fn decode_i64(value []u8) (i64, int)
|
||||
```
|
||||
|
||||
decode_i64 decodes an i64 and returns the number of bytes used from the given leb128 encoded array `value`
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## decode_u32
|
||||
```v
|
||||
fn decode_u32(value []u8) (u32, int)
|
||||
```
|
||||
|
||||
decode_u32 decodes an u32 and returns the number of bytes used from the given leb128 encoded array `value`
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## decode_u64
|
||||
```v
|
||||
fn decode_u64(value []u8) (u64, int)
|
||||
```
|
||||
|
||||
decode_u64 decodes an u64 and returns the number of bytes used from the given leb128 encoded array `value`
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## encode_i32
|
||||
```v
|
||||
fn encode_i32(value i32) []u8
|
||||
```
|
||||
|
||||
encode_i32 encodes the `value` as leb128 encoded byte array
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## encode_i64
|
||||
```v
|
||||
fn encode_i64(value i64) []u8
|
||||
```
|
||||
|
||||
encode_i64 encodes the `value` as leb128 encoded byte array
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## encode_u32
|
||||
```v
|
||||
fn encode_u32(value u32) []u8
|
||||
```
|
||||
|
||||
encode_u32 encodes the `value` as leb128 encoded byte array
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## encode_u64
|
||||
```v
|
||||
fn encode_u64(value u64) []u8
|
||||
```
|
||||
|
||||
encode_u64 encodes the `value` as leb128 encoded byte array
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:18:04
|
||||
94
aiprompts/v_core/encoding/txtar.md
Normal file
94
aiprompts/v_core/encoding/txtar.md
Normal file
@@ -0,0 +1,94 @@
|
||||
# module txtar
|
||||
|
||||
|
||||
## Contents
|
||||
- [pack](#pack)
|
||||
- [parse](#parse)
|
||||
- [parse_file](#parse_file)
|
||||
- [unpack](#unpack)
|
||||
- [Archive](#Archive)
|
||||
- [str](#str)
|
||||
- [unpack_to](#unpack_to)
|
||||
- [File](#File)
|
||||
|
||||
## pack
|
||||
```v
|
||||
fn pack(path string, comment string) !Archive
|
||||
```
|
||||
|
||||
pack will create a txtar archive, given a path. When the path is a folder, it will walk over all files in that base folder, read their contents and create a File entry for each. When the path is a file, it will create an Archive, that contains just a single File entry, for that single file.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## parse
|
||||
```v
|
||||
fn parse(content string) Archive
|
||||
```
|
||||
|
||||
parse parses the serialized form of an Archive. The returned Archive holds slices of data.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## parse_file
|
||||
```v
|
||||
fn parse_file(file_path string) !Archive
|
||||
```
|
||||
|
||||
parse_file parses the given `file_path` as an archive. It will return an error, only if the `file_path` is not readable. See the README.md, or the test txtar_test.v, for a description of the format.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## unpack
|
||||
```v
|
||||
fn unpack(a &Archive, path string) !
|
||||
```
|
||||
|
||||
unpack will extract *all files* in the archive `a`, into the base folder `path`. Note that all file paths will be appended to the base folder `path`, i.e. if you have a File with `path` field == 'abc/def/x.v', and base folder path == '/tmp', then the final path for that File, will be '/tmp/abc/def/x.v' Note that unpack will try to create any of the intermediate folders like /tmp, /tmp/abc, /tmp/abc/def, if they do not already exist.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Archive
|
||||
```v
|
||||
struct Archive {
|
||||
pub mut:
|
||||
comment string // the start of the archive; contains potentially multiple lines, before the files
|
||||
files []File // a series of files
|
||||
}
|
||||
```
|
||||
|
||||
Archive is a collection of files
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## str
|
||||
```v
|
||||
fn (a &Archive) str() string
|
||||
```
|
||||
|
||||
str returns a string representation of the `a` Archive. It is suitable for storing in a text file. It is also in the same format, that txtar.parse/1 expects.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## unpack_to
|
||||
```v
|
||||
fn (a &Archive) unpack_to(path string) !
|
||||
```
|
||||
|
||||
unpack_to extracts the content of the archive `a`, into the folder `path`.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## File
|
||||
```v
|
||||
struct File {
|
||||
pub mut:
|
||||
path string // 'abc/def.v' from the `-- abc/def.v --` header
|
||||
content string // everything after that, till the next `-- name --` line.
|
||||
}
|
||||
```
|
||||
|
||||
File is a single file in an Archive. Each starting with a `-- FILENAME --` line.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:18:04
|
||||
170
aiprompts/v_core/encoding/utf8.md
Normal file
170
aiprompts/v_core/encoding/utf8.md
Normal file
@@ -0,0 +1,170 @@
|
||||
# module utf8
|
||||
|
||||
|
||||
## Contents
|
||||
- [get_rune](#get_rune)
|
||||
- [is_control](#is_control)
|
||||
- [is_global_punct](#is_global_punct)
|
||||
- [is_letter](#is_letter)
|
||||
- [is_number](#is_number)
|
||||
- [is_punct](#is_punct)
|
||||
- [is_rune_global_punct](#is_rune_global_punct)
|
||||
- [is_rune_punct](#is_rune_punct)
|
||||
- [is_space](#is_space)
|
||||
- [len](#len)
|
||||
- [raw_index](#raw_index)
|
||||
- [reverse](#reverse)
|
||||
- [to_lower](#to_lower)
|
||||
- [to_upper](#to_upper)
|
||||
- [validate](#validate)
|
||||
- [validate_str](#validate_str)
|
||||
|
||||
## get_rune
|
||||
```v
|
||||
fn get_rune(s string, index int) rune
|
||||
```
|
||||
|
||||
get_rune convert a UTF-8 unicode codepoint in string[index] into a UTF-32 encoded rune
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## is_control
|
||||
```v
|
||||
fn is_control(r rune) bool
|
||||
```
|
||||
|
||||
is_control return true if the rune is control code
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## is_global_punct
|
||||
```v
|
||||
fn is_global_punct(s string, index int) bool
|
||||
```
|
||||
|
||||
is_global_punct return true if the string[index] byte of is the start of a global unicode punctuation
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## is_letter
|
||||
```v
|
||||
fn is_letter(r rune) bool
|
||||
```
|
||||
|
||||
is_letter returns true if the rune is unicode letter or in unicode category L
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## is_number
|
||||
```v
|
||||
fn is_number(r rune) bool
|
||||
```
|
||||
|
||||
is_number returns true if the rune is unicode number or in unicode category N
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## is_punct
|
||||
```v
|
||||
fn is_punct(s string, index int) bool
|
||||
```
|
||||
|
||||
is_punct return true if the string[index] byte is the start of a unicode western punctuation
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## is_rune_global_punct
|
||||
```v
|
||||
fn is_rune_global_punct(r rune) bool
|
||||
```
|
||||
|
||||
is_rune_global_punct return true if the input unicode is a global unicode punctuation
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## is_rune_punct
|
||||
```v
|
||||
fn is_rune_punct(r rune) bool
|
||||
```
|
||||
|
||||
is_rune_punct return true if the input unicode is a western unicode punctuation
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## is_space
|
||||
```v
|
||||
fn is_space(r rune) bool
|
||||
```
|
||||
|
||||
is_space returns true if the rune is character in unicode category Z with property white space or the following character set:
|
||||
```
|
||||
`\t`, `\n`, `\v`, `\f`, `\r`, ` `, 0x85 (NEL), 0xA0 (NBSP)
|
||||
```
|
||||
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## len
|
||||
```v
|
||||
fn len(s string) int
|
||||
```
|
||||
|
||||
len return the length as number of unicode chars from a string
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## raw_index
|
||||
```v
|
||||
fn raw_index(s string, index int) string
|
||||
```
|
||||
|
||||
raw_index - get the raw unicode character from the UTF-8 string by the given index value as UTF-8 string. example: utf8.raw_index('我是V Lang', 1) => '是'
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## reverse
|
||||
```v
|
||||
fn reverse(s string) string
|
||||
```
|
||||
|
||||
reverse - returns a reversed string. example: utf8.reverse('你好世界hello world') => 'dlrow olleh界世好你'.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## to_lower
|
||||
```v
|
||||
fn to_lower(s string) string
|
||||
```
|
||||
|
||||
to_lower return an lowercase string from a string
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## to_upper
|
||||
```v
|
||||
fn to_upper(s string) string
|
||||
```
|
||||
|
||||
to_upper return an uppercase string from a string
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## validate
|
||||
```v
|
||||
fn validate(data &u8, len int) bool
|
||||
```
|
||||
|
||||
validate reports if data consists of valid UTF-8 runes
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## validate_str
|
||||
```v
|
||||
fn validate_str(str string) bool
|
||||
```
|
||||
|
||||
validate_str reports if str consists of valid UTF-8 runes
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:18:04
|
||||
329
aiprompts/v_core/encoding/xml.md
Normal file
329
aiprompts/v_core/encoding/xml.md
Normal file
@@ -0,0 +1,329 @@
|
||||
# module xml
|
||||
|
||||
|
||||
## Contents
|
||||
- [Constants](#Constants)
|
||||
- [escape_text](#escape_text)
|
||||
- [parse_single_node](#parse_single_node)
|
||||
- [unescape_text](#unescape_text)
|
||||
- [XMLDocument.from_file](#XMLDocument.from_file)
|
||||
- [XMLDocument.from_reader](#XMLDocument.from_reader)
|
||||
- [XMLDocument.from_string](#XMLDocument.from_string)
|
||||
- [DTDListItem](#DTDListItem)
|
||||
- [XMLNodeContents](#XMLNodeContents)
|
||||
- [DTDElement](#DTDElement)
|
||||
- [DTDEntity](#DTDEntity)
|
||||
- [DocumentType](#DocumentType)
|
||||
- [DocumentTypeDefinition](#DocumentTypeDefinition)
|
||||
- [EscapeConfig](#EscapeConfig)
|
||||
- [UnescapeConfig](#UnescapeConfig)
|
||||
- [XMLCData](#XMLCData)
|
||||
- [XMLComment](#XMLComment)
|
||||
- [XMLDocument](#XMLDocument)
|
||||
- [get_element_by_id](#get_element_by_id)
|
||||
- [get_elements_by_attribute](#get_elements_by_attribute)
|
||||
- [get_elements_by_tag](#get_elements_by_tag)
|
||||
- [pretty_str](#pretty_str)
|
||||
- [str](#str)
|
||||
- [validate](#validate)
|
||||
- [XMLNode](#XMLNode)
|
||||
- [get_element_by_id](#get_element_by_id)
|
||||
- [get_elements_by_attribute](#get_elements_by_attribute)
|
||||
- [get_elements_by_tag](#get_elements_by_tag)
|
||||
- [pretty_str](#pretty_str)
|
||||
|
||||
## Constants
|
||||
```v
|
||||
const default_entities = {
|
||||
'lt': '<'
|
||||
'gt': '>'
|
||||
'amp': '&'
|
||||
'apos': "'"
|
||||
'quot': '"'
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const default_entities_reverse = {
|
||||
'<': 'lt'
|
||||
'>': 'gt'
|
||||
'&': 'amp'
|
||||
"'": 'apos'
|
||||
'"': 'quot'
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## escape_text
|
||||
```v
|
||||
fn escape_text(content string, config EscapeConfig) string
|
||||
```
|
||||
|
||||
escape_text replaces all entities in the given string with their respective XML entity strings. See default_entities, which can be overridden.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## parse_single_node
|
||||
```v
|
||||
fn parse_single_node(first_char u8, mut reader io.Reader) !XMLNode
|
||||
```
|
||||
|
||||
parse_single_node parses a single XML node from the reader. The first character of the tag is passed in as the first_char parameter. This function is meant to assist in parsing nested nodes one at a time. Using this function as opposed to the recommended static functions makes it easier to parse smaller nodes in extremely large XML documents without running out of memory.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## unescape_text
|
||||
```v
|
||||
fn unescape_text(content string, config UnescapeConfig) !string
|
||||
```
|
||||
|
||||
unescape_text replaces all entities in the given string with their respective original characters or strings. See default_entities_reverse, which can be overridden.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## XMLDocument.from_file
|
||||
```v
|
||||
fn XMLDocument.from_file(path string) !XMLDocument
|
||||
```
|
||||
|
||||
XMLDocument.from_file parses an XML document from a file. Note that the file is read in its entirety and then parsed. If the file is too large, try using the XMLDocument.from_reader function instead.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## XMLDocument.from_reader
|
||||
```v
|
||||
fn XMLDocument.from_reader(mut reader io.Reader) !XMLDocument
|
||||
```
|
||||
|
||||
XMLDocument.from_reader parses an XML document from a reader. This is the most generic way to parse an XML document from any arbitrary source that implements that io.Reader interface.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## XMLDocument.from_string
|
||||
```v
|
||||
fn XMLDocument.from_string(raw_contents string) !XMLDocument
|
||||
```
|
||||
|
||||
XMLDocument.from_string parses an XML document from a string.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## DTDListItem
|
||||
```v
|
||||
type DTDListItem = DTDElement | DTDEntity
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## XMLNodeContents
|
||||
```v
|
||||
type XMLNodeContents = XMLCData | XMLComment | XMLNode | string
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## DTDElement
|
||||
```v
|
||||
struct DTDElement {
|
||||
pub:
|
||||
name string @[required]
|
||||
definition []string @[required]
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## DTDEntity
|
||||
```v
|
||||
struct DTDEntity {
|
||||
pub:
|
||||
name string @[required]
|
||||
value string @[required]
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## DocumentType
|
||||
```v
|
||||
struct DocumentType {
|
||||
pub:
|
||||
name string @[required]
|
||||
dtd DTDInfo
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## DocumentTypeDefinition
|
||||
```v
|
||||
struct DocumentTypeDefinition {
|
||||
pub:
|
||||
name string
|
||||
list []DTDListItem
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## EscapeConfig
|
||||
```v
|
||||
struct EscapeConfig {
|
||||
pub:
|
||||
reverse_entities map[string]string = default_entities_reverse
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## UnescapeConfig
|
||||
```v
|
||||
struct UnescapeConfig {
|
||||
pub:
|
||||
entities map[string]string = default_entities
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## XMLCData
|
||||
```v
|
||||
struct XMLCData {
|
||||
pub:
|
||||
text string @[required]
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## XMLComment
|
||||
```v
|
||||
struct XMLComment {
|
||||
pub:
|
||||
text string @[required]
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## XMLDocument
|
||||
```v
|
||||
struct XMLDocument {
|
||||
Prolog
|
||||
pub:
|
||||
root XMLNode @[required]
|
||||
}
|
||||
```
|
||||
|
||||
XMLDocument is the struct that represents a single XML document. It contains the prolog and the single root node. The prolog struct is embedded into the XMLDocument struct, so that the prolog fields are accessible directly from the this struct. Public prolog fields include version, enccoding, comments preceding the root node, and the document type definition.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## get_element_by_id
|
||||
```v
|
||||
fn (doc XMLDocument) get_element_by_id(id string) ?XMLNode
|
||||
```
|
||||
|
||||
get_element_by_id returns the first element with the given id, or none if no such element exists.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## get_elements_by_attribute
|
||||
```v
|
||||
fn (doc XMLDocument) get_elements_by_attribute(attribute string, value string) []XMLNode
|
||||
```
|
||||
|
||||
get_elements_by_attribute returns all elements with the given attribute-value pair. If there are no such elements, an empty array is returned.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## get_elements_by_tag
|
||||
```v
|
||||
fn (doc XMLDocument) get_elements_by_tag(tag string) []XMLNode
|
||||
```
|
||||
|
||||
get_elements_by_tag returns all elements with the given tag name. If there are no such elements, an empty array is returned.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## pretty_str
|
||||
```v
|
||||
fn (doc XMLDocument) pretty_str(indent string) string
|
||||
```
|
||||
|
||||
pretty_str returns a pretty-printed version of the XML document. It requires the string used to indent each level of the document.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## str
|
||||
```v
|
||||
fn (doc XMLDocument) str() string
|
||||
```
|
||||
|
||||
str returns a string representation of the XML document. It uses a 2-space indentation to pretty-print the document.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## validate
|
||||
```v
|
||||
fn (doc XMLDocument) validate() !XMLDocument
|
||||
```
|
||||
|
||||
validate checks the document is well-formed and valid. It returns a new document with the parsed entities expanded when validation is successful. Otherwise it returns an error.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## XMLNode
|
||||
```v
|
||||
struct XMLNode {
|
||||
pub:
|
||||
name string @[required]
|
||||
attributes map[string]string
|
||||
children []XMLNodeContents
|
||||
}
|
||||
```
|
||||
|
||||
XMLNode represents a single XML node. It contains the node name, a map of attributes, and a list of children. The children can be other XML nodes, CDATA, plain text, or comments.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## get_element_by_id
|
||||
```v
|
||||
fn (node XMLNode) get_element_by_id(id string) ?XMLNode
|
||||
```
|
||||
|
||||
get_element_by_id returns the first element with the given id, or none if no such element exists in the subtree rooted at this node.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## get_elements_by_attribute
|
||||
```v
|
||||
fn (node XMLNode) get_elements_by_attribute(attribute string, value string) []XMLNode
|
||||
```
|
||||
|
||||
get_elements_by_attribute returns all elements with the given attribute-value pair in the subtree rooted at this node. If there are no such elements, an empty array is returned.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## get_elements_by_tag
|
||||
```v
|
||||
fn (node XMLNode) get_elements_by_tag(tag string) []XMLNode
|
||||
```
|
||||
|
||||
get_elements_by_tag returns all elements with the given tag name in the subtree rooted at this node. If there are no such elements, an empty array is returned.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## pretty_str
|
||||
```v
|
||||
fn (node XMLNode) pretty_str(original_indent string, depth int, reverse_entities map[string]string) string
|
||||
```
|
||||
|
||||
pretty_str returns a pretty-printed version of the XML node. It requires the current indentation the node is at, the depth of the node in the tree, and a map of reverse entities to use when escaping text.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:18:04
|
||||
419
aiprompts/v_core/io/io.md
Normal file
419
aiprompts/v_core/io/io.md
Normal file
@@ -0,0 +1,419 @@
|
||||
# module io
|
||||
|
||||
|
||||
## Contents
|
||||
- [Constants](#Constants)
|
||||
- [cp](#cp)
|
||||
- [make_readerwriter](#make_readerwriter)
|
||||
- [new_buffered_reader](#new_buffered_reader)
|
||||
- [new_buffered_writer](#new_buffered_writer)
|
||||
- [new_multi_writer](#new_multi_writer)
|
||||
- [read_all](#read_all)
|
||||
- [read_any](#read_any)
|
||||
- [RandomReader](#RandomReader)
|
||||
- [RandomWriter](#RandomWriter)
|
||||
- [Reader](#Reader)
|
||||
- [ReaderWriter](#ReaderWriter)
|
||||
- [Writer](#Writer)
|
||||
- [ReaderWriterImpl](#ReaderWriterImpl)
|
||||
- [read](#read)
|
||||
- [write](#write)
|
||||
- [BufferedReadLineConfig](#BufferedReadLineConfig)
|
||||
- [BufferedReader](#BufferedReader)
|
||||
- [read](#read)
|
||||
- [free](#free)
|
||||
- [end_of_stream](#end_of_stream)
|
||||
- [read_line](#read_line)
|
||||
- [BufferedReaderConfig](#BufferedReaderConfig)
|
||||
- [BufferedWriter](#BufferedWriter)
|
||||
- [reset](#reset)
|
||||
- [buffered](#buffered)
|
||||
- [flush](#flush)
|
||||
- [available](#available)
|
||||
- [write](#write)
|
||||
- [BufferedWriterConfig](#BufferedWriterConfig)
|
||||
- [CopySettings](#CopySettings)
|
||||
- [Eof](#Eof)
|
||||
- [MultiWriter](#MultiWriter)
|
||||
- [write](#write)
|
||||
- [NotExpected](#NotExpected)
|
||||
- [ReadAllConfig](#ReadAllConfig)
|
||||
|
||||
## Constants
|
||||
```v
|
||||
const read_all_len = 10 * 1024
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const read_all_grow_len = 1024
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## cp
|
||||
```v
|
||||
fn cp(mut src Reader, mut dst Writer, params CopySettings) !
|
||||
```
|
||||
|
||||
cp copies from `src` to `dst` by allocating a maximum of 1024 bytes buffer for reading until either EOF is reached on `src` or an error occurs. An error is returned if an error is encountered during write.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## make_readerwriter
|
||||
```v
|
||||
fn make_readerwriter(r Reader, w Writer) ReaderWriterImpl
|
||||
```
|
||||
|
||||
make_readerwriter takes a rstream and a wstream and makes an rwstream with them.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new_buffered_reader
|
||||
```v
|
||||
fn new_buffered_reader(o BufferedReaderConfig) &BufferedReader
|
||||
```
|
||||
|
||||
new_buffered_reader creates a new BufferedReader.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new_buffered_writer
|
||||
```v
|
||||
fn new_buffered_writer(o BufferedWriterConfig) !&BufferedWriter
|
||||
```
|
||||
|
||||
new_buffered_writer creates a new BufferedWriter with the specified BufferedWriterConfig. Returns an error when cap is 0 or negative.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new_multi_writer
|
||||
```v
|
||||
fn new_multi_writer(writers ...Writer) Writer
|
||||
```
|
||||
|
||||
new_multi_writer returns a Writer that writes to all writers. The write function of the returned Writer writes to all writers of the MultiWriter, returns the length of bytes written, and if any writer fails to write the full length an error is returned and writing to other writers stops, and if any writer returns an error the error is returned immediately and writing to other writers stops.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## read_all
|
||||
```v
|
||||
fn read_all(config ReadAllConfig) ![]u8
|
||||
```
|
||||
|
||||
read_all reads all bytes from a reader until either a 0 length read or if read_to_end_of_stream is true then the end of the stream (`none`).
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## read_any
|
||||
```v
|
||||
fn read_any(mut r Reader) ![]u8
|
||||
```
|
||||
|
||||
read_any reads any available bytes from a reader (until the reader returns a read of 0 length).
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## RandomReader
|
||||
```v
|
||||
interface RandomReader {
|
||||
read_from(pos u64, mut buf []u8) !int
|
||||
}
|
||||
```
|
||||
|
||||
RandomReader represents a stream of readable data from at a random location.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## RandomWriter
|
||||
```v
|
||||
interface RandomWriter {
|
||||
write_to(pos u64, buf []u8) !int
|
||||
}
|
||||
```
|
||||
|
||||
RandomWriter is the interface that wraps the `write_to` method, which writes `buf.len` bytes to the underlying data stream at a random `pos`.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Reader
|
||||
```v
|
||||
interface Reader {
|
||||
// read reads up to buf.len bytes and places
|
||||
// them into buf.
|
||||
// A type that implements this should return
|
||||
// `io.Eof` on end of stream (EOF) instead of just returning 0
|
||||
mut:
|
||||
read(mut buf []u8) !int
|
||||
}
|
||||
```
|
||||
|
||||
Reader represents a stream of data that can be read.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## ReaderWriter
|
||||
```v
|
||||
interface ReaderWriter {
|
||||
Reader
|
||||
Writer
|
||||
}
|
||||
```
|
||||
|
||||
ReaderWriter represents a stream that can be read and written.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Writer
|
||||
```v
|
||||
interface Writer {
|
||||
mut:
|
||||
write(buf []u8) !int
|
||||
}
|
||||
```
|
||||
|
||||
Writer is the interface that wraps the `write` method, which writes `buf.len` bytes to the underlying data stream.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## ReaderWriterImpl
|
||||
## read
|
||||
```v
|
||||
fn (mut r ReaderWriterImpl) read(mut buf []u8) !int
|
||||
```
|
||||
|
||||
read reads up to `buf.len` bytes into `buf`. It returns the number of bytes read or any error encountered.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## write
|
||||
```v
|
||||
fn (mut r ReaderWriterImpl) write(buf []u8) !int
|
||||
```
|
||||
|
||||
write writes `buf.len` bytes from `buf` to the underlying data stream. It returns the number of bytes written or any error encountered.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## BufferedReadLineConfig
|
||||
```v
|
||||
struct BufferedReadLineConfig {
|
||||
pub:
|
||||
delim u8 = `\n` // line delimiter
|
||||
}
|
||||
```
|
||||
|
||||
BufferedReadLineConfig are options that can be given to the read_line() function.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## BufferedReader
|
||||
```v
|
||||
struct BufferedReader {
|
||||
mut:
|
||||
reader Reader
|
||||
buf []u8
|
||||
offset int // current offset in the buffer
|
||||
len int
|
||||
fails int // how many times fill_buffer has read 0 bytes in a row
|
||||
mfails int // maximum fails, after which we can assume that the stream has ended
|
||||
pub mut:
|
||||
end_of_stream bool // whether we reached the end of the upstream reader
|
||||
total_read int // total number of bytes read
|
||||
}
|
||||
```
|
||||
|
||||
BufferedReader provides a buffered interface for a reader.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## read
|
||||
```v
|
||||
fn (mut r BufferedReader) read(mut buf []u8) !int
|
||||
```
|
||||
|
||||
read fufills the Reader interface.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## free
|
||||
```v
|
||||
fn (mut r BufferedReader) free()
|
||||
```
|
||||
|
||||
free deallocates the memory for a buffered reader's internal buffer.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## end_of_stream
|
||||
```v
|
||||
fn (r BufferedReader) end_of_stream() bool
|
||||
```
|
||||
|
||||
end_of_stream returns whether the end of the stream was reached.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## read_line
|
||||
```v
|
||||
fn (mut r BufferedReader) read_line(config BufferedReadLineConfig) !string
|
||||
```
|
||||
|
||||
read_line attempts to read a line from the buffered reader. It will read until it finds the specified line delimiter such as (\n, the default or \0) or the end of stream.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## BufferedReaderConfig
|
||||
```v
|
||||
struct BufferedReaderConfig {
|
||||
pub:
|
||||
reader Reader
|
||||
cap int = 128 * 1024 // large for fast reading of big(ish) files
|
||||
retries int = 2 // how many times to retry before assuming the stream ended
|
||||
}
|
||||
```
|
||||
|
||||
BufferedReaderConfig are options that can be given to a buffered reader.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## BufferedWriter
|
||||
```v
|
||||
struct BufferedWriter {
|
||||
mut:
|
||||
n int
|
||||
wr Writer
|
||||
pub mut:
|
||||
buf []u8
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## reset
|
||||
```v
|
||||
fn (mut b BufferedWriter) reset()
|
||||
```
|
||||
|
||||
reset resets the buffer to its initial state.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## buffered
|
||||
```v
|
||||
fn (b BufferedWriter) buffered() int
|
||||
```
|
||||
|
||||
buffered returns the number of bytes currently stored in the buffer.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## flush
|
||||
```v
|
||||
fn (mut b BufferedWriter) flush() !
|
||||
```
|
||||
|
||||
flush writes the buffered data to the underlying writer and clears the buffer, ensures all data is written. Returns an error if the writer fails to write all buffered data.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## available
|
||||
```v
|
||||
fn (b BufferedWriter) available() int
|
||||
```
|
||||
|
||||
available returns the amount of available space left in the buffer.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## write
|
||||
```v
|
||||
fn (mut b BufferedWriter) write(src []u8) !int
|
||||
```
|
||||
|
||||
write writes `src` in the buffer, flushing it to the underlying writer as needed, and returns the number of bytes written.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## BufferedWriterConfig
|
||||
```v
|
||||
struct BufferedWriterConfig {
|
||||
pub:
|
||||
writer Writer
|
||||
cap int = 128 * 1024
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## CopySettings
|
||||
```v
|
||||
struct CopySettings {
|
||||
pub mut:
|
||||
buffer_size int = 64 * 1024 // The buffer size used during the copying. A larger buffer is more performant, but uses more RAM.
|
||||
}
|
||||
```
|
||||
|
||||
CopySettings provides additional options to io.cp
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Eof
|
||||
```v
|
||||
struct Eof {
|
||||
Error
|
||||
}
|
||||
```
|
||||
|
||||
Eof error means that we reach the end of the stream.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## MultiWriter
|
||||
```v
|
||||
struct MultiWriter {
|
||||
pub mut:
|
||||
writers []Writer
|
||||
}
|
||||
```
|
||||
|
||||
MultiWriter writes to all its writers.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## write
|
||||
```v
|
||||
fn (mut m MultiWriter) write(buf []u8) !int
|
||||
```
|
||||
|
||||
write writes to all writers of the MultiWriter. Returns the length of bytes written. If any writer fails to write the full length an error is returned and writing to other writers stops. If any writer returns an error the error is returned immediately and writing to other writers stops.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## NotExpected
|
||||
```v
|
||||
struct NotExpected {
|
||||
cause string
|
||||
code int
|
||||
}
|
||||
```
|
||||
|
||||
NotExpected is a generic error that means that we receave a not expected error.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## ReadAllConfig
|
||||
```v
|
||||
struct ReadAllConfig {
|
||||
pub:
|
||||
read_to_end_of_stream bool
|
||||
reader Reader
|
||||
}
|
||||
```
|
||||
|
||||
ReadAllConfig allows options to be passed for the behaviour of read_all.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:19:15
|
||||
219
aiprompts/v_core/io/string_reader.md
Normal file
219
aiprompts/v_core/io/string_reader.md
Normal file
@@ -0,0 +1,219 @@
|
||||
# module string_reader
|
||||
|
||||
|
||||
## Contents
|
||||
- [StringReader.new](#StringReader.new)
|
||||
- [StringReader](#StringReader)
|
||||
- [needs_fill](#needs_fill)
|
||||
- [needs_fill_until](#needs_fill_until)
|
||||
- [fill_buffer](#fill_buffer)
|
||||
- [fill_buffer_until](#fill_buffer_until)
|
||||
- [read_all_bytes](#read_all_bytes)
|
||||
- [read_all](#read_all)
|
||||
- [read_bytes](#read_bytes)
|
||||
- [read_string](#read_string)
|
||||
- [read](#read)
|
||||
- [read_line](#read_line)
|
||||
- [write](#write)
|
||||
- [get_data](#get_data)
|
||||
- [get_part](#get_part)
|
||||
- [get_string](#get_string)
|
||||
- [get_string_part](#get_string_part)
|
||||
- [flush](#flush)
|
||||
- [free](#free)
|
||||
- [StringReaderParams](#StringReaderParams)
|
||||
|
||||
## StringReader.new
|
||||
```v
|
||||
fn StringReader.new(params StringReaderParams) StringReader
|
||||
```
|
||||
|
||||
new creates a new StringReader and sets the string builder size to `initial_size`. If a source
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## StringReader
|
||||
```v
|
||||
struct StringReader {
|
||||
mut:
|
||||
reader ?io.Reader
|
||||
offset int // current offset in the buffer
|
||||
pub mut:
|
||||
end_of_stream bool // whether we reached the end of the upstream reader
|
||||
builder strings.Builder
|
||||
}
|
||||
```
|
||||
|
||||
StringReader is able to read data from a Reader interface and/or source string to a dynamically growing buffer using a string builder. Unlike the BufferedReader, StringReader will keep the entire contents of the buffer in memory, allowing the incoming data to be reused and read in an efficient matter. The StringReader will not set a maximum capacity to the string builders buffer and could grow very large.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## needs_fill
|
||||
```v
|
||||
fn (r StringReader) needs_fill() bool
|
||||
```
|
||||
|
||||
needs_fill returns whether the buffer needs refilling
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## needs_fill_until
|
||||
```v
|
||||
fn (r StringReader) needs_fill_until(n int) bool
|
||||
```
|
||||
|
||||
needs_fill_until returns whether the buffer needs refilling in order to read `n` bytes
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## fill_buffer
|
||||
```v
|
||||
fn (mut r StringReader) fill_buffer(read_till_end_of_stream bool) !int
|
||||
```
|
||||
|
||||
fill_bufer tries to read data into the buffer until either a 0 length read or if read_to_end_of_stream is true then the end of the stream. It returns the number of bytes read
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## fill_buffer_until
|
||||
```v
|
||||
fn (mut r StringReader) fill_buffer_until(n int) !int
|
||||
```
|
||||
|
||||
fill_buffer_until tries read `n` amount of bytes from the reader into the buffer and returns the actual number of bytes read
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## read_all_bytes
|
||||
```v
|
||||
fn (mut r StringReader) read_all_bytes(read_till_end_of_stream bool) ![]u8
|
||||
```
|
||||
|
||||
read_all_bytes reads all bytes from a reader until either a 0 length read or if read_to_end_of_stream is true then the end of the stream. It returns a copy of the read data
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## read_all
|
||||
```v
|
||||
fn (mut r StringReader) read_all(read_till_end_of_stream bool) !string
|
||||
```
|
||||
|
||||
read_all reads all bytes from a reader until either a 0 length read or if read_to_end_of_stream is true then the end of the stream. It produces a string from the read data
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## read_bytes
|
||||
```v
|
||||
fn (mut r StringReader) read_bytes(n int) ![]u8
|
||||
```
|
||||
|
||||
read_bytes tries to read n amount of bytes from the reader
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## read_string
|
||||
```v
|
||||
fn (mut r StringReader) read_string(n int) !string
|
||||
```
|
||||
|
||||
read_bytes tries to read `n` amount of bytes from the reader and produces a string from the read data
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## read
|
||||
```v
|
||||
fn (mut r StringReader) read(mut buf []u8) !int
|
||||
```
|
||||
|
||||
read implements the Reader interface
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## read_line
|
||||
```v
|
||||
fn (mut r StringReader) read_line(config io.BufferedReadLineConfig) !string
|
||||
```
|
||||
|
||||
read_line attempts to read a line from the reader. It will read until it finds the specified line delimiter such as (\n, the default or \0) or the end of stream.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## write
|
||||
```v
|
||||
fn (mut r StringReader) write(buf []u8) !int
|
||||
```
|
||||
|
||||
write implements the Writer interface
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## get_data
|
||||
```v
|
||||
fn (r StringReader) get_data() []u8
|
||||
```
|
||||
|
||||
get_data returns a copy of the buffer
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## get_part
|
||||
```v
|
||||
fn (r StringReader) get_part(start int, n int) ![]u8
|
||||
```
|
||||
|
||||
get get_part returns a copy of a part of the buffer from `start` till `start` + `n`
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## get_string
|
||||
```v
|
||||
fn (r StringReader) get_string() string
|
||||
```
|
||||
|
||||
get_string produces a string from all the bytes in the buffer
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## get_string_part
|
||||
```v
|
||||
fn (r StringReader) get_string_part(start int, n int) !string
|
||||
```
|
||||
|
||||
get_string_part produces a string from `start` till `start` + `n` of the buffer
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## flush
|
||||
```v
|
||||
fn (mut r StringReader) flush() string
|
||||
```
|
||||
|
||||
flush clears the stringbuilder and returns the resulting string and the stringreaders offset is reset to 0
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## free
|
||||
```v
|
||||
fn (mut r StringReader) free()
|
||||
```
|
||||
|
||||
free frees the memory block used for the string builders buffer, a new string builder with size 0 is initialized and the stringreaders offset is reset to 0
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## StringReaderParams
|
||||
```v
|
||||
struct StringReaderParams {
|
||||
pub:
|
||||
// the reader interface
|
||||
reader ?io.Reader
|
||||
// initialize the builder with this source string
|
||||
source ?string
|
||||
// if no source is given the string builder is initialized with this size
|
||||
initial_size int
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:19:15
|
||||
50
aiprompts/v_core/io/util.md
Normal file
50
aiprompts/v_core/io/util.md
Normal file
@@ -0,0 +1,50 @@
|
||||
# module util
|
||||
|
||||
|
||||
## Contents
|
||||
- [temp_dir](#temp_dir)
|
||||
- [temp_file](#temp_file)
|
||||
- [TempDirOptions](#TempDirOptions)
|
||||
- [TempFileOptions](#TempFileOptions)
|
||||
|
||||
## temp_dir
|
||||
```v
|
||||
fn temp_dir(tdo TempFileOptions) !string
|
||||
```
|
||||
|
||||
temp_dir returns a uniquely named, writable, directory path.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## temp_file
|
||||
```v
|
||||
fn temp_file(tfo TempFileOptions) !(os.File, string)
|
||||
```
|
||||
|
||||
temp_file returns a uniquely named, open, writable, `os.File` and it's path.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## TempDirOptions
|
||||
```v
|
||||
struct TempDirOptions {
|
||||
pub:
|
||||
path string = os.temp_dir()
|
||||
pattern string
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## TempFileOptions
|
||||
```v
|
||||
struct TempFileOptions {
|
||||
pub:
|
||||
path string = os.temp_dir()
|
||||
pattern string
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:19:15
|
||||
86
aiprompts/v_core/maps/maps.md
Normal file
86
aiprompts/v_core/maps/maps.md
Normal file
@@ -0,0 +1,86 @@
|
||||
# module maps
|
||||
|
||||
|
||||
## Contents
|
||||
- [filter](#filter)
|
||||
- [flat_map](#flat_map)
|
||||
- [from_array](#from_array)
|
||||
- [invert](#invert)
|
||||
- [merge](#merge)
|
||||
- [merge_in_place](#merge_in_place)
|
||||
- [to_array](#to_array)
|
||||
- [to_map](#to_map)
|
||||
|
||||
## filter
|
||||
```v
|
||||
fn filter[K, V](m map[K]V, f fn (key K, val V) bool) map[K]V
|
||||
```
|
||||
|
||||
filter filters map entries by the given predicate function
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## flat_map
|
||||
```v
|
||||
fn flat_map[K, V, I](m map[K]V, f fn (key K, val V) []I) []I
|
||||
```
|
||||
|
||||
flat_map maps map entries into arrays and flattens into a one-dimensional array
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## from_array
|
||||
```v
|
||||
fn from_array[T](array []T) map[int]T
|
||||
```
|
||||
|
||||
from_array maps array into map with index to element per entry
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## invert
|
||||
```v
|
||||
fn invert[K, V](m map[K]V) map[V]K
|
||||
```
|
||||
|
||||
invert returns a new map, created by swapping key to value and vice versa for each entry.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## merge
|
||||
```v
|
||||
fn merge[K, V](m1 map[K]V, m2 map[K]V) map[K]V
|
||||
```
|
||||
|
||||
merge produces a map, that is the result of merging the first map `m1`, with the second map `m2`. If a key exists in both maps, the value from m2, will override the value from m1. The original maps `m1` and `m2`, will not be modified. The return value is a new map.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## merge_in_place
|
||||
```v
|
||||
fn merge_in_place[K, V](mut m1 map[K]V, m2 map[K]V)
|
||||
```
|
||||
|
||||
merge_in_place merges all elements of `m2` into the mutable map `m1`. If a key exists in both maps, the value from `m1` will be overwritten by the value from `m2`. Note that this function modifes `m1`, while `m2` will not be.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## to_array
|
||||
```v
|
||||
fn to_array[K, V, I](m map[K]V, f fn (key K, val V) I) []I
|
||||
```
|
||||
|
||||
to_array maps map entries into one-dimensional array
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## to_map
|
||||
```v
|
||||
fn to_map[K, V, X, Y](m map[K]V, f fn (key K, val V) (X, Y)) map[X]Y
|
||||
```
|
||||
|
||||
to_map maps map entries into new entries and constructs a new map
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:19:30
|
||||
136
aiprompts/v_core/net/conv.md
Normal file
136
aiprompts/v_core/net/conv.md
Normal file
@@ -0,0 +1,136 @@
|
||||
# module conv
|
||||
|
||||
|
||||
## Contents
|
||||
- [hton16](#hton16)
|
||||
- [hton32](#hton32)
|
||||
- [hton64](#hton64)
|
||||
- [htonf32](#htonf32)
|
||||
- [htonf64](#htonf64)
|
||||
- [ntoh16](#ntoh16)
|
||||
- [ntoh32](#ntoh32)
|
||||
- [ntoh64](#ntoh64)
|
||||
- [reverse_bytes_u16](#reverse_bytes_u16)
|
||||
- [reverse_bytes_u32](#reverse_bytes_u32)
|
||||
- [reverse_bytes_u64](#reverse_bytes_u64)
|
||||
- [u64tovarint](#u64tovarint)
|
||||
- [varinttou64](#varinttou64)
|
||||
|
||||
## hton16
|
||||
```v
|
||||
fn hton16(host u16) u16
|
||||
```
|
||||
|
||||
hton16 converts the 16 bit value `host` to the net format (htons)
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## hton32
|
||||
```v
|
||||
fn hton32(host u32) u32
|
||||
```
|
||||
|
||||
hton32 converts the 32 bit value `host` to the net format (htonl)
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## hton64
|
||||
```v
|
||||
fn hton64(host u64) u64
|
||||
```
|
||||
|
||||
hton64 converts the 64 bit value `host` to the net format (htonll)
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## htonf32
|
||||
```v
|
||||
fn htonf32(host f32) f32
|
||||
```
|
||||
|
||||
htonf32 converts the 32 bit double `host` to the net format
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## htonf64
|
||||
```v
|
||||
fn htonf64(host f64) f64
|
||||
```
|
||||
|
||||
htonf64 converts the 64 bit double `host` to the net format
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## ntoh16
|
||||
```v
|
||||
fn ntoh16(net u16) u16
|
||||
```
|
||||
|
||||
ntoh16 converts the 16 bit value `net` to the host format (ntohs)
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## ntoh32
|
||||
```v
|
||||
fn ntoh32(net u32) u32
|
||||
```
|
||||
|
||||
ntoh32 converts the 32 bit value `net` to the host format (ntohl)
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## ntoh64
|
||||
```v
|
||||
fn ntoh64(net u64) u64
|
||||
```
|
||||
|
||||
ntoh64 converts the 64 bit value `net` to the host format (ntohll)
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## reverse_bytes_u16
|
||||
```v
|
||||
fn reverse_bytes_u16(a u16) u16
|
||||
```
|
||||
|
||||
reverse_bytes_u16 reverse a u16's byte order
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## reverse_bytes_u32
|
||||
```v
|
||||
fn reverse_bytes_u32(a u32) u32
|
||||
```
|
||||
|
||||
reverse_bytes_u32 reverse a u32's byte order
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## reverse_bytes_u64
|
||||
```v
|
||||
fn reverse_bytes_u64(a u64) u64
|
||||
```
|
||||
|
||||
reverse_bytes_u64 reverse a u64's byte order
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## u64tovarint
|
||||
```v
|
||||
fn u64tovarint(n u64) ![]u8
|
||||
```
|
||||
|
||||
u64tovarint converts the given 64 bit number `n`, where n < 2^62 to a byte array, using the variable length unsigned integer encoding from: https://datatracker.ietf.org/doc/html/rfc9000#section-16 . The returned array length .len, will be in [1,2,4,8] .
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## varinttou64
|
||||
```v
|
||||
fn varinttou64(b []u8) !(u64, u8)
|
||||
```
|
||||
|
||||
varinttou64 parses a variable length number from the start of the given byte array `b`. If it succeeds, it returns the decoded number, and the length of the parsed byte span.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:16:36
|
||||
88
aiprompts/v_core/net/ftp.md
Normal file
88
aiprompts/v_core/net/ftp.md
Normal file
@@ -0,0 +1,88 @@
|
||||
# module ftp
|
||||
|
||||
|
||||
## Contents
|
||||
- [new](#new)
|
||||
- [FTP](#FTP)
|
||||
- [connect](#connect)
|
||||
- [login](#login)
|
||||
- [close](#close)
|
||||
- [pwd](#pwd)
|
||||
- [cd](#cd)
|
||||
- [dir](#dir)
|
||||
- [get](#get)
|
||||
|
||||
## new
|
||||
```v
|
||||
fn new() FTP
|
||||
```
|
||||
|
||||
new returns an `FTP` instance.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## FTP
|
||||
## connect
|
||||
```v
|
||||
fn (mut zftp FTP) connect(oaddress string) !bool
|
||||
```
|
||||
|
||||
connect establishes an FTP connection to the host at `oaddress` (ip:port).
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## login
|
||||
```v
|
||||
fn (mut zftp FTP) login(user string, passwd string) !bool
|
||||
```
|
||||
|
||||
login sends the "USER `user`" and "PASS `passwd`" commands to the remote host.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## close
|
||||
```v
|
||||
fn (mut zftp FTP) close() !
|
||||
```
|
||||
|
||||
close closes the FTP connection.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## pwd
|
||||
```v
|
||||
fn (mut zftp FTP) pwd() !string
|
||||
```
|
||||
|
||||
pwd returns the current working directory on the remote host for the logged in user.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## cd
|
||||
```v
|
||||
fn (mut zftp FTP) cd(dir string) !
|
||||
```
|
||||
|
||||
cd changes the current working directory to the specified remote directory `dir`.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## dir
|
||||
```v
|
||||
fn (mut zftp FTP) dir() ![]string
|
||||
```
|
||||
|
||||
dir returns a list of the files in the current working directory.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## get
|
||||
```v
|
||||
fn (mut zftp FTP) get(file string) ![]u8
|
||||
```
|
||||
|
||||
get retrieves `file` from the remote host.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:16:36
|
||||
316
aiprompts/v_core/net/html.md
Normal file
316
aiprompts/v_core/net/html.md
Normal file
@@ -0,0 +1,316 @@
|
||||
# module html
|
||||
|
||||
|
||||
## Contents
|
||||
- [parse](#parse)
|
||||
- [parse_file](#parse_file)
|
||||
- [CloseTagType](#CloseTagType)
|
||||
- [DocumentObjectModel](#DocumentObjectModel)
|
||||
- [get_root](#get_root)
|
||||
- [get_tags](#get_tags)
|
||||
- [get_tags_by_class_name](#get_tags_by_class_name)
|
||||
- [get_tags_by_attribute](#get_tags_by_attribute)
|
||||
- [get_tags_by_attribute_value](#get_tags_by_attribute_value)
|
||||
- [GetTagsOptions](#GetTagsOptions)
|
||||
- [Parser](#Parser)
|
||||
- [add_code_tag](#add_code_tag)
|
||||
- [split_parse](#split_parse)
|
||||
- [parse_html](#parse_html)
|
||||
- [finalize](#finalize)
|
||||
- [get_dom](#get_dom)
|
||||
- [Tag](#Tag)
|
||||
- [text](#text)
|
||||
- [str](#str)
|
||||
- [get_tag](#get_tag)
|
||||
- [get_tags](#get_tags)
|
||||
- [get_tag_by_attribute](#get_tag_by_attribute)
|
||||
- [get_tags_by_attribute](#get_tags_by_attribute)
|
||||
- [get_tag_by_attribute_value](#get_tag_by_attribute_value)
|
||||
- [get_tags_by_attribute_value](#get_tags_by_attribute_value)
|
||||
- [get_tag_by_class_name](#get_tag_by_class_name)
|
||||
- [get_tags_by_class_name](#get_tags_by_class_name)
|
||||
|
||||
## parse
|
||||
```v
|
||||
fn parse(text string) DocumentObjectModel
|
||||
```
|
||||
|
||||
parse parses and returns the DOM from the given text.
|
||||
|
||||
Note: this function converts tags to lowercase. E.g. <MyTag>content</MyTag> is parsed as <mytag>content</mytag>.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## parse_file
|
||||
```v
|
||||
fn parse_file(filename string) DocumentObjectModel
|
||||
```
|
||||
|
||||
parse_file parses and returns the DOM from the contents of a file.
|
||||
|
||||
Note: this function converts tags to lowercase. E.g. <MyTag>content</MyTag> is parsed as <mytag>content</mytag>.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## CloseTagType
|
||||
```v
|
||||
enum CloseTagType {
|
||||
in_name
|
||||
new_tag
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## DocumentObjectModel
|
||||
```v
|
||||
struct DocumentObjectModel {
|
||||
mut:
|
||||
root &Tag = unsafe { nil }
|
||||
constructed bool
|
||||
btree BTree
|
||||
all_tags []&Tag
|
||||
all_attributes map[string][]&Tag
|
||||
close_tags map[string]bool // add a counter to see count how many times is closed and parse correctly
|
||||
attributes map[string][]string
|
||||
tag_attributes map[string][][]&Tag
|
||||
tag_type map[string][]&Tag
|
||||
debug_file os.File
|
||||
}
|
||||
```
|
||||
|
||||
The W3C Document Object Model (DOM) is a platform and language-neutral interface that allows programs and scripts to dynamically access and update the content, structure, and style of a document.
|
||||
|
||||
https://www.w3.org/TR/WD-DOM/introduction.html
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## get_root
|
||||
```v
|
||||
fn (dom &DocumentObjectModel) get_root() &Tag
|
||||
```
|
||||
|
||||
get_root returns the root of the document.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## get_tags
|
||||
```v
|
||||
fn (dom &DocumentObjectModel) get_tags(options GetTagsOptions) []&Tag
|
||||
```
|
||||
|
||||
get_tags returns all tags stored in the document.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## get_tags_by_class_name
|
||||
```v
|
||||
fn (dom &DocumentObjectModel) get_tags_by_class_name(names ...string) []&Tag
|
||||
```
|
||||
|
||||
get_tags_by_class_name retrieves all tags recursively in the document root that have the given class name(s).
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## get_tags_by_attribute
|
||||
```v
|
||||
fn (dom &DocumentObjectModel) get_tags_by_attribute(name string) []&Tag
|
||||
```
|
||||
|
||||
get_tags_by_attribute retrieves all tags in the document that have the given attribute name.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## get_tags_by_attribute_value
|
||||
```v
|
||||
fn (mut dom DocumentObjectModel) get_tags_by_attribute_value(name string, value string) []&Tag
|
||||
```
|
||||
|
||||
get_tags_by_attribute_value retrieves all tags in the document that have the given attribute name and value.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## GetTagsOptions
|
||||
```v
|
||||
struct GetTagsOptions {
|
||||
pub:
|
||||
name string
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Parser
|
||||
```v
|
||||
struct Parser {
|
||||
mut:
|
||||
dom DocumentObjectModel
|
||||
lexical_attributes LexicalAttributes = LexicalAttributes{
|
||||
current_tag: &Tag{}
|
||||
}
|
||||
filename string = 'direct-parse'
|
||||
initialized bool
|
||||
tags []&Tag
|
||||
debug_file os.File
|
||||
}
|
||||
```
|
||||
|
||||
Parser is responsible for reading the HTML strings and converting them into a `DocumentObjectModel`.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## add_code_tag
|
||||
```v
|
||||
fn (mut parser Parser) add_code_tag(name string)
|
||||
```
|
||||
|
||||
This function is used to add a tag for the parser ignore it's content. For example, if you have an html or XML with a custom tag, like `<script>`, using this function, like `add_code_tag('script')` will make all `script` tags content be jumped, so you still have its content, but will not confuse the parser with it's `>` or `<`.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## split_parse
|
||||
```v
|
||||
fn (mut parser Parser) split_parse(data string)
|
||||
```
|
||||
|
||||
split_parse parses the HTML fragment
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## parse_html
|
||||
```v
|
||||
fn (mut parser Parser) parse_html(data string)
|
||||
```
|
||||
|
||||
parse_html parses the given HTML string
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## finalize
|
||||
```v
|
||||
fn (mut parser Parser) finalize()
|
||||
```
|
||||
|
||||
finalize finishes the parsing stage .
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## get_dom
|
||||
```v
|
||||
fn (mut parser Parser) get_dom() DocumentObjectModel
|
||||
```
|
||||
|
||||
get_dom returns the parser's current DOM representation.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Tag
|
||||
```v
|
||||
struct Tag {
|
||||
pub mut:
|
||||
name string
|
||||
content string
|
||||
children []&Tag
|
||||
attributes map[string]string // attributes will be like map[name]value
|
||||
last_attribute string
|
||||
class_set datatypes.Set[string]
|
||||
parent &Tag = unsafe { nil }
|
||||
position_in_parent int
|
||||
closed bool
|
||||
close_type CloseTagType = .in_name
|
||||
}
|
||||
```
|
||||
|
||||
Tag holds the information of an HTML tag.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## text
|
||||
```v
|
||||
fn (tag &Tag) text() string
|
||||
```
|
||||
|
||||
text returns the text contents of the tag.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## str
|
||||
```v
|
||||
fn (tag &Tag) str() string
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## get_tag
|
||||
```v
|
||||
fn (tag &Tag) get_tag(name string) ?&Tag
|
||||
```
|
||||
|
||||
get_tag retrieves the first found child tag in the tag that has the given tag name.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## get_tags
|
||||
```v
|
||||
fn (tag &Tag) get_tags(name string) []&Tag
|
||||
```
|
||||
|
||||
get_tags retrieves all child tags recursively in the tag that have the given tag name.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## get_tag_by_attribute
|
||||
```v
|
||||
fn (tag &Tag) get_tag_by_attribute(name string) ?&Tag
|
||||
```
|
||||
|
||||
get_tag_by_attribute retrieves the first found child tag in the tag that has the given attribute name.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## get_tags_by_attribute
|
||||
```v
|
||||
fn (tag &Tag) get_tags_by_attribute(name string) []&Tag
|
||||
```
|
||||
|
||||
get_tags_by_attribute retrieves all child tags recursively in the tag that have the given attribute name.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## get_tag_by_attribute_value
|
||||
```v
|
||||
fn (tag &Tag) get_tag_by_attribute_value(name string, value string) ?&Tag
|
||||
```
|
||||
|
||||
get_tag_by_attribute_value retrieves the first found child tag in the tag that has the given attribute name and value.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## get_tags_by_attribute_value
|
||||
```v
|
||||
fn (tag &Tag) get_tags_by_attribute_value(name string, value string) []&Tag
|
||||
```
|
||||
|
||||
get_tags_by_attribute_value retrieves all child tags recursively in the tag that have the given attribute name and value.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## get_tag_by_class_name
|
||||
```v
|
||||
fn (tag &Tag) get_tag_by_class_name(names ...string) ?&Tag
|
||||
```
|
||||
|
||||
get_tag_by_class_name retrieves the first found child tag in the tag that has the given class name(s).
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## get_tags_by_class_name
|
||||
```v
|
||||
fn (tag &Tag) get_tags_by_class_name(names ...string) []&Tag
|
||||
```
|
||||
|
||||
get_tags_by_class_name retrieves all child tags recursively in the tag that have the given class name(s).
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:16:36
|
||||
1630
aiprompts/v_core/net/http.md
Normal file
1630
aiprompts/v_core/net/http.md
Normal file
File diff suppressed because it is too large
Load Diff
365
aiprompts/v_core/net/mbedtls.md
Normal file
365
aiprompts/v_core/net/mbedtls.md
Normal file
@@ -0,0 +1,365 @@
|
||||
# module mbedtls
|
||||
|
||||
|
||||
## Contents
|
||||
- [new_ssl_conn](#new_ssl_conn)
|
||||
- [new_ssl_listener](#new_ssl_listener)
|
||||
- [new_sslcerts](#new_sslcerts)
|
||||
- [new_sslcerts_from_file](#new_sslcerts_from_file)
|
||||
- [new_sslcerts_in_memory](#new_sslcerts_in_memory)
|
||||
- [C.mbedtls_ctr_drbg_context](#C.mbedtls_ctr_drbg_context)
|
||||
- [C.mbedtls_entropy_context](#C.mbedtls_entropy_context)
|
||||
- [C.mbedtls_net_context](#C.mbedtls_net_context)
|
||||
- [C.mbedtls_pk_context](#C.mbedtls_pk_context)
|
||||
- [C.mbedtls_ssl_config](#C.mbedtls_ssl_config)
|
||||
- [C.mbedtls_ssl_context](#C.mbedtls_ssl_context)
|
||||
- [C.mbedtls_ssl_recv_t](#C.mbedtls_ssl_recv_t)
|
||||
- [C.mbedtls_ssl_recv_timeout_t](#C.mbedtls_ssl_recv_timeout_t)
|
||||
- [C.mbedtls_ssl_send_t](#C.mbedtls_ssl_send_t)
|
||||
- [C.mbedtls_x509_crl](#C.mbedtls_x509_crl)
|
||||
- [C.mbedtls_x509_crt](#C.mbedtls_x509_crt)
|
||||
- [SSLCerts](#SSLCerts)
|
||||
- [cleanup](#cleanup)
|
||||
- [SSLConn](#SSLConn)
|
||||
- [close](#close)
|
||||
- [shutdown](#shutdown)
|
||||
- [connect](#connect)
|
||||
- [dial](#dial)
|
||||
- [addr](#addr)
|
||||
- [peer_addr](#peer_addr)
|
||||
- [socket_read_into_ptr](#socket_read_into_ptr)
|
||||
- [read](#read)
|
||||
- [write_ptr](#write_ptr)
|
||||
- [write](#write)
|
||||
- [write_string](#write_string)
|
||||
- [SSLConnectConfig](#SSLConnectConfig)
|
||||
- [SSLListener](#SSLListener)
|
||||
- [shutdown](#shutdown)
|
||||
- [accept](#accept)
|
||||
|
||||
## new_ssl_conn
|
||||
```v
|
||||
fn new_ssl_conn(config SSLConnectConfig) !&SSLConn
|
||||
```
|
||||
|
||||
new_ssl_conn returns a new SSLConn with the given config.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new_ssl_listener
|
||||
```v
|
||||
fn new_ssl_listener(saddr string, config SSLConnectConfig) !&SSLListener
|
||||
```
|
||||
|
||||
create a new SSLListener binding to `saddr`
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new_sslcerts
|
||||
```v
|
||||
fn new_sslcerts() &SSLCerts
|
||||
```
|
||||
|
||||
new_sslcerts initializes and returns a pair of SSL certificates and key
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new_sslcerts_from_file
|
||||
```v
|
||||
fn new_sslcerts_from_file(verify string, cert string, cert_key string) !&SSLCerts
|
||||
```
|
||||
|
||||
new_sslcerts_from_file creates a new pair of SSL certificates, given their paths on the filesystem.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new_sslcerts_in_memory
|
||||
```v
|
||||
fn new_sslcerts_in_memory(verify string, cert string, cert_key string) !&SSLCerts
|
||||
```
|
||||
|
||||
new_sslcerts_in_memory creates a pair of SSL certificates, given their contents (not paths).
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## C.mbedtls_ctr_drbg_context
|
||||
```v
|
||||
struct C.mbedtls_ctr_drbg_context {}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## C.mbedtls_entropy_context
|
||||
```v
|
||||
struct C.mbedtls_entropy_context {}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## C.mbedtls_net_context
|
||||
```v
|
||||
struct C.mbedtls_net_context {
|
||||
mut:
|
||||
fd int
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## C.mbedtls_pk_context
|
||||
```v
|
||||
struct C.mbedtls_pk_context {}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## C.mbedtls_ssl_config
|
||||
```v
|
||||
struct C.mbedtls_ssl_config {}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## C.mbedtls_ssl_context
|
||||
```v
|
||||
struct C.mbedtls_ssl_context {}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## C.mbedtls_ssl_recv_t
|
||||
```v
|
||||
struct C.mbedtls_ssl_recv_t {}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## C.mbedtls_ssl_recv_timeout_t
|
||||
```v
|
||||
struct C.mbedtls_ssl_recv_timeout_t {}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## C.mbedtls_ssl_send_t
|
||||
```v
|
||||
struct C.mbedtls_ssl_send_t {}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## C.mbedtls_x509_crl
|
||||
```v
|
||||
struct C.mbedtls_x509_crl {}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## C.mbedtls_x509_crt
|
||||
```v
|
||||
struct C.mbedtls_x509_crt {}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## SSLCerts
|
||||
```v
|
||||
struct SSLCerts {
|
||||
pub mut:
|
||||
cacert C.mbedtls_x509_crt
|
||||
client_cert C.mbedtls_x509_crt
|
||||
client_key C.mbedtls_pk_context
|
||||
}
|
||||
```
|
||||
|
||||
SSLCerts represents a pair of CA and client certificates + key
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## cleanup
|
||||
```v
|
||||
fn (mut c SSLCerts) cleanup()
|
||||
```
|
||||
|
||||
cleanup frees the SSL certificates
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## SSLConn
|
||||
```v
|
||||
struct SSLConn {
|
||||
pub:
|
||||
config SSLConnectConfig
|
||||
pub mut:
|
||||
server_fd C.mbedtls_net_context
|
||||
ssl C.mbedtls_ssl_context
|
||||
conf C.mbedtls_ssl_config
|
||||
certs &SSLCerts = unsafe { nil }
|
||||
handle int
|
||||
duration time.Duration
|
||||
opened bool
|
||||
ip string
|
||||
|
||||
owns_socket bool
|
||||
}
|
||||
```
|
||||
|
||||
SSLConn is the current connection
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## close
|
||||
```v
|
||||
fn (mut s SSLConn) close() !
|
||||
```
|
||||
|
||||
close terminates the ssl connection and does cleanup
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## shutdown
|
||||
```v
|
||||
fn (mut s SSLConn) shutdown() !
|
||||
```
|
||||
|
||||
shutdown terminates the ssl connection and does cleanup
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## connect
|
||||
```v
|
||||
fn (mut s SSLConn) connect(mut tcp_conn net.TcpConn, hostname string) !
|
||||
```
|
||||
|
||||
connect sets up an ssl connection on an existing TCP connection
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## dial
|
||||
```v
|
||||
fn (mut s SSLConn) dial(hostname string, port int) !
|
||||
```
|
||||
|
||||
dial opens an ssl connection on hostname:port
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## addr
|
||||
```v
|
||||
fn (s &SSLConn) addr() !net.Addr
|
||||
```
|
||||
|
||||
addr retrieves the local ip address and port number for this connection
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## peer_addr
|
||||
```v
|
||||
fn (s &SSLConn) peer_addr() !net.Addr
|
||||
```
|
||||
|
||||
peer_addr retrieves the ip address and port number used by the peer
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## socket_read_into_ptr
|
||||
```v
|
||||
fn (mut s SSLConn) socket_read_into_ptr(buf_ptr &u8, len int) !int
|
||||
```
|
||||
|
||||
socket_read_into_ptr reads `len` bytes into `buf`
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## read
|
||||
```v
|
||||
fn (mut s SSLConn) read(mut buffer []u8) !int
|
||||
```
|
||||
|
||||
read reads data from the ssl connection into `buffer`
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## write_ptr
|
||||
```v
|
||||
fn (mut s SSLConn) write_ptr(bytes &u8, len int) !int
|
||||
```
|
||||
|
||||
write_ptr writes `len` bytes from `bytes` to the ssl connection
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## write
|
||||
```v
|
||||
fn (mut s SSLConn) write(bytes []u8) !int
|
||||
```
|
||||
|
||||
write writes data from `bytes` to the ssl connection
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## write_string
|
||||
```v
|
||||
fn (mut s SSLConn) write_string(str string) !int
|
||||
```
|
||||
|
||||
write_string writes a string to the ssl connection
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## SSLConnectConfig
|
||||
```v
|
||||
struct SSLConnectConfig {
|
||||
pub:
|
||||
verify string // the path to a rootca.pem file, containing trusted CA certificate(s)
|
||||
cert string // the path to a cert.pem file, containing client certificate(s) for the request
|
||||
cert_key string // the path to a key.pem file, containing private keys for the client certificate(s)
|
||||
validate bool // set this to true, if you want to stop requests, when their certificates are found to be invalid
|
||||
|
||||
in_memory_verification bool // if true, verify, cert, and cert_key are read from memory, not from a file
|
||||
|
||||
get_certificate ?fn (mut SSLListener, string) !&SSLCerts
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## SSLListener
|
||||
```v
|
||||
struct SSLListener {
|
||||
saddr string
|
||||
config SSLConnectConfig
|
||||
mut:
|
||||
server_fd C.mbedtls_net_context
|
||||
ssl C.mbedtls_ssl_context
|
||||
conf C.mbedtls_ssl_config
|
||||
certs &SSLCerts = unsafe { nil }
|
||||
opened bool
|
||||
// handle int
|
||||
// duration time.Duration
|
||||
}
|
||||
```
|
||||
|
||||
SSLListener listens on a TCP port and accepts connection secured with TLS
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## shutdown
|
||||
```v
|
||||
fn (mut l SSLListener) shutdown() !
|
||||
```
|
||||
|
||||
finish the listener and clean up resources
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## accept
|
||||
```v
|
||||
fn (mut l SSLListener) accept() !&SSLConn
|
||||
```
|
||||
|
||||
accepts a new connection and returns a SSLConn of the connected client
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:16:36
|
||||
14
aiprompts/v_core/net/net.http.chunked.md
Normal file
14
aiprompts/v_core/net/net.http.chunked.md
Normal file
@@ -0,0 +1,14 @@
|
||||
# module net.http.chunked
|
||||
|
||||
|
||||
## Contents
|
||||
- [decode](#decode)
|
||||
|
||||
## decode
|
||||
```v
|
||||
fn decode(text string) !string
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:16:36
|
||||
53
aiprompts/v_core/net/net.http.file.md
Normal file
53
aiprompts/v_core/net/net.http.file.md
Normal file
@@ -0,0 +1,53 @@
|
||||
# module net.http.file
|
||||
|
||||
|
||||
## Contents
|
||||
- [serve](#serve)
|
||||
- [Entity](#Entity)
|
||||
- [StaticServeParams](#StaticServeParams)
|
||||
|
||||
## serve
|
||||
```v
|
||||
fn serve(params StaticServeParams)
|
||||
```
|
||||
|
||||
serve will start a static files web server.
|
||||
|
||||
The most common usage is the following: `v -e 'import net.http.file; file.serve()'` will listen for http requests on port 4001 by default, and serve all the files in the current folder.
|
||||
|
||||
Another example: `v -e 'import net.http.file; file.serve(folder: "/tmp")'` will serve all files inside the /tmp folder.
|
||||
|
||||
Another example: `v -e 'import net.http.file; file.serve(folder: "~/Projects", on: ":5002")'` will expose all the files inside the ~/Projects folder, on http://localhost:5002/ .
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Entity
|
||||
```v
|
||||
struct Entity {
|
||||
os.FileInfo
|
||||
path string
|
||||
mod_time time.Time
|
||||
url string
|
||||
fname string
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## StaticServeParams
|
||||
```v
|
||||
struct StaticServeParams {
|
||||
pub mut:
|
||||
folder string = $d('http_folder', '.') // The folder, that will be used as a base for serving all static resources; If it was /tmp, then: http://localhost:4001/x.txt => /tmp/x.txt . Customize with `-d http_folder=vlib/_docs`.
|
||||
index_file string = $d('http_index_file', 'index.html') // A request for http://localhost:4001/ will map to `index.html`, if that file is present.
|
||||
auto_index bool = $d('http_auto_index', true) // when an index_file is *not* present, a request for http://localhost:4001/ will list automatically all files in the folder.
|
||||
on string = $d('http_on', 'localhost:4001') // on which address:port to listen for http requests.
|
||||
filter_myexe bool = true // whether to filter the name of the static file executable from the automatic folder listings for / . Useful with `v -e 'import net.http.file; file.serve()'`
|
||||
workers int = runtime.nr_jobs() // how many worker threads to use for serving the responses, by default it is limited to the number of available cores; can be controlled with setting VJOBS
|
||||
shutdown_after time.Duration = time.infinite // after this time has passed, the webserver will gracefully shutdown on its own
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:16:36
|
||||
69
aiprompts/v_core/net/net.http.mime.md
Normal file
69
aiprompts/v_core/net/net.http.mime.md
Normal file
@@ -0,0 +1,69 @@
|
||||
# module net.http.mime
|
||||
|
||||
|
||||
## Contents
|
||||
- [exists](#exists)
|
||||
- [get_complete_mime_type](#get_complete_mime_type)
|
||||
- [get_content_type](#get_content_type)
|
||||
- [get_default_ext](#get_default_ext)
|
||||
- [get_mime_type](#get_mime_type)
|
||||
- [MimeType](#MimeType)
|
||||
|
||||
## exists
|
||||
```v
|
||||
fn exists(mt string) bool
|
||||
```
|
||||
|
||||
returns true if the given MIME type exists
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## get_complete_mime_type
|
||||
```v
|
||||
fn get_complete_mime_type(mt string) MimeType
|
||||
```
|
||||
|
||||
returns a `MimeType` for the given MIME type
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## get_content_type
|
||||
```v
|
||||
fn get_content_type(mt string) string
|
||||
```
|
||||
|
||||
returns a `content-type` header ready to use for the given MIME type
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## get_default_ext
|
||||
```v
|
||||
fn get_default_ext(mt string) string
|
||||
```
|
||||
|
||||
returns the default extension for the given MIME type
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## get_mime_type
|
||||
```v
|
||||
fn get_mime_type(ext string) string
|
||||
```
|
||||
|
||||
returns the MIME type for the given file extension
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## MimeType
|
||||
```v
|
||||
struct MimeType {
|
||||
source string
|
||||
extensions []string
|
||||
compressible bool
|
||||
charset string
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:16:36
|
||||
1373
aiprompts/v_core/net/net.md
Normal file
1373
aiprompts/v_core/net/net.md
Normal file
File diff suppressed because it is too large
Load Diff
203
aiprompts/v_core/net/openssl.md
Normal file
203
aiprompts/v_core/net/openssl.md
Normal file
@@ -0,0 +1,203 @@
|
||||
# module openssl
|
||||
|
||||
|
||||
## Contents
|
||||
- [new_ssl_conn](#new_ssl_conn)
|
||||
- [C.BIO](#C.BIO)
|
||||
- [C.SSL](#C.SSL)
|
||||
- [C.SSL_CTX](#C.SSL_CTX)
|
||||
- [C.SSL_METHOD](#C.SSL_METHOD)
|
||||
- [C.X509](#C.X509)
|
||||
- [SSLConn](#SSLConn)
|
||||
- [close](#close)
|
||||
- [shutdown](#shutdown)
|
||||
- [connect](#connect)
|
||||
- [dial](#dial)
|
||||
- [addr](#addr)
|
||||
- [peer_addr](#peer_addr)
|
||||
- [socket_read_into_ptr](#socket_read_into_ptr)
|
||||
- [read](#read)
|
||||
- [write_ptr](#write_ptr)
|
||||
- [write](#write)
|
||||
- [write_string](#write_string)
|
||||
- [SSLConnectConfig](#SSLConnectConfig)
|
||||
|
||||
## new_ssl_conn
|
||||
```v
|
||||
fn new_ssl_conn(config SSLConnectConfig) !&SSLConn
|
||||
```
|
||||
|
||||
new_ssl_conn instance an new SSLCon struct
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## C.BIO
|
||||
```v
|
||||
struct C.BIO {
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## C.SSL
|
||||
```v
|
||||
struct C.SSL {
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## C.SSL_CTX
|
||||
```v
|
||||
struct C.SSL_CTX {
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## C.SSL_METHOD
|
||||
```v
|
||||
struct C.SSL_METHOD {
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## C.X509
|
||||
```v
|
||||
struct C.X509 {
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## SSLConn
|
||||
```v
|
||||
struct SSLConn {
|
||||
pub:
|
||||
config SSLConnectConfig
|
||||
pub mut:
|
||||
sslctx &C.SSL_CTX = unsafe { nil }
|
||||
ssl &C.SSL = unsafe { nil }
|
||||
handle int
|
||||
duration time.Duration
|
||||
|
||||
owns_socket bool
|
||||
}
|
||||
```
|
||||
|
||||
SSLConn is the current connection
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## close
|
||||
```v
|
||||
fn (mut s SSLConn) close() !
|
||||
```
|
||||
|
||||
close closes the ssl connection and does cleanup
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## shutdown
|
||||
```v
|
||||
fn (mut s SSLConn) shutdown() !
|
||||
```
|
||||
|
||||
shutdown closes the ssl connection and does cleanup
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## connect
|
||||
```v
|
||||
fn (mut s SSLConn) connect(mut tcp_conn net.TcpConn, hostname string) !
|
||||
```
|
||||
|
||||
connect to server using OpenSSL
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## dial
|
||||
```v
|
||||
fn (mut s SSLConn) dial(hostname string, port int) !
|
||||
```
|
||||
|
||||
dial opens an ssl connection on hostname:port
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## addr
|
||||
```v
|
||||
fn (s &SSLConn) addr() !net.Addr
|
||||
```
|
||||
|
||||
addr retrieves the local ip address and port number for this connection
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## peer_addr
|
||||
```v
|
||||
fn (s &SSLConn) peer_addr() !net.Addr
|
||||
```
|
||||
|
||||
peer_addr retrieves the ip address and port number used by the peer
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## socket_read_into_ptr
|
||||
```v
|
||||
fn (mut s SSLConn) socket_read_into_ptr(buf_ptr &u8, len int) !int
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## read
|
||||
```v
|
||||
fn (mut s SSLConn) read(mut buffer []u8) !int
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## write_ptr
|
||||
```v
|
||||
fn (mut s SSLConn) write_ptr(bytes &u8, len int) !int
|
||||
```
|
||||
|
||||
write_ptr writes `len` bytes from `bytes` to the ssl connection
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## write
|
||||
```v
|
||||
fn (mut s SSLConn) write(bytes []u8) !int
|
||||
```
|
||||
|
||||
write writes data from `bytes` to the ssl connection
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## write_string
|
||||
```v
|
||||
fn (mut s SSLConn) write_string(str string) !int
|
||||
```
|
||||
|
||||
write_string writes a string to the ssl connection
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## SSLConnectConfig
|
||||
```v
|
||||
struct SSLConnectConfig {
|
||||
pub:
|
||||
verify string // the path to a rootca.pem file, containing trusted CA certificate(s)
|
||||
cert string // the path to a cert.pem file, containing client certificate(s) for the request
|
||||
cert_key string // the path to a key.pem file, containing private keys for the client certificate(s)
|
||||
validate bool // set this to true, if you want to stop requests, when their certificates are found to be invalid
|
||||
|
||||
in_memory_verification bool // if true, verify, cert, and cert_key are read from memory, not from a file
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:16:36
|
||||
114
aiprompts/v_core/net/smtp.md
Normal file
114
aiprompts/v_core/net/smtp.md
Normal file
@@ -0,0 +1,114 @@
|
||||
# module smtp
|
||||
|
||||
|
||||
## Contents
|
||||
- [new_client](#new_client)
|
||||
- [BodyType](#BodyType)
|
||||
- [Attachment](#Attachment)
|
||||
- [Client](#Client)
|
||||
- [reconnect](#reconnect)
|
||||
- [send](#send)
|
||||
- [quit](#quit)
|
||||
- [Mail](#Mail)
|
||||
|
||||
## new_client
|
||||
```v
|
||||
fn new_client(config Client) !&Client
|
||||
```
|
||||
|
||||
new_client returns a new SMTP client and connects to it
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## BodyType
|
||||
```v
|
||||
enum BodyType {
|
||||
text
|
||||
html
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Attachment
|
||||
```v
|
||||
struct Attachment {
|
||||
pub:
|
||||
cid string
|
||||
filename string
|
||||
bytes []u8
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Client
|
||||
```v
|
||||
struct Client {
|
||||
mut:
|
||||
conn net.TcpConn
|
||||
ssl_conn &ssl.SSLConn = unsafe { nil }
|
||||
reader ?&io.BufferedReader
|
||||
pub:
|
||||
server string
|
||||
port int = 25
|
||||
username string
|
||||
password string
|
||||
from string
|
||||
ssl bool
|
||||
starttls bool
|
||||
pub mut:
|
||||
is_open bool
|
||||
encrypted bool
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## reconnect
|
||||
```v
|
||||
fn (mut c Client) reconnect() !
|
||||
```
|
||||
|
||||
reconnect reconnects to the SMTP server if the connection was closed
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## send
|
||||
```v
|
||||
fn (mut c Client) send(config Mail) !
|
||||
```
|
||||
|
||||
send sends an email
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## quit
|
||||
```v
|
||||
fn (mut c Client) quit() !
|
||||
```
|
||||
|
||||
quit closes the connection to the server
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Mail
|
||||
```v
|
||||
struct Mail {
|
||||
pub:
|
||||
from string
|
||||
to string
|
||||
cc string
|
||||
bcc string
|
||||
date time.Time = time.now()
|
||||
subject string
|
||||
body_type BodyType
|
||||
body string
|
||||
attachments []Attachment
|
||||
boundary string
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:16:36
|
||||
62
aiprompts/v_core/net/socks.md
Normal file
62
aiprompts/v_core/net/socks.md
Normal file
@@ -0,0 +1,62 @@
|
||||
# module socks
|
||||
|
||||
|
||||
## Contents
|
||||
- [new_socks5_dialer](#new_socks5_dialer)
|
||||
- [socks5_dial](#socks5_dial)
|
||||
- [socks5_ssl_dial](#socks5_ssl_dial)
|
||||
- [SOCKS5Dialer](#SOCKS5Dialer)
|
||||
- [dial](#dial)
|
||||
|
||||
## new_socks5_dialer
|
||||
```v
|
||||
fn new_socks5_dialer(base net.Dialer, proxy_address string, username string, password string) net.Dialer
|
||||
```
|
||||
|
||||
new_socks5_dialer creates a dialer that will use a SOCKS5 proxy server to initiate connections. An underlying dialer is required to initiate the connection to the proxy server. Most users should use either net.default_tcp_dialer or ssl.create_ssl_dialer.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## socks5_dial
|
||||
```v
|
||||
fn socks5_dial(proxy_url string, host string, username string, password string) !&net.TcpConn
|
||||
```
|
||||
|
||||
socks5_dial create new instance of &net.TcpConn
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## socks5_ssl_dial
|
||||
```v
|
||||
fn socks5_ssl_dial(proxy_url string, host string, username string, password string) !&ssl.SSLConn
|
||||
```
|
||||
|
||||
socks5_ssl_dial create new instance of &ssl.SSLConn
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## SOCKS5Dialer
|
||||
```v
|
||||
struct SOCKS5Dialer {
|
||||
pub:
|
||||
dialer net.Dialer
|
||||
proxy_address string
|
||||
username string
|
||||
password string
|
||||
}
|
||||
```
|
||||
|
||||
SOCKS5Dialer implements the Dialer interface initiating connections through a SOCKS5 proxy.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## dial
|
||||
```v
|
||||
fn (sd SOCKS5Dialer) dial(address string) !net.Connection
|
||||
```
|
||||
|
||||
dial initiates a new connection through the SOCKS5 proxy.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:16:36
|
||||
68
aiprompts/v_core/net/ssl.md
Normal file
68
aiprompts/v_core/net/ssl.md
Normal file
@@ -0,0 +1,68 @@
|
||||
# module ssl
|
||||
|
||||
|
||||
## Contents
|
||||
- [new_ssl_conn](#new_ssl_conn)
|
||||
- [new_ssl_dialer](#new_ssl_dialer)
|
||||
- [SSLConn](#SSLConn)
|
||||
- [SSLConnectConfig](#SSLConnectConfig)
|
||||
- [SSLDialer](#SSLDialer)
|
||||
- [dial](#dial)
|
||||
|
||||
## new_ssl_conn
|
||||
```v
|
||||
fn new_ssl_conn(config SSLConnectConfig) !&SSLConn
|
||||
```
|
||||
|
||||
new_ssl_conn returns a new SSLConn with the given config.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new_ssl_dialer
|
||||
```v
|
||||
fn new_ssl_dialer(config SSLConnectConfig) net.Dialer
|
||||
```
|
||||
|
||||
create_ssl_dialer creates a dialer that will initiate SSL secured connections.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## SSLConn
|
||||
```v
|
||||
struct SSLConn {
|
||||
mbedtls.SSLConn
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## SSLConnectConfig
|
||||
```v
|
||||
struct SSLConnectConfig {
|
||||
mbedtls.SSLConnectConfig
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## SSLDialer
|
||||
```v
|
||||
struct SSLDialer {
|
||||
config SSLConnectConfig
|
||||
}
|
||||
```
|
||||
|
||||
SSLDialer is a concrete instance of the Dialer interface, for creating SSL socket connections.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## dial
|
||||
```v
|
||||
fn (d SSLDialer) dial(address string) !net.Connection
|
||||
```
|
||||
|
||||
dial initiates a new SSL connection.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:16:36
|
||||
441
aiprompts/v_core/net/unix.md
Normal file
441
aiprompts/v_core/net/unix.md
Normal file
@@ -0,0 +1,441 @@
|
||||
# module unix
|
||||
|
||||
|
||||
## Contents
|
||||
- [close](#close)
|
||||
- [connect_stream](#connect_stream)
|
||||
- [listen_stream](#listen_stream)
|
||||
- [shutdown](#shutdown)
|
||||
- [stream_socket_from_handle](#stream_socket_from_handle)
|
||||
- [ListenOptions](#ListenOptions)
|
||||
- [StreamConn](#StreamConn)
|
||||
- [addr](#addr)
|
||||
- [peer_addr](#peer_addr)
|
||||
- [close](#close)
|
||||
- [write_ptr](#write_ptr)
|
||||
- [write](#write)
|
||||
- [write_string](#write_string)
|
||||
- [read_ptr](#read_ptr)
|
||||
- [read](#read)
|
||||
- [read_deadline](#read_deadline)
|
||||
- [set_read_deadline](#set_read_deadline)
|
||||
- [write_deadline](#write_deadline)
|
||||
- [set_write_deadline](#set_write_deadline)
|
||||
- [read_timeout](#read_timeout)
|
||||
- [set_read_timeout](#set_read_timeout)
|
||||
- [write_timeout](#write_timeout)
|
||||
- [set_write_timeout](#set_write_timeout)
|
||||
- [wait_for_read](#wait_for_read)
|
||||
- [wait_for_write](#wait_for_write)
|
||||
- [str](#str)
|
||||
- [StreamListener](#StreamListener)
|
||||
- [accept](#accept)
|
||||
- [accept_deadline](#accept_deadline)
|
||||
- [set_accept_deadline](#set_accept_deadline)
|
||||
- [accept_timeout](#accept_timeout)
|
||||
- [set_accept_timeout](#set_accept_timeout)
|
||||
- [wait_for_accept](#wait_for_accept)
|
||||
- [close](#close)
|
||||
- [unlink](#unlink)
|
||||
- [unlink_on_signal](#unlink_on_signal)
|
||||
- [addr](#addr)
|
||||
- [StreamSocket](#StreamSocket)
|
||||
- [set_option_bool](#set_option_bool)
|
||||
- [set_option_int](#set_option_int)
|
||||
- [UnixDialer](#UnixDialer)
|
||||
- [dial](#dial)
|
||||
|
||||
## close
|
||||
```v
|
||||
fn close(handle int) !
|
||||
```
|
||||
|
||||
close a socket, given its file descriptor `handle`.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## connect_stream
|
||||
```v
|
||||
fn connect_stream(socket_path string) !&StreamConn
|
||||
```
|
||||
|
||||
connect_stream returns a SOCK_STREAM connection for an unix domain socket on `socket_path`
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## listen_stream
|
||||
```v
|
||||
fn listen_stream(socket_path string, options ListenOptions) !&StreamListener
|
||||
```
|
||||
|
||||
listen_stream creates an unix domain socket at `socket_path`
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## shutdown
|
||||
```v
|
||||
fn shutdown(handle int, config net.ShutdownConfig) int
|
||||
```
|
||||
|
||||
shutdown shutsdown a socket, given its file descriptor `handle`. By default it shuts it down in both directions, both for reading and for writing. You can change that using `net.shutdown(handle, how: .read)` or `net.shutdown(handle, how: .write)`
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## stream_socket_from_handle
|
||||
```v
|
||||
fn stream_socket_from_handle(sockfd int) !&StreamSocket
|
||||
```
|
||||
|
||||
stream_socket_from_handle returns a `StreamSocket` instance from the raw file descriptor `sockfd`
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## ListenOptions
|
||||
```v
|
||||
struct ListenOptions {
|
||||
pub:
|
||||
backlog int = 128
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## StreamConn
|
||||
```v
|
||||
struct StreamConn {
|
||||
pub mut:
|
||||
sock StreamSocket
|
||||
mut:
|
||||
handle int
|
||||
write_deadline time.Time
|
||||
read_deadline time.Time
|
||||
read_timeout time.Duration
|
||||
write_timeout time.Duration
|
||||
is_blocking bool
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## addr
|
||||
```v
|
||||
fn (c StreamConn) addr() !net.Addr
|
||||
```
|
||||
|
||||
addr returns the local address of the stream
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## peer_addr
|
||||
```v
|
||||
fn (c StreamConn) peer_addr() !net.Addr
|
||||
```
|
||||
|
||||
peer_addr returns the address of the remote peer of the stream
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## close
|
||||
```v
|
||||
fn (mut c StreamConn) close() !
|
||||
```
|
||||
|
||||
close closes the connection
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## write_ptr
|
||||
```v
|
||||
fn (mut c StreamConn) write_ptr(b &u8, len int) !int
|
||||
```
|
||||
|
||||
write_ptr blocks and attempts to write all data
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## write
|
||||
```v
|
||||
fn (mut c StreamConn) write(bytes []u8) !int
|
||||
```
|
||||
|
||||
write blocks and attempts to write all data
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## write_string
|
||||
```v
|
||||
fn (mut c StreamConn) write_string(s string) !int
|
||||
```
|
||||
|
||||
write_string blocks and attempts to write all data
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## read_ptr
|
||||
```v
|
||||
fn (mut c StreamConn) read_ptr(buf_ptr &u8, len int) !int
|
||||
```
|
||||
|
||||
read_ptr attempts to write all data
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## read
|
||||
```v
|
||||
fn (mut c StreamConn) read(mut buf []u8) !int
|
||||
```
|
||||
|
||||
read data into `buf`
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## read_deadline
|
||||
```v
|
||||
fn (mut c StreamConn) read_deadline() !time.Time
|
||||
```
|
||||
|
||||
read_deadline returns the read deadline
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## set_read_deadline
|
||||
```v
|
||||
fn (mut c StreamConn) set_read_deadline(deadline time.Time)
|
||||
```
|
||||
|
||||
set_read_deadlien sets the read deadline
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## write_deadline
|
||||
```v
|
||||
fn (mut c StreamConn) write_deadline() !time.Time
|
||||
```
|
||||
|
||||
write_deadline returns the write deadline
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## set_write_deadline
|
||||
```v
|
||||
fn (mut c StreamConn) set_write_deadline(deadline time.Time)
|
||||
```
|
||||
|
||||
set_write_deadline sets the write deadline
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## read_timeout
|
||||
```v
|
||||
fn (c &StreamConn) read_timeout() time.Duration
|
||||
```
|
||||
|
||||
read_timeout returns the read timeout
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## set_read_timeout
|
||||
```v
|
||||
fn (mut c StreamConn) set_read_timeout(t time.Duration)
|
||||
```
|
||||
|
||||
set_read_timeout sets the read timeout
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## write_timeout
|
||||
```v
|
||||
fn (c &StreamConn) write_timeout() time.Duration
|
||||
```
|
||||
|
||||
write_timeout returns the write timeout
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## set_write_timeout
|
||||
```v
|
||||
fn (mut c StreamConn) set_write_timeout(t time.Duration)
|
||||
```
|
||||
|
||||
set_write_timeout sets the write timeout
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## wait_for_read
|
||||
```v
|
||||
fn (mut c StreamConn) wait_for_read() !
|
||||
```
|
||||
|
||||
wait_for_read blocks until the socket is ready to read
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## wait_for_write
|
||||
```v
|
||||
fn (mut c StreamConn) wait_for_write() !
|
||||
```
|
||||
|
||||
wait_for_read blocks until the socket is ready to write
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## str
|
||||
```v
|
||||
fn (c StreamConn) str() string
|
||||
```
|
||||
|
||||
str returns a string representation of connection `c`
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## StreamListener
|
||||
```v
|
||||
struct StreamListener {
|
||||
pub mut:
|
||||
sock StreamSocket
|
||||
mut:
|
||||
accept_timeout time.Duration
|
||||
accept_deadline time.Time
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## accept
|
||||
```v
|
||||
fn (mut l StreamListener) accept() !&StreamConn
|
||||
```
|
||||
|
||||
accept accepts blocks until a new connection occurs
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## accept_deadline
|
||||
```v
|
||||
fn (l &StreamListener) accept_deadline() !time.Time
|
||||
```
|
||||
|
||||
accept_deadline returns the deadline until a new client is accepted
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## set_accept_deadline
|
||||
```v
|
||||
fn (mut l StreamListener) set_accept_deadline(deadline time.Time)
|
||||
```
|
||||
|
||||
set_accept_deadline sets the deadlinme until a new client is accepted
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## accept_timeout
|
||||
```v
|
||||
fn (l &StreamListener) accept_timeout() time.Duration
|
||||
```
|
||||
|
||||
accept_timeout returns the timeout until a new client is accepted
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## set_accept_timeout
|
||||
```v
|
||||
fn (mut l StreamListener) set_accept_timeout(t time.Duration)
|
||||
```
|
||||
|
||||
set_accept_timeout sets the timeout until a new client is accepted
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## wait_for_accept
|
||||
```v
|
||||
fn (mut l StreamListener) wait_for_accept() !
|
||||
```
|
||||
|
||||
wait_for_accept blocks until a client can be accepted
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## close
|
||||
```v
|
||||
fn (mut l StreamListener) close() !
|
||||
```
|
||||
|
||||
close closes the listening socket and unlinks/removes the socket file
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## unlink
|
||||
```v
|
||||
fn (mut l StreamListener) unlink() !
|
||||
```
|
||||
|
||||
unlink removes the unix socket from the file system
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## unlink_on_signal
|
||||
```v
|
||||
fn (mut l StreamListener) unlink_on_signal(signum os.Signal) !
|
||||
```
|
||||
|
||||
unlink_on_signal removes the socket from the filesystem when signal `signum` occurs
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## addr
|
||||
```v
|
||||
fn (mut l StreamListener) addr() !net.Addr
|
||||
```
|
||||
|
||||
addr returns the `net.Addr` version of the listening socket's path
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## StreamSocket
|
||||
```v
|
||||
struct StreamSocket {
|
||||
net.Socket
|
||||
mut:
|
||||
socket_path string
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## set_option_bool
|
||||
```v
|
||||
fn (mut s StreamSocket) set_option_bool(opt net.SocketOption, value bool) !
|
||||
```
|
||||
|
||||
set_option_bool sets a boolean option on the socket
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## set_option_int
|
||||
```v
|
||||
fn (mut s StreamSocket) set_option_int(opt net.SocketOption, value int) !
|
||||
```
|
||||
|
||||
set_option_bool sets an int option on the socket
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## UnixDialer
|
||||
```v
|
||||
struct UnixDialer {}
|
||||
```
|
||||
|
||||
UnixDialer is a concrete instance of the Dialer interface, for creating unix socket connections.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## dial
|
||||
```v
|
||||
fn (u UnixDialer) dial(address string) !net.Connection
|
||||
```
|
||||
|
||||
dial will try to create a new abstract connection to the given address. It will return an error, if that is not possible.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:16:36
|
||||
370
aiprompts/v_core/net/urllib.md
Normal file
370
aiprompts/v_core/net/urllib.md
Normal file
@@ -0,0 +1,370 @@
|
||||
# module urllib
|
||||
|
||||
|
||||
## Contents
|
||||
- [ishex](#ishex)
|
||||
- [new_values](#new_values)
|
||||
- [parse](#parse)
|
||||
- [parse_query](#parse_query)
|
||||
- [path_escape](#path_escape)
|
||||
- [path_unescape](#path_unescape)
|
||||
- [query_escape](#query_escape)
|
||||
- [query_unescape](#query_unescape)
|
||||
- [split_host_port](#split_host_port)
|
||||
- [user](#user)
|
||||
- [valid_userinfo](#valid_userinfo)
|
||||
- [URL](#URL)
|
||||
- [debug](#debug)
|
||||
- [set_path](#set_path)
|
||||
- [escaped_path](#escaped_path)
|
||||
- [str](#str)
|
||||
- [is_abs](#is_abs)
|
||||
- [parse](#parse)
|
||||
- [resolve_reference](#resolve_reference)
|
||||
- [query](#query)
|
||||
- [request_uri](#request_uri)
|
||||
- [hostname](#hostname)
|
||||
- [port](#port)
|
||||
- [Values](#Values)
|
||||
- [add](#add)
|
||||
- [del](#del)
|
||||
- [encode](#encode)
|
||||
- [get](#get)
|
||||
- [get_all](#get_all)
|
||||
- [set](#set)
|
||||
- [to_map](#to_map)
|
||||
- [values](#values)
|
||||
|
||||
## ishex
|
||||
```v
|
||||
fn ishex(c u8) bool
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new_values
|
||||
```v
|
||||
fn new_values() Values
|
||||
```
|
||||
|
||||
new_values returns a new Values struct for creating urlencoded query string parameters. it can also be to post form data with application/x-www-form-urlencoded. values.encode() will return the encoded data
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## parse
|
||||
```v
|
||||
fn parse(rawurl string) !URL
|
||||
```
|
||||
|
||||
parse parses rawurl into a URL structure.
|
||||
|
||||
The rawurl may be relative (a path, without a host) or absolute (starting with a scheme). Trying to parse a hostname and path without a scheme is invalid but may not necessarily return an error, due to parsing ambiguities.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## parse_query
|
||||
```v
|
||||
fn parse_query(query string) !Values
|
||||
```
|
||||
|
||||
Values maps a string key to a list of values. It is typically used for query parameters and form values. Unlike in the http.Header map, the keys in a Values map are case-sensitive. parseQuery parses the URL-encoded query string and returns a map listing the values specified for each key. parseQuery always returns a non-nil map containing all the valid query parameters found; err describes the first decoding error encountered, if any.
|
||||
|
||||
Query is expected to be a list of key=value settings separated by ampersands or semicolons. A setting without an equals sign is interpreted as a key set to an empty value.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## path_escape
|
||||
```v
|
||||
fn path_escape(s string) string
|
||||
```
|
||||
|
||||
path_escape escapes the string so it can be safely placed inside a URL path segment, replacing special characters (including /) with %XX sequences as needed.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## path_unescape
|
||||
```v
|
||||
fn path_unescape(s string) !string
|
||||
```
|
||||
|
||||
path_unescape does the inverse transformation of path_escape, converting each 3-byte encoded substring of the form '%AB' into the hex-decoded byte 0xAB. It returns an error if any % is not followed by two hexadecimal digits.
|
||||
|
||||
path_unescape is identical to query_unescape except that it does not unescape '+' to ' ' (space).
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## query_escape
|
||||
```v
|
||||
fn query_escape(s string) string
|
||||
```
|
||||
|
||||
query_escape escapes the string so it can be safely placed inside a URL query.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## query_unescape
|
||||
```v
|
||||
fn query_unescape(s string) !string
|
||||
```
|
||||
|
||||
query_unescape does the inverse transformation of query_escape, converting each 3-byte encoded substring of the form '%AB' into the hex-decoded byte 0xAB. It returns an error if any % is not followed by two hexadecimal digits.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## split_host_port
|
||||
```v
|
||||
fn split_host_port(hostport string) (string, string)
|
||||
```
|
||||
|
||||
split_host_port separates host and port. If the port is not valid, it returns the entire input as host, and it doesn't check the validity of the host. Per RFC 3986, it requires ports to be numeric.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## user
|
||||
```v
|
||||
fn user(username string) &Userinfo
|
||||
```
|
||||
|
||||
user returns a Userinfo containing the provided username and no password set.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## valid_userinfo
|
||||
```v
|
||||
fn valid_userinfo(s string) bool
|
||||
```
|
||||
|
||||
valid_userinfo reports whether s is a valid userinfo string per RFC 3986 Section 3.2.1: userinfo = *( unreserved / pct-encoded / sub-delims / ':' ) unreserved = ALPHA / DIGIT / '-' / '.' / '_' / '~' sub-delims = '!' / '$' / '&' / ''' / '(' / ')' / '*' / '+' / ',' / ';' / '='
|
||||
|
||||
It doesn't validate pct-encoded. The caller does that via fn unescape.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## URL
|
||||
```v
|
||||
struct URL {
|
||||
pub mut:
|
||||
scheme string
|
||||
opaque string // encoded opaque data
|
||||
user &Userinfo = unsafe { nil } // username and password information
|
||||
host string // host or host:port
|
||||
path string // path (relative paths may omit leading slash)
|
||||
raw_path string // encoded path hint (see escaped_path method)
|
||||
force_query bool // append a query ('?') even if raw_query is empty
|
||||
raw_query string // encoded query values, without '?'
|
||||
fragment string // fragment for references, without '#'
|
||||
}
|
||||
```
|
||||
|
||||
A URL represents a parsed URL (technically, a URI reference). The general form represented is: [scheme:][//[userinfo@]host][/]path[?query][#fragment] URLs that do not start with a slash after the scheme are interpreted as: scheme:opaque[?query][#fragment]
|
||||
|
||||
Note that the path field is stored in decoded form: /%47%6f%2f becomes /Go/. A consequence is that it is impossible to tell which slashes in the path were slashes in the raw URL and which were %2f. This distinction is rarely important, but when it is, the code should use raw_path, an optional field which only gets set if the default encoding is different from path.
|
||||
|
||||
URL's String method uses the escaped_path method to obtain the path. See the escaped_path method for more details.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## debug
|
||||
```v
|
||||
fn (url &URL) debug() string
|
||||
```
|
||||
|
||||
debug returns a string representation of *ALL* the fields of the given URL
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## set_path
|
||||
```v
|
||||
fn (mut u URL) set_path(p string) !bool
|
||||
```
|
||||
|
||||
set_path sets the path and raw_path fields of the URL based on the provided escaped path p. It maintains the invariant that raw_path is only specified when it differs from the default encoding of the path. For example:- set_path('/foo/bar') will set path='/foo/bar' and raw_path=''
|
||||
- set_path('/foo%2fbar') will set path='/foo/bar' and raw_path='/foo%2fbar'
|
||||
set_path will return an error only if the provided path contains an invalid escaping.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## escaped_path
|
||||
```v
|
||||
fn (u &URL) escaped_path() string
|
||||
```
|
||||
|
||||
escaped_path returns the escaped form of u.path. In general there are multiple possible escaped forms of any path. escaped_path returns u.raw_path when it is a valid escaping of u.path. Otherwise escaped_path ignores u.raw_path and computes an escaped form on its own. The String and request_uri methods use escaped_path to construct their results. In general, code should call escaped_path instead of reading u.raw_path directly.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## str
|
||||
```v
|
||||
fn (u URL) str() string
|
||||
```
|
||||
|
||||
str reassembles the URL into a valid URL string. The general form of the result is one of:
|
||||
|
||||
scheme:opaque?query#fragment scheme://userinfo@host/path?query#fragment
|
||||
|
||||
If u.opaque is non-empty, String uses the first form; otherwise it uses the second form. Any non-ASCII characters in host are escaped. To obtain the path, String uses u.escaped_path().
|
||||
|
||||
In the second form, the following rules apply:- if u.scheme is empty, scheme: is omitted.
|
||||
- if u.user is nil, userinfo@ is omitted.
|
||||
- if u.host is empty, host/ is omitted.
|
||||
- if u.scheme and u.host are empty and u.user is nil,
|
||||
the entire scheme://userinfo@host/ is omitted.- if u.host is non-empty and u.path begins with a /,
|
||||
the form host/path does not add its own /.- if u.raw_query is empty, ?query is omitted.
|
||||
- if u.fragment is empty, #fragment is omitted.
|
||||
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## is_abs
|
||||
```v
|
||||
fn (u &URL) is_abs() bool
|
||||
```
|
||||
|
||||
is_abs reports whether the URL is absolute. Absolute means that it has a non-empty scheme.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## parse
|
||||
```v
|
||||
fn (u &URL) parse(ref string) !URL
|
||||
```
|
||||
|
||||
parse parses a URL in the context of the receiver. The provided URL may be relative or absolute. parse returns nil, err on parse failure, otherwise its return value is the same as resolve_reference.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## resolve_reference
|
||||
```v
|
||||
fn (u &URL) resolve_reference(ref &URL) !URL
|
||||
```
|
||||
|
||||
resolve_reference resolves a URI reference to an absolute URI from an absolute base URI u, per RFC 3986 Section 5.2. The URI reference may be relative or absolute. resolve_reference always returns a new URL instance, even if the returned URL is identical to either the base or reference. If ref is an absolute URL, then resolve_reference ignores base and returns a copy of ref.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## query
|
||||
```v
|
||||
fn (u &URL) query() Values
|
||||
```
|
||||
|
||||
query parses raw_query and returns the corresponding values. It silently discards malformed value pairs. To check errors use parseQuery.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## request_uri
|
||||
```v
|
||||
fn (u &URL) request_uri() string
|
||||
```
|
||||
|
||||
request_uri returns the encoded path?query or opaque?query string that would be used in an HTTP request for u.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## hostname
|
||||
```v
|
||||
fn (u &URL) hostname() string
|
||||
```
|
||||
|
||||
hostname returns u.host, stripping any valid port number if present.
|
||||
|
||||
If the result is enclosed in square brackets, as literal IPv6 addresses are, the square brackets are removed from the result.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## port
|
||||
```v
|
||||
fn (u &URL) port() string
|
||||
```
|
||||
|
||||
port returns the port part of u.host, without the leading colon. If u.host doesn't contain a port, port returns an empty string.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Values
|
||||
```v
|
||||
struct Values {
|
||||
pub mut:
|
||||
data []QueryValue
|
||||
len int
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## add
|
||||
```v
|
||||
fn (mut v Values) add(key string, value string)
|
||||
```
|
||||
|
||||
add adds the value to key. It appends to any existing values associated with key.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## del
|
||||
```v
|
||||
fn (mut v Values) del(key string)
|
||||
```
|
||||
|
||||
del deletes the values associated with key.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## encode
|
||||
```v
|
||||
fn (v Values) encode() string
|
||||
```
|
||||
|
||||
encode encodes the values into ``URL encoded'' form ('bar=baz&foo=quux'). The syntx of the query string is specified in the RFC173 https://datatracker.ietf.org/doc/html/rfc1738
|
||||
|
||||
HTTP grammar
|
||||
|
||||
httpurl = "http://" hostport [ "/" hpath [ "?" search ]] hpath = hsegment *[ "/" hsegment ] hsegment = *[ uchar | ";" | ":" | "@" | "&" | "=" ] search = *[ uchar | ";" | ":" | "@" | "&" | "=" ]
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## get
|
||||
```v
|
||||
fn (v &Values) get(key string) ?string
|
||||
```
|
||||
|
||||
get gets the first value associated with the given key. If there are no values associated with the key, get returns none.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## get_all
|
||||
```v
|
||||
fn (v &Values) get_all(key string) []string
|
||||
```
|
||||
|
||||
get_all gets the all the values associated with the given key. If there are no values associated with the key, get returns a empty []string.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## set
|
||||
```v
|
||||
fn (mut v Values) set(key string, value string)
|
||||
```
|
||||
|
||||
set sets the key to value. It replaces any existing values, or create a new bucket with the new key if it is missed.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## to_map
|
||||
```v
|
||||
fn (v Values) to_map() map[string][]string
|
||||
```
|
||||
|
||||
return a map <key []value> of the query string
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## values
|
||||
```v
|
||||
fn (v Values) values() []string
|
||||
```
|
||||
|
||||
return the list of values in the query string
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:16:36
|
||||
641
aiprompts/v_core/net/websocket.md
Normal file
641
aiprompts/v_core/net/websocket.md
Normal file
@@ -0,0 +1,641 @@
|
||||
# module websocket
|
||||
|
||||
|
||||
## Contents
|
||||
- [new_client](#new_client)
|
||||
- [new_server](#new_server)
|
||||
- [AcceptClientFn](#AcceptClientFn)
|
||||
- [SocketCloseFn](#SocketCloseFn)
|
||||
- [SocketCloseFn2](#SocketCloseFn2)
|
||||
- [SocketErrorFn](#SocketErrorFn)
|
||||
- [SocketErrorFn2](#SocketErrorFn2)
|
||||
- [SocketMessageFn](#SocketMessageFn)
|
||||
- [SocketMessageFn2](#SocketMessageFn2)
|
||||
- [SocketOpenFn](#SocketOpenFn)
|
||||
- [SocketOpenFn2](#SocketOpenFn2)
|
||||
- [Uri](#Uri)
|
||||
- [str](#str)
|
||||
- [OPCode](#OPCode)
|
||||
- [State](#State)
|
||||
- [Client](#Client)
|
||||
- [close](#close)
|
||||
- [connect](#connect)
|
||||
- [free](#free)
|
||||
- [get_state](#get_state)
|
||||
- [listen](#listen)
|
||||
- [on_close](#on_close)
|
||||
- [on_close_ref](#on_close_ref)
|
||||
- [on_error](#on_error)
|
||||
- [on_error_ref](#on_error_ref)
|
||||
- [on_message](#on_message)
|
||||
- [on_message_ref](#on_message_ref)
|
||||
- [on_open](#on_open)
|
||||
- [on_open_ref](#on_open_ref)
|
||||
- [parse_frame_header](#parse_frame_header)
|
||||
- [ping](#ping)
|
||||
- [pong](#pong)
|
||||
- [read_next_message](#read_next_message)
|
||||
- [reset_state](#reset_state)
|
||||
- [set_state](#set_state)
|
||||
- [validate_frame](#validate_frame)
|
||||
- [write](#write)
|
||||
- [write_ptr](#write_ptr)
|
||||
- [write_string](#write_string)
|
||||
- [ClientOpt](#ClientOpt)
|
||||
- [ClientState](#ClientState)
|
||||
- [Message](#Message)
|
||||
- [free](#free)
|
||||
- [Server](#Server)
|
||||
- [free](#free)
|
||||
- [get_ping_interval](#get_ping_interval)
|
||||
- [get_state](#get_state)
|
||||
- [handle_handshake](#handle_handshake)
|
||||
- [listen](#listen)
|
||||
- [on_close](#on_close)
|
||||
- [on_close_ref](#on_close_ref)
|
||||
- [on_connect](#on_connect)
|
||||
- [on_message](#on_message)
|
||||
- [on_message_ref](#on_message_ref)
|
||||
- [set_ping_interval](#set_ping_interval)
|
||||
- [set_state](#set_state)
|
||||
- [ServerClient](#ServerClient)
|
||||
- [ServerOpt](#ServerOpt)
|
||||
- [ServerState](#ServerState)
|
||||
|
||||
## new_client
|
||||
```v
|
||||
fn new_client(address string, opt ClientOpt) !&Client
|
||||
```
|
||||
|
||||
new_client instance a new websocket client
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new_server
|
||||
```v
|
||||
fn new_server(family net.AddrFamily, port int, route string, opt ServerOpt) &Server
|
||||
```
|
||||
|
||||
new_server instance a new websocket server on provided port and route
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## AcceptClientFn
|
||||
```v
|
||||
type AcceptClientFn = fn (mut c ServerClient) !bool
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## SocketCloseFn
|
||||
```v
|
||||
type SocketCloseFn = fn (mut c Client, code int, reason string) !
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## SocketCloseFn2
|
||||
```v
|
||||
type SocketCloseFn2 = fn (mut c Client, code int, reason string, v voidptr) !
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## SocketErrorFn
|
||||
```v
|
||||
type SocketErrorFn = fn (mut c Client, err string) !
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## SocketErrorFn2
|
||||
```v
|
||||
type SocketErrorFn2 = fn (mut c Client, err string, v voidptr) !
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## SocketMessageFn
|
||||
```v
|
||||
type SocketMessageFn = fn (mut c Client, msg &Message) !
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## SocketMessageFn2
|
||||
```v
|
||||
type SocketMessageFn2 = fn (mut c Client, msg &Message, v voidptr) !
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## SocketOpenFn
|
||||
```v
|
||||
type SocketOpenFn = fn (mut c Client) !
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## SocketOpenFn2
|
||||
```v
|
||||
type SocketOpenFn2 = fn (mut c Client, v voidptr) !
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Uri
|
||||
## str
|
||||
```v
|
||||
fn (u Uri) str() string
|
||||
```
|
||||
|
||||
str returns the string representation of the Uri
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## OPCode
|
||||
```v
|
||||
enum OPCode {
|
||||
continuation = 0x00
|
||||
text_frame = 0x01
|
||||
binary_frame = 0x02
|
||||
close = 0x08
|
||||
ping = 0x09
|
||||
pong = 0x0A
|
||||
}
|
||||
```
|
||||
|
||||
OPCode represents the supported websocket frame types
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## State
|
||||
```v
|
||||
enum State {
|
||||
connecting = 0
|
||||
open
|
||||
closing
|
||||
closed
|
||||
}
|
||||
```
|
||||
|
||||
State represents the state of the websocket connection.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Client
|
||||
```v
|
||||
struct Client {
|
||||
is_server bool
|
||||
mut:
|
||||
ssl_conn &ssl.SSLConn = unsafe { nil } // secure connection used when wss is used
|
||||
flags []Flag // flags used in handshake
|
||||
fragments []Fragment // current fragments
|
||||
message_callbacks []MessageEventHandler // all callbacks on_message
|
||||
error_callbacks []ErrorEventHandler // all callbacks on_error
|
||||
open_callbacks []OpenEventHandler // all callbacks on_open
|
||||
close_callbacks []CloseEventHandler // all callbacks on_close
|
||||
pub:
|
||||
is_ssl bool // true if secure socket is used
|
||||
uri Uri // uri of current connection
|
||||
id string // unique id of client
|
||||
read_timeout i64
|
||||
write_timeout i64
|
||||
pub mut:
|
||||
header http.Header // headers that will be passed when connecting
|
||||
conn &net.TcpConn = unsafe { nil } // underlying TCP socket connection
|
||||
nonce_size int = 16 // size of nounce used for masking
|
||||
panic_on_callback bool // set to true of callbacks can panic
|
||||
client_state shared ClientState // current state of connection
|
||||
// logger used to log messages
|
||||
logger &log.Logger = default_logger
|
||||
resource_name string // name of current resource
|
||||
last_pong_ut i64 // last time in unix time we got a pong message
|
||||
}
|
||||
```
|
||||
|
||||
Client represents websocket client
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## close
|
||||
```v
|
||||
fn (mut ws Client) close(code int, message string) !
|
||||
```
|
||||
|
||||
close closes the websocket connection
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## connect
|
||||
```v
|
||||
fn (mut ws Client) connect() !
|
||||
```
|
||||
|
||||
connect connects to remote websocket server
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## free
|
||||
```v
|
||||
fn (c &Client) free()
|
||||
```
|
||||
|
||||
free handles manual free memory of Client struct
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## get_state
|
||||
```v
|
||||
fn (ws &Client) get_state() State
|
||||
```
|
||||
|
||||
get_state return the current state of the websocket connection
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## listen
|
||||
```v
|
||||
fn (mut ws Client) listen() !
|
||||
```
|
||||
|
||||
listen listens and processes incoming messages
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## on_close
|
||||
```v
|
||||
fn (mut ws Client) on_close(fun SocketCloseFn)
|
||||
```
|
||||
|
||||
on_close registers a callback on closed socket
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## on_close_ref
|
||||
```v
|
||||
fn (mut ws Client) on_close_ref(fun SocketCloseFn2, ref voidptr)
|
||||
```
|
||||
|
||||
on_close_ref registers a callback on closed socket and provides a reference object
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## on_error
|
||||
```v
|
||||
fn (mut ws Client) on_error(fun SocketErrorFn)
|
||||
```
|
||||
|
||||
on_error registers a callback on errors
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## on_error_ref
|
||||
```v
|
||||
fn (mut ws Client) on_error_ref(fun SocketErrorFn2, ref voidptr)
|
||||
```
|
||||
|
||||
on_error_ref registers a callback on errors and provides a reference object
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## on_message
|
||||
```v
|
||||
fn (mut ws Client) on_message(fun SocketMessageFn)
|
||||
```
|
||||
|
||||
on_message registers a callback on new messages
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## on_message_ref
|
||||
```v
|
||||
fn (mut ws Client) on_message_ref(fun SocketMessageFn2, ref voidptr)
|
||||
```
|
||||
|
||||
on_message_ref registers a callback on new messages and provides a reference object
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## on_open
|
||||
```v
|
||||
fn (mut ws Client) on_open(fun SocketOpenFn)
|
||||
```
|
||||
|
||||
on_open registers a callback on successful opening the websocket
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## on_open_ref
|
||||
```v
|
||||
fn (mut ws Client) on_open_ref(fun SocketOpenFn2, ref voidptr)
|
||||
```
|
||||
|
||||
on_open_ref registers a callback on successful opening the websocket and provides a reference object
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## parse_frame_header
|
||||
```v
|
||||
fn (mut ws Client) parse_frame_header() !Frame
|
||||
```
|
||||
|
||||
parse_frame_header parses next message by decoding the incoming frames
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## ping
|
||||
```v
|
||||
fn (mut ws Client) ping() !
|
||||
```
|
||||
|
||||
ping sends ping message to server
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## pong
|
||||
```v
|
||||
fn (mut ws Client) pong() !
|
||||
```
|
||||
|
||||
pong sends pong message to server,
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## read_next_message
|
||||
```v
|
||||
fn (mut ws Client) read_next_message() !Message
|
||||
```
|
||||
|
||||
read_next_message reads 1 to n frames to compose a message
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## reset_state
|
||||
```v
|
||||
fn (mut ws Client) reset_state() !
|
||||
```
|
||||
|
||||
reset_state resets the websocket and initialize default settings
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## set_state
|
||||
```v
|
||||
fn (mut ws Client) set_state(state State)
|
||||
```
|
||||
|
||||
set_state sets current state of the websocket connection
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## validate_frame
|
||||
```v
|
||||
fn (mut ws Client) validate_frame(frame &Frame) !
|
||||
```
|
||||
|
||||
validate_client validates client frame rules from RFC6455
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## write
|
||||
```v
|
||||
fn (mut ws Client) write(bytes []u8, code OPCode) !int
|
||||
```
|
||||
|
||||
write writes a byte array with a websocket messagetype to socket
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## write_ptr
|
||||
```v
|
||||
fn (mut ws Client) write_ptr(bytes &u8, payload_len int, code OPCode) !int
|
||||
```
|
||||
|
||||
write_ptr writes len bytes provided a byteptr with a websocket messagetype
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## write_string
|
||||
```v
|
||||
fn (mut ws Client) write_string(str string) !int
|
||||
```
|
||||
|
||||
write_str, writes a string with a websocket texttype to socket
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## ClientOpt
|
||||
```v
|
||||
struct ClientOpt {
|
||||
pub:
|
||||
read_timeout i64 = 30 * time.second
|
||||
write_timeout i64 = 30 * time.second
|
||||
logger &log.Logger = default_logger
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## ClientState
|
||||
```v
|
||||
struct ClientState {
|
||||
pub mut:
|
||||
state State = .closed // current state of connection
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Message
|
||||
```v
|
||||
struct Message {
|
||||
pub:
|
||||
opcode OPCode // websocket frame type of this message
|
||||
payload []u8 // payload of the message
|
||||
}
|
||||
```
|
||||
|
||||
Message represents a whole message combined from 1 to n frames
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## free
|
||||
```v
|
||||
fn (m &Message) free()
|
||||
```
|
||||
|
||||
free handles manual free memory of Message struct
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Server
|
||||
```v
|
||||
struct Server {
|
||||
mut:
|
||||
logger &log.Logger = default_logger
|
||||
ls &net.TcpListener = unsafe { nil } // listener used to get incoming connection to socket
|
||||
accept_client_callbacks []AcceptClientFn // accept client callback functions
|
||||
message_callbacks []MessageEventHandler // new message callback functions
|
||||
close_callbacks []CloseEventHandler // close message callback functions
|
||||
pub:
|
||||
family net.AddrFamily = .ip
|
||||
port int // port used as listen to incoming connections
|
||||
is_ssl bool // true if secure connection (not supported yet on server)
|
||||
pub mut:
|
||||
server_state shared ServerState
|
||||
}
|
||||
```
|
||||
|
||||
Server represents a websocket server connection
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## free
|
||||
```v
|
||||
fn (mut s Server) free()
|
||||
```
|
||||
|
||||
free manages manual free of memory for Server instance
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## get_ping_interval
|
||||
```v
|
||||
fn (mut s Server) get_ping_interval() int
|
||||
```
|
||||
|
||||
get_ping_interval return the interval that the server will send ping messages to clients
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## get_state
|
||||
```v
|
||||
fn (s &Server) get_state() State
|
||||
```
|
||||
|
||||
get_state return current state in a thread safe way
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## handle_handshake
|
||||
```v
|
||||
fn (mut s Server) handle_handshake(mut conn net.TcpConn, key string) !&ServerClient
|
||||
```
|
||||
|
||||
handle_handshake use an existing connection to respond to the handshake for a given key
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## listen
|
||||
```v
|
||||
fn (mut s Server) listen() !
|
||||
```
|
||||
|
||||
listen start listen and process to incoming connections from websocket clients
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## on_close
|
||||
```v
|
||||
fn (mut s Server) on_close(fun SocketCloseFn)
|
||||
```
|
||||
|
||||
on_close registers a callback on closed socket
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## on_close_ref
|
||||
```v
|
||||
fn (mut s Server) on_close_ref(fun SocketCloseFn2, ref voidptr)
|
||||
```
|
||||
|
||||
on_close_ref registers a callback on closed socket and provides a reference object
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## on_connect
|
||||
```v
|
||||
fn (mut s Server) on_connect(fun AcceptClientFn) !
|
||||
```
|
||||
|
||||
on_connect registers a callback when client connects to the server
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## on_message
|
||||
```v
|
||||
fn (mut s Server) on_message(fun SocketMessageFn)
|
||||
```
|
||||
|
||||
on_message registers a callback on new messages
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## on_message_ref
|
||||
```v
|
||||
fn (mut s Server) on_message_ref(fun SocketMessageFn2, ref voidptr)
|
||||
```
|
||||
|
||||
on_message_ref registers a callback on new messages and provides a reference object
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## set_ping_interval
|
||||
```v
|
||||
fn (mut s Server) set_ping_interval(seconds int)
|
||||
```
|
||||
|
||||
set_ping_interval sets the interval that the server will send ping messages to clients
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## set_state
|
||||
```v
|
||||
fn (mut s Server) set_state(state State)
|
||||
```
|
||||
|
||||
set_state sets current state in a thread safe way
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## ServerClient
|
||||
```v
|
||||
struct ServerClient {
|
||||
pub:
|
||||
resource_name string // resource that the client access
|
||||
client_key string // unique key of client
|
||||
pub mut:
|
||||
server &Server = unsafe { nil }
|
||||
client &Client = unsafe { nil }
|
||||
}
|
||||
```
|
||||
|
||||
ServerClient represents a connected client
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## ServerOpt
|
||||
```v
|
||||
struct ServerOpt {
|
||||
pub:
|
||||
logger &log.Logger = default_logger
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## ServerState
|
||||
```v
|
||||
struct ServerState {
|
||||
mut:
|
||||
ping_interval int = 30 // interval for sending ping to clients (seconds)
|
||||
state State = .closed // current state of connection
|
||||
pub mut:
|
||||
clients map[string]&ServerClient // clients connected to this server
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:16:36
|
||||
527
aiprompts/v_core/orm/orm.md
Normal file
527
aiprompts/v_core/orm/orm.md
Normal file
@@ -0,0 +1,527 @@
|
||||
# module orm
|
||||
|
||||
|
||||
## Contents
|
||||
- [Constants](#Constants)
|
||||
- [new_query](#new_query)
|
||||
- [orm_select_gen](#orm_select_gen)
|
||||
- [orm_stmt_gen](#orm_stmt_gen)
|
||||
- [orm_table_gen](#orm_table_gen)
|
||||
- [Connection](#Connection)
|
||||
- [Primitive](#Primitive)
|
||||
- [QueryBuilder[T]](#QueryBuilder[T])
|
||||
- [reset](#reset)
|
||||
- [where](#where)
|
||||
- [or_where](#or_where)
|
||||
- [order](#order)
|
||||
- [limit](#limit)
|
||||
- [offset](#offset)
|
||||
- [select](#select)
|
||||
- [set](#set)
|
||||
- [query](#query)
|
||||
- [count](#count)
|
||||
- [insert](#insert)
|
||||
- [insert_many](#insert_many)
|
||||
- [update](#update)
|
||||
- [delete](#delete)
|
||||
- [create](#create)
|
||||
- [drop](#drop)
|
||||
- [last_id](#last_id)
|
||||
- [MathOperationKind](#MathOperationKind)
|
||||
- [OperationKind](#OperationKind)
|
||||
- [OrderType](#OrderType)
|
||||
- [SQLDialect](#SQLDialect)
|
||||
- [StmtKind](#StmtKind)
|
||||
- [InfixType](#InfixType)
|
||||
- [Null](#Null)
|
||||
- [QueryBuilder](#QueryBuilder)
|
||||
- [QueryData](#QueryData)
|
||||
- [SelectConfig](#SelectConfig)
|
||||
- [Table](#Table)
|
||||
- [TableField](#TableField)
|
||||
|
||||
## Constants
|
||||
```v
|
||||
const num64 = [typeof[i64]().idx, typeof[u64]().idx]
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const nums = [
|
||||
typeof[i8]().idx,
|
||||
typeof[i16]().idx,
|
||||
typeof[int]().idx,
|
||||
typeof[u8]().idx,
|
||||
typeof[u16]().idx,
|
||||
typeof[u32]().idx,
|
||||
typeof[bool]().idx,
|
||||
]
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const float = [
|
||||
typeof[f32]().idx,
|
||||
typeof[f64]().idx,
|
||||
]
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const type_string = typeof[string]().idx
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const serial = -1
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const time_ = -2
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const enum_ = -3
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const type_idx = {
|
||||
'i8': typeof[i8]().idx
|
||||
'i16': typeof[i16]().idx
|
||||
'int': typeof[int]().idx
|
||||
'i64': typeof[i64]().idx
|
||||
'u8': typeof[u8]().idx
|
||||
'u16': typeof[u16]().idx
|
||||
'u32': typeof[u32]().idx
|
||||
'u64': typeof[u64]().idx
|
||||
'f32': typeof[f32]().idx
|
||||
'f64': typeof[f64]().idx
|
||||
'bool': typeof[bool]().idx
|
||||
'string': typeof[string]().idx
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const string_max_len = 2048
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const null_primitive = Primitive(Null{})
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new_query
|
||||
```v
|
||||
fn new_query[T](conn Connection) &QueryBuilder[T]
|
||||
```
|
||||
|
||||
new_query create a new query object for struct `T`
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## orm_select_gen
|
||||
```v
|
||||
fn orm_select_gen(cfg SelectConfig, q string, num bool, qm string, start_pos int, where QueryData) string
|
||||
```
|
||||
|
||||
Generates an sql select stmt, from universal parameter orm - See SelectConfig q, num, qm, start_pos - see orm_stmt_gen where - See QueryData
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## orm_stmt_gen
|
||||
```v
|
||||
fn orm_stmt_gen(sql_dialect SQLDialect, table Table, q string, kind StmtKind, num bool, qm string,
|
||||
start_pos int, data QueryData, where QueryData) (string, QueryData)
|
||||
```
|
||||
|
||||
Generates an sql stmt, from universal parameter q - The quotes character, which can be different in every type, so it's variable num - Stmt uses nums at prepared statements (? or ?1) qm - Character for prepared statement (qm for question mark, as in sqlite) start_pos - When num is true, it's the start position of the counter
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## orm_table_gen
|
||||
```v
|
||||
fn orm_table_gen(sql_dialect SQLDialect, table Table, q string, defaults bool, def_unique_len int, fields []TableField, sql_from_v fn (int) !string,
|
||||
alternative bool) !string
|
||||
```
|
||||
|
||||
Generates an sql table stmt, from universal parameter table - Table struct q - see orm_stmt_gen defaults - enables default values in stmt def_unique_len - sets default unique length for texts fields - See TableField sql_from_v - Function which maps type indices to sql type names alternative - Needed for msdb
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Connection
|
||||
```v
|
||||
interface Connection {
|
||||
mut:
|
||||
select(config SelectConfig, data QueryData, where QueryData) ![][]Primitive
|
||||
insert(table Table, data QueryData) !
|
||||
update(table Table, data QueryData, where QueryData) !
|
||||
delete(table Table, where QueryData) !
|
||||
create(table Table, fields []TableField) !
|
||||
drop(table Table) !
|
||||
last_id() int
|
||||
}
|
||||
```
|
||||
|
||||
Interfaces gets called from the backend and can be implemented Since the orm supports arrays aswell, they have to be returned too. A row is represented as []Primitive, where the data is connected to the fields of the struct by their index. The indices are mapped with the SelectConfig.field array. This is the mapping for a struct. To have an array, there has to be an array of structs, basically [][]Primitive
|
||||
|
||||
Every function without last_id() returns an optional, which returns an error if present last_id returns the last inserted id of the db
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Primitive
|
||||
```v
|
||||
type Primitive = InfixType
|
||||
| Null
|
||||
| bool
|
||||
| f32
|
||||
| f64
|
||||
| i16
|
||||
| i64
|
||||
| i8
|
||||
| int
|
||||
| string
|
||||
| time.Time
|
||||
| u16
|
||||
| u32
|
||||
| u64
|
||||
| u8
|
||||
| []Primitive
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## QueryBuilder[T]
|
||||
## reset
|
||||
```v
|
||||
fn (qb_ &QueryBuilder[T]) reset() &QueryBuilder[T]
|
||||
```
|
||||
|
||||
reset reset a query object, but keep the connection and table name
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## where
|
||||
```v
|
||||
fn (qb_ &QueryBuilder[T]) where(condition string, params ...Primitive) !&QueryBuilder[T]
|
||||
```
|
||||
|
||||
where create a `where` clause, it will `AND` with previous `where` clause. valid token in the `condition` include: `field's names`, `operator`, `(`, `)`, `?`, `AND`, `OR`, `||`, `&&`, valid `operator` incldue: `=`, `!=`, `<>`, `>=`, `<=`, `>`, `<`, `LIKE`, `ILIKE`, `IS NULL`, `IS NOT NULL`, `IN`, `NOT IN` example: `where('(a > ? AND b <= ?) OR (c <> ? AND (x = ? OR y = ?))', a, b, c, x, y)`
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## or_where
|
||||
```v
|
||||
fn (qb_ &QueryBuilder[T]) or_where(condition string, params ...Primitive) !&QueryBuilder[T]
|
||||
```
|
||||
|
||||
or_where create a `where` clause, it will `OR` with previous `where` clause.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## order
|
||||
```v
|
||||
fn (qb_ &QueryBuilder[T]) order(order_type OrderType, field string) !&QueryBuilder[T]
|
||||
```
|
||||
|
||||
order create a `order` clause
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## limit
|
||||
```v
|
||||
fn (qb_ &QueryBuilder[T]) limit(limit int) !&QueryBuilder[T]
|
||||
```
|
||||
|
||||
limit create a `limit` clause
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## offset
|
||||
```v
|
||||
fn (qb_ &QueryBuilder[T]) offset(offset int) !&QueryBuilder[T]
|
||||
```
|
||||
|
||||
offset create a `offset` clause
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## select
|
||||
```v
|
||||
fn (qb_ &QueryBuilder[T]) select(fields ...string) !&QueryBuilder[T]
|
||||
```
|
||||
|
||||
select create a `select` clause
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## set
|
||||
```v
|
||||
fn (qb_ &QueryBuilder[T]) set(assign string, values ...Primitive) !&QueryBuilder[T]
|
||||
```
|
||||
|
||||
set create a `set` clause for `update`
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## query
|
||||
```v
|
||||
fn (qb_ &QueryBuilder[T]) query() ![]T
|
||||
```
|
||||
|
||||
query start a query and return result in struct `T`
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## count
|
||||
```v
|
||||
fn (qb_ &QueryBuilder[T]) count() !int
|
||||
```
|
||||
|
||||
count start a count query and return result
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## insert
|
||||
```v
|
||||
fn (qb_ &QueryBuilder[T]) insert[T](value T) !&QueryBuilder[T]
|
||||
```
|
||||
|
||||
insert insert a record into the database
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## insert_many
|
||||
```v
|
||||
fn (qb_ &QueryBuilder[T]) insert_many[T](values []T) !&QueryBuilder[T]
|
||||
```
|
||||
|
||||
insert_many insert records into the database
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## update
|
||||
```v
|
||||
fn (qb_ &QueryBuilder[T]) update() !&QueryBuilder[T]
|
||||
```
|
||||
|
||||
update update record(s) in the database
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## delete
|
||||
```v
|
||||
fn (qb_ &QueryBuilder[T]) delete() !&QueryBuilder[T]
|
||||
```
|
||||
|
||||
delete delete record(s) in the database
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## create
|
||||
```v
|
||||
fn (qb_ &QueryBuilder[T]) create() !&QueryBuilder[T]
|
||||
```
|
||||
|
||||
create create a table
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## drop
|
||||
```v
|
||||
fn (qb_ &QueryBuilder[T]) drop() !&QueryBuilder[T]
|
||||
```
|
||||
|
||||
drop drop a table
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## last_id
|
||||
```v
|
||||
fn (qb_ &QueryBuilder[T]) last_id() int
|
||||
```
|
||||
|
||||
last_id returns the last inserted id of the db
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## MathOperationKind
|
||||
```v
|
||||
enum MathOperationKind {
|
||||
add // +
|
||||
sub // -
|
||||
mul // *
|
||||
div // /
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## OperationKind
|
||||
```v
|
||||
enum OperationKind {
|
||||
neq // !=
|
||||
eq // ==
|
||||
gt // >
|
||||
lt // <
|
||||
ge // >=
|
||||
le // <=
|
||||
orm_like // LIKE
|
||||
orm_ilike // ILIKE
|
||||
is_null // IS NULL
|
||||
is_not_null // IS NOT NULL
|
||||
in // IN
|
||||
not_in // NOT IN
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## OrderType
|
||||
```v
|
||||
enum OrderType {
|
||||
asc
|
||||
desc
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## SQLDialect
|
||||
```v
|
||||
enum SQLDialect {
|
||||
default
|
||||
mysql
|
||||
pg
|
||||
sqlite
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## StmtKind
|
||||
```v
|
||||
enum StmtKind {
|
||||
insert
|
||||
update
|
||||
delete
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## InfixType
|
||||
```v
|
||||
struct InfixType {
|
||||
pub:
|
||||
name string
|
||||
operator MathOperationKind
|
||||
right Primitive
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Null
|
||||
```v
|
||||
struct Null {}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## QueryBuilder
|
||||
```v
|
||||
struct QueryBuilder[T] {
|
||||
pub mut:
|
||||
meta []TableField
|
||||
valid_sql_field_names []string
|
||||
conn Connection
|
||||
config SelectConfig
|
||||
data QueryData
|
||||
where QueryData
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## QueryData
|
||||
```v
|
||||
struct QueryData {
|
||||
pub mut:
|
||||
fields []string
|
||||
data []Primitive
|
||||
types []int
|
||||
parentheses [][]int
|
||||
kinds []OperationKind
|
||||
auto_fields []int
|
||||
is_and []bool
|
||||
}
|
||||
```
|
||||
|
||||
Examples for QueryData in SQL: abc == 3 && b == 'test' => fields[abc, b]; data[3, 'test']; types[index of int, index of string]; kinds[.eq, .eq]; is_and[true]; Every field, data, type & kind of operation in the expr share the same index in the arrays is_and defines how they're addicted to each other either and or or parentheses defines which fields will be inside () auto_fields are indexes of fields where db should generate a value when absent in an insert
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## SelectConfig
|
||||
```v
|
||||
struct SelectConfig {
|
||||
pub mut:
|
||||
table Table
|
||||
is_count bool
|
||||
has_where bool
|
||||
has_order bool
|
||||
order string
|
||||
order_type OrderType
|
||||
has_limit bool
|
||||
primary string = 'id' // should be set if primary is different than 'id' and 'has_limit' is false
|
||||
has_offset bool
|
||||
fields []string
|
||||
types []int
|
||||
}
|
||||
```
|
||||
|
||||
table - Table struct is_count - Either the data will be returned or an integer with the count has_where - Select all or use a where expr has_order - Order the results order - Name of the column which will be ordered order_type - Type of order (asc, desc) has_limit - Limits the output data primary - Name of the primary field has_offset - Add an offset to the result fields - Fields to select types - Types to select
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Table
|
||||
```v
|
||||
struct Table {
|
||||
pub mut:
|
||||
name string
|
||||
attrs []VAttribute
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## TableField
|
||||
```v
|
||||
struct TableField {
|
||||
pub mut:
|
||||
name string
|
||||
typ int
|
||||
nullable bool
|
||||
default_val string
|
||||
attrs []VAttribute
|
||||
is_arr bool
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:19:37
|
||||
502
aiprompts/v_core/regex/regex.md
Normal file
502
aiprompts/v_core/regex/regex.md
Normal file
@@ -0,0 +1,502 @@
|
||||
# module regex
|
||||
|
||||
|
||||
## Contents
|
||||
- [Constants](#Constants)
|
||||
- [new](#new)
|
||||
- [regex_base](#regex_base)
|
||||
- [regex_opt](#regex_opt)
|
||||
- [FnLog](#FnLog)
|
||||
- [FnReplace](#FnReplace)
|
||||
- [FnValidator](#FnValidator)
|
||||
- [RE](#RE)
|
||||
- [compile_opt](#compile_opt)
|
||||
- [find](#find)
|
||||
- [find_all](#find_all)
|
||||
- [find_all_str](#find_all_str)
|
||||
- [find_from](#find_from)
|
||||
- [get_code](#get_code)
|
||||
- [get_group_bounds_by_id](#get_group_bounds_by_id)
|
||||
- [get_group_bounds_by_name](#get_group_bounds_by_name)
|
||||
- [get_group_by_id](#get_group_by_id)
|
||||
- [get_group_by_name](#get_group_by_name)
|
||||
- [get_group_list](#get_group_list)
|
||||
- [get_query](#get_query)
|
||||
- [match_base](#match_base)
|
||||
- [match_string](#match_string)
|
||||
- [matches_string](#matches_string)
|
||||
- [replace](#replace)
|
||||
- [replace_by_fn](#replace_by_fn)
|
||||
- [replace_n](#replace_n)
|
||||
- [replace_simple](#replace_simple)
|
||||
- [reset](#reset)
|
||||
- [split](#split)
|
||||
- [Re_group](#Re_group)
|
||||
|
||||
## Constants
|
||||
```v
|
||||
const v_regex_version = '1.0 alpha' // regex module version
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const max_code_len = 256 // default small base code len for the regex programs
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const max_quantifier = 1073741824 // default max repetitions allowed for the quantifiers = 2^30
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const spaces = [` `, `\t`, `\n`, `\r`, `\v`, `\f`]
|
||||
```
|
||||
|
||||
spaces chars (here only westerns!!) TODO: manage all the spaces from unicode
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const new_line_list = [`\n`, `\r`]
|
||||
```
|
||||
|
||||
new line chars for now only '\n'
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const no_match_found = -1
|
||||
```
|
||||
|
||||
Results
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const compile_ok = 0 // the regex string compiled, all ok
|
||||
```
|
||||
|
||||
Errors
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const err_char_unknown = -2 // the char used is unknow to the system
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const err_undefined = -3 // the compiler symbol is undefined
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const err_internal_error = -4 // Bug in the regex system!!
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const err_cc_alloc_overflow = -5 // memory for char class full!!
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const err_syntax_error = -6 // syntax error in regex compiling
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const err_groups_overflow = -7 // max number of groups reached
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const err_groups_max_nested = -8 // max number of nested group reached
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const err_group_not_balanced = -9 // group not balanced
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const err_group_qm_notation = -10 // group invalid notation
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const err_invalid_or_with_cc = -11 // invalid or on two consecutive char class
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const err_neg_group_quantifier = -12 // negation groups can not have quantifier
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const err_consecutive_dots = -13
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const f_nl = 0x00000001 // end the match when find a new line symbol
|
||||
```
|
||||
|
||||
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const f_ms = 0x00000002 // match true only if the match is at the start of the string
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const f_me = 0x00000004 // match true only if the match is at the end of the string
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const f_efm = 0x00000100 // exit on first token matched, used by search
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const f_bin = 0x00000200 // work only on bytes, ignore utf-8
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const f_src = 0x00020000
|
||||
```
|
||||
|
||||
behaviour modifier flags
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new
|
||||
```v
|
||||
fn new() RE
|
||||
```
|
||||
|
||||
new create a RE of small size, usually sufficient for ordinary use
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## regex_base
|
||||
```v
|
||||
fn regex_base(pattern string) (RE, int, int)
|
||||
```
|
||||
|
||||
regex_base returns a regex object (`RE`) generated from `pattern` string and detailed information in re_err, err_pos, if an error occurred.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## regex_opt
|
||||
```v
|
||||
fn regex_opt(pattern string) !RE
|
||||
```
|
||||
|
||||
regex_opt create new RE object from RE pattern string
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## FnLog
|
||||
```v
|
||||
type FnLog = fn (string)
|
||||
```
|
||||
|
||||
Log function prototype
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## FnReplace
|
||||
```v
|
||||
type FnReplace = fn (re RE, in_txt string, start int, end int) string
|
||||
```
|
||||
|
||||
type of function used for custom replace in_txt source text start index of the start of the match in in_txt end index of the end of the match in in_txt the match is in in_txt[start..end]
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## FnValidator
|
||||
```v
|
||||
type FnValidator = fn (u8) bool
|
||||
```
|
||||
|
||||
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## RE
|
||||
```v
|
||||
struct RE {
|
||||
pub mut:
|
||||
prog []Token
|
||||
prog_len int // regex program len
|
||||
// char classes storage
|
||||
cc []CharClass // char class list
|
||||
cc_index int // index
|
||||
// groups
|
||||
group_count int // number of groups in this regex struct
|
||||
groups []int // groups index results
|
||||
group_max_nested int = 3 // max nested group
|
||||
group_max int = 8 // max allowed number of different groups
|
||||
|
||||
state_list []StateObj
|
||||
|
||||
group_csave_flag bool // flag to enable continuous saving
|
||||
group_csave []int //= []int{} // groups continuous save list
|
||||
|
||||
group_map map[string]int // groups names map
|
||||
|
||||
group_stack []int
|
||||
group_data []int
|
||||
// flags
|
||||
flag int // flag for optional parameters
|
||||
// Debug/log
|
||||
debug int // enable in order to have the unroll of the code 0 = NO_DEBUG, 1 = LIGHT 2 = VERBOSE
|
||||
log_func FnLog = simple_log // log function, can be customized by the user
|
||||
query string // query string
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## compile_opt
|
||||
```v
|
||||
fn (mut re RE) compile_opt(pattern string) !
|
||||
```
|
||||
|
||||
compile_opt compile RE pattern string
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## find
|
||||
```v
|
||||
fn (mut re RE) find(in_txt string) (int, int)
|
||||
```
|
||||
|
||||
find try to find the first match in the input string
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## find_all
|
||||
```v
|
||||
fn (mut re RE) find_all(in_txt string) []int
|
||||
```
|
||||
|
||||
find_all find all the non overlapping occurrences of the match pattern and return the start and end index of the match
|
||||
|
||||
Usage:
|
||||
```v
|
||||
blurb := 'foobar boo steelbar toolbox foot tooooot'
|
||||
mut re := regex.regex_opt('f|t[eo]+')?
|
||||
res := re.find_all(blurb) // [0, 3, 12, 15, 20, 23, 28, 31, 33, 39]
|
||||
```
|
||||
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## find_all_str
|
||||
```v
|
||||
fn (mut re RE) find_all_str(in_txt string) []string
|
||||
```
|
||||
|
||||
find_all_str find all the non overlapping occurrences of the match pattern, return a string list
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## find_from
|
||||
```v
|
||||
fn (mut re RE) find_from(in_txt string, start int) (int, int)
|
||||
```
|
||||
|
||||
find try to find the first match in the input string strarting from start index
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## get_code
|
||||
```v
|
||||
fn (re &RE) get_code() string
|
||||
```
|
||||
|
||||
get_code return the compiled code as regex string, note: may be different from the source!
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## get_group_bounds_by_id
|
||||
```v
|
||||
fn (re &RE) get_group_bounds_by_id(group_id int) (int, int)
|
||||
```
|
||||
|
||||
get_group_by_id get a group boundaries by its id
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## get_group_bounds_by_name
|
||||
```v
|
||||
fn (re &RE) get_group_bounds_by_name(group_name string) (int, int)
|
||||
```
|
||||
|
||||
get_group_bounds_by_name get a group boundaries by its name
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## get_group_by_id
|
||||
```v
|
||||
fn (re &RE) get_group_by_id(in_txt string, group_id int) string
|
||||
```
|
||||
|
||||
get_group_by_id get a group string by its id
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## get_group_by_name
|
||||
```v
|
||||
fn (re &RE) get_group_by_name(in_txt string, group_name string) string
|
||||
```
|
||||
|
||||
get_group_by_name get a group boundaries by its name
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## get_group_list
|
||||
```v
|
||||
fn (re &RE) get_group_list() []Re_group
|
||||
```
|
||||
|
||||
get_group_list return a list of Re_group for the found groups
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## get_query
|
||||
```v
|
||||
fn (re &RE) get_query() string
|
||||
```
|
||||
|
||||
get_query return a string with a reconstruction of the query starting from the regex program code
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## match_base
|
||||
```v
|
||||
fn (mut re RE) match_base(in_txt &u8, in_txt_len int) (int, int)
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## match_string
|
||||
```v
|
||||
fn (re &RE) match_string(in_txt string) (int, int)
|
||||
```
|
||||
|
||||
match_string Match the pattern with the in_txt string
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## matches_string
|
||||
```v
|
||||
fn (re &RE) matches_string(in_txt string) bool
|
||||
```
|
||||
|
||||
matches_string Checks if the pattern matches the in_txt string
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## replace
|
||||
```v
|
||||
fn (mut re RE) replace(in_txt string, repl_str string) string
|
||||
```
|
||||
|
||||
replace return a string where the matches are replaced with the repl_str string, this function supports groups in the replace string
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## replace_by_fn
|
||||
```v
|
||||
fn (mut re RE) replace_by_fn(in_txt string, repl_fn FnReplace) string
|
||||
```
|
||||
|
||||
replace_by_fn return a string where the matches are replaced with the string from the repl_fn callback function
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## replace_n
|
||||
```v
|
||||
fn (mut re RE) replace_n(in_txt string, repl_str string, count int) string
|
||||
```
|
||||
|
||||
replace_n return a string where the first count matches are replaced with the repl_str string, if count is > 0 the replace began from the start of the string toward the end if count is < 0 the replace began from the end of the string toward the start if count is 0 do nothing
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## replace_simple
|
||||
```v
|
||||
fn (mut re RE) replace_simple(in_txt string, repl string) string
|
||||
```
|
||||
|
||||
replace_simple return a string where the matches are replaced with the replace string
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## reset
|
||||
```v
|
||||
fn (mut re RE) reset()
|
||||
```
|
||||
|
||||
Reset RE object
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## split
|
||||
```v
|
||||
fn (mut re RE) split(in_txt string) []string
|
||||
```
|
||||
|
||||
split returns the sections of string around the regex
|
||||
|
||||
Usage:
|
||||
```v
|
||||
blurb := 'foobar boo steelbar toolbox foot tooooot'
|
||||
mut re := regex.regex_opt('f|t[eo]+')?
|
||||
res := re.split(blurb) // ['bar boo s', 'lbar ', 'lbox ', 't ', 't']
|
||||
```
|
||||
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Re_group
|
||||
```v
|
||||
struct Re_group {
|
||||
pub:
|
||||
start int = -1
|
||||
end int = -1
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:19:51
|
||||
452
aiprompts/v_core/string/strings.md
Normal file
452
aiprompts/v_core/string/strings.md
Normal file
@@ -0,0 +1,452 @@
|
||||
# module strings
|
||||
|
||||
|
||||
## Contents
|
||||
- [dice_coefficient](#dice_coefficient)
|
||||
- [find_between_pair_rune](#find_between_pair_rune)
|
||||
- [find_between_pair_string](#find_between_pair_string)
|
||||
- [find_between_pair_u8](#find_between_pair_u8)
|
||||
- [hamming_distance](#hamming_distance)
|
||||
- [hamming_similarity](#hamming_similarity)
|
||||
- [jaro_similarity](#jaro_similarity)
|
||||
- [jaro_winkler_similarity](#jaro_winkler_similarity)
|
||||
- [levenshtein_distance](#levenshtein_distance)
|
||||
- [levenshtein_distance_percentage](#levenshtein_distance_percentage)
|
||||
- [new_builder](#new_builder)
|
||||
- [repeat](#repeat)
|
||||
- [repeat_string](#repeat_string)
|
||||
- [split_capital](#split_capital)
|
||||
- [Builder](#Builder)
|
||||
- [reuse_as_plain_u8_array](#reuse_as_plain_u8_array)
|
||||
- [write_ptr](#write_ptr)
|
||||
- [write_rune](#write_rune)
|
||||
- [write_runes](#write_runes)
|
||||
- [write_u8](#write_u8)
|
||||
- [write_byte](#write_byte)
|
||||
- [write_decimal](#write_decimal)
|
||||
- [write](#write)
|
||||
- [drain_builder](#drain_builder)
|
||||
- [byte_at](#byte_at)
|
||||
- [write_string](#write_string)
|
||||
- [write_string2](#write_string2)
|
||||
- [go_back](#go_back)
|
||||
- [spart](#spart)
|
||||
- [cut_last](#cut_last)
|
||||
- [cut_to](#cut_to)
|
||||
- [go_back_to](#go_back_to)
|
||||
- [writeln](#writeln)
|
||||
- [writeln2](#writeln2)
|
||||
- [last_n](#last_n)
|
||||
- [after](#after)
|
||||
- [str](#str)
|
||||
- [ensure_cap](#ensure_cap)
|
||||
- [grow_len](#grow_len)
|
||||
- [free](#free)
|
||||
|
||||
## dice_coefficient
|
||||
```v
|
||||
fn dice_coefficient(s1 string, s2 string) f32
|
||||
```
|
||||
|
||||
dice_coefficient implements the Sørensen–Dice coefficient. It finds the similarity between two strings, and returns a coefficient between 0.0 (not similar) and 1.0 (exact match).
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## find_between_pair_rune
|
||||
```v
|
||||
fn find_between_pair_rune(input string, start rune, end rune) string
|
||||
```
|
||||
|
||||
find_between_pair_rune returns the string found between the pair of marks defined by `start` and `end`. As opposed to the `find_between`, `all_after*`, `all_before*` methods defined on the `string` type, this function can extract content between *nested* marks in `input`. If `start` and `end` marks are nested in `input`, the characters between the *outermost* mark pair is returned. It is expected that `start` and `end` marks are *balanced*, meaning that the amount of `start` marks equal the amount of `end` marks in the `input`. An empty string is returned otherwise. Using two identical marks as `start` and `end` results in undefined output behavior. find_between_pair_rune is inbetween the fastest and slowest in the find_between_pair_* family of functions.
|
||||
|
||||
Examples
|
||||
```v
|
||||
|
||||
assert strings.find_between_pair_rune('(V) (NOT V)',`(`,`)`) == 'V'
|
||||
|
||||
assert strings.find_between_pair_rune('s {X{Y}} s',`{`,`}`) == 'X{Y}'
|
||||
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## find_between_pair_string
|
||||
```v
|
||||
fn find_between_pair_string(input string, start string, end string) string
|
||||
```
|
||||
|
||||
find_between_pair_string returns the string found between the pair of marks defined by `start` and `end`. As opposed to the `find_between`, `all_after*`, `all_before*` methods defined on the `string` type, this function can extract content between *nested* marks in `input`. If `start` and `end` marks are nested in `input`, the characters between the *outermost* mark pair is returned. It is expected that `start` and `end` marks are *balanced*, meaning that the amount of `start` marks equal the amount of `end` marks in the `input`. An empty string is returned otherwise. Using two identical marks as `start` and `end` results in undefined output behavior. find_between_pair_string is the slowest in the find_between_pair_* function family.
|
||||
|
||||
Examples
|
||||
```v
|
||||
|
||||
assert strings.find_between_pair_string('/*V*/ /*NOT V*/','/*','*/') == 'V'
|
||||
|
||||
assert strings.find_between_pair_string('s {{X{{Y}}}} s','{{','}}') == 'X{{Y}}'
|
||||
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## find_between_pair_u8
|
||||
```v
|
||||
fn find_between_pair_u8(input string, start u8, end u8) string
|
||||
```
|
||||
|
||||
find_between_pair_byte returns the string found between the pair of marks defined by `start` and `end`. As opposed to the `find_between`, `all_after*`, `all_before*` methods defined on the `string` type, this function can extract content between *nested* marks in `input`. If `start` and `end` marks are nested in `input`, the characters between the *outermost* mark pair is returned. It is expected that `start` and `end` marks are *balanced*, meaning that the amount of `start` marks equal the amount of `end` marks in the `input`. An empty string is returned otherwise. Using two identical marks as `start` and `end` results in undefined output behavior. find_between_pair_byte is the fastest in the find_between_pair_* family of functions.
|
||||
|
||||
Examples
|
||||
```v
|
||||
|
||||
assert strings.find_between_pair_u8('(V) (NOT V)',`(`,`)`) == 'V'
|
||||
|
||||
assert strings.find_between_pair_u8('s {X{Y}} s',`{`,`}`) == 'X{Y}'
|
||||
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## hamming_distance
|
||||
```v
|
||||
fn hamming_distance(a string, b string) int
|
||||
```
|
||||
|
||||
hamming_distance uses the Hamming Distance algorithm to calculate the distance between two strings `a` and `b` (lower is closer).
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## hamming_similarity
|
||||
```v
|
||||
fn hamming_similarity(a string, b string) f32
|
||||
```
|
||||
|
||||
hamming_similarity uses the Hamming Distance algorithm to calculate the distance between two strings `a` and `b`. It returns a coefficient between 0.0 (not similar) and 1.0 (exact match).
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## jaro_similarity
|
||||
```v
|
||||
fn jaro_similarity(a string, b string) f64
|
||||
```
|
||||
|
||||
jaro_similarity uses the Jaro Distance algorithm to calculate the distance between two strings `a` and `b`. It returns a coefficient between 0.0 (not similar) and 1.0 (exact match).
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## jaro_winkler_similarity
|
||||
```v
|
||||
fn jaro_winkler_similarity(a string, b string) f64
|
||||
```
|
||||
|
||||
jaro_winkler_similarity uses the Jaro Winkler Distance algorithm to calculate the distance between two strings `a` and `b`. It returns a coefficient between 0.0 (not similar) and 1.0 (exact match). The scaling factor(`p=0.1`) in Jaro-Winkler gives higher weight to prefix similarities, making it especially effective for cases where slight misspellings or prefixes are common.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## levenshtein_distance
|
||||
```v
|
||||
fn levenshtein_distance(a string, b string) int
|
||||
```
|
||||
|
||||
levenshtein_distance uses the Levenshtein Distance algorithm to calculate the distance between between two strings `a` and `b` (lower is closer).
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## levenshtein_distance_percentage
|
||||
```v
|
||||
fn levenshtein_distance_percentage(a string, b string) f32
|
||||
```
|
||||
|
||||
levenshtein_distance_percentage uses the Levenshtein Distance algorithm to calculate how similar two strings are as a percentage (higher is closer).
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new_builder
|
||||
```v
|
||||
fn new_builder(initial_size int) Builder
|
||||
```
|
||||
|
||||
new_builder returns a new string builder, with an initial capacity of `initial_size`.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## repeat
|
||||
```v
|
||||
fn repeat(c u8, n int) string
|
||||
```
|
||||
|
||||
strings.repeat - fill a string with `n` repetitions of the character `c`
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## repeat_string
|
||||
```v
|
||||
fn repeat_string(s string, n int) string
|
||||
```
|
||||
|
||||
strings.repeat_string - gives you `n` repetitions of the substring `s`
|
||||
|
||||
Note: strings.repeat, that repeats a single byte, is between 2x and 24x faster than strings.repeat_string called for a 1 char string.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## split_capital
|
||||
```v
|
||||
fn split_capital(s string) []string
|
||||
```
|
||||
|
||||
split_capital returns an array containing the contents of `s` split by capital letters.
|
||||
|
||||
Examples
|
||||
```v
|
||||
|
||||
assert strings.split_capital('XYZ') == ['X', 'Y', 'Z']
|
||||
|
||||
assert strings.split_capital('XYStar') == ['X', 'Y', 'Star']
|
||||
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Builder
|
||||
```v
|
||||
type Builder = []u8
|
||||
```
|
||||
|
||||
strings.Builder is used to efficiently append many strings to a large dynamically growing buffer, then use the resulting large string. Using a string builder is much better for performance/memory usage than doing constantly string concatenation.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## reuse_as_plain_u8_array
|
||||
```v
|
||||
fn (mut b Builder) reuse_as_plain_u8_array() []u8
|
||||
```
|
||||
|
||||
reuse_as_plain_u8_array allows using the Builder instance as a plain []u8 return value. It is useful, when you have accumulated data in the builder, that you want to pass/access as []u8 later, without copying or freeing the buffer. NB: you *should NOT use* the string builder instance after calling this method. Use only the return value after calling this method.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## write_ptr
|
||||
```v
|
||||
fn (mut b Builder) write_ptr(ptr &u8, len int)
|
||||
```
|
||||
|
||||
write_ptr writes `len` bytes provided byteptr to the accumulated buffer
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## write_rune
|
||||
```v
|
||||
fn (mut b Builder) write_rune(r rune)
|
||||
```
|
||||
|
||||
write_rune appends a single rune to the accumulated buffer
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## write_runes
|
||||
```v
|
||||
fn (mut b Builder) write_runes(runes []rune)
|
||||
```
|
||||
|
||||
write_runes appends all the given runes to the accumulated buffer.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## write_u8
|
||||
```v
|
||||
fn (mut b Builder) write_u8(data u8)
|
||||
```
|
||||
|
||||
write_u8 appends a single `data` byte to the accumulated buffer
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## write_byte
|
||||
```v
|
||||
fn (mut b Builder) write_byte(data u8)
|
||||
```
|
||||
|
||||
write_byte appends a single `data` byte to the accumulated buffer
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## write_decimal
|
||||
```v
|
||||
fn (mut b Builder) write_decimal(n i64)
|
||||
```
|
||||
|
||||
write_decimal appends a decimal representation of the number `n` into the builder `b`, without dynamic allocation. The higher order digits come first, i.e. 6123 will be written with the digit `6` first, then `1`, then `2` and `3` last.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## write
|
||||
```v
|
||||
fn (mut b Builder) write(data []u8) !int
|
||||
```
|
||||
|
||||
write implements the io.Writer interface, that is why it returns how many bytes were written to the string builder.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## drain_builder
|
||||
```v
|
||||
fn (mut b Builder) drain_builder(mut other Builder, other_new_cap int)
|
||||
```
|
||||
|
||||
drain_builder writes all of the `other` builder content, then re-initialises `other`, so that the `other` strings builder is ready to receive new content.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## byte_at
|
||||
```v
|
||||
fn (b &Builder) byte_at(n int) u8
|
||||
```
|
||||
|
||||
byte_at returns a byte, located at a given index `i`.
|
||||
|
||||
Note: it can panic, if there are not enough bytes in the strings builder yet.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## write_string
|
||||
```v
|
||||
fn (mut b Builder) write_string(s string)
|
||||
```
|
||||
|
||||
write appends the string `s` to the buffer
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## write_string2
|
||||
```v
|
||||
fn (mut b Builder) write_string2(s1 string, s2 string)
|
||||
```
|
||||
|
||||
write_string2 appends the strings `s1` and `s2` to the buffer.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## go_back
|
||||
```v
|
||||
fn (mut b Builder) go_back(n int)
|
||||
```
|
||||
|
||||
go_back discards the last `n` bytes from the buffer.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## spart
|
||||
```v
|
||||
fn (b &Builder) spart(start_pos int, n int) string
|
||||
```
|
||||
|
||||
spart returns a part of the buffer as a string
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## cut_last
|
||||
```v
|
||||
fn (mut b Builder) cut_last(n int) string
|
||||
```
|
||||
|
||||
cut_last cuts the last `n` bytes from the buffer and returns them.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## cut_to
|
||||
```v
|
||||
fn (mut b Builder) cut_to(pos int) string
|
||||
```
|
||||
|
||||
cut_to cuts the string after `pos` and returns it. if `pos` is superior to builder length, returns an empty string and cancel further operations
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## go_back_to
|
||||
```v
|
||||
fn (mut b Builder) go_back_to(pos int)
|
||||
```
|
||||
|
||||
go_back_to resets the buffer to the given position `pos`.
|
||||
|
||||
Note: pos should be < than the existing buffer length.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## writeln
|
||||
```v
|
||||
fn (mut b Builder) writeln(s string)
|
||||
```
|
||||
|
||||
writeln appends the string `s`, and then a newline character.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## writeln2
|
||||
```v
|
||||
fn (mut b Builder) writeln2(s1 string, s2 string)
|
||||
```
|
||||
|
||||
writeln2 appends two strings: `s1` + `\n`, and `s2` + `\n`, to the buffer.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## last_n
|
||||
```v
|
||||
fn (b &Builder) last_n(n int) string
|
||||
```
|
||||
|
||||
last_n(5) returns 'world' buf == 'hello world'
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## after
|
||||
```v
|
||||
fn (b &Builder) after(n int) string
|
||||
```
|
||||
|
||||
after(6) returns 'world' buf == 'hello world'
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## str
|
||||
```v
|
||||
fn (mut b Builder) str() string
|
||||
```
|
||||
|
||||
str returns a copy of all of the accumulated buffer content.
|
||||
|
||||
Note: after a call to b.str(), the builder b will be empty, and could be used again. The returned string *owns* its own separate copy of the accumulated data that was in the string builder, before the .str() call.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## ensure_cap
|
||||
```v
|
||||
fn (mut b Builder) ensure_cap(n int)
|
||||
```
|
||||
|
||||
ensure_cap ensures that the buffer has enough space for at least `n` bytes by growing the buffer if necessary.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## grow_len
|
||||
```v
|
||||
fn (mut b Builder) grow_len(n int)
|
||||
```
|
||||
|
||||
grow_len grows the length of the buffer by `n` bytes if necessary
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## free
|
||||
```v
|
||||
fn (mut b Builder) free()
|
||||
```
|
||||
|
||||
free frees the memory block, used for the buffer.
|
||||
|
||||
Note: do not use the builder, after a call to free().
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:20:02
|
||||
212
aiprompts/v_core/string/textscanner.md
Normal file
212
aiprompts/v_core/string/textscanner.md
Normal file
@@ -0,0 +1,212 @@
|
||||
# module textscanner
|
||||
|
||||
|
||||
## Contents
|
||||
- [new](#new)
|
||||
- [TextScanner](#TextScanner)
|
||||
- [free](#free)
|
||||
- [remaining](#remaining)
|
||||
- [next](#next)
|
||||
- [skip](#skip)
|
||||
- [skip_n](#skip_n)
|
||||
- [peek](#peek)
|
||||
- [peek_u8](#peek_u8)
|
||||
- [peek_n](#peek_n)
|
||||
- [peek_n_u8](#peek_n_u8)
|
||||
- [back](#back)
|
||||
- [back_n](#back_n)
|
||||
- [peek_back](#peek_back)
|
||||
- [peek_back_n](#peek_back_n)
|
||||
- [current](#current)
|
||||
- [reset](#reset)
|
||||
- [goto_end](#goto_end)
|
||||
- [skip_whitespace](#skip_whitespace)
|
||||
|
||||
## new
|
||||
```v
|
||||
fn new(input string) TextScanner
|
||||
```
|
||||
|
||||
new returns a stack allocated instance of TextScanner.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## TextScanner
|
||||
```v
|
||||
struct TextScanner {
|
||||
pub:
|
||||
input string
|
||||
ilen int
|
||||
pub mut:
|
||||
pos int // current position; pos is *always* kept in [0,ilen]
|
||||
}
|
||||
```
|
||||
|
||||
TextScanner simplifies writing small scanners/parsers. It helps by providing safe methods to scan texts character by character, peek for the next characters, go back, etc.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## free
|
||||
```v
|
||||
fn (mut ss TextScanner) free()
|
||||
```
|
||||
|
||||
free frees all allocated resources.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## remaining
|
||||
```v
|
||||
fn (ss &TextScanner) remaining() int
|
||||
```
|
||||
|
||||
remaining returns how many characters remain from current position.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## next
|
||||
```v
|
||||
fn (mut ss TextScanner) next() int
|
||||
```
|
||||
|
||||
next returns the next character code from the input text. next returns `-1` if it can't reach the next character. next advances the scanner position.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## skip
|
||||
```v
|
||||
fn (mut ss TextScanner) skip()
|
||||
```
|
||||
|
||||
skip skips one character ahead; `skip()` is slightly faster than `.next()`. `skip()` does not return a result.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## skip_n
|
||||
```v
|
||||
fn (mut ss TextScanner) skip_n(n int)
|
||||
```
|
||||
|
||||
skip_n skips ahead `n` characters, stopping at the end of the input.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## peek
|
||||
```v
|
||||
fn (ss &TextScanner) peek() int
|
||||
```
|
||||
|
||||
peek returns the *next* character code from the input text. peek returns `-1` if it can't peek the next character. unlike `next()`, `peek()` does not change the state of the scanner.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## peek_u8
|
||||
```v
|
||||
fn (ss &TextScanner) peek_u8() u8
|
||||
```
|
||||
|
||||
peek_u8 returns the *next* character code from the input text, as a byte/u8. unlike `next()`, `peek_u8()` does not change the state of the scanner.
|
||||
|
||||
Note: peek_u8 returns `0`, if it can't peek the next character.
|
||||
|
||||
Note: use `peek()`, instead of `peek_u8()`, if your input itself can legitimately contain bytes with value `0`.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## peek_n
|
||||
```v
|
||||
fn (ss &TextScanner) peek_n(n int) int
|
||||
```
|
||||
|
||||
peek_n returns the character code from the input text at position + `n`. peek_n returns `-1` if it can't peek `n` characters ahead. ts.peek_n(0) == ts.current() . ts.peek_n(1) == ts.peek() .
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## peek_n_u8
|
||||
```v
|
||||
fn (ss &TextScanner) peek_n_u8(n int) u8
|
||||
```
|
||||
|
||||
peek_n_u8 returns the character code from the input text, at position + `n`, as a byte/u8.
|
||||
|
||||
Note: peek_n_u8 returns `0`, if it can't peek the next character.
|
||||
|
||||
Note: use `peek_n()`, instead of `peek_n_u8()`, if your input itself can legitimately contain bytes with value `0`.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## back
|
||||
```v
|
||||
fn (mut ss TextScanner) back()
|
||||
```
|
||||
|
||||
back goes back one character from the current scanner position.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## back_n
|
||||
```v
|
||||
fn (mut ss TextScanner) back_n(n int)
|
||||
```
|
||||
|
||||
back_n goes back `n` characters from the current scanner position.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## peek_back
|
||||
```v
|
||||
fn (ss &TextScanner) peek_back() int
|
||||
```
|
||||
|
||||
peek_back returns the *previous* character code from the input text. peek_back returns `-1` if it can't peek the previous character. unlike `back()`, `peek_back()` does not change the state of the scanner.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## peek_back_n
|
||||
```v
|
||||
fn (ss &TextScanner) peek_back_n(n int) int
|
||||
```
|
||||
|
||||
peek_back_n returns the character code from the input text at position - `n`. peek_back_n returns `-1` if it can't peek `n` characters back. ts.peek_back_n(0) == ts.current() ts.peek_back_n(1) == ts.peek_back()
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## current
|
||||
```v
|
||||
fn (mut ss TextScanner) current() int
|
||||
```
|
||||
|
||||
current returns the current character code from the input text. current returns `-1` at the start of the input text.
|
||||
|
||||
Note: after `c := ts.next()`, `ts.current()` will also return `c`.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## reset
|
||||
```v
|
||||
fn (mut ss TextScanner) reset()
|
||||
```
|
||||
|
||||
reset resets the internal state of the scanner. After calling .reset(), .next() will start reading again from the start of the input text.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## goto_end
|
||||
```v
|
||||
fn (mut ss TextScanner) goto_end()
|
||||
```
|
||||
|
||||
goto_end has the same effect as `for ts.next() != -1 {}`. i.e. after calling .goto_end(), the scanner will be at the end of the input text. Further .next() calls will return -1, unless you go back.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## skip_whitespace
|
||||
```v
|
||||
fn (mut ss TextScanner) skip_whitespace()
|
||||
```
|
||||
|
||||
skip_whitespace advances the scanner pass any space characters in the input.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:20:02
|
||||
16
aiprompts/v_core/time/misc.md
Normal file
16
aiprompts/v_core/time/misc.md
Normal file
@@ -0,0 +1,16 @@
|
||||
# module misc
|
||||
|
||||
|
||||
## Contents
|
||||
- [random](#random)
|
||||
|
||||
## random
|
||||
```v
|
||||
fn random() time.Time
|
||||
```
|
||||
|
||||
random returns a random time struct in *the past*.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:20:30
|
||||
1428
aiprompts/v_core/time/time.md
Normal file
1428
aiprompts/v_core/time/time.md
Normal file
File diff suppressed because it is too large
Load Diff
368
aiprompts/v_core/toml/ast.md
Normal file
368
aiprompts/v_core/toml/ast.md
Normal file
@@ -0,0 +1,368 @@
|
||||
# module ast
|
||||
|
||||
|
||||
## Contents
|
||||
- [DateTimeType](#DateTimeType)
|
||||
- [str](#str)
|
||||
- [Key](#Key)
|
||||
- [str](#str)
|
||||
- [Value](#Value)
|
||||
- [str](#str)
|
||||
- [Bare](#Bare)
|
||||
- [str](#str)
|
||||
- [Bool](#Bool)
|
||||
- [str](#str)
|
||||
- [Comment](#Comment)
|
||||
- [str](#str)
|
||||
- [Date](#Date)
|
||||
- [str](#str)
|
||||
- [DateTime](#DateTime)
|
||||
- [str](#str)
|
||||
- [EOF](#EOF)
|
||||
- [str](#str)
|
||||
- [Null](#Null)
|
||||
- [str](#str)
|
||||
- [Number](#Number)
|
||||
- [str](#str)
|
||||
- [i64](#i64)
|
||||
- [f64](#f64)
|
||||
- [Quoted](#Quoted)
|
||||
- [str](#str)
|
||||
- [Root](#Root)
|
||||
- [str](#str)
|
||||
- [Time](#Time)
|
||||
- [str](#str)
|
||||
|
||||
## DateTimeType
|
||||
```v
|
||||
type DateTimeType = Date | DateTime | Time
|
||||
```
|
||||
|
||||
DateTimeType is a sumtype representing all possible date types found in a TOML document.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## str
|
||||
```v
|
||||
fn (dtt DateTimeType) str() string
|
||||
```
|
||||
|
||||
str returns the `string` representation of the `DateTimeType` type.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Key
|
||||
```v
|
||||
type Key = Bare | Bool | Null | Number | Quoted
|
||||
```
|
||||
|
||||
Key is a sumtype representing all types of keys that can be found in a TOML document.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## str
|
||||
```v
|
||||
fn (k Key) str() string
|
||||
```
|
||||
|
||||
str returns the string representation of the key. This is implemented by all the variants of Key.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Value
|
||||
```v
|
||||
type Value = Bool
|
||||
| Date
|
||||
| DateTime
|
||||
| Null
|
||||
| Number
|
||||
| Quoted
|
||||
| Time
|
||||
| []Value
|
||||
| map[string]Value
|
||||
```
|
||||
|
||||
Value is a sumtype representing all possible value types found in a TOML document.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## str
|
||||
```v
|
||||
fn (v Value) str() string
|
||||
```
|
||||
|
||||
str outputs the value in JSON-like format for eased debugging
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Bare
|
||||
```v
|
||||
struct Bare {
|
||||
pub:
|
||||
text string
|
||||
pos token.Pos
|
||||
}
|
||||
```
|
||||
|
||||
Bare is the data representation of a TOML bare type (`bare_key = ...`). Bare types can appear only as keys in TOML documents. Otherwise they take the form of Bool or Numbers.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## str
|
||||
```v
|
||||
fn (b Bare) str() string
|
||||
```
|
||||
|
||||
str returns the `string` representation of the `Bare` type.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Bool
|
||||
```v
|
||||
struct Bool {
|
||||
pub:
|
||||
text string
|
||||
pos token.Pos
|
||||
}
|
||||
```
|
||||
|
||||
Bool is the data representation of a TOML boolean type (`... = true`). Bool types can appear only as values in TOML documents. Keys named `true` or `false` are considered as Bare types.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## str
|
||||
```v
|
||||
fn (b Bool) str() string
|
||||
```
|
||||
|
||||
str returns the `string` representation of the `Bool` type.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Comment
|
||||
```v
|
||||
struct Comment {
|
||||
pub:
|
||||
text string
|
||||
pos token.Pos
|
||||
}
|
||||
```
|
||||
|
||||
Comment is the data representation of a TOML comment (`# This is a comment`).
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## str
|
||||
```v
|
||||
fn (c Comment) str() string
|
||||
```
|
||||
|
||||
str returns the `string` representation of the `Comment` type.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Date
|
||||
```v
|
||||
struct Date {
|
||||
pub:
|
||||
text string
|
||||
pos token.Pos
|
||||
}
|
||||
```
|
||||
|
||||
Date is the data representation of a TOML date type (`YYYY-MM-DD`). Date types can appear both as keys and values in TOML documents. Keys named like dates e.g. `1980-12-29` are considered Bare key types.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## str
|
||||
```v
|
||||
fn (d Date) str() string
|
||||
```
|
||||
|
||||
str returns the `string` representation of the `Date` type.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## DateTime
|
||||
```v
|
||||
struct DateTime {
|
||||
pub mut:
|
||||
text string
|
||||
pub:
|
||||
pos token.Pos
|
||||
date Date
|
||||
time Time
|
||||
}
|
||||
```
|
||||
|
||||
DateTime is the data representation of a TOML date-time type (`YYYY-MM-DDTHH:MM:SS.milli`). DateTime types can appear only as values in TOML documents.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## str
|
||||
```v
|
||||
fn (dt DateTime) str() string
|
||||
```
|
||||
|
||||
str returns the `string` representation of the `DateTime` type.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## EOF
|
||||
```v
|
||||
struct EOF {
|
||||
pub:
|
||||
pos token.Pos
|
||||
}
|
||||
```
|
||||
|
||||
EOF is the data representation of the end of the TOML document.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## str
|
||||
```v
|
||||
fn (e EOF) str() string
|
||||
```
|
||||
|
||||
str returns the `string` representation of the `EOF` type.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Null
|
||||
```v
|
||||
struct Null {
|
||||
pub:
|
||||
text string
|
||||
pos token.Pos
|
||||
}
|
||||
```
|
||||
|
||||
Null is used in sumtype checks as a "default" value when nothing else is possible.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## str
|
||||
```v
|
||||
fn (n Null) str() string
|
||||
```
|
||||
|
||||
str returns the `string` representation of the `Null` type
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Number
|
||||
```v
|
||||
struct Number {
|
||||
pub:
|
||||
pos token.Pos
|
||||
pub mut:
|
||||
text string
|
||||
}
|
||||
```
|
||||
|
||||
Number is the data representation of a TOML number type (`25 = 5e2`). Number types can appear both as keys and values in TOML documents. Number can be integers, floats, infinite, NaN - they can have exponents (`5e2`) and be sign prefixed (`+2`).
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## str
|
||||
```v
|
||||
fn (n Number) str() string
|
||||
```
|
||||
|
||||
str returns the `string` representation of the `Number` type.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## i64
|
||||
```v
|
||||
fn (n Number) i64() i64
|
||||
```
|
||||
|
||||
i64 returns the `n Number` as an `i64` value.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## f64
|
||||
```v
|
||||
fn (n Number) f64() f64
|
||||
```
|
||||
|
||||
f64 returns the `n Number` as an `f64` value.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Quoted
|
||||
```v
|
||||
struct Quoted {
|
||||
pub mut:
|
||||
text string
|
||||
pub:
|
||||
pos token.Pos
|
||||
is_multiline bool
|
||||
quote u8
|
||||
}
|
||||
```
|
||||
|
||||
Quoted is the data representation of a TOML quoted type (`"quoted-key" = "I'm a quoted value"`). Quoted types can appear both as keys and values in TOML documents.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## str
|
||||
```v
|
||||
fn (q Quoted) str() string
|
||||
```
|
||||
|
||||
str returns the `string` representation of the `Quoted` type.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Root
|
||||
```v
|
||||
struct Root {
|
||||
pub:
|
||||
input input.Config // User input configuration
|
||||
pub mut:
|
||||
comments []Comment
|
||||
table Value
|
||||
// errors []errors.Error // all the checker errors in the file
|
||||
}
|
||||
```
|
||||
|
||||
Root represents the root structure of any parsed TOML text snippet or file.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## str
|
||||
```v
|
||||
fn (r Root) str() string
|
||||
```
|
||||
|
||||
str returns the string representation of the root node.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Time
|
||||
```v
|
||||
struct Time {
|
||||
pub:
|
||||
text string
|
||||
offset int
|
||||
pos token.Pos
|
||||
}
|
||||
```
|
||||
|
||||
Time is the data representation of a TOML time type (`HH:MM:SS.milli`). Time types can appear only as values in TOML documents.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## str
|
||||
```v
|
||||
fn (t Time) str() string
|
||||
```
|
||||
|
||||
str returns the `string` representation of the `Time` type.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:20:35
|
||||
57
aiprompts/v_core/toml/checker.md
Normal file
57
aiprompts/v_core/toml/checker.md
Normal file
@@ -0,0 +1,57 @@
|
||||
# module checker
|
||||
|
||||
|
||||
## Contents
|
||||
- [Constants](#Constants)
|
||||
- [Checker](#Checker)
|
||||
- [check](#check)
|
||||
- [check_quoted](#check_quoted)
|
||||
- [check_comment](#check_comment)
|
||||
|
||||
## Constants
|
||||
```v
|
||||
const allowed_basic_escape_chars = [`u`, `U`, `b`, `t`, `n`, `f`, `r`, `"`, `\\`]
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Checker
|
||||
```v
|
||||
struct Checker {
|
||||
pub:
|
||||
scanner &scanner.Scanner = unsafe { nil }
|
||||
}
|
||||
```
|
||||
|
||||
Checker checks a tree of TOML `ast.Value`'s for common errors.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## check
|
||||
```v
|
||||
fn (c &Checker) check(n &ast.Value) !
|
||||
```
|
||||
|
||||
check checks the `ast.Value` and all it's children for common errors.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## check_quoted
|
||||
```v
|
||||
fn (c &Checker) check_quoted(q ast.Quoted) !
|
||||
```
|
||||
|
||||
check_quoted returns an error if `q` is not a valid quoted TOML string.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## check_comment
|
||||
```v
|
||||
fn (c &Checker) check_comment(comment ast.Comment) !
|
||||
```
|
||||
|
||||
check_comment returns an error if the contents of `comment` isn't a valid TOML comment.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:20:35
|
||||
39
aiprompts/v_core/toml/decoder.md
Normal file
39
aiprompts/v_core/toml/decoder.md
Normal file
@@ -0,0 +1,39 @@
|
||||
# module decoder
|
||||
|
||||
|
||||
## Contents
|
||||
- [decode_quoted_escapes](#decode_quoted_escapes)
|
||||
- [Decoder](#Decoder)
|
||||
- [decode](#decode)
|
||||
|
||||
## decode_quoted_escapes
|
||||
```v
|
||||
fn decode_quoted_escapes(mut q ast.Quoted) !
|
||||
```
|
||||
|
||||
decode_quoted_escapes returns an error for any disallowed escape sequences. Delimiters in TOML has significant meaning: '/''' delimits *literal* strings (WYSIWYG / What-you-see-is-what-you-get) "/""" delimits *basic* strings Allowed escapes in *basic* strings are: \b - backspace (U+0008) \t - tab (U+0009) \n - linefeed (U+000A) \f - form feed (U+000C) \r - carriage return (U+000D) \" - quote (U+0022) \\ - backslash (U+005C) \uXXXX - Unicode (U+XXXX) \UXXXXXXXX - Unicode (U+XXXXXXXX)
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Decoder
|
||||
```v
|
||||
struct Decoder {
|
||||
pub:
|
||||
scanner &scanner.Scanner = unsafe { nil }
|
||||
}
|
||||
```
|
||||
|
||||
Decoder decode special sequences in a tree of TOML `ast.Value`'s.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## decode
|
||||
```v
|
||||
fn (d Decoder) decode(mut n ast.Value) !
|
||||
```
|
||||
|
||||
decode decodes certain `ast.Value`'s and all it's children.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:20:35
|
||||
30
aiprompts/v_core/toml/input.md
Normal file
30
aiprompts/v_core/toml/input.md
Normal file
@@ -0,0 +1,30 @@
|
||||
# module input
|
||||
|
||||
|
||||
## Contents
|
||||
- [Config](#Config)
|
||||
- [read_input](#read_input)
|
||||
|
||||
## Config
|
||||
```v
|
||||
struct Config {
|
||||
pub:
|
||||
text string // TOML text
|
||||
file_path string // '/path/to/file.toml'
|
||||
}
|
||||
```
|
||||
|
||||
Config is used to configure input to the toml module. Only one of the fields `text` and `file_path` is allowed to be set at time of configuration.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## read_input
|
||||
```v
|
||||
fn (c Config) read_input() !string
|
||||
```
|
||||
|
||||
read_input returns either Config.text or the read file contents of Config.file_path depending on which one is not empty.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:20:35
|
||||
415
aiprompts/v_core/toml/parser.md
Normal file
415
aiprompts/v_core/toml/parser.md
Normal file
@@ -0,0 +1,415 @@
|
||||
# module parser
|
||||
|
||||
|
||||
## Contents
|
||||
- [Constants](#Constants)
|
||||
- [new_parser](#new_parser)
|
||||
- [DottedKey](#DottedKey)
|
||||
- [str](#str)
|
||||
- [Config](#Config)
|
||||
- [Parser](#Parser)
|
||||
- [init](#init)
|
||||
- [parse](#parse)
|
||||
- [find_table](#find_table)
|
||||
- [allocate_table](#allocate_table)
|
||||
- [sub_table_key](#sub_table_key)
|
||||
- [find_sub_table](#find_sub_table)
|
||||
- [find_in_table](#find_in_table)
|
||||
- [find_array_of_tables](#find_array_of_tables)
|
||||
- [allocate_in_table](#allocate_in_table)
|
||||
- [dotted_key](#dotted_key)
|
||||
- [root_table](#root_table)
|
||||
- [table_contents](#table_contents)
|
||||
- [inline_table](#inline_table)
|
||||
- [array_of_tables](#array_of_tables)
|
||||
- [array_of_tables_contents](#array_of_tables_contents)
|
||||
- [double_array_of_tables](#double_array_of_tables)
|
||||
- [double_array_of_tables_contents](#double_array_of_tables_contents)
|
||||
- [array](#array)
|
||||
- [comment](#comment)
|
||||
- [key](#key)
|
||||
- [key_value](#key_value)
|
||||
- [dotted_key_value](#dotted_key_value)
|
||||
- [value](#value)
|
||||
- [number_or_date](#number_or_date)
|
||||
- [bare](#bare)
|
||||
- [quoted](#quoted)
|
||||
- [boolean](#boolean)
|
||||
- [number](#number)
|
||||
- [date_time](#date_time)
|
||||
- [date](#date)
|
||||
- [time](#time)
|
||||
- [eof](#eof)
|
||||
|
||||
## Constants
|
||||
```v
|
||||
const all_formatting = [token.Kind.whitespace, .tab, .cr, .nl]
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const space_formatting = [token.Kind.whitespace, .tab]
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const keys_and_space_formatting = [token.Kind.whitespace, .tab, .minus, .bare, .quoted, .boolean,
|
||||
.number, .underscore]
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new_parser
|
||||
```v
|
||||
fn new_parser(config Config) Parser
|
||||
```
|
||||
|
||||
new_parser returns a new, stack allocated, `Parser`.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## DottedKey
|
||||
## str
|
||||
```v
|
||||
fn (dk DottedKey) str() string
|
||||
```
|
||||
|
||||
str returns the dotted key as a string.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Config
|
||||
```v
|
||||
struct Config {
|
||||
pub:
|
||||
scanner &scanner.Scanner = unsafe { nil }
|
||||
run_checks bool = true
|
||||
decode_values bool = true
|
||||
}
|
||||
```
|
||||
|
||||
Config is used to configure a Parser instance. `run_checks` is used to en- or disable running of the strict `checker.Checker` type checks. `decode_values` is used to en- or disable decoding of values with the `decoder.Decoder`.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Parser
|
||||
```v
|
||||
struct Parser {
|
||||
pub:
|
||||
config Config
|
||||
mut:
|
||||
scanner &scanner.Scanner = unsafe { nil }
|
||||
prev_tok token.Token
|
||||
tok token.Token
|
||||
peek_tok token.Token
|
||||
tokens []token.Token // To be able to peek more than one token ahead.
|
||||
skip_next bool
|
||||
// The root map (map is called table in TOML world)
|
||||
root_map map[string]ast.Value
|
||||
root_map_key DottedKey
|
||||
explicit_declared []DottedKey
|
||||
explicit_declared_array_of_tables []DottedKey
|
||||
implicit_declared []DottedKey
|
||||
// Array of Tables state
|
||||
last_aot DottedKey
|
||||
last_aot_index int
|
||||
// Root of the tree
|
||||
ast_root &ast.Root = &ast.Root{}
|
||||
}
|
||||
```
|
||||
|
||||
Parser contains the necessary fields for keeping the state of the parsing process.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## init
|
||||
```v
|
||||
fn (mut p Parser) init() !
|
||||
```
|
||||
|
||||
init initializes the parser.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## parse
|
||||
```v
|
||||
fn (mut p Parser) parse() !&ast.Root
|
||||
```
|
||||
|
||||
parse starts parsing the input and returns the root of the generated AST.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## find_table
|
||||
```v
|
||||
fn (mut p Parser) find_table() !&map[string]ast.Value
|
||||
```
|
||||
|
||||
find_table returns a reference to a map if found in the *root* table given a "dotted" key (`a.b.c`). If some segments of the key does not exist in the root table find_table will allocate a new map for each segment. This behavior is needed because you can reference maps by multiple keys "dotted" (separated by "." periods) in TOML documents. See also `find_in_table`.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## allocate_table
|
||||
```v
|
||||
fn (mut p Parser) allocate_table(key DottedKey) !
|
||||
```
|
||||
|
||||
allocate_table allocates all tables in "dotted" `key` (`a.b.c`) in the *root* table.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## sub_table_key
|
||||
```v
|
||||
fn (mut p Parser) sub_table_key(key DottedKey) (DottedKey, DottedKey)
|
||||
```
|
||||
|
||||
sub_table_key returns the logic parts of a dotted key (`a.b.c`) for use with the `find_sub_table` method.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## find_sub_table
|
||||
```v
|
||||
fn (mut p Parser) find_sub_table(key DottedKey) !&map[string]ast.Value
|
||||
```
|
||||
|
||||
find_sub_table returns a reference to a map if found in the *root* table given a "dotted" key (`a.b.c`). If some segments of the key does not exist in the input map find_sub_table will allocate a new map for the segment. This behavior is needed because you can reference maps by multiple keys "dotted" (separated by "." periods) in TOML documents. See also `find_in_table`.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## find_in_table
|
||||
```v
|
||||
fn (mut p Parser) find_in_table(mut table map[string]ast.Value, key DottedKey) !&map[string]ast.Value
|
||||
```
|
||||
|
||||
find_in_table returns a reference to a map if found in `table` given a "dotted" key (`a.b.c`). If some segments of the key does not exist in the input map find_in_table will allocate a new map for the segment. This behavior is needed because you can reference maps by multiple keys "dotted" (separated by "." periods) in TOML documents.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## find_array_of_tables
|
||||
```v
|
||||
fn (mut p Parser) find_array_of_tables() ![]ast.Value
|
||||
```
|
||||
|
||||
find_array_of_tables returns an array if found in the root table based on the parser's last encountered "Array Of Tables" key. If the state key does not exist find_array_in_table will return an error.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## allocate_in_table
|
||||
```v
|
||||
fn (mut p Parser) allocate_in_table(mut table map[string]ast.Value, key DottedKey) !
|
||||
```
|
||||
|
||||
allocate_in_table allocates all tables in "dotted" `key` (`a.b.c`) in `table`.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## dotted_key
|
||||
```v
|
||||
fn (mut p Parser) dotted_key() !DottedKey
|
||||
```
|
||||
|
||||
dotted_key returns a string of the next tokens parsed as sub/nested/path keys (e.g. `a.b.c`). In TOML, this form of key is referred to as a "dotted" key.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## root_table
|
||||
```v
|
||||
fn (mut p Parser) root_table() !
|
||||
```
|
||||
|
||||
root_table parses next tokens into the root map of `ast.Value`s. The V `map` type is corresponding to a "table" in TOML.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## table_contents
|
||||
```v
|
||||
fn (mut p Parser) table_contents(mut tbl map[string]ast.Value) !
|
||||
```
|
||||
|
||||
table_contents parses next tokens into a map of `ast.Value`s. The V `map` type is corresponding to a "table" in TOML.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## inline_table
|
||||
```v
|
||||
fn (mut p Parser) inline_table(mut tbl map[string]ast.Value) !
|
||||
```
|
||||
|
||||
inline_table parses next tokens into a map of `ast.Value`s. The V map type is corresponding to a "table" in TOML.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## array_of_tables
|
||||
```v
|
||||
fn (mut p Parser) array_of_tables(mut table map[string]ast.Value) !
|
||||
```
|
||||
|
||||
array_of_tables parses next tokens into an array of `ast.Value`s.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## array_of_tables_contents
|
||||
```v
|
||||
fn (mut p Parser) array_of_tables_contents() ![]ast.Value
|
||||
```
|
||||
|
||||
array_of_tables_contents parses next tokens into an array of `ast.Value`s.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## double_array_of_tables
|
||||
```v
|
||||
fn (mut p Parser) double_array_of_tables(mut table map[string]ast.Value) !
|
||||
```
|
||||
|
||||
double_array_of_tables parses next tokens into an array of tables of arrays of `ast.Value`s...
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## double_array_of_tables_contents
|
||||
```v
|
||||
fn (mut p Parser) double_array_of_tables_contents(target_key DottedKey) ![]ast.Value
|
||||
```
|
||||
|
||||
double_array_of_tables_contents parses next tokens into an array of `ast.Value`s.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## array
|
||||
```v
|
||||
fn (mut p Parser) array() ![]ast.Value
|
||||
```
|
||||
|
||||
array parses next tokens into an array of `ast.Value`s.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## comment
|
||||
```v
|
||||
fn (mut p Parser) comment() ast.Comment
|
||||
```
|
||||
|
||||
comment returns an `ast.Comment` type.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## key
|
||||
```v
|
||||
fn (mut p Parser) key() !ast.Key
|
||||
```
|
||||
|
||||
key parse and returns an `ast.Key` type. Keys are the token(s) appearing before an assignment operator (=).
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## key_value
|
||||
```v
|
||||
fn (mut p Parser) key_value() !(ast.Key, ast.Value)
|
||||
```
|
||||
|
||||
key_value parse and returns a pair `ast.Key` and `ast.Value` type. see also `key()` and `value()`
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## dotted_key_value
|
||||
```v
|
||||
fn (mut p Parser) dotted_key_value() !(DottedKey, ast.Value)
|
||||
```
|
||||
|
||||
dotted_key_value parse and returns a pair `DottedKey` and `ast.Value` type. see also `key()` and `value()`
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## value
|
||||
```v
|
||||
fn (mut p Parser) value() !ast.Value
|
||||
```
|
||||
|
||||
value parse and returns an `ast.Value` type. values are the token(s) appearing after an assignment operator (=).
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## number_or_date
|
||||
```v
|
||||
fn (mut p Parser) number_or_date() !ast.Value
|
||||
```
|
||||
|
||||
number_or_date parse and returns an `ast.Value` type as one of [`ast.Date`, `ast.Time`, `ast.DateTime`, `ast.Number`]
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## bare
|
||||
```v
|
||||
fn (mut p Parser) bare() !ast.Bare
|
||||
```
|
||||
|
||||
bare parse and returns an `ast.Bare` type.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## quoted
|
||||
```v
|
||||
fn (mut p Parser) quoted() ast.Quoted
|
||||
```
|
||||
|
||||
quoted parse and returns an `ast.Quoted` type.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## boolean
|
||||
```v
|
||||
fn (mut p Parser) boolean() !ast.Bool
|
||||
```
|
||||
|
||||
boolean parse and returns an `ast.Bool` type.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## number
|
||||
```v
|
||||
fn (mut p Parser) number() ast.Number
|
||||
```
|
||||
|
||||
number parse and returns an `ast.Number` type.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## date_time
|
||||
```v
|
||||
fn (mut p Parser) date_time() !ast.DateTimeType
|
||||
```
|
||||
|
||||
date_time parses dates and time in RFC 3339 format. https://datatracker.ietf.org/doc/html/rfc3339
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## date
|
||||
```v
|
||||
fn (mut p Parser) date() !ast.Date
|
||||
```
|
||||
|
||||
date parse and returns an `ast.Date` type.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## time
|
||||
```v
|
||||
fn (mut p Parser) time() !ast.Time
|
||||
```
|
||||
|
||||
time parse and returns an `ast.Time` type.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## eof
|
||||
```v
|
||||
fn (mut p Parser) eof() ast.EOF
|
||||
```
|
||||
|
||||
eof returns an `ast.EOF` type.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:20:35
|
||||
220
aiprompts/v_core/toml/scanner.md
Normal file
220
aiprompts/v_core/toml/scanner.md
Normal file
@@ -0,0 +1,220 @@
|
||||
# module scanner
|
||||
|
||||
|
||||
## Contents
|
||||
- [Constants](#Constants)
|
||||
- [new_scanner](#new_scanner)
|
||||
- [new_simple](#new_simple)
|
||||
- [new_simple_file](#new_simple_file)
|
||||
- [new_simple_text](#new_simple_text)
|
||||
- [Config](#Config)
|
||||
- [Scanner](#Scanner)
|
||||
- [scan](#scan)
|
||||
- [free](#free)
|
||||
- [remaining](#remaining)
|
||||
- [next](#next)
|
||||
- [skip](#skip)
|
||||
- [skip_n](#skip_n)
|
||||
- [at](#at)
|
||||
- [peek](#peek)
|
||||
- [reset](#reset)
|
||||
- [excerpt](#excerpt)
|
||||
- [state](#state)
|
||||
- [State](#State)
|
||||
|
||||
## Constants
|
||||
```v
|
||||
const digit_extras = [`_`, `.`, `x`, `o`, `b`, `e`, `E`]
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const end_of_text = u32(~0)
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new_scanner
|
||||
```v
|
||||
fn new_scanner(config Config) !&Scanner
|
||||
```
|
||||
|
||||
new_scanner returns a new *heap* allocated `Scanner` instance, based on the file in config.input.file_path, or based on the text in config.input.text .
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new_simple
|
||||
```v
|
||||
fn new_simple(config Config) !Scanner
|
||||
```
|
||||
|
||||
new_simple returns a new *stack* allocated `Scanner` instance.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new_simple_file
|
||||
```v
|
||||
fn new_simple_file(path string) !Scanner
|
||||
```
|
||||
|
||||
new_simple_file returns a new *stack* allocated `Scanner` instance ready for parsing TOML in file read from `path`.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new_simple_text
|
||||
```v
|
||||
fn new_simple_text(text string) !Scanner
|
||||
```
|
||||
|
||||
new_simple_text returns a new *stack* allocated `Scanner` instance ready for parsing TOML in `text`.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Config
|
||||
```v
|
||||
struct Config {
|
||||
pub:
|
||||
input input.Config
|
||||
tokenize_formatting bool = true // if true, generate tokens for `\n`, ` `, `\t`, `\r` etc.
|
||||
}
|
||||
```
|
||||
|
||||
Config is used to configure a Scanner instance. Only one of the fields `text` and `file_path` is allowed to be set at time of configuration.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Scanner
|
||||
```v
|
||||
struct Scanner {
|
||||
pub:
|
||||
config Config
|
||||
text string // the input TOML text
|
||||
mut:
|
||||
col int // current column number (x coordinate)
|
||||
line_nr int = 1 // current line number (y coordinate)
|
||||
pos int // current flat/index position in the `text` field
|
||||
header_len int // Length, how many bytes of header was found
|
||||
// Quirks
|
||||
is_left_of_assign bool = true // indicates if the scanner is on the *left* side of an assignment
|
||||
}
|
||||
```
|
||||
|
||||
Scanner contains the necessary fields for the state of the scan process. the task the scanner does is also referred to as "lexing" or "tokenizing". The Scanner methods are based on much of the work in `vlib/strings/textscanner`.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## scan
|
||||
```v
|
||||
fn (mut s Scanner) scan() !token.Token
|
||||
```
|
||||
|
||||
scan returns the next token from the input.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## free
|
||||
```v
|
||||
fn (mut s Scanner) free()
|
||||
```
|
||||
|
||||
free frees all allocated resources.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## remaining
|
||||
```v
|
||||
fn (s &Scanner) remaining() int
|
||||
```
|
||||
|
||||
remaining returns how many characters remain in the text input.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## next
|
||||
```v
|
||||
fn (mut s Scanner) next() u32
|
||||
```
|
||||
|
||||
next returns the next character code from the input text. next returns `end_of_text` if it can't reach the next character.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## skip
|
||||
```v
|
||||
fn (mut s Scanner) skip()
|
||||
```
|
||||
|
||||
skip skips one character ahead.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## skip_n
|
||||
```v
|
||||
fn (mut s Scanner) skip_n(n int)
|
||||
```
|
||||
|
||||
skip_n skips ahead `n` characters. If the skip goes out of bounds from the length of `Scanner.text`, the scanner position will be sat to the last character possible.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## at
|
||||
```v
|
||||
fn (s &Scanner) at() u32
|
||||
```
|
||||
|
||||
at returns the *current* character code from the input text. at returns `end_of_text` if it can't get the current character. unlike `next()`, `at()` does not change the state of the scanner.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## peek
|
||||
```v
|
||||
fn (s &Scanner) peek(n int) u32
|
||||
```
|
||||
|
||||
peek returns the character code from the input text at position + `n`. peek returns `end_of_text` if it can't peek `n` characters ahead.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## reset
|
||||
```v
|
||||
fn (mut s Scanner) reset()
|
||||
```
|
||||
|
||||
reset resets the internal state of the scanner.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## excerpt
|
||||
```v
|
||||
fn (s &Scanner) excerpt(pos int, margin int) string
|
||||
```
|
||||
|
||||
excerpt returns a string excerpt of the input text centered at `pos`. The `margin` argument defines how many chacters on each side of `pos` is returned
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## state
|
||||
```v
|
||||
fn (s &Scanner) state() State
|
||||
```
|
||||
|
||||
state returns a read-only view of the scanner's internal state.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## State
|
||||
```v
|
||||
struct State {
|
||||
pub:
|
||||
col int // current column number (x coordinate)
|
||||
line_nr int = 1 // current line number (y coordinate)
|
||||
pos int // current flat/index position in the `text` field
|
||||
}
|
||||
```
|
||||
|
||||
State is a read-only copy of the scanner's internal state. See also `Scanner.state()`.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:20:35
|
||||
26
aiprompts/v_core/toml/to.md
Normal file
26
aiprompts/v_core/toml/to.md
Normal file
@@ -0,0 +1,26 @@
|
||||
# module to
|
||||
|
||||
|
||||
## Contents
|
||||
- [json](#json)
|
||||
- [json_any](#json_any)
|
||||
|
||||
## json
|
||||
```v
|
||||
fn json(doa DocOrAny) string
|
||||
```
|
||||
|
||||
json returns `doa` as a JSON encoded string.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## json_any
|
||||
```v
|
||||
fn json_any(a toml.Any) json2.Any
|
||||
```
|
||||
|
||||
json_any returns `Any` as a `x.json2.Any` type.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:20:35
|
||||
84
aiprompts/v_core/toml/token.md
Normal file
84
aiprompts/v_core/toml/token.md
Normal file
@@ -0,0 +1,84 @@
|
||||
# module token
|
||||
|
||||
|
||||
## Contents
|
||||
- [Kind](#Kind)
|
||||
- [Pos](#Pos)
|
||||
- [Token](#Token)
|
||||
- [pos](#pos)
|
||||
|
||||
## Kind
|
||||
```v
|
||||
enum Kind {
|
||||
unknown
|
||||
eof
|
||||
bare // user
|
||||
boolean // true or false
|
||||
number // 123
|
||||
quoted // 'foo', "foo", """foo""" or '''foo'''
|
||||
plus // +
|
||||
minus // -
|
||||
underscore // _
|
||||
comma // ,
|
||||
colon // :
|
||||
hash // # comment
|
||||
assign // =
|
||||
lcbr // {
|
||||
rcbr // }
|
||||
lsbr // [
|
||||
rsbr // ]
|
||||
nl // \n linefeed / newline character
|
||||
cr // \r carriage return
|
||||
tab // \t character
|
||||
whitespace // ` `
|
||||
period // .
|
||||
_end_
|
||||
}
|
||||
```
|
||||
|
||||
Kind represents a logical type of entity found in any given TOML document.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Pos
|
||||
```v
|
||||
struct Pos {
|
||||
pub:
|
||||
len int // length of the literal in the source
|
||||
line_nr int // the line number in the source where the token occurred
|
||||
pos int // the position of the token in scanner text
|
||||
col int // the column in the source where the token occurred
|
||||
}
|
||||
```
|
||||
|
||||
Position represents a position in a TOML document.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Token
|
||||
```v
|
||||
struct Token {
|
||||
pub:
|
||||
kind Kind // the token number/enum; for quick comparisons
|
||||
lit string // literal representation of the token
|
||||
col int // the column in the source where the token occurred
|
||||
line_nr int // the line number in the source where the token occurred
|
||||
pos int // the position of the token in scanner text
|
||||
len int // length of the literal
|
||||
}
|
||||
```
|
||||
|
||||
Token holds information about the current scan of bytes.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## pos
|
||||
```v
|
||||
fn (tok &Token) pos() Pos
|
||||
```
|
||||
|
||||
pos returns the exact position of a token in the input.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:20:35
|
||||
80
aiprompts/v_core/toml/toml.ast.walker.md
Normal file
80
aiprompts/v_core/toml/toml.ast.walker.md
Normal file
@@ -0,0 +1,80 @@
|
||||
# module toml.ast.walker
|
||||
|
||||
|
||||
## Contents
|
||||
- [inspect](#inspect)
|
||||
- [walk](#walk)
|
||||
- [walk_and_modify](#walk_and_modify)
|
||||
- [Modifier](#Modifier)
|
||||
- [Visitor](#Visitor)
|
||||
- [Inspector](#Inspector)
|
||||
- [visit](#visit)
|
||||
- [InspectorFn](#InspectorFn)
|
||||
|
||||
## inspect
|
||||
```v
|
||||
fn inspect(value &ast.Value, data voidptr, inspector_callback InspectorFn) !
|
||||
```
|
||||
|
||||
inspect traverses and checks the AST Value node on a depth-first order and based on the data given
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## walk
|
||||
```v
|
||||
fn walk(visitor Visitor, value &ast.Value) !
|
||||
```
|
||||
|
||||
walk traverses the AST using the given visitor
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## walk_and_modify
|
||||
```v
|
||||
fn walk_and_modify(modifier Modifier, mut value ast.Value) !
|
||||
```
|
||||
|
||||
walk_and_modify traverses the AST using the given modifier and lets the visitor modify the contents.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Modifier
|
||||
```v
|
||||
interface Modifier {
|
||||
modify(mut value ast.Value) !
|
||||
}
|
||||
```
|
||||
|
||||
Modifier defines a modify method which is invoked by the walker on each Value node it encounters.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Visitor
|
||||
```v
|
||||
interface Visitor {
|
||||
visit(value &ast.Value) !
|
||||
}
|
||||
```
|
||||
|
||||
Visitor defines a visit method which is invoked by the walker on each Value node it encounters.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Inspector
|
||||
## visit
|
||||
```v
|
||||
fn (i &Inspector) visit(value &ast.Value) !
|
||||
```
|
||||
|
||||
visit calls the inspector callback on the specified Value node.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## InspectorFn
|
||||
```v
|
||||
type InspectorFn = fn (value &ast.Value, data voidptr) !
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:20:35
|
||||
498
aiprompts/v_core/toml/toml.md
Normal file
498
aiprompts/v_core/toml/toml.md
Normal file
@@ -0,0 +1,498 @@
|
||||
# module toml
|
||||
|
||||
|
||||
## Contents
|
||||
- [Constants](#Constants)
|
||||
- [ast_to_any](#ast_to_any)
|
||||
- [decode](#decode)
|
||||
- [encode](#encode)
|
||||
- [parse_dotted_key](#parse_dotted_key)
|
||||
- [parse_file](#parse_file)
|
||||
- [parse_text](#parse_text)
|
||||
- [Any](#Any)
|
||||
- [string](#string)
|
||||
- [to_toml](#to_toml)
|
||||
- [int](#int)
|
||||
- [i64](#i64)
|
||||
- [u64](#u64)
|
||||
- [f32](#f32)
|
||||
- [f64](#f64)
|
||||
- [array](#array)
|
||||
- [as_map](#as_map)
|
||||
- [bool](#bool)
|
||||
- [date](#date)
|
||||
- [time](#time)
|
||||
- [datetime](#datetime)
|
||||
- [default_to](#default_to)
|
||||
- [value](#value)
|
||||
- [value_opt](#value_opt)
|
||||
- [reflect](#reflect)
|
||||
- [[]Any](#[]Any)
|
||||
- [value](#value)
|
||||
- [as_strings](#as_strings)
|
||||
- [to_toml](#to_toml)
|
||||
- [map[string]Any](#map[string]Any)
|
||||
- [value](#value)
|
||||
- [as_strings](#as_strings)
|
||||
- [to_toml](#to_toml)
|
||||
- [to_inline_toml](#to_inline_toml)
|
||||
- [Config](#Config)
|
||||
- [Date](#Date)
|
||||
- [str](#str)
|
||||
- [DateTime](#DateTime)
|
||||
- [str](#str)
|
||||
- [Doc](#Doc)
|
||||
- [decode](#decode)
|
||||
- [to_any](#to_any)
|
||||
- [reflect](#reflect)
|
||||
- [value](#value)
|
||||
- [value_opt](#value_opt)
|
||||
- [Null](#Null)
|
||||
- [Time](#Time)
|
||||
- [str](#str)
|
||||
|
||||
## Constants
|
||||
```v
|
||||
const null = Any(Null{})
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## ast_to_any
|
||||
```v
|
||||
fn ast_to_any(value ast.Value) Any
|
||||
```
|
||||
|
||||
ast_to_any converts `from` ast.Value to toml.Any value.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## decode
|
||||
```v
|
||||
fn decode[T](toml_txt string) !T
|
||||
```
|
||||
|
||||
decode decodes a TOML `string` into the target type `T`. If `T` has a custom `.from_toml()` method, it will be used instead of the default.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## encode
|
||||
```v
|
||||
fn encode[T](typ T) string
|
||||
```
|
||||
|
||||
encode encodes the type `T` into a TOML string. If `T` has a custom `.to_toml()` method, it will be used instead of the default.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## parse_dotted_key
|
||||
```v
|
||||
fn parse_dotted_key(key string) ![]string
|
||||
```
|
||||
|
||||
parse_dotted_key converts `key` string to an array of strings. parse_dotted_key preserves strings delimited by both `"` and `'`.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## parse_file
|
||||
```v
|
||||
fn parse_file(path string) !Doc
|
||||
```
|
||||
|
||||
parse_file parses the TOML file in `path`.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## parse_text
|
||||
```v
|
||||
fn parse_text(text string) !Doc
|
||||
```
|
||||
|
||||
parse_text parses the TOML document provided in `text`.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Any
|
||||
```v
|
||||
type Any = Date
|
||||
| DateTime
|
||||
| Null
|
||||
| Time
|
||||
| []Any
|
||||
| bool
|
||||
| f32
|
||||
| f64
|
||||
| i64
|
||||
| int
|
||||
| map[string]Any
|
||||
| string
|
||||
| u64
|
||||
```
|
||||
|
||||
Pretty much all the same builtin types as the `json2.Any` type plus `DateTime`,`Date`,`Time`
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## string
|
||||
```v
|
||||
fn (a Any) string() string
|
||||
```
|
||||
|
||||
string returns `Any` as a string.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## to_toml
|
||||
```v
|
||||
fn (a Any) to_toml() string
|
||||
```
|
||||
|
||||
to_toml returns `Any` as a TOML encoded value.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## int
|
||||
```v
|
||||
fn (a Any) int() int
|
||||
```
|
||||
|
||||
int returns `Any` as an 32-bit integer.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## i64
|
||||
```v
|
||||
fn (a Any) i64() i64
|
||||
```
|
||||
|
||||
i64 returns `Any` as a 64-bit integer.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## u64
|
||||
```v
|
||||
fn (a Any) u64() u64
|
||||
```
|
||||
|
||||
u64 returns `Any` as a 64-bit unsigned integer.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## f32
|
||||
```v
|
||||
fn (a Any) f32() f32
|
||||
```
|
||||
|
||||
f32 returns `Any` as a 32-bit float.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## f64
|
||||
```v
|
||||
fn (a Any) f64() f64
|
||||
```
|
||||
|
||||
f64 returns `Any` as a 64-bit float.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## array
|
||||
```v
|
||||
fn (a Any) array() []Any
|
||||
```
|
||||
|
||||
array returns `Any` as an array.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## as_map
|
||||
```v
|
||||
fn (a Any) as_map() map[string]Any
|
||||
```
|
||||
|
||||
as_map returns `Any` as a map (TOML table).
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## bool
|
||||
```v
|
||||
fn (a Any) bool() bool
|
||||
```
|
||||
|
||||
bool returns `Any` as a boolean.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## date
|
||||
```v
|
||||
fn (a Any) date() Date
|
||||
```
|
||||
|
||||
date returns `Any` as a `toml.Date` struct.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## time
|
||||
```v
|
||||
fn (a Any) time() Time
|
||||
```
|
||||
|
||||
time returns `Any` as a `toml.Time` struct.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## datetime
|
||||
```v
|
||||
fn (a Any) datetime() DateTime
|
||||
```
|
||||
|
||||
datetime returns `Any` as a `toml.DateTime` struct.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## default_to
|
||||
```v
|
||||
fn (a Any) default_to(value Any) Any
|
||||
```
|
||||
|
||||
default_to returns `value` if `a Any` is `Null`. This can be used to set default values when retrieving values. E.g.: `toml_doc.value('wrong.key').default_to(123).int()`
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## value
|
||||
```v
|
||||
fn (a Any) value(key string) Any
|
||||
```
|
||||
|
||||
value queries a value from the `Any` type. `key` supports a small query syntax scheme: Maps can be queried in "dotted" form e.g. `a.b.c`. quoted keys are supported as `a."b.c"` or `a.'b.c'`. Arrays can be queried with `a[0].b[1].[2]`.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## value_opt
|
||||
```v
|
||||
fn (a Any) value_opt(key string) !Any
|
||||
```
|
||||
|
||||
value_opt queries a value from the current element's tree. Returns an error if the key is not valid or there is no value for the key.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## reflect
|
||||
```v
|
||||
fn (a Any) reflect[T]() T
|
||||
```
|
||||
|
||||
reflect returns `T` with `T.<field>`'s value set to the value of any 1st level TOML key by the same name.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## []Any
|
||||
## value
|
||||
```v
|
||||
fn (a []Any) value(key string) Any
|
||||
```
|
||||
|
||||
value queries a value from the array. `key` supports a small query syntax scheme: The array can be queried with `[0].b[1].[2]`. Maps can be queried in "dotted" form e.g. `a.b.c`. quoted keys are supported as `a."b.c"` or `a.'b.c'`.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## as_strings
|
||||
```v
|
||||
fn (a []Any) as_strings() []string
|
||||
```
|
||||
|
||||
as_strings returns the contents of the array as `[]string`
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## to_toml
|
||||
```v
|
||||
fn (a []Any) to_toml() string
|
||||
```
|
||||
|
||||
to_toml returns the contents of the array as a TOML encoded `string`.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## map[string]Any
|
||||
## value
|
||||
```v
|
||||
fn (m map[string]Any) value(key string) Any
|
||||
```
|
||||
|
||||
value queries a value from the map. `key` supports a small query syntax scheme: Maps can be queried in "dotted" form e.g. `a.b.c`. quoted keys are supported as `a."b.c"` or `a.'b.c'`. Arrays can be queried with `a[0].b[1].[2]`.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## as_strings
|
||||
```v
|
||||
fn (m map[string]Any) as_strings() map[string]string
|
||||
```
|
||||
|
||||
as_strings returns the contents of the map as `map[string]string`
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## to_toml
|
||||
```v
|
||||
fn (m map[string]Any) to_toml() string
|
||||
```
|
||||
|
||||
to_toml returns the contents of the map as a TOML encoded `string`.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## to_inline_toml
|
||||
```v
|
||||
fn (m map[string]Any) to_inline_toml() string
|
||||
```
|
||||
|
||||
to_inline_toml returns the contents of the map as an inline table encoded TOML `string`.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Config
|
||||
```v
|
||||
struct Config {
|
||||
pub:
|
||||
text string // TOML text
|
||||
file_path string // '/path/to/file.toml'
|
||||
parse_comments bool
|
||||
}
|
||||
```
|
||||
|
||||
Config is used to configure the toml parser. Only one of the fields `text` or `file_path`, is allowed to be set at time of configuration.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Date
|
||||
```v
|
||||
struct Date {
|
||||
pub:
|
||||
date string
|
||||
}
|
||||
```
|
||||
|
||||
Date is the representation of an RFC 3339 date-only string.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## str
|
||||
```v
|
||||
fn (d Date) str() string
|
||||
```
|
||||
|
||||
str returns the RFC 3339 date-only string representation.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## DateTime
|
||||
```v
|
||||
struct DateTime {
|
||||
pub:
|
||||
datetime string
|
||||
}
|
||||
```
|
||||
|
||||
DateTime is the representation of an RFC 3339 datetime string.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## str
|
||||
```v
|
||||
fn (dt DateTime) str() string
|
||||
```
|
||||
|
||||
str returns the RFC 3339 string representation of the datetime.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Doc
|
||||
```v
|
||||
struct Doc {
|
||||
pub:
|
||||
ast &ast.Root = unsafe { nil }
|
||||
}
|
||||
```
|
||||
|
||||
Doc is a representation of a TOML document. A document can be constructed from a `string` buffer or from a file path
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## decode
|
||||
```v
|
||||
fn (d Doc) decode[T]() !T
|
||||
```
|
||||
|
||||
decode decodes a TOML `string` into the target struct type `T`.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## to_any
|
||||
```v
|
||||
fn (d Doc) to_any() Any
|
||||
```
|
||||
|
||||
to_any converts the `Doc` to toml.Any type.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## reflect
|
||||
```v
|
||||
fn (d Doc) reflect[T]() T
|
||||
```
|
||||
|
||||
reflect returns `T` with `T.<field>`'s value set to the value of any 1st level TOML key by the same name.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## value
|
||||
```v
|
||||
fn (d Doc) value(key string) Any
|
||||
```
|
||||
|
||||
value queries a value from the TOML document. `key` supports a small query syntax scheme: Maps can be queried in "dotted" form e.g. `a.b.c`. quoted keys are supported as `a."b.c"` or `a.'b.c'`. Arrays can be queried with `a[0].b[1].[2]`.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## value_opt
|
||||
```v
|
||||
fn (d Doc) value_opt(key string) !Any
|
||||
```
|
||||
|
||||
value_opt queries a value from the TOML document. Returns an error if the key is not valid or there is no value for the key.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Null
|
||||
```v
|
||||
struct Null {
|
||||
}
|
||||
```
|
||||
|
||||
Null is used in sumtype checks as a "default" value when nothing else is possible.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Time
|
||||
```v
|
||||
struct Time {
|
||||
pub:
|
||||
time string
|
||||
}
|
||||
```
|
||||
|
||||
Time is the representation of an RFC 3339 time-only string.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## str
|
||||
```v
|
||||
fn (t Time) str() string
|
||||
```
|
||||
|
||||
str returns the RFC 3339 time-only string representation.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:20:35
|
||||
46
aiprompts/v_core/toml/util.md
Normal file
46
aiprompts/v_core/toml/util.md
Normal file
@@ -0,0 +1,46 @@
|
||||
# module util
|
||||
|
||||
|
||||
## Contents
|
||||
- [is_ascii_control_character](#is_ascii_control_character)
|
||||
- [is_illegal_ascii_control_character](#is_illegal_ascii_control_character)
|
||||
- [is_key_char](#is_key_char)
|
||||
- [printdbg](#printdbg)
|
||||
|
||||
## is_ascii_control_character
|
||||
```v
|
||||
fn is_ascii_control_character(byte_char u8) bool
|
||||
```
|
||||
|
||||
is_ascii_control_character returns true if `byte_char` is an ASCII control character.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## is_illegal_ascii_control_character
|
||||
```v
|
||||
fn is_illegal_ascii_control_character(byte_char u8) bool
|
||||
```
|
||||
|
||||
is_illegal_ascii_control_character returns true if a `byte_char` ASCII control character is considered "illegal" in TOML .
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## is_key_char
|
||||
```v
|
||||
fn is_key_char(c u8) bool
|
||||
```
|
||||
|
||||
is_key_char returns true if the given u8 is a valid key character.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## printdbg
|
||||
```v
|
||||
fn printdbg(id string, message string)
|
||||
```
|
||||
|
||||
printdbg is a utility function for displaying a key:pair error message when `-d trace_toml` is passed to the compiler.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:20:35
|
||||
161
aiprompts/v_core/veb/assets.md
Normal file
161
aiprompts/v_core/veb/assets.md
Normal file
@@ -0,0 +1,161 @@
|
||||
# module assets
|
||||
|
||||
|
||||
## Contents
|
||||
- [minify_css](#minify_css)
|
||||
- [minify_js](#minify_js)
|
||||
- [AssetType](#AssetType)
|
||||
- [Asset](#Asset)
|
||||
- [AssetManager](#AssetManager)
|
||||
- [handle_assets](#handle_assets)
|
||||
- [handle_assets_at](#handle_assets_at)
|
||||
- [get_assets](#get_assets)
|
||||
- [add](#add)
|
||||
- [cleanup_cache](#cleanup_cache)
|
||||
- [exists](#exists)
|
||||
- [include](#include)
|
||||
- [combine](#combine)
|
||||
|
||||
## minify_css
|
||||
```v
|
||||
fn minify_css(css string) string
|
||||
```
|
||||
|
||||
|
||||
|
||||
Todo: implement proper minification
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## minify_js
|
||||
```v
|
||||
fn minify_js(js string) string
|
||||
```
|
||||
|
||||
|
||||
|
||||
Todo: implement proper minification
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## AssetType
|
||||
```v
|
||||
enum AssetType {
|
||||
css
|
||||
js
|
||||
all
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Asset
|
||||
```v
|
||||
struct Asset {
|
||||
pub:
|
||||
kind AssetType
|
||||
file_path string
|
||||
last_modified time.Time
|
||||
include_name string
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## AssetManager
|
||||
```v
|
||||
struct AssetManager {
|
||||
mut:
|
||||
css []Asset
|
||||
js []Asset
|
||||
cached_file_names []string
|
||||
pub mut:
|
||||
// when true assets will be minified
|
||||
minify bool
|
||||
// the directory to store the cached/combined files
|
||||
cache_dir string
|
||||
// how a combined file should be named. For example for css the extension '.css'
|
||||
// will be added to the end of `combined_file_name`
|
||||
combined_file_name string = 'combined'
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## handle_assets
|
||||
```v
|
||||
fn (mut am AssetManager) handle_assets(directory_path string) !
|
||||
```
|
||||
|
||||
handle_assets recursively walks `directory_path` and adds any assets to the asset manager
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## handle_assets_at
|
||||
```v
|
||||
fn (mut am AssetManager) handle_assets_at(directory_path string, prepend string) !
|
||||
```
|
||||
|
||||
handle_assets_at recursively walks `directory_path` and adds any assets to the asset manager. The include name of assets are prefixed with `prepend`
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## get_assets
|
||||
```v
|
||||
fn (am AssetManager) get_assets(asset_type AssetType) []Asset
|
||||
```
|
||||
|
||||
get all assets of type `asset_type`
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## add
|
||||
```v
|
||||
fn (mut am AssetManager) add(asset_type AssetType, file_path string, include_name string) !
|
||||
```
|
||||
|
||||
add an asset to the asset manager
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## cleanup_cache
|
||||
```v
|
||||
fn (mut am AssetManager) cleanup_cache() !
|
||||
```
|
||||
|
||||
cleanup_cache removes all files in the cache directory that aren't cached at the time this function is called
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## exists
|
||||
```v
|
||||
fn (am AssetManager) exists(asset_type AssetType, include_name string) bool
|
||||
```
|
||||
|
||||
check if an asset is already added to the asset manager
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## include
|
||||
```v
|
||||
fn (am AssetManager) include(asset_type AssetType, include_name string) veb.RawHtml
|
||||
```
|
||||
|
||||
include css/js files in your veb app from templates Usage example:
|
||||
```html
|
||||
@{app.am.include(.css, 'main.css')}
|
||||
```
|
||||
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## combine
|
||||
```v
|
||||
fn (mut am AssetManager) combine(asset_type AssetType) !string
|
||||
```
|
||||
|
||||
combine assets of type `asset_type` into a single file and return the outputted file path. If you call `combine` with asset type `all` the function will return an empty string, the minified files will be available at `combined_file_name`.`asset_type`
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:17:41
|
||||
114
aiprompts/v_core/veb/auth.md
Normal file
114
aiprompts/v_core/veb/auth.md
Normal file
@@ -0,0 +1,114 @@
|
||||
# module auth
|
||||
|
||||
|
||||
## Contents
|
||||
- [compare_password_with_hash](#compare_password_with_hash)
|
||||
- [generate_salt](#generate_salt)
|
||||
- [hash_password_with_salt](#hash_password_with_salt)
|
||||
- [new](#new)
|
||||
- [set_rand_crypto_safe_seed](#set_rand_crypto_safe_seed)
|
||||
- [Auth[T]](#Auth[T])
|
||||
- [add_token](#add_token)
|
||||
- [find_token](#find_token)
|
||||
- [delete_tokens](#delete_tokens)
|
||||
- [Auth](#Auth)
|
||||
- [Request](#Request)
|
||||
- [Token](#Token)
|
||||
|
||||
## compare_password_with_hash
|
||||
```v
|
||||
fn compare_password_with_hash(plain_text_password string, salt string, hashed string) bool
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## generate_salt
|
||||
```v
|
||||
fn generate_salt() string
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## hash_password_with_salt
|
||||
```v
|
||||
fn hash_password_with_salt(plain_text_password string, salt string) string
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## new
|
||||
```v
|
||||
fn new[T](db T) Auth[T]
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## set_rand_crypto_safe_seed
|
||||
```v
|
||||
fn set_rand_crypto_safe_seed()
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Auth[T]
|
||||
## add_token
|
||||
```v
|
||||
fn (mut app Auth[T]) add_token(user_id int) !string
|
||||
```
|
||||
|
||||
fn (mut app App) add_token(user_id int, ip string) !string {
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## find_token
|
||||
```v
|
||||
fn (app &Auth[T]) find_token(value string) ?Token
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## delete_tokens
|
||||
```v
|
||||
fn (mut app Auth[T]) delete_tokens(user_id int) !
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Auth
|
||||
```v
|
||||
struct Auth[T] {
|
||||
db T
|
||||
// pub:
|
||||
// salt string
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Request
|
||||
```v
|
||||
struct Request {
|
||||
pub:
|
||||
client_id string
|
||||
client_secret string
|
||||
code string
|
||||
state string
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Token
|
||||
```v
|
||||
struct Token {
|
||||
pub:
|
||||
id int @[primary; sql: serial]
|
||||
user_id int
|
||||
value string
|
||||
// ip string
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:17:41
|
||||
120
aiprompts/v_core/veb/csrf.md
Normal file
120
aiprompts/v_core/veb/csrf.md
Normal file
@@ -0,0 +1,120 @@
|
||||
# module csrf
|
||||
|
||||
|
||||
## Contents
|
||||
- [middleware](#middleware)
|
||||
- [protect](#protect)
|
||||
- [set_token](#set_token)
|
||||
- [CsrfConfig](#CsrfConfig)
|
||||
- [CsrfContext](#CsrfContext)
|
||||
- [set_csrf_token](#set_csrf_token)
|
||||
- [clear_csrf_token](#clear_csrf_token)
|
||||
- [csrf_token_input](#csrf_token_input)
|
||||
|
||||
## middleware
|
||||
```v
|
||||
fn middleware[T](config CsrfConfig) veb.MiddlewareOptions[T]
|
||||
```
|
||||
|
||||
middleware returns a handler that you can use with veb's middleware
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## protect
|
||||
```v
|
||||
fn protect(mut ctx veb.Context, config &CsrfConfig) bool
|
||||
```
|
||||
|
||||
protect returns false and sends an http 401 response when the csrf verification fails. protect will always return true if the current request method is in `config.safe_methods`.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## set_token
|
||||
```v
|
||||
fn set_token(mut ctx veb.Context, config &CsrfConfig) string
|
||||
```
|
||||
|
||||
set_token returns the csrftoken and sets an encrypted cookie with the hmac of `config.get_secret` and the csrftoken
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## CsrfConfig
|
||||
```v
|
||||
struct CsrfConfig {
|
||||
pub:
|
||||
secret string
|
||||
// how long the random part of the csrf-token should be
|
||||
nonce_length int = 64
|
||||
// HTTP "safe" methods meaning they shouldn't alter state.
|
||||
// If a request with any of these methods is made, `protect` will always return true
|
||||
// https://datatracker.ietf.org/doc/html/rfc7231#section-4.2.1
|
||||
safe_methods []http.Method = [.get, .head, .options]
|
||||
// which hosts are allowed, enforced by checking the Origin and Referer header
|
||||
// if allowed_hosts contains '*' the check will be skipped.
|
||||
// Subdomains need to be included separately: a request from `"sub.example.com"`
|
||||
// will be rejected when `allowed_host = ['example.com']`.
|
||||
allowed_hosts []string
|
||||
// if set to true both the Referer and Origin headers must match `allowed_hosts`
|
||||
// else if either one is valid the request is accepted
|
||||
check_origin_and_referer bool = true
|
||||
// the name of the csrf-token in the hidden html input
|
||||
token_name string = 'csrftoken'
|
||||
// the name of the cookie that contains the session id
|
||||
session_cookie string
|
||||
// cookie options
|
||||
cookie_name string = 'csrftoken'
|
||||
same_site http.SameSite = .same_site_strict_mode
|
||||
cookie_path string = '/'
|
||||
// how long the cookie stays valid in seconds. Default is 30 days
|
||||
max_age int = 60 * 60 * 24 * 30
|
||||
cookie_domain string
|
||||
// whether the cookie can be send only over HTTPS
|
||||
secure bool
|
||||
// enable printing verbose statements
|
||||
verbose bool
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## CsrfContext
|
||||
```v
|
||||
struct CsrfContext {
|
||||
pub mut:
|
||||
config CsrfConfig
|
||||
exempt bool
|
||||
// the csrftoken that should be placed in an html form
|
||||
csrf_token string
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## set_csrf_token
|
||||
```v
|
||||
fn (mut ctx CsrfContext) set_csrf_token[T](mut user_context T) string
|
||||
```
|
||||
|
||||
set_token generates a new csrf_token and adds a Cookie to the response
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## clear_csrf_token
|
||||
```v
|
||||
fn (ctx &CsrfContext) clear_csrf_token[T](mut user_context T)
|
||||
```
|
||||
|
||||
clear the csrf token and cookie header from the context
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## csrf_token_input
|
||||
```v
|
||||
fn (ctx &CsrfContext) csrf_token_input() veb.RawHtml
|
||||
```
|
||||
|
||||
csrf_token_input returns an HTML hidden input containing the csrf token
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:17:41
|
||||
54
aiprompts/v_core/veb/oauth.md
Normal file
54
aiprompts/v_core/veb/oauth.md
Normal file
@@ -0,0 +1,54 @@
|
||||
# module oauth
|
||||
|
||||
|
||||
## Contents
|
||||
- [TokenPostType](#TokenPostType)
|
||||
- [Context](#Context)
|
||||
- [get_token](#get_token)
|
||||
- [Request](#Request)
|
||||
|
||||
## TokenPostType
|
||||
```v
|
||||
enum TokenPostType {
|
||||
form
|
||||
json
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Context
|
||||
```v
|
||||
struct Context {
|
||||
pub:
|
||||
token_url string
|
||||
client_id string
|
||||
client_secret string
|
||||
token_post_type TokenPostType = .form
|
||||
redirect_uri string
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## get_token
|
||||
```v
|
||||
fn (ctx &Context) get_token(code string) string
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Request
|
||||
```v
|
||||
struct Request {
|
||||
pub:
|
||||
client_id string
|
||||
client_secret string
|
||||
code string
|
||||
state string
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:17:41
|
||||
59
aiprompts/v_core/veb/request_id.md
Normal file
59
aiprompts/v_core/veb/request_id.md
Normal file
@@ -0,0 +1,59 @@
|
||||
# module request_id
|
||||
|
||||
|
||||
## Contents
|
||||
- [middleware](#middleware)
|
||||
- [Config](#Config)
|
||||
- [RequestIdContext](#RequestIdContext)
|
||||
- [get_request_id](#get_request_id)
|
||||
|
||||
## middleware
|
||||
```v
|
||||
fn middleware[T](config Config) veb.MiddlewareOptions[T]
|
||||
```
|
||||
|
||||
middleware returns a handler that you can use with veb's middleware
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Config
|
||||
```v
|
||||
struct Config {
|
||||
pub:
|
||||
// Next defines a function to skip this middleware when returned true.
|
||||
next ?fn (ctx &veb.Context) bool
|
||||
// Generator defines a function to generate the unique identifier.
|
||||
generator fn () string = rand.uuid_v4
|
||||
// Header is the header key where to get/set the unique request ID.
|
||||
header string = 'X-Request-ID'
|
||||
// Allow empty sets whether to allow empty request IDs
|
||||
allow_empty bool
|
||||
// Force determines whether to always generate a new ID even if one exists
|
||||
force bool
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## RequestIdContext
|
||||
```v
|
||||
struct RequestIdContext {
|
||||
pub mut:
|
||||
request_id_config Config
|
||||
request_id_exempt bool
|
||||
request_id string
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## get_request_id
|
||||
```v
|
||||
fn (ctx &RequestIdContext) get_request_id() string
|
||||
```
|
||||
|
||||
get_request_id returns the current request ID
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:17:41
|
||||
65
aiprompts/v_core/veb/sse.md
Normal file
65
aiprompts/v_core/veb/sse.md
Normal file
@@ -0,0 +1,65 @@
|
||||
# module sse
|
||||
|
||||
|
||||
## Contents
|
||||
- [start_connection](#start_connection)
|
||||
- [SSEConnection](#SSEConnection)
|
||||
- [send_message](#send_message)
|
||||
- [close](#close)
|
||||
- [SSEMessage](#SSEMessage)
|
||||
|
||||
## start_connection
|
||||
```v
|
||||
fn start_connection(mut ctx veb.Context) &SSEConnection
|
||||
```
|
||||
|
||||
start an SSE connection
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## SSEConnection
|
||||
```v
|
||||
struct SSEConnection {
|
||||
pub mut:
|
||||
conn &net.TcpConn @[required]
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## send_message
|
||||
```v
|
||||
fn (mut sse SSEConnection) send_message(message SSEMessage) !
|
||||
```
|
||||
|
||||
send_message sends a single message to the http client that listens for SSE. It does not close the connection, so you can use it many times in a loop.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## close
|
||||
```v
|
||||
fn (mut sse SSEConnection) close()
|
||||
```
|
||||
|
||||
send a 'close' event and close the tcp connection.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## SSEMessage
|
||||
```v
|
||||
struct SSEMessage {
|
||||
pub mut:
|
||||
id string
|
||||
event string
|
||||
data string
|
||||
retry int
|
||||
}
|
||||
```
|
||||
|
||||
This module implements the server side of `Server Sent Events`. See https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#event_stream_format as well as https://html.spec.whatwg.org/multipage/server-sent-events.html#server-sent-events for detailed description of the protocol, and a simple web browser client example.
|
||||
|
||||
> Event stream format > The event stream is a simple stream of text data which must be encoded using UTF-8. > Messages in the event stream are separated by a pair of newline characters. > A colon as the first character of a line is in essence a comment, and is ignored. > Note: The comment line can be used to prevent connections from timing out; > a server can send a comment periodically to keep the connection alive. > > Each message consists of one or more lines of text listing the fields for that message. > Each field is represented by the field name, followed by a colon, followed by the text > data for that field's value.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:17:41
|
||||
967
aiprompts/v_core/veb/veb.md
Normal file
967
aiprompts/v_core/veb/veb.md
Normal file
@@ -0,0 +1,967 @@
|
||||
# module veb
|
||||
|
||||
|
||||
## Contents
|
||||
- [Constants](#Constants)
|
||||
- [controller](#controller)
|
||||
- [controller_host](#controller_host)
|
||||
- [cors](#cors)
|
||||
- [decode_gzip](#decode_gzip)
|
||||
- [encode_gzip](#encode_gzip)
|
||||
- [no_result](#no_result)
|
||||
- [raw](#raw)
|
||||
- [run](#run)
|
||||
- [run_at](#run_at)
|
||||
- [tr](#tr)
|
||||
- [tr_plural](#tr_plural)
|
||||
- [StaticApp](#StaticApp)
|
||||
- [FileResponse](#FileResponse)
|
||||
- [done](#done)
|
||||
- [MiddlewareHandler](#MiddlewareHandler)
|
||||
- [Middleware[T]](#Middleware[T])
|
||||
- [str](#str)
|
||||
- [use](#use)
|
||||
- [route_use](#route_use)
|
||||
- [RawHtml](#RawHtml)
|
||||
- [RequestParams](#RequestParams)
|
||||
- [request_done](#request_done)
|
||||
- [StringResponse](#StringResponse)
|
||||
- [done](#done)
|
||||
- [RedirectType](#RedirectType)
|
||||
- [Context](#Context)
|
||||
- [before_request](#before_request)
|
||||
- [error](#error)
|
||||
- [file](#file)
|
||||
- [get_cookie](#get_cookie)
|
||||
- [get_custom_header](#get_custom_header)
|
||||
- [get_header](#get_header)
|
||||
- [html](#html)
|
||||
- [ip](#ip)
|
||||
- [json](#json)
|
||||
- [json_pretty](#json_pretty)
|
||||
- [no_content](#no_content)
|
||||
- [not_found](#not_found)
|
||||
- [ok](#ok)
|
||||
- [redirect](#redirect)
|
||||
- [request_error](#request_error)
|
||||
- [send_response_to_client](#send_response_to_client)
|
||||
- [server_error](#server_error)
|
||||
- [server_error_with_status](#server_error_with_status)
|
||||
- [set_content_type](#set_content_type)
|
||||
- [set_cookie](#set_cookie)
|
||||
- [set_custom_header](#set_custom_header)
|
||||
- [set_header](#set_header)
|
||||
- [takeover_conn](#takeover_conn)
|
||||
- [text](#text)
|
||||
- [user_agent](#user_agent)
|
||||
- [Controller](#Controller)
|
||||
- [register_controller](#register_controller)
|
||||
- [register_host_controller](#register_host_controller)
|
||||
- [ControllerPath](#ControllerPath)
|
||||
- [CorsOptions](#CorsOptions)
|
||||
- [set_headers](#set_headers)
|
||||
- [validate_request](#validate_request)
|
||||
- [Middleware](#Middleware)
|
||||
- [MiddlewareOptions](#MiddlewareOptions)
|
||||
- [RedirectParams](#RedirectParams)
|
||||
- [Result](#Result)
|
||||
- [RunParams](#RunParams)
|
||||
- [StaticHandler](#StaticHandler)
|
||||
- [handle_static](#handle_static)
|
||||
- [host_handle_static](#host_handle_static)
|
||||
- [mount_static_folder_at](#mount_static_folder_at)
|
||||
- [host_mount_static_folder_at](#host_mount_static_folder_at)
|
||||
- [serve_static](#serve_static)
|
||||
- [host_serve_static](#host_serve_static)
|
||||
|
||||
## Constants
|
||||
```v
|
||||
const methods_with_form = [http.Method.post, .put, .patch]
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const http_404 = http.new_response(
|
||||
status: .not_found
|
||||
body: '404 Not Found'
|
||||
header: http.new_header(
|
||||
key: .content_type
|
||||
value: 'text/plain'
|
||||
).join(headers_close)
|
||||
)
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const max_http_post_size = $d('veb_max_http_post_size_bytes', 1048576)
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const http_408 = http.new_response(
|
||||
status: .request_timeout
|
||||
body: '408 Request Timeout'
|
||||
header: http.new_header(
|
||||
key: .content_type
|
||||
value: 'text/plain'
|
||||
).join(headers_close)
|
||||
)
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const default_port = int($d('veb_default_port', 8080))
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const cors_safelisted_response_headers = [http.CommonHeader.cache_control, .content_language,
|
||||
.content_length, .content_type, .expires, .last_modified, .pragma].map(it.str()).join(',')
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const mime_types = {
|
||||
'.aac': 'audio/aac'
|
||||
'.abw': 'application/x-abiword'
|
||||
'.arc': 'application/x-freearc'
|
||||
'.avi': 'video/x-msvideo'
|
||||
'.azw': 'application/vnd.amazon.ebook'
|
||||
'.bin': 'application/octet-stream'
|
||||
'.bmp': 'image/bmp'
|
||||
'.bz': 'application/x-bzip'
|
||||
'.bz2': 'application/x-bzip2'
|
||||
'.cda': 'application/x-cdf'
|
||||
'.csh': 'application/x-csh'
|
||||
'.css': 'text/css'
|
||||
'.csv': 'text/csv'
|
||||
'.doc': 'application/msword'
|
||||
'.docx': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
|
||||
'.eot': 'application/vnd.ms-fontobject'
|
||||
'.epub': 'application/epub+zip'
|
||||
'.gz': 'application/gzip'
|
||||
'.gif': 'image/gif'
|
||||
'.htm': 'text/html'
|
||||
'.html': 'text/html'
|
||||
'.ico': 'image/vnd.microsoft.icon'
|
||||
'.ics': 'text/calendar'
|
||||
'.jar': 'application/java-archive'
|
||||
'.jpeg': 'image/jpeg'
|
||||
'.jpg': 'image/jpeg'
|
||||
'.js': 'text/javascript'
|
||||
'.json': 'application/json'
|
||||
'.jsonld': 'application/ld+json'
|
||||
'.mid': 'audio/midi audio/x-midi'
|
||||
'.midi': 'audio/midi audio/x-midi'
|
||||
'.mjs': 'text/javascript'
|
||||
'.mp3': 'audio/mpeg'
|
||||
'.mp4': 'video/mp4'
|
||||
'.mpeg': 'video/mpeg'
|
||||
'.mpkg': 'application/vnd.apple.installer+xml'
|
||||
'.odp': 'application/vnd.oasis.opendocument.presentation'
|
||||
'.ods': 'application/vnd.oasis.opendocument.spreadsheet'
|
||||
'.odt': 'application/vnd.oasis.opendocument.text'
|
||||
'.oga': 'audio/ogg'
|
||||
'.ogv': 'video/ogg'
|
||||
'.ogx': 'application/ogg'
|
||||
'.opus': 'audio/opus'
|
||||
'.otf': 'font/otf'
|
||||
'.png': 'image/png'
|
||||
'.pdf': 'application/pdf'
|
||||
'.php': 'application/x-httpd-php'
|
||||
'.ppt': 'application/vnd.ms-powerpoint'
|
||||
'.pptx': 'application/vnd.openxmlformats-officedocument.presentationml.presentation'
|
||||
'.rar': 'application/vnd.rar'
|
||||
'.rtf': 'application/rtf'
|
||||
'.scss': 'text/css'
|
||||
'.sh': 'application/x-sh'
|
||||
'.svg': 'image/svg+xml'
|
||||
'.swf': 'application/x-shockwave-flash'
|
||||
'.tar': 'application/x-tar'
|
||||
'.tif': 'image/tiff'
|
||||
'.tiff': 'image/tiff'
|
||||
'.ts': 'video/mp2t'
|
||||
'.ttf': 'font/ttf'
|
||||
'.txt': 'text/plain'
|
||||
'.vsd': 'application/vnd.visio'
|
||||
'.wasm': 'application/wasm'
|
||||
'.wav': 'audio/wav'
|
||||
'.weba': 'audio/webm'
|
||||
'.webm': 'video/webm'
|
||||
'.webp': 'image/webp'
|
||||
'.woff': 'font/woff'
|
||||
'.woff2': 'font/woff2'
|
||||
'.xhtml': 'application/xhtml+xml'
|
||||
'.xls': 'application/vnd.ms-excel'
|
||||
'.xlsx': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
||||
'.xml': 'application/xml'
|
||||
'.xul': 'application/vnd.mozilla.xul+xml'
|
||||
'.zip': 'application/zip'
|
||||
'.3gp': 'video/3gpp'
|
||||
'.3g2': 'video/3gpp2'
|
||||
'.7z': 'application/x-7z-compressed'
|
||||
'.m3u8': 'application/vnd.apple.mpegurl'
|
||||
'.vsh': 'text/x-vlang'
|
||||
'.v': 'text/x-vlang'
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const http_500 = http.new_response(
|
||||
status: .internal_server_error
|
||||
body: '500 Internal Server Error'
|
||||
header: http.new_header(
|
||||
key: .content_type
|
||||
value: 'text/plain'
|
||||
).join(headers_close)
|
||||
)
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const http_400 = http.new_response(
|
||||
status: .bad_request
|
||||
body: '400 Bad Request'
|
||||
header: http.new_header(
|
||||
key: .content_type
|
||||
value: 'text/plain'
|
||||
).join(headers_close)
|
||||
)
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const http_413 = http.new_response(
|
||||
status: .request_entity_too_large
|
||||
body: '413 Request entity is too large'
|
||||
header: http.new_header(
|
||||
key: .content_type
|
||||
value: 'text/plain'
|
||||
).join(headers_close)
|
||||
)
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const http_302 = http.new_response(
|
||||
status: .found
|
||||
body: '302 Found'
|
||||
header: headers_close
|
||||
)
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
```v
|
||||
const headers_close = http.new_custom_header_from_map({
|
||||
'Server': 'veb'
|
||||
})!
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## controller
|
||||
```v
|
||||
fn controller[A, X](path string, mut global_app A) !&ControllerPath
|
||||
```
|
||||
|
||||
controller generates a new Controller for the main app
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## controller_host
|
||||
```v
|
||||
fn controller_host[A, X](host string, path string, mut global_app A) &ControllerPath
|
||||
```
|
||||
|
||||
controller_host generates a controller which only handles incoming requests from the `host` domain
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## cors
|
||||
```v
|
||||
fn cors[T](options CorsOptions) MiddlewareOptions[T]
|
||||
```
|
||||
|
||||
cors handles cross-origin requests by adding Access-Control-* headers to a preflight request and validating the headers of a cross-origin request. Usage example:
|
||||
```v
|
||||
app.use(veb.cors[Context](veb.CorsOptions{
|
||||
origins: ['*']
|
||||
allowed_methods: [.get, .head, .patch, .put, .post, .delete]
|
||||
}))
|
||||
```
|
||||
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## decode_gzip
|
||||
```v
|
||||
fn decode_gzip[T]() MiddlewareOptions[T]
|
||||
```
|
||||
|
||||
decode_gzip decodes the body of a gzip'ed HTTP request. Register this middleware before you do anything with the request body! Usage example: app.use(veb.decode_gzip[Context]())
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## encode_gzip
|
||||
```v
|
||||
fn encode_gzip[T]() MiddlewareOptions[T]
|
||||
```
|
||||
|
||||
encode_gzip adds gzip encoding to the HTTP Response body. This middleware does not encode files, if you return `ctx.file()`. Register this middleware as last! Usage example: app.use(veb.encode_gzip[Context]())
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## no_result
|
||||
```v
|
||||
fn no_result() Result
|
||||
```
|
||||
|
||||
no_result does nothing, but returns `veb.Result`. Only use it when you are sure a response will be send over the connection, or in combination with `Context.takeover_conn`
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## raw
|
||||
```v
|
||||
fn raw(s string) RawHtml
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## run
|
||||
```v
|
||||
fn run[A, X](mut global_app A, port int)
|
||||
```
|
||||
|
||||
run - start a new veb server, listening to all available addresses, at the specified `port`
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## run_at
|
||||
```v
|
||||
fn run_at[A, X](mut global_app A, params RunParams) !
|
||||
```
|
||||
|
||||
run_at - start a new veb server, listening only on a specific address `host`, at the specified `port` Usage example: veb.run_at(new_app(), host: 'localhost' port: 8099 family: .ip)!
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## tr
|
||||
```v
|
||||
fn tr(lang string, key string) string
|
||||
```
|
||||
|
||||
Used by %key in templates
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## tr_plural
|
||||
```v
|
||||
fn tr_plural(lang string, key string, amount int) string
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## StaticApp
|
||||
```v
|
||||
interface StaticApp {
|
||||
mut:
|
||||
static_files map[string]string
|
||||
static_mime_types map[string]string
|
||||
static_hosts map[string]string
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## FileResponse
|
||||
## done
|
||||
```v
|
||||
fn (mut fr FileResponse) done()
|
||||
```
|
||||
|
||||
close the open file and reset the struct to its default values
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## MiddlewareHandler
|
||||
```v
|
||||
type MiddlewareHandler[T] = fn (mut T) bool
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Middleware[T]
|
||||
## str
|
||||
```v
|
||||
fn (m &Middleware[T]) str() string
|
||||
```
|
||||
|
||||
string representation of Middleware
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## use
|
||||
```v
|
||||
fn (mut m Middleware[T]) use(options MiddlewareOptions[T])
|
||||
```
|
||||
|
||||
use registers a global middleware handler
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## route_use
|
||||
```v
|
||||
fn (mut m Middleware[T]) route_use(route string, options MiddlewareOptions[T])
|
||||
```
|
||||
|
||||
route_use registers a middleware handler for a specific route(s)
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## RawHtml
|
||||
```v
|
||||
type RawHtml = string
|
||||
```
|
||||
|
||||
A type which doesn't get filtered inside templates
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## RequestParams
|
||||
## request_done
|
||||
```v
|
||||
fn (mut params RequestParams) request_done(fd int)
|
||||
```
|
||||
|
||||
reset request parameters for `fd`: reset content-length index and the http request
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## StringResponse
|
||||
## done
|
||||
```v
|
||||
fn (mut sr StringResponse) done()
|
||||
```
|
||||
|
||||
free the current string and reset the struct to its default values
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## RedirectType
|
||||
```v
|
||||
enum RedirectType {
|
||||
found = int(http.Status.found)
|
||||
moved_permanently = int(http.Status.moved_permanently)
|
||||
see_other = int(http.Status.see_other)
|
||||
temporary_redirect = int(http.Status.temporary_redirect)
|
||||
permanent_redirect = int(http.Status.permanent_redirect)
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Context
|
||||
```v
|
||||
struct Context {
|
||||
mut:
|
||||
// veb will try to infer the content type base on file extension,
|
||||
// and if `content_type` is not empty the `Content-Type` header will always be
|
||||
// set to this value
|
||||
content_type string
|
||||
// done is set to true when a response can be sent over `conn`
|
||||
done bool
|
||||
// if true the response should not be sent and the connection should be closed
|
||||
// manually.
|
||||
takeover bool
|
||||
// how the http response should be handled by veb's backend
|
||||
return_type ContextReturnType = .normal
|
||||
return_file string
|
||||
// If the `Connection: close` header is present the connection should always be closed
|
||||
client_wants_to_close bool
|
||||
pub:
|
||||
// TODO: move this to `handle_request`
|
||||
// time.ticks() from start of veb connection handle.
|
||||
// You can use it to determine how much time is spent on your request.
|
||||
page_gen_start i64
|
||||
pub mut:
|
||||
req http.Request
|
||||
custom_mime_types map[string]string
|
||||
// TCP connection to client. Only for advanced usage!
|
||||
conn &net.TcpConn = unsafe { nil }
|
||||
// Map containing query params for the route.
|
||||
// http://localhost:3000/index?q=vpm&order_by=desc => { 'q': 'vpm', 'order_by': 'desc' }
|
||||
query map[string]string
|
||||
// Multipart-form fields.
|
||||
form map[string]string
|
||||
// Files from multipart-form.
|
||||
files map[string][]http.FileData
|
||||
res http.Response
|
||||
// use form_error to pass errors from the context to your frontend
|
||||
form_error string
|
||||
livereload_poll_interval_ms int = 250
|
||||
}
|
||||
```
|
||||
|
||||
The Context struct represents the Context which holds the HTTP request and response. It has fields for the query, form, files and methods for handling the request and response
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## before_request
|
||||
```v
|
||||
fn (mut ctx Context) before_request() Result
|
||||
```
|
||||
|
||||
before_request is always the first function that is executed and acts as middleware
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## error
|
||||
```v
|
||||
fn (mut ctx Context) error(s string)
|
||||
```
|
||||
|
||||
Set s to the form error
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## file
|
||||
```v
|
||||
fn (mut ctx Context) file(file_path string) Result
|
||||
```
|
||||
|
||||
Response HTTP_OK with file as payload
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## get_cookie
|
||||
```v
|
||||
fn (ctx &Context) get_cookie(key string) ?string
|
||||
```
|
||||
|
||||
Gets a cookie by a key
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## get_custom_header
|
||||
```v
|
||||
fn (ctx &Context) get_custom_header(key string) !string
|
||||
```
|
||||
|
||||
returns the request header data from the key
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## get_header
|
||||
```v
|
||||
fn (ctx &Context) get_header(key http.CommonHeader) !string
|
||||
```
|
||||
|
||||
returns the request header data from the key
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## html
|
||||
```v
|
||||
fn (mut ctx Context) html(s string) Result
|
||||
```
|
||||
|
||||
Response with payload and content-type `text/html`
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## ip
|
||||
```v
|
||||
fn (ctx &Context) ip() string
|
||||
```
|
||||
|
||||
Returns the ip address from the current user
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## json
|
||||
```v
|
||||
fn (mut ctx Context) json[T](j T) Result
|
||||
```
|
||||
|
||||
Response with json_s as payload and content-type `application/json`
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## json_pretty
|
||||
```v
|
||||
fn (mut ctx Context) json_pretty[T](j T) Result
|
||||
```
|
||||
|
||||
Response with a pretty-printed JSON result
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## no_content
|
||||
```v
|
||||
fn (mut ctx Context) no_content() Result
|
||||
```
|
||||
|
||||
send a 204 No Content response without body and content-type
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## not_found
|
||||
```v
|
||||
fn (mut ctx Context) not_found() Result
|
||||
```
|
||||
|
||||
returns a HTTP 404 response
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## ok
|
||||
```v
|
||||
fn (mut ctx Context) ok(s string) Result
|
||||
```
|
||||
|
||||
Response HTTP_OK with s as payload
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## redirect
|
||||
```v
|
||||
fn (mut ctx Context) redirect(url string, params RedirectParams) Result
|
||||
```
|
||||
|
||||
Redirect to an url
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## request_error
|
||||
```v
|
||||
fn (mut ctx Context) request_error(msg string) Result
|
||||
```
|
||||
|
||||
send an error 400 with a message
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## send_response_to_client
|
||||
```v
|
||||
fn (mut ctx Context) send_response_to_client(mimetype string, response string) Result
|
||||
```
|
||||
|
||||
send_response_to_client finalizes the response headers and sets Content-Type to `mimetype` and the response body to `response`
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## server_error
|
||||
```v
|
||||
fn (mut ctx Context) server_error(msg string) Result
|
||||
```
|
||||
|
||||
send an error 500 with a message
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## server_error_with_status
|
||||
```v
|
||||
fn (mut ctx Context) server_error_with_status(s http.Status) Result
|
||||
```
|
||||
|
||||
send an error with a custom status
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## set_content_type
|
||||
```v
|
||||
fn (mut ctx Context) set_content_type(mime string)
|
||||
```
|
||||
|
||||
set_content_type sets the Content-Type header to `mime`
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## set_cookie
|
||||
```v
|
||||
fn (mut ctx Context) set_cookie(cookie http.Cookie)
|
||||
```
|
||||
|
||||
Sets a cookie
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## set_custom_header
|
||||
```v
|
||||
fn (mut ctx Context) set_custom_header(key string, value string) !
|
||||
```
|
||||
|
||||
set a custom header on the response object
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## set_header
|
||||
```v
|
||||
fn (mut ctx Context) set_header(key http.CommonHeader, value string)
|
||||
```
|
||||
|
||||
set a header on the response object
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## takeover_conn
|
||||
```v
|
||||
fn (mut ctx Context) takeover_conn()
|
||||
```
|
||||
|
||||
takeover_conn prevents veb from automatically sending a response and closing the connection. You are responsible for closing the connection. In takeover mode if you call a Context method the response will be directly send over the connection and you can send multiple responses. This function is useful when you want to keep the connection alive and/or send multiple responses. Like with the SSE.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## text
|
||||
```v
|
||||
fn (mut ctx Context) text(s string) Result
|
||||
```
|
||||
|
||||
Response with `s` as payload and content-type `text/plain`
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## user_agent
|
||||
```v
|
||||
fn (ctx &Context) user_agent() string
|
||||
```
|
||||
|
||||
user_agent returns the user-agent header for the current client
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Controller
|
||||
```v
|
||||
struct Controller {
|
||||
pub mut:
|
||||
controllers []&ControllerPath
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## register_controller
|
||||
```v
|
||||
fn (mut c Controller) register_controller[A, X](path string, mut global_app A) !
|
||||
```
|
||||
|
||||
register_controller adds a new Controller to your app
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## register_host_controller
|
||||
```v
|
||||
fn (mut c Controller) register_host_controller[A, X](host string, path string, mut global_app A) !
|
||||
```
|
||||
|
||||
register_controller adds a new Controller to your app
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## ControllerPath
|
||||
```v
|
||||
struct ControllerPath {
|
||||
pub:
|
||||
path string
|
||||
handler ControllerHandler = unsafe { nil }
|
||||
pub mut:
|
||||
host string
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## CorsOptions
|
||||
```v
|
||||
struct CorsOptions {
|
||||
pub:
|
||||
// from which origin(s) can cross-origin requests be made; `Access-Control-Allow-Origin`
|
||||
origins []string @[required]
|
||||
// indicate whether the server allows credentials, e.g. cookies, in cross-origin requests.
|
||||
// ;`Access-Control-Allow-Credentials`
|
||||
allow_credentials bool
|
||||
// allowed HTTP headers for a cross-origin request; `Access-Control-Allow-Headers`
|
||||
allowed_headers []string
|
||||
// allowed HTTP methods for a cross-origin request; `Access-Control-Allow-Methods`
|
||||
allowed_methods []http.Method
|
||||
// indicate if clients are able to access other headers than the "CORS-safelisted"
|
||||
// response headers; `Access-Control-Expose-Headers`
|
||||
expose_headers []string
|
||||
// how long the results of a preflight request can be cached, value is in seconds
|
||||
// ; `Access-Control-Max-Age`
|
||||
max_age ?int
|
||||
}
|
||||
```
|
||||
|
||||
CorsOptions is used to set CORS response headers. See https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#the_http_response_headers
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## set_headers
|
||||
```v
|
||||
fn (options &CorsOptions) set_headers(mut ctx Context)
|
||||
```
|
||||
|
||||
set_headers adds the CORS headers on the response
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## validate_request
|
||||
```v
|
||||
fn (options &CorsOptions) validate_request(mut ctx Context) bool
|
||||
```
|
||||
|
||||
validate_request checks if a cross-origin request is made and verifies the CORS headers. If a cross-origin request is invalid this method will send a response using `ctx`.
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Middleware
|
||||
```v
|
||||
struct Middleware[T] {
|
||||
mut:
|
||||
global_handlers []voidptr
|
||||
global_handlers_after []voidptr
|
||||
route_handlers []RouteMiddleware
|
||||
route_handlers_after []RouteMiddleware
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## MiddlewareOptions
|
||||
```v
|
||||
struct MiddlewareOptions[T] {
|
||||
pub:
|
||||
handler fn (mut ctx T) bool @[required]
|
||||
after bool
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## RedirectParams
|
||||
```v
|
||||
struct RedirectParams {
|
||||
pub:
|
||||
typ RedirectType
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## Result
|
||||
```v
|
||||
struct Result {}
|
||||
```
|
||||
|
||||
A dummy structure that returns from routes to indicate that you actually sent something to a user
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## RunParams
|
||||
```v
|
||||
struct RunParams {
|
||||
pub:
|
||||
// use `family: .ip, host: 'localhost'` when you want it to bind only to 127.0.0.1
|
||||
family net.AddrFamily = .ip6
|
||||
host string
|
||||
port int = default_port
|
||||
show_startup_message bool = true
|
||||
timeout_in_seconds int = 30
|
||||
}
|
||||
```
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## StaticHandler
|
||||
```v
|
||||
struct StaticHandler {
|
||||
pub mut:
|
||||
static_files map[string]string
|
||||
static_mime_types map[string]string
|
||||
static_hosts map[string]string
|
||||
}
|
||||
```
|
||||
|
||||
StaticHandler provides methods to handle static files in your veb App
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## handle_static
|
||||
```v
|
||||
fn (mut sh StaticHandler) handle_static(directory_path string, root bool) !bool
|
||||
```
|
||||
|
||||
handle_static is used to mark a folder (relative to the current working folder) as one that contains only static resources (css files, images etc). If `root` is set the mount path for the dir will be in '/' Usage:
|
||||
```v
|
||||
os.chdir( os.executable() )?
|
||||
app.handle_static('assets', true)
|
||||
```
|
||||
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## host_handle_static
|
||||
```v
|
||||
fn (mut sh StaticHandler) host_handle_static(host string, directory_path string, root bool) !bool
|
||||
```
|
||||
|
||||
host_handle_static is used to mark a folder (relative to the current working folder) as one that contains only static resources (css files, images etc). If `root` is set the mount path for the dir will be in '/' Usage:
|
||||
```v
|
||||
os.chdir( os.executable() )?
|
||||
app.host_handle_static('localhost', 'assets', true)
|
||||
```
|
||||
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## mount_static_folder_at
|
||||
```v
|
||||
fn (mut sh StaticHandler) mount_static_folder_at(directory_path string, mount_path string) !bool
|
||||
```
|
||||
|
||||
mount_static_folder_at - makes all static files in `directory_path` and inside it, available at http://server/mount_path For example: suppose you have called .mount_static_folder_at('/var/share/myassets', '/assets'), and you have a file /var/share/myassets/main.css . => That file will be available at URL: http://server/assets/main.css .
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## host_mount_static_folder_at
|
||||
```v
|
||||
fn (mut sh StaticHandler) host_mount_static_folder_at(host string, directory_path string, mount_path string) !bool
|
||||
```
|
||||
|
||||
host_mount_static_folder_at - makes all static files in `directory_path` and inside it, available at http://host/mount_path For example: suppose you have called .host_mount_static_folder_at('localhost', '/var/share/myassets', '/assets'), and you have a file /var/share/myassets/main.css . => That file will be available at URL: http://localhost/assets/main.css .
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## serve_static
|
||||
```v
|
||||
fn (mut sh StaticHandler) serve_static(url string, file_path string) !
|
||||
```
|
||||
|
||||
Serves a file static `url` is the access path on the site, `file_path` is the real path to the file, `mime_type` is the file type
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
## host_serve_static
|
||||
```v
|
||||
fn (mut sh StaticHandler) host_serve_static(host string, url string, file_path string) !
|
||||
```
|
||||
|
||||
Serves a file static `url` is the access path on the site, `file_path` is the real path to the file `host` is the host to serve the file from
|
||||
|
||||
[[Return to contents]](#Contents)
|
||||
|
||||
#### Powered by vdoc. Generated on: 2 Sep 2025 07:17:41
|
||||
Reference in New Issue
Block a user