add yaml convertor 77/58177/1
authorLvbo163 <lv.bo163@zte.com.cn>
Tue, 31 Jul 2018 07:00:20 +0000 (15:00 +0800)
committerLvbo163 <lv.bo163@zte.com.cn>
Tue, 31 Jul 2018 07:00:20 +0000 (15:00 +0800)
support yaml string convert

Issue-ID: MSB-235

Change-Id: Iddce914d09b6bbe550d417506f1b24f652a8ce70
Signed-off-by: Lvbo163 <lv.bo163@zte.com.cn>
.gitignore
msb2pilot/src/msb2pilot/Gopkg.lock
msb2pilot/src/msb2pilot/util/yaml.go [new file with mode: 0644]

index 7b9b626..5e84c66 100644 (file)
@@ -4,6 +4,7 @@
 *.so\r
 *.log\r
 config\r
+msb2pilot.exe\r
 \r
 # Folders\r
 _obj\r
index f4320f4..9a704e7 100644 (file)
   revision = "9e8dc3f972df6c8fcc0375ef492c24d0bb204857"
   version = "1.6.3"
 
+[[projects]]
+  name = "gopkg.in/yaml.v2"
+  packages = ["."]
+  revision = "5420a8b6744d3b0345ab293f6fcba19c978f1183"
+  version = "v2.2.1"
+
 [solve-meta]
   analyzer-name = "dep"
   analyzer-version = 1
-  inputs-digest = "9e242ef2da883faa526d0301106c1de8202a8b14eecebf2470863a2e60ea195b"
+  inputs-digest = "fa4cfc44b5a6fe6939a41f6fd3f2efca1f840f04854eee11cfd79b975074e048"
   solver-name = "gps-cdcl"
   solver-version = 1
diff --git a/msb2pilot/src/msb2pilot/util/yaml.go b/msb2pilot/src/msb2pilot/util/yaml.go
new file mode 100644 (file)
index 0000000..6de09a5
--- /dev/null
@@ -0,0 +1,43 @@
+/**
+ * Copyright (c) 2018 ZTE Corporation.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and the Apache License 2.0 which both accompany this distribution,
+ * and are available at http://www.eclipse.org/legal/epl-v10.html
+ * and http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Contributors:
+ *     ZTE - initial Project
+ */
+package util
+
+import (
+       "gopkg.in/yaml.v2"
+)
+
+/**
+* type T struct {
+*   F int `yaml:"a, omitempty"`
+*   B int
+* }
+* var t T
+* yaml.Marshal(&T{B:2})   /// returns "b: 2 \n"
+* yaml.Marshal(&T{F:1})   // returns "a: 1 \nb: 0\n"
+ */
+func MarshalYaml(in interface{}) (string, error) {
+       b, err := yaml.Marshal(in)
+       if err != nil {
+               return "", err
+       } else {
+               return string(b), nil
+       }
+}
+
+/**
+* var t T
+* yaml.Unmarshal([]byte("a: 1\nb: 2"), &t)
+*
+ */
+func UnmarshalYaml(str string, out interface{}) error {
+       return yaml.Unmarshal([]byte(str), out)
+}