mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
all: update attributes to use new syntax
This commit is contained in:
parent
dd81cb98c6
commit
757929392e
739 changed files with 2982 additions and 2982 deletions
|
@ -12,7 +12,7 @@ module cjson
|
|||
#flag @VEXEROOT/thirdparty/cJSON/cJSON.o
|
||||
#include "cJSON.h"
|
||||
|
||||
[typedef]
|
||||
@[typedef]
|
||||
pub struct C.cJSON {
|
||||
pub:
|
||||
next &C.cJSON // next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem
|
||||
|
@ -142,7 +142,7 @@ pub fn create_null() &Node {
|
|||
|
||||
// delete removes the given node from memory.
|
||||
// NB: DO NOT USE that node, after you have called `unsafe { delete(node) }` !
|
||||
[unsafe]
|
||||
@[unsafe]
|
||||
pub fn delete(node &Node) {
|
||||
C.cJSON_Delete(node)
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ struct TestTwin {
|
|||
|
||||
struct TestTwins {
|
||||
mut:
|
||||
twins []TestTwin [required]
|
||||
twins []TestTwin @[required]
|
||||
}
|
||||
|
||||
fn test_json_decode_fails_to_decode_unrecognised_array_of_dicts() {
|
||||
|
@ -58,9 +58,9 @@ mut:
|
|||
description string
|
||||
id int
|
||||
total_comments int
|
||||
file_name string [skip]
|
||||
comments []Comment [skip]
|
||||
skip_field string [json: '-']
|
||||
file_name string @[skip]
|
||||
comments []Comment @[skip]
|
||||
skip_field string @[json: '-']
|
||||
}
|
||||
|
||||
fn test_skip_fields_should_be_initialised_by_json_decode() {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import json
|
||||
|
||||
[json_as_number]
|
||||
@[json_as_number]
|
||||
pub enum MessageType {
|
||||
error = 1
|
||||
warning = 2
|
||||
|
|
|
@ -17,7 +17,7 @@ pub enum CPUType {
|
|||
arm32
|
||||
}
|
||||
|
||||
[heap]
|
||||
@[heap]
|
||||
pub struct Node {
|
||||
pub:
|
||||
name string = 'mymachine'
|
||||
|
|
|
@ -9,7 +9,7 @@ pub:
|
|||
skip ?int
|
||||
fields ?[]string // This breaks the compiler when encoding to JSON
|
||||
conflicts ?bool
|
||||
read_quorum ?int [json: r]
|
||||
read_quorum ?int @[json: r]
|
||||
update ?bool
|
||||
stable ?bool
|
||||
stale ?string
|
||||
|
|
|
@ -4,8 +4,8 @@ pub struct MyStruct {
|
|||
pub mut:
|
||||
code int
|
||||
message string
|
||||
data string [omitempty]
|
||||
data2 ?string [omitempty]
|
||||
data string @[omitempty]
|
||||
data2 ?string @[omitempty]
|
||||
}
|
||||
|
||||
fn test_simple() {
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
import json
|
||||
|
||||
struct OmitEmptyStruct {
|
||||
bug Struct [omitempty]
|
||||
bug Struct @[omitempty]
|
||||
}
|
||||
|
||||
type MyAlias = string
|
||||
|
||||
struct OmitEmptyAlias {
|
||||
bug MyAlias [omitempty]
|
||||
bug MyAlias @[omitempty]
|
||||
}
|
||||
|
||||
struct Struct {
|
||||
|
@ -15,17 +15,17 @@ struct Struct {
|
|||
}
|
||||
|
||||
struct OmitEmptyMap {
|
||||
bug map[string]string [omitempty]
|
||||
bug map[string]string @[omitempty]
|
||||
}
|
||||
|
||||
struct OmitEmptyArray {
|
||||
bug []string [omitempty]
|
||||
bug []string @[omitempty]
|
||||
}
|
||||
|
||||
type MySum = int | string
|
||||
|
||||
struct OmitEmptySumType {
|
||||
bug MySum [omitempty]
|
||||
bug MySum @[omitempty]
|
||||
}
|
||||
|
||||
struct FNumStruct {
|
||||
|
@ -33,7 +33,7 @@ struct FNumStruct {
|
|||
}
|
||||
|
||||
struct OmitEmptyFNumStruct {
|
||||
bug FNumStruct [omitempty]
|
||||
bug FNumStruct @[omitempty]
|
||||
}
|
||||
|
||||
fn test_struct() {
|
||||
|
|
|
@ -2,10 +2,10 @@ import json
|
|||
|
||||
pub struct Dto {
|
||||
pub:
|
||||
key string [raw]
|
||||
key2 string [raw]
|
||||
data ?string [raw]
|
||||
optional ?string [raw]
|
||||
key string @[raw]
|
||||
key2 string @[raw]
|
||||
data ?string @[raw]
|
||||
optional ?string @[raw]
|
||||
}
|
||||
|
||||
fn test_main() {
|
||||
|
|
|
@ -12,15 +12,15 @@ pub mut:
|
|||
}
|
||||
|
||||
struct Node {
|
||||
location NodeLocation [json: 'loc']
|
||||
location NodeLocation @[json: 'loc']
|
||||
}
|
||||
|
||||
struct NodeLocation {
|
||||
source_file ?SourceFile [json: 'includedFrom']
|
||||
source_file ?SourceFile @[json: 'includedFrom']
|
||||
}
|
||||
|
||||
struct SourceFile {
|
||||
path string [json: 'file']
|
||||
path string @[json: 'file']
|
||||
}
|
||||
|
||||
fn test_encode_decode() {
|
||||
|
|
|
@ -52,7 +52,7 @@ pub fn encode_pretty(x voidptr) string {
|
|||
return ''
|
||||
}
|
||||
|
||||
[markused]
|
||||
@[markused]
|
||||
fn decode_int(root &C.cJSON) int {
|
||||
if isnil(root) {
|
||||
return 0
|
||||
|
@ -60,7 +60,7 @@ fn decode_int(root &C.cJSON) int {
|
|||
return root.valueint
|
||||
}
|
||||
|
||||
[markused]
|
||||
@[markused]
|
||||
fn decode_i8(root &C.cJSON) i8 {
|
||||
if isnil(root) {
|
||||
return i8(0)
|
||||
|
@ -68,7 +68,7 @@ fn decode_i8(root &C.cJSON) i8 {
|
|||
return i8(root.valueint)
|
||||
}
|
||||
|
||||
[markused]
|
||||
@[markused]
|
||||
fn decode_i16(root &C.cJSON) i16 {
|
||||
if isnil(root) {
|
||||
return i16(0)
|
||||
|
@ -76,7 +76,7 @@ fn decode_i16(root &C.cJSON) i16 {
|
|||
return i16(root.valueint)
|
||||
}
|
||||
|
||||
[markused]
|
||||
@[markused]
|
||||
fn decode_i64(root &C.cJSON) i64 {
|
||||
if isnil(root) {
|
||||
return i64(0)
|
||||
|
@ -85,12 +85,12 @@ fn decode_i64(root &C.cJSON) i64 {
|
|||
}
|
||||
|
||||
// TODO: remove when `byte` is removed
|
||||
[markused]
|
||||
@[markused]
|
||||
fn decode_byte(root &C.cJSON) u8 {
|
||||
return decode_u8(root)
|
||||
}
|
||||
|
||||
[markused]
|
||||
@[markused]
|
||||
fn decode_u8(root &C.cJSON) u8 {
|
||||
if isnil(root) {
|
||||
return u8(0)
|
||||
|
@ -98,7 +98,7 @@ fn decode_u8(root &C.cJSON) u8 {
|
|||
return u8(root.valueint)
|
||||
}
|
||||
|
||||
[markused]
|
||||
@[markused]
|
||||
fn decode_u16(root &C.cJSON) u16 {
|
||||
if isnil(root) {
|
||||
return u16(0)
|
||||
|
@ -106,7 +106,7 @@ fn decode_u16(root &C.cJSON) u16 {
|
|||
return u16(root.valueint)
|
||||
}
|
||||
|
||||
[markused]
|
||||
@[markused]
|
||||
fn decode_u32(root &C.cJSON) u32 {
|
||||
if isnil(root) {
|
||||
return u32(0)
|
||||
|
@ -114,7 +114,7 @@ fn decode_u32(root &C.cJSON) u32 {
|
|||
return u32(root.valueint)
|
||||
}
|
||||
|
||||
[markused]
|
||||
@[markused]
|
||||
fn decode_u64(root &C.cJSON) u64 {
|
||||
if isnil(root) {
|
||||
return u64(0)
|
||||
|
@ -122,7 +122,7 @@ fn decode_u64(root &C.cJSON) u64 {
|
|||
return u64(root.valuedouble)
|
||||
}
|
||||
|
||||
[markused]
|
||||
@[markused]
|
||||
fn decode_f32(root &C.cJSON) f32 {
|
||||
if isnil(root) {
|
||||
return f32(0)
|
||||
|
@ -130,7 +130,7 @@ fn decode_f32(root &C.cJSON) f32 {
|
|||
return f32(root.valuedouble)
|
||||
}
|
||||
|
||||
[markused]
|
||||
@[markused]
|
||||
fn decode_f64(root &C.cJSON) f64 {
|
||||
if isnil(root) {
|
||||
return f64(0)
|
||||
|
@ -138,7 +138,7 @@ fn decode_f64(root &C.cJSON) f64 {
|
|||
return root.valuedouble
|
||||
}
|
||||
|
||||
[markused]
|
||||
@[markused]
|
||||
fn decode_rune(root &C.cJSON) rune {
|
||||
if isnil(root) {
|
||||
return rune(0)
|
||||
|
@ -151,7 +151,7 @@ fn decode_rune(root &C.cJSON) rune {
|
|||
return unsafe { tos_clone(&u8(root.valuestring)).runes().first() }
|
||||
}
|
||||
|
||||
[markused]
|
||||
@[markused]
|
||||
fn decode_string(root &C.cJSON) string {
|
||||
if isnil(root) {
|
||||
return ''
|
||||
|
@ -162,7 +162,7 @@ fn decode_string(root &C.cJSON) string {
|
|||
return unsafe { tos_clone(&u8(root.valuestring)) } // , _strlen(root.valuestring))
|
||||
}
|
||||
|
||||
[markused]
|
||||
@[markused]
|
||||
fn decode_bool(root &C.cJSON) bool {
|
||||
if isnil(root) {
|
||||
return false
|
||||
|
@ -172,86 +172,86 @@ fn decode_bool(root &C.cJSON) bool {
|
|||
|
||||
// ///////////////////
|
||||
|
||||
[markused]
|
||||
@[markused]
|
||||
fn encode_int(val int) &C.cJSON {
|
||||
return C.cJSON_CreateNumber(val)
|
||||
}
|
||||
|
||||
[markused]
|
||||
@[markused]
|
||||
fn encode_i8(val i8) &C.cJSON {
|
||||
return C.cJSON_CreateNumber(val)
|
||||
}
|
||||
|
||||
[markused]
|
||||
@[markused]
|
||||
fn encode_i16(val i16) &C.cJSON {
|
||||
return C.cJSON_CreateNumber(val)
|
||||
}
|
||||
|
||||
[markused]
|
||||
@[markused]
|
||||
fn encode_i64(val i64) &C.cJSON {
|
||||
return C.cJSON_CreateNumber(val)
|
||||
}
|
||||
|
||||
// TODO: remove when `byte` is removed
|
||||
[markused]
|
||||
@[markused]
|
||||
fn encode_byte(root u8) &C.cJSON {
|
||||
return encode_u8(root)
|
||||
}
|
||||
|
||||
[markused]
|
||||
@[markused]
|
||||
fn encode_u8(val u8) &C.cJSON {
|
||||
return C.cJSON_CreateNumber(val)
|
||||
}
|
||||
|
||||
[markused]
|
||||
@[markused]
|
||||
fn encode_u16(val u16) &C.cJSON {
|
||||
return C.cJSON_CreateNumber(val)
|
||||
}
|
||||
|
||||
[markused]
|
||||
@[markused]
|
||||
fn encode_u32(val u32) &C.cJSON {
|
||||
return C.cJSON_CreateNumber(val)
|
||||
}
|
||||
|
||||
[markused]
|
||||
@[markused]
|
||||
fn encode_u64(val u64) &C.cJSON {
|
||||
return C.cJSON_CreateNumber(val)
|
||||
}
|
||||
|
||||
[markused]
|
||||
@[markused]
|
||||
fn encode_f32(val f32) &C.cJSON {
|
||||
return C.cJSON_CreateNumber(val)
|
||||
}
|
||||
|
||||
[markused]
|
||||
@[markused]
|
||||
fn encode_f64(val f64) &C.cJSON {
|
||||
return C.cJSON_CreateNumber(val)
|
||||
}
|
||||
|
||||
[markused]
|
||||
@[markused]
|
||||
fn encode_bool(val bool) &C.cJSON {
|
||||
return C.cJSON_CreateBool(val)
|
||||
}
|
||||
|
||||
[markused]
|
||||
@[markused]
|
||||
fn encode_rune(val rune) &C.cJSON {
|
||||
return C.cJSON_CreateString(&char(val.str().str))
|
||||
}
|
||||
|
||||
[markused]
|
||||
@[markused]
|
||||
fn encode_string(val string) &C.cJSON {
|
||||
return C.cJSON_CreateString(&char(val.str))
|
||||
}
|
||||
|
||||
// ///////////////////////
|
||||
// user := decode_User(json_parse(js_string_var))
|
||||
[markused]
|
||||
@[markused]
|
||||
fn json_parse(s string) &C.cJSON {
|
||||
return C.cJSON_Parse(&char(s.str))
|
||||
}
|
||||
|
||||
// json_string := json_print(encode_User(user))
|
||||
[markused]
|
||||
@[markused]
|
||||
fn json_print(data &C.cJSON) string {
|
||||
s := C.cJSON_PrintUnformatted(data)
|
||||
r := unsafe { tos_clone(&u8(s)) }
|
||||
|
|
|
@ -2,7 +2,7 @@ import json
|
|||
|
||||
struct TestOptionalRawString {
|
||||
id int
|
||||
data ?string [raw]
|
||||
data ?string @[raw]
|
||||
}
|
||||
|
||||
fn test_raw_opt() {
|
||||
|
|
|
@ -31,7 +31,7 @@ const currency_id = 'cconst'
|
|||
|
||||
struct Price {
|
||||
net f64
|
||||
currency_id string [json: currencyId] = currency_id
|
||||
currency_id string = currency_id @[json: currencyId]
|
||||
}
|
||||
|
||||
fn test_field_with_default_expr() {
|
||||
|
@ -130,10 +130,10 @@ struct User2 {
|
|||
struct User {
|
||||
age int
|
||||
nums []int
|
||||
last_name string [json: lastName]
|
||||
is_registered bool [json: IsRegistered]
|
||||
typ int [json: 'type']
|
||||
pets string [json: 'pet_animals'; raw]
|
||||
last_name string @[json: lastName]
|
||||
is_registered bool @[json: IsRegistered]
|
||||
typ int @[json: 'type']
|
||||
pets string @[json: 'pet_animals'; raw]
|
||||
}
|
||||
|
||||
fn test_parse_user() {
|
||||
|
@ -190,7 +190,7 @@ fn test_encode_user() {
|
|||
|
||||
struct Color {
|
||||
space string
|
||||
point string [raw]
|
||||
point string @[raw]
|
||||
}
|
||||
|
||||
fn test_raw_json_field() {
|
||||
|
@ -449,7 +449,7 @@ fn test_pretty() {
|
|||
|
||||
struct Foo3 {
|
||||
name string
|
||||
age int [omitempty]
|
||||
age int @[omitempty]
|
||||
}
|
||||
|
||||
fn test_omit_empty() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue